'created'); public $handler = 'search2'; public function __construct($page, $ignores=array('search2', 'browse2')) { $lookval = null; $used = false; foreach ($page as $p) { $used = false; if ( in_array($p, $ignores) ) continue; if (is_null($lookval) ) { // TODO: can validate here the validnes of $p as a fieldname $lookval = trim($p); } else if ( !is_null($lookval) ) { if (!strcmp($p, '__x__')) $p = ''; $this->v[$lookval] = $p; $lookval = null; $used = true; } } if (!$used && $p) $this->v[$p] = ""; } public function initFromInput() { global $CONFIG; // fields $fnames = array('_fulltext', 'language', 'keywords', 'lotype', 'license', 'curriculumSubject', 'creator', 'vauthor', 'not_older_than', 'not_newer_than', 'min', 'max'); foreach($fnames as $name) { $v = get_input($name); if ($name == "max" && $v == "20") $v = 0; if ($v) $this->set($name, $v); } // annotations foreach ($CONFIG->curriculum_config['annotations'] as $name => $anno) { if (!$anno['search']) continue; $v = get_input($name); if (!strcmp($v, "1")) $this->set(':'.$name, $v); } // types $filters = get_input('filter'); $filter = implode($filters, ''); if ($filter) $this->set('filter', $filter); } public function toURL() { global $CONFIG; $r = array(); foreach ($this->v as $k=>$v) { $r[] = urlencode($k); $r[] = urlencode($v); } return $CONFIG->wwwroot.'pg/waramu/'.$this->handler.'/'.implode($r, '/'); } public function toQuery($format="") { $csns = getCurrentCurriculumArray(); $q = '<'.'?xml version="1.0" encoding="UTF-8"?'.">\n"; $q .= 'v as $k=>$v) { $x = $this->translateForQuery($k, $v); foreach ($x as $y) { $k = $y[0]; $v = $y[1]; $params = ""; if ($k == "_sort" && $format == "count") continue; if (count($y) == 3) $params = $y[2]; $q .= "\t<".$k.$params.">".$v."\n"; } } $q .= ''; return $q; } public function doQuery($format='list_of_ids', $return_list=false) { $w = waramu_get(); $q = $this->toQuery($format); $ch = null; if ($format == "count") { $ch = cache_count_query($q); } if (!is_null($ch)) { return $ch; } $rawids = $w->listIdentifiers("", $q); if ($format == "count") { $cv = $rawids['count'][0][0]; cache_value($q, $cv); return $cv; } $rids = $rawids['identifiers'][0]['id']; $new_ids = array(); foreach ($rids as $rid) { $new_ids []= $rid[0]; } if ($return_list) return $new_ids; $sort_vals = array('created', 'download', 'favorites', 'title'); $c = elgg_view('object/listing_header', array('ids' => $new_ids, 'sort_val' => $this->get("sort"), 'sort_vals' => $sort_vals, 'show_count' => 1, 'b' => $this)); return $c; } public function get($k) { if (array_key_exists($k, $this->v)) return $this->v[$k]; return false; } public function set($k, $v) { $this->v[$k] = $v; } public function buildURL($rk, $rv) { global $CONFIG; $r = array(); if (!$rv) $rv = '__x__'; foreach ($this->v as $k=>$v) { if (!$v) $v = '__x__'; $r[] = urlencode($k); if (!strcmp($k, $rk)) { $r[] = urlencode($rv); } else { $r[] = urlencode($v); } } if (!array_key_exists($rk, $this->v)) { $r[] = $rk; $r[] = urlencode($rv); } return $CONFIG->wwwroot.'pg/waramu/'.$this->handler.'/'.implode('/', $r); } public function canQuery() { foreach ($this->v as $k=>$v) { if ($k == "sort") continue; if (!is_null($v) && strlen($v)>0) return true; } return false; } public function isFilter($code) { $f = $this->get("filter"); if ( strstr($f, $code) ) return true; return false; } public function getReverseFilterValue($code) { if (!$this->isFilter($code)) return $this->get("filter").$code; return str_replace($code, '', $this->get("filter")); } private function translateForQuery($k, $v) { global $CONFIG; $r = array(); if ($k == "curriculumSubject") { $cs = getCurriculumSubject($v); $cs = $cs[0]; $r[] = array('cs:'.$k, ($cs->eid)-1, ' param="higher"'); $r[] = array('cs:'.$k, $cs->end, ' param="lower"'); } else if ($k == "sort") { if (!in_array($v, array("created", "title"))) return; if (strlen($v) > 0) { $param = ""; if ($v == 'created') $param = ' param="descending"'; if ($v == 'title') $param = ' lang="et"'; $r[] = array("_sort", $v, $param); } } else if ($k == "filter") { $ft = array(); for ($i=0;$igetFilterByCode($v[$i]); if (is_null($filter)) continue; $ft[] = $filter['schema']; } if ($ft) $r[] = array("_schema", implode($ft, ",")); } else if (substr($k, 0, 1) == ':') { $r[] = array('anno'.$k, $v); } else if ($k == "not_older_than" || $k == "not_newer_than") { $param = ' param="higher"'; if ($k == "not_newer_than") $param = ' param="lower"'; $r[] = array("created", date( 'Y-m-d H:i:s', strtotime($v)),$param); } else if ($k == "license") { foreach ($CONFIG->curriculum_config['licenses'] as $full=>$lic) { if ($v == $lic) $r[] = array($k, $full); } } else if ($k == 'creator') { $r[] = array('_owner', $v); } else { $r[] = array($k, $v); } return $r; } private function getFilterByCode($code) { global $CONFIG; foreach ($CONFIG->curriculum_config['filters'] as $filter) { if ($filter['code'] == $code) return $filter; } return null; } } ?>