Exemplo n.º 1
0
 private function _prepare_sort()
 {
     global $Conf;
     $this->default_sort_column = PaperColumn::lookup("id");
     $this->sorters[0]->field = null;
     if ($this->search->sorters) {
         foreach ($this->search->sorters as $sorter) {
             if ($sorter->type && ($field = PaperColumn::lookup($sorter->type)) && $field->prepare($this, PaperColumn::PREP_SORT) && $field->comparator) {
                 $sorter->field = $field;
             } else {
                 if ($sorter->type) {
                     if ($this->contact->can_view_tags(null) && ($tagger = new Tagger()) && ($tag = $tagger->check($sorter->type)) && ($result = Dbl::qe("select paperId from PaperTag where tag=? limit 1", $tag)) && edb_nrows($result)) {
                         $this->search->warn("Unrecognized sort “" . htmlspecialchars($sorter->type) . "”. Did you mean “sort:#" . htmlspecialchars($sorter->type) . "”?");
                     } else {
                         $this->search->warn("Unrecognized sort “" . htmlspecialchars($sorter->type) . "”.");
                     }
                     continue;
                 }
             }
             ListSorter::push($this->sorters, $sorter);
         }
         if (count($this->sorters) > 1 && $this->sorters[0]->empty) {
             array_shift($this->sorters);
         }
     }
     if (get($this->sorters[0], "field")) {
         /* all set */
     } else {
         if ($this->sorters[0]->type && ($c = PaperColumn::lookup($this->sorters[0]->type)) && $c->prepare($this, PaperColumn::PREP_SORT)) {
             $this->sorters[0]->field = $c;
         } else {
             $this->sorters[0]->field = $this->default_sort_column;
         }
     }
     $this->sorters[0]->type = $this->sorters[0]->field->name;
     // set defaults
     foreach ($this->sorters as $s) {
         if ($s->reverse === null) {
             $s->reverse = false;
         }
         if ($s->score === null) {
             $s->score = ListSorter::default_score_sort();
         }
     }
 }