dbprefix}koolielu_waramu_queue WHERE ID='$r'"); return $data[0]; } */ function waramu_isInLocalQueue($id) { global $CONFIG; $data = get_data("SELECT * FROM {$CONFIG->dbprefix}koolielu_waramu_queue WHERE waramu_id='$id'"); return $data[0]; } function waramu_getModerationQueue() { global $CONFIG; $ids = get_data("SELECT waramu_id FROM {$CONFIG->dbprefix}koolielu_waramu_queue WHERE status=0 ORDER BY time"); $res = array(); foreach($ids as $id) { $res[] = $id->waramu_id; } return $res; } function waramu_getRejectedQueue() { global $CONFIG; $ids = get_data("SELECT waramu_id FROM {$CONFIG->dbprefix}koolielu_waramu_queue WHERE status=2 ORDER BY time"); $res = array(); foreach ($ids as $id) { $res[] = $id->waramu_id; } return $res; } function waramu_getUserModerationQueue() { // returns pending resources queue for logged in user, depending his role global $CONFIG; $ids = get_data("SELECT waramu_id, subjects FROM {$CONFIG->dbprefix}koolielu_waramu_queue WHERE status=0 ORDER BY time"); $res = array(); $curuser = get_loggedin_user(); $rl = $curuser->real_interest; if ($rl && !is_array($rl)) { $rl = array($rl); } foreach($ids as $id) { $rid = $id->waramu_id; try { $obj = waramu_getResource("", $rid); } catch (Exception $e) { continue; } if ($obj->isPublished()) continue; $obj_subjects = explode(',', substr($id->subjects, 1, -1)); // admin has to see all pending resources if (isadminloggedin()) { $res[] = $obj; } else { // moderator can see only those resources where he is resource subject(s) moderator if (is_array($obj_subjects) && count($obj_subjects) > 0) { if (isModerator($obj_subjects) && (!isEditor())) { $add = false; if ($rl) { foreach($obj->get("curriculumSubject") as $ocs) { //$sub = getCurriculumSubject($ocs[0]); $ctr = array(); foreach (getCurriculumTree($ocs[0]) as $ctrv) { $ctr[] = $ctrv->eid; } foreach ($rl as $rlo) { if (in_array($rlo, $ctr)) { $add = true; } } } } else { $add = true; } if ($add) $res[] = $obj; } else if (isEditor()) { // in case there's no moderators in those subjects $obj_subjects_moderators = getAllModerators($obj_subjects); if (!$obj_subjects_moderators) $res[] = $obj; } // and editor sees resources, where subject isn't marked } else if (isEditor()) { $res[] = $obj; } } } return $res; } function getUserPrivateResources($user_guid, $sort_val="created", $qadd=null) { // If not provided, use current loggedin user instead $username = get_loggedin_user()->username; if (!empty($user_guid)) { $provided_user = get_user($user_guid); if ($provided_user) { $username = $provided_user->username; } } $ids = array(); $w = waramu_get(); $identity = $w->Identify(); $suffix = $identity['identity'][0]['suffix'][0][0]; $sort_param = ""; if ($sort_val == "created") { // in case sorting by date, get newest before $sort_param = "<_sort param=\"descending\">created"; } else if ($sort_val == "title") { $sort_param = "<_sort>".$sort_val.""; } $q = "<_owner>".$username."@".$suffix."".$sort_param; if ( $qadd != null ) { $q .= $qadd; } $q .= '<_schema param="in">http://koolielu.ee/schemas/Reference,http://koolielu.ee/schemas/Material,http://koolielu.ee/schemas/Media'; $q .= ''; $idefs = $w->listIdentifiers("", $q); $waramuids = $idefs['identifiers'][0]['id']; foreach($waramuids as $wid) { $ids[] = $wid[0]; } return $ids; } function getUserPublishedResources($user_guid, $sort_val="created") { $q = "*"; return getUserPrivateResources($user_guid, $sort_val, $q); } function getCommunityResources($userids, $sort_val=false) { $resources = getMultiUserPublishedResources($userids, $sort_val); if ($sort_val && $sort_val!="created" && $sort_val != "title") { $res = array(); $desc = false; foreach ($resources as $rid) { $stat = getResourceStat($rid); $res []= array('id'=>$rid, 'download'=>$stat['url'], 'favorites'=>$stat['favorite']); } sksort($res, $sort_val, $desc); $sids = array(); foreach ($res as $re) { $sids []= $re['id']; } return $sids; } return $resources; } function getMultiUserPublishedResources($userids, $sortval) { global $CONFIG; // Return empty list by default $ids = array(); $w = waramu_get(); $ident = $w->Identify(); $suffix = $ident['identity'][0]['suffix'][0][0]; if (!$userids || !is_array($userids) || sizeof($userids) < 1) { return $ids; } $userids_str = implode(",",$userids); $users = array(); foreach ($userids as $uid) { $users[] = get_user($uid)->username."@".$suffix; } $query = ""; $query .= "<_owner param=\"in\">".implode(",", $users).""; $query .= "*"; if ( $sortval == "created" || $sortval == "title" ) { $query .= "<_sort lang=\"et\">".$sortval.""; } $query .= ""; $idefs = $w->listIdentifiers("", $query); $waramuids = $idefs['identifiers'][0]['id']; foreach($waramuids as $wid) { $ids[] = $wid[0]; } return $ids; } /** * returns a list of IDs of user's pending resources * */ function getUserPendingResources($user_guid, $sort_val="created") { return getUsersResourcesByStatus($user_guid, 0, $sort_val); } /** * returns a list of IDs of user's rejected resources * */ function getUserRejectedResources($user_guid, $sort_val="created") { return getUsersResourcesByStatus($user_guid, 2, $sort_val); } function getUsersResourcesByStatus($user_guid, $status, $sort_val="created") { global $CONFIG; $user_resources = get_data("SELECT waramu_id FROM {$CONFIG->dbprefix}koolielu_waramu_queue WHERE status=$status AND user_guid = $user_guid ORDER BY time DESC"); $ids = array(); foreach ($user_resources as $r) { $ids[] = $r->waramu_id; } if ($sort_val == "title") { $ids = sortMaterials($ids, "title", "asc"); } return $ids; } function sortMaterials($ids, $sort="created", $sort_order="asc") { /* returns ids ordered either created (date) or title*/ $array_for_sort = array(); foreach ($ids as $id) { $obj = waramu_getResource("", $id); if ($obj) { if ($sort == "created") $param = $obj->getDate(); else if ($sort == "title") $param = strtolower($obj->getTitle()); $array_for_sort[$id] = $param; } } asort($array_for_sort); if ($sort_order == "desc") $array_for_sort = array_reverse($array_for_sort); $sorted_ids = array(); foreach ($array_for_sort as $id => $title) { $sorted_ids[] = $id; } return $sorted_ids; } /** * builds an appUser string. * requires UserEntity as a parameter * */ function buildAppUser($u) { $au = ''; $au .= ''.$u->username.''; if ( count($u->subjects) > 0 || isEditor() ) { $au .= ""; if ( count($u->subjects) > 0 ) { // In case of just one subject, we will be dealing with a string $u_subjects = $u->subjects; if ($u_subjects && !is_array($u_subjects)) { // Now we make it a list $u_subjects = array($u_subjects); } foreach ($u_subjects as $sub) { $au .= "".$sub.""; } } if ( isEditor() ) $au .= "editor"; $au .= ""; } $au .= ''; return $au; } function buildACL($obj_subjects) { $acl = ""; $acl .= "editor"; if ( count($obj_subjects) > 0 ) { foreach ( $obj_subjects as $os ) { $acl .= "".$os.""; } } $acl .= ""; return $acl; } function getCombinedFieldList() { $w = waramu_get(); // list types $rats = $w->listTypes(); $ts = $rats['types'][0]['type']; $ids = array(); foreach($ts as $t) { $ids[] = $t['id'][0][0]; } // describe all types $fields = array(); $included = array("curriculumSubject"); foreach($ids as $tid) { $td = $w->describeType($tid); foreach($td->listFields() as $d) { if ( $d['@attributes']['vocabulary'] == '1' || $d['@attributes']['fixedVocabulary'] == '1' || in_array($d['@attributes']['name'], $included) ) { if ( !in_array($d['@attributes']['name'], $fields) ) { $fields[$d['@attributes']['name']] = $d; } } } } return $fields; } function getAdvancedFields() { return array('intendedEndUserRole', 'LREkeywords', 'context', 'mdLanguage'); } /** * returns a field description and waramu's type ID where this field is found. * array('typeID' => ..., 'description' => ...); * * if $all is specified then returns all fields from all types. * * If no fields are found, returns null * */ function waramu_getField($fid, $all=false) { $w = waramu_get(); // list types $rats = $w->listTypes(); $ts = $rats['types'][0]['type']; $ids = array(); foreach($ts as $t) { $ids[] = $t['id'][0][0]; } $res = array(); // describe all types $fields = array(); foreach($ids as $tid) { $td = $w->describeType($tid); foreach($td->listFields() as $d) { if ( $d['@attributes']['name'] == $fid ) { if ( $all ) { $res[] = array('typeID' => $tid, 'description' => $d); } else { return array('typeID' => $tid, 'description' => $d); } } } } if ( count($res) == 0 || !$all ) { return null; } return $res; } function waramu_getCombinedVocabulary($fid) { //TODO: needs testing! //$flist = waramu_getField($fid, $all=true); $voc = array(); $w = waramu_get(); //foreach ($flist as $field ) { //$fieldvoc = $w->getVocabulary("", $field['typeID'], $fid); $fieldvoc = $w->getVocabulary("", null, $fid); $gs = $fieldvoc['vocabulary'][0]['unit']; foreach ($gs as $g) { $el = $g['element'][0][0]; $co = (int) $g['count'][0][0]; if ( !array_key_exists($el, $voc) ) $voc[$el] = 0; $voc[$el] = $voc[$el]+$co; } //} return $voc; } function getSubjectLREkeyword($subject_id) { $lre_keys = array( "263251" => "91", //art "198001" => "144", //biology "208201" => "195", //chemistry "325251" => "256", //computer science "333851" => "383", //business education "339000" => "404", //educational technologies "50901" => "427", //English language "167301" => "431", //environmental education "51" => "440", //Estonian language "30351" => array("440", "710"), //Estonian language (foreign), language teaching "322701" => array("493", "710"), //Finnish language "112051" => array("520", "710"), //French language "186251" => "540", //geography "73951" => array("548", "710"), //German language "309801" => "576", //handigrafts "289101" => "576", //handigrafts "306051" => "576", //handigrafts "232101" => "590", //history "137701" => "790", //mathematics "246651" => "856", //music education "267051" => "974", //physical education "219801" => "978", //physics "317251" => "1017", //pre-school education "334953" => "1024", //primary education "235201" => "1040", //psyhology "17201" => "1115", //Russian language "106351" => array("1115", "710"), //Russian language (foreign) "245101" => "1209", //society "333001" => "1227", //special education "330051" => array("1263", "710") //Swedish language ); // get level one subject $main_subject_id = getCurriculumMainSubject($subject_id); $subject_lre_keys = $lre_keys[$main_subject_id]; if (is_string($subject_lre_keys)) $subject_lre_keys = array($subject_lre_keys); return $subject_lre_keys; } // returns resource owner guid (if resource is created in koolielu), otherwise returns false function waramu_getResourceOwner($obj) { $op = $obj->getOwnerPrintable(); if (!is_null($op[0])) { return $op[0]->getGUID(); } return false; } // returns resource moderator guid (id resource is created in koolielu), otherwise returns false function waramu_getResourceModerator($rid) { global $CONFIG; $res = get_data_row("SELECT * FROM {$CONFIG->dbprefix}koolielu_waramu_resources WHERE waramu_id='$rid'"); if ($res) { return $res->moderator_guid; } return false; } // front page resource function newFrontPageResource($rid, $subtype, $user_guid, $description, $subject) { global $CONFIG; // delete previous data delete_data("DELETE from {$CONFIG->dbprefix}koolielu_frontpage_resource where subtype='$subtype' and subject='$subject';"); // insert new insert_data("INSERT into {$CONFIG->dbprefix}koolielu_frontpage_resource (ID, subtype, user_guid, description, subject) values ('$rid', '$subtype', $user_guid, '$description', '$subject');"); } // See if this resource is already on the frontpage function isFrontPageResource($rid) { global $CONFIG; $res = get_data("SELECT COUNT(*) FROM {$CONFIG->dbprefix}koolielu_frontpage_resource WHERE ID='$rid';"); if ($res) { $res_count = (int) array_pop(get_object_vars($res[0])); if ($res_count > 0) { return true; } } return false; } // Delete frontpage material function removeFrontPageResource($rid) { global $CONFIG; $res = get_data_row("SELECT * FROM {$CONFIG->dbprefix}koolielu_frontpage_resource WHERE ID='$rid';"); $user_guid = $res->user_guid; // delete image deleteImageFile($rid.".jpg", $user_guid); // delete data delete_data("DELETE from {$CONFIG->dbprefix}koolielu_frontpage_resource where ID='$rid';"); } function setResourceStat($wid, $stat='read', $mode='+') { if ( in_array($stat, array('read','url','favorite','collection')) && in_array($mode, array('+','-'))) { global $CONFIG; return insert_data("INSERT INTO {$CONFIG->dbprefix}koolielu_resource_stats (waramu_id, {$stat}_stat) VALUES ('$wid', 1) ON DUPLICATE KEY UPDATE {$stat}_stat={$stat}_stat{$mode}1"); } return 0; } function getResourceStat($wid) { global $CONFIG; $stats = get_data("SELECT * FROM {$CONFIG->dbprefix}koolielu_resource_stats WHERE waramu_id='$wid'"); $st = array('read'=>0,'url'=>0,'favorite'=>0,'collection'=>0); if ($stats) { $stat = $stats[0]; $st = array('read'=>$stat->read_stat, 'url'=>$stat->url_stat, 'favorite'=>$stat->favorite_stat, 'collection'=>$stat->collection_stat); } return $st; } function addremoveFavoriteResource($wid, $kws="") { global $CONFIG; $uid = get_loggedin_user()->getGUID(); if ( delete_data("DELETE FROM {$CONFIG->dbprefix}koolielu_favorite_resources WHERE waramu_id='$wid' AND userid={$uid}") ) { setResourceStat($wid, 'favorite', '-'); } else { if ( insert_data("INSERT INTO {$CONFIG->dbprefix}koolielu_favorite_resources (waramu_id, userid, keywords) VALUES ('$wid', {$uid}, '$kws')") ) { setResourceStat($wid, 'favorite'); } } } function isFavoriteResource($wid) { global $CONFIG; $uo = get_loggedin_user(); if ( $uo ) { return get_data("SELECT keywords FROM {$CONFIG->dbprefix}koolielu_favorite_resources WHERE waramu_id='$wid' AND userid=".$uo->getGUID()); } return false; } function getTempStore() { $ke = getKeDataPath(); $uid = get_loggedin_user()->getGUID(); if ( !is_dir($ke . "tempstore/" . $uid . "/") ) { mkdir($ke . "tempstore/" . $uid . "/", 0755); } return $ke . "tempstore/" . $uid . "/"; } function getTempFilelist() { $path = opendir(getTempStore()); $res = array(); while ( false != ($file = readdir($path) ) ) { if ( substr($file, 0, 1) == "." ) continue; $res[] = $file; } return $res; } function getLocalStore($rid) { $ke = getKeDataPath(); if ( !is_dir($ke . "localstore/" . $rid . "/") ) { mkdir($ke . "localstore/" . $rid . "/", 0755); } return $ke . "localstore/" . $rid . "/"; } function getLocalFilelist($rid) { $path = opendir(getLocalStore($rid)); $res = array(); while ( false != ($file = readdir($path) ) ) { if ( substr($file, 0, 1) == "." ) continue; $res[] = $file; } return $res; } function listFavoriteLikers($wid) { global $CONFIG; return get_data("SELECT userid FROM {$CONFIG->dbprefix}koolielu_favorite_resources WHERE waramu_id='$wid'"); } function listMyFavorites($uid=false) { global $CONFIG; if (!$uid) { $uid = get_loggedin_user()->getGUID(); } return get_data("SELECT waramu_id FROM {$CONFIG->dbprefix}koolielu_favorite_resources WHERE userid=".$uid); } /** * * Collections * **/ /** * returns a list of all user's collections. * Optionally, if second parameter $wid is provided, two arrays * are returned, first containing a list of resource id-s and second * containing a list of resource id-s where $wid is present * */ function getAllUserCollections($user, $wid=null, $sort=null) { $w = waramu_get(); $idef = $w->Identify(); if (is_null($sort)) $sort = 'updated'; $q = 'username.'@'.$idef['identity'][0]['suffix'][0][0].''; $q .= ' <_schema>http://trac.htk.tlu.ee/waramu/Collection'; //$q .= ' *'; $q .= ' <_sort param="descending">'.$sort.''; $q .= ''; $rrids = $w->listIdentifiers(buildAppUser($user), $q); $res = array(); foreach ($rrids['identifiers'][0]['id'] as $rid) { $id = $rid[0]; $res[] = $id; } if (!is_null($wid)) { $rc = getResourceCollections($wid); return array($res, $rc); } else { return $res; } } function getCollectionsFlexi($user=null, $wid=null, $sort=null, $tag=null, $limit=null, $astagclud=false) { $w = waramu_get(); $idef = $w->Identify(); if (!$sort) $sort = 'updated'; $sortord = 'descending'; if ($sort=='title') $sortord = 'ascending'; $q = 'username.'@'.$idef['identity'][0]['suffix'][0][0].''; $q .= ' <_schema>http://trac.htk.tlu.ee/waramu/Collection'; if ($wid) $q .= ' '.$wid.''; if ($tag) $q .= ' '.$tag.''; //TODO: escape! //if (!isadminloggedin()) { $only_koolielu_resources = true; if ($user && get_loggedin_user()) { if ($user->getGUID() == get_loggedin_user()->getGUID()) { $only_koolielu_resources = false; } } if (!$only_koolielu_resources && isadminloggedin()) { $only_koolielu_resources = false; } if ($only_koolielu_resources) $q .= ' *'; if (!$astagclud) $q .= ' <_sort param="'.$sortord.'">'.$sort.''; if ($limit) $q .= ' <_limit>'.$limit.''; if ($astagclud) $q .= ' <_field>keywords'; $q .= ''; $rrids = $w->listIdentifiers(buildAppUser($user), $q); if ($astagclud) return $rrids; $res = array(); foreach ($rrids['identifiers'][0]['id'] as $rid) { $id = $rid[0]; $res[] = $id; } return $res; } function getResourceCollections($rid) { $w = waramu_get(); $q = ''; $q .= ' <_sort param="descending">updated'; $q .= ''; $rrids = $w->listIdentifiers(buildAppUser($user), $q); $res = array(); foreach ($rrids['identifiers'][0]['id'] as $rid) { $id = $rid[0]; $res[] = $id; } return $res; } function updateCollectionTags($collection) { $resources = $collection->resources; if (is_string($resources)) $resources = array($resources); $collection_tags = array(); foreach ($resources as $rid) { $resource = waramu_getResource("", $rid); $resource_tags = $resource->getKeywords(); $collection_tags = array_merge($collection_tags, $resource_tags); } $collection_tags = array_unique($collection_tags); $collection->tags = $collection_tags; $collection->save(); } function newCollection($name, $rid) { $obj = waramu_getResource(buildAppUser(get_loggedin_user()), $rid); $doc = new DOMDocument("1.0", "UTF-8"); $doc->formatOutput = true; $data = $doc->createElementNS("http://trac.htk.tlu.ee/waramu/Collection", "data"); $doc->appendChild($data); $title_e = $doc->createElement("title"); $title_e->setAttribute("lang", get_current_language()); $title_e->appendChild($doc->createTextNode($name)); $data->appendChild($title_e); $items_e = $doc->createElement("items"); $val1 = $doc->createElement("value"); $val1->setAttribute("position", "1"); $val1->appendChild($doc->createTextNode($rid)); $items_e->appendChild($val1); $data->appendChild($items_e); $tinyxml = $doc->saveXML(); $w = waramu_get(); $rcode = $w->newResource(buildAppUser(get_loggedin_user()), $tinyxml); //if (!is_int($rcode)) { //$w->addAnnotation(buildAppUser(get_loggedin_user()), $rcode, array('name'=>'koolielu', 'value'=>'1')); //} return $rcode; } function removeFromCollection($rid, $ref_to_rem) { $obj = waramu_getResource(buildAppUser(get_loggedin_user()), $rid); $refs = $obj->getItems(); unset($refs[$ref_to_rem]); _post_new_collection_items($rid, $refs); } function addToCollection($rid, $ref_to_add) { $obj = waramu_getResource(buildAppUser(get_loggedin_user()), $rid); $refs = $obj->getItems(); $maxpos = max(array_values($refs)); $newpos = $maxpos + 1; $refs[$ref_to_add] = $newpos; _post_new_collection_items($rid, $refs); } /** * add keywords and curriculumSubject info * from $rid to $cid (from resource to collection) * */ function enrichCollection($cid, $rid) { $coll = waramu_getResource(buildAppUser(get_loggedin_user()), $cid); $obj = waramu_getResource(buildAppUser(get_loggedin_user()), $rid); $collc = $coll->get('curriculumSubject'); if (!is_array($collc)) { $collc = array(); } $objc = $obj->get('curriculumSubject'); if (!is_array($objc)) { $objc = array(); } $newcs = array_merge($collc, $objc); $seen = array(); $doc = new DOMDocument("1.0", "UTF-8"); $doc->formatOutput = true; $data = $doc->createElementNS("http://trac.htk.tlu.ee/waramu/Collection", "data"); $doc->appendChild($data); $needs_update = true; $cse = $doc->createElementNS(getCurrentCSNS(), "curriculumSubject"); foreach($newcs as $csi) { if (in_array($csi, $seen)) continue; $seen[] = $csi; $csve = $doc->createElementNS($csi['@schema'][0], "value"); $csve->appendChild($doc->createTextNode($csi[0])); $cse->appendChild($csve); } $data->appendChild($cse); $l1 = $obj->getAllLanguages(); $l2 = $coll->getAllLanguages(); $langs = array_unique(array_merge($l1, $l2)); //TODO:XXX: its eating other languages $kwelems = array(); $need_kw_up = false; foreach($langs as $lang) { $cvals = $coll->getMVArray("keywords", $lang); $ovals = $obj->getMVArray("keywords", $lang); $nvals = array_unique(array_merge($cvals, $ovals)); if (count($cvals)!=count($nvals)) { $needs_update = true; $need_kw_up = true; } $cse = $doc->createElement("keywords"); $cse->setAttribute("lang", $lang); foreach($nvals as $nv) { $nve = $doc->createElement("value"); $nve->appendChild($doc->createTextNode($nv)); $cse->appendChild($nve); } //$data->appendChild($cse); $kwelems[] = $cse; } if ($need_kw_up) { foreach($kwelems as $kw) { $data->appendChild($kw); } } if ($needs_update) { $w = waramu_get(); $xml = $doc->saveXML(); $w->updateResource(buildAppUser(get_loggedin_user()), $cid, $xml); } } function _post_new_collection_items($rid, $newrefs) { $xml = '<'.'?'.'xml version="1.0" encoding="UTF-8"'.'?'.'>'; $xml .= ''; $xml .= ''; foreach ($newrefs as $k => $v) { $xml .= ''.$k.''; } $xml .= ''; $xml .= ''; $w = waramu_get(); $w->updateResource(buildAppUser(get_loggedin_user()), $rid, $xml); } /** * * Quality marks * **/ function getAllQualityMarks($wid) { global $CONFIG; $quality_marks = get_data("SELECT * FROM {$CONFIG->dbprefix}koolielu_quality_marks ORDER BY title;"); $res_quality_marks = getResourceQualityMarks($wid); $all_marks = array(); $res_marks = array(); foreach ($quality_marks as $quality_mark) { $all_marks[$quality_mark->title] = $quality_mark->ID; foreach ($res_quality_marks as $res_mark) { if ($quality_mark->ID == $res_mark->quality_mark_id) $res_marks[] = $quality_mark->ID; } } $marks = array("all_quality_marks" => $all_marks, "resource_quality_marks" => $res_marks); return $marks; } function getResourceQualityMarks($wid) { global $CONFIG; $res_quality_marks = get_data("SELECT * FROM {$CONFIG->dbprefix}koolielu_resources_quality_marks WHERE waramu_id='$wid' ORDER BY time;"); return $res_quality_marks; } function renderSortBlock($cs=null) { $c = ""; /*translation:Sorted by*/ $c .= "
".elgg_echo("koolielu:sortedby").": "; $sort_opts = array( /*translation:Created*/ 'created'=>elgg_echo('koolielu:sortby_Created'), /*translation:Updated*/ 'updated'=>elgg_echo('koolielu:sortby_Updated'), /*translation:Resources*/ //'resources'=>elgg_echo('koolielu:sortby_Resources'), /*translation:Title*/ 'title'=>elgg_echo('koolielu:sortby_Title') ); foreach ($sort_opts as $k => $v) { $tn = 'a'; if (!is_null($cs) && !strcmp($k, $cs)) $tn = 'span'; $c .= '<'.$tn; if (!is_null($cs) && !strcmp($k, $cs)) { $c .= ' style="text-decoration:underline;"'; } else { $hr = explode('?', $_SERVER['REQUEST_URI']); $pstr = $hr[1]; if (is_null($pstr)) $pstr = ""; $x = array(); parse_str($pstr, $x); $x['sort'] = $k; $hr = implode('&', $x); $tmp = array(); foreach($x as $k1 => $v1) { $tmp[] = $k1.'='.$v1; } $c .= ' href="?'.implode('&', $tmp).'"'; } $c .= '>'.$v.' '; } $c .= '
'; return $c; } function getCurrentCurriculumArray() { global $CONFIG; return array($CONFIG->curriculum_config['default_curriculum_id'], $CONFIG->curriculum_config['default_curriculum']); } function getCurrentCSNS() { global $CONFIG; return $CONFIG->curriculum_config['default_curriculum']; } function getCurrentCurriculumID() { global $CONFIG; return $CONFIG->curriculum_config['default_curriculum_id']; } function getCurriculumIDFor($ns) { global $CONFIG; foreach ($CONFIG->curriculum_config['taxonomymappers'] as $k => $tm) { if ($k == $ns) { return $tm[0]; } } } function serveAllSuitableLotypes() { $lotypes = array( /*translation:assessment*/ "assessment" => elgg_echo("koolielu:lotype_assessment"), /*translation:course*/ "course" => elgg_echo("koolielu:lotype_course"), /*translation:drill and practice*/ "drill and practice" => elgg_echo("koolielu:lotype_drill_and_practice"), /*translation:educational game*/ "educational game" => elgg_echo("koolielu:lotype_educational_game"), /*translation:experiment*/ "experiment" => elgg_echo("koolielu:lotype_experiment"), /*translation:glossary*/ "glossary" => elgg_echo("koolielu:lotype_glossary"), /*translation:lesson plan*/ "lesson plan" => elgg_echo("koolielu:lotype_lesson_plan"), /*translation:presentation*/ "presentation" => elgg_echo("koolielu:lotype_presentation"), /*translation:reference*/ "reference" => elgg_echo("koolielu:lotype_reference"), /*translation:simulation*/ "simulation" => elgg_echo("koolielu:lotype_simulation"), /*translation:tool*/ "tool" => elgg_echo("koolielu:lotype_tool"), /*translation:audio*/ "audio" => elgg_echo("koolielu:lotype_audio"), /*translation:image*/ "image" => elgg_echo("koolielu:lotype_image"), /*translation:text*/ "text" => elgg_echo("koolielu:lotype_text"), /*translation:video*/ "video" => elgg_echo("koolielu:lotype_video"), /*translation:web page*/ "web page" => elgg_echo("koolielu:lotype_web_page"), /*translation:other*/ "other" => elgg_echo("koolielu:lotype_other") ); asort($lotypes); return $lotypes; } Class Schemas { public static function getSchema($name) { return "schema...".$name; } } Class Schema { private $d; function Schema($o) { if ($o['description']) { $o = $o['description'][0]['fields'][0]; } $this->d = $o; } function listFields() { //$td = $td['description'][0]['fields'][0]['field']; $td = $this->d['field']; return $td; } } class AnnotationWrapper { private $d; function AnnotationWrapper($ar) { $this->d = $ar; } function value() { return $this->d['value'][0][0]; } } function getCollectionSchema() { return "http://trac.htk.tlu.ee/waramu/Collection"; } function getMediaSchema() { return "http://koolielu.ee/schemas/Media"; } function buildCSTagcloud($id) { $w = waramu_get(); $lvoc = false; if ($id) $lvoc = getCurriculumChildren($id); if (!$lvoc && (is_null($id) || !$id)) { $lvoc = getCurriculumChildren(); } $r = array(); if ($lvoc) { $subcount = array(); $smax = -1; $smin = 9999999; $b = new Browser($page, array("browse2")); foreach ( $lvoc as $v ) { $b->set("curriculumSubject", $v->eid); $xres = $b->doQuery("count"); $idefs = (int) $xres; if ( $idefs > $smax ) $smax = $idefs; if ( $idefs < $smin ) $smin = $idefs; $subcount[] = array($idefs, $v, $v->title, $idefs); } foreach($subcount as $sub) { $tag = $sub[2]; $tac = $sub[0]; if ($tac==0) $tac=0.7; $siz = round((log($tac) / log($smax)) * 100) + 60; if ($siz < 100) { $siz = max($siz + 25, 100); } //$c .= "wwwroot . "pg/waramu/browse/curriculumSubject/".$sub[1]->eid."\" style=\"font-size:".$siz."%\" title=\"{$tag} ({$sub[3]})\">".$tag." ({$sub[3]})"; //$c .= " "; $r[] = array($sub[1]->eid, $tag, $siz, $sub[3]); } } return $r; } function download($url) { $c = curl_init($url); curl_setopt($c, CURLOPT_USERAGENT, 'Koolielu grap'); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($c); return $response; } function convertToDefault($ns, $eid) { global $CONFIG; if (!is_numeric($eid)) die('nnic'); if (!is_numeric($ns)) { $ns = getCurriculumIDFor($ns); } if ($ns == getCurrentCurriculumID()) return $eid; $data = get_data("SELECT toeid FROM {$CONFIG->dbprefix}curriculum_map WHERE fromtax={$ns} AND totax=".getCurrentCurriculumID()." AND fromeid={$eid}"); if (sizeof($data)>0) { $x = array(); foreach($data as $d) { array_push($x, $d->toeid); } return $x; } return null; } function cache_count_query($q) { global $CONFIG; $q = mysql_real_escape_string($q); $r = get_data("SELECT value FROM {$CONFIG->dbprefix}waramu_count_cache WHERE query='".$q."' AND date_add(created, interval 5 minute) > now()"); if (sizeof($r) == 1) { return $r[0]->value; } return null; } function cache_value($q, $v) { global $CONFIG; $q = mysql_real_escape_string($q); delete_data("DELETE FROM {$CONFIG->dbprefix}waramu_count_cache where query='".$q."'"); insert_data("INSERT INTO {$CONFIG->dbprefix}waramu_count_cache (query, value) VALUES ('".$q."', ".$v.")"); } ?>