Exemplo n.º 1
0
 /**
  * name: get_list
  * params:
  */
 public function get_data_bycond($field, $filters, $sortby = sorting::DEFAULT_SORT, $sortdir = sorting::SORT_DIR_DEFAULT, $page = null, $count = 10)
 {
     $cond = $this->hash_filters($filters);
     if (!$this->cache_enabled || !$this->filtered_data[$field][$cond]) {
         $dir = $this->conf->paths['storage'];
         if (is_file($path = $this->conf->paths['lists'] . "/" . $this->conf->lists_paths[$field] . file_storage_config::IVAL_PF) && file_exists($path)) {
             $data = explode($this->separator2, file_get_contents($path));
         } else {
             return $this->filtered_data[$field][$cond] = null;
         }
         if ($sortdir == sorting::SORT_DIR_DESC) {
             rsort($data);
         }
         foreach ($data as $tmpdata) {
             $tmp = explode($this->separator1, rtrim($tmpdata));
             $obval = $tmp[0];
             $obid = $tmp[1];
             $add = false;
             if (is_array($filters)) {
                 foreach ($filters as $filter) {
                     if ($filter instanceof file_storage_filter) {
                         $add = $add || $this->check_cond($filter, $obval);
                     }
                 }
             } elseif ($filters instanceof file_storage_filter) {
                 $add = $add || $this->check_cond($filters, $obval);
                 if ($this->need_break($filters, $obval, $sortdir)) {
                     break;
                 }
             }
             if ($add) {
                 $file = file_get_contents($dir . "/" . rtrim($obid));
                 $this->filtered_data[$field][$cond][] = unserialize($file);
             }
         }
     }
     $pager = new pager(count($this->filtered_data[$field][$cond]), $count);
     return $pager->get_page($this->filtered_data[$field][$cond], $page);
 }