Example #1
0
 public function search()
 {
     $cp = FilePermissions::getGlobal();
     if (!$cp->canSearchFiles() && !$cp->canAddFile()) {
         return false;
     }
     if ($_REQUEST['submitSearch']) {
         $this->searchRequest->resetSearchRequest();
     }
     $req = $this->searchRequest->getSearchRequest();
     $columns = FileSearchColumnSet::getCurrent();
     if (!$this->fileList->getActiveSortColumn()) {
         $col = $columns->getDefaultSortColumn();
         $this->fileList->sanitizedSortBy($col->getColumnKey(), $col->getColumnDefaultSortDirection());
     }
     // first thing, we check to see if a saved search is being used
     if (isset($req['fssID'])) {
         $fs = FileSet::getByID($req['fssID']);
         if ($fs->getFileSetType() == FileSet::TYPE_SAVED_SEARCH) {
             $req = $fs->getSavedSearchRequest();
             $columns = $fs->getSavedSearchColumns();
             $colsort = $columns->getDefaultSortColumn();
             $this->fileList->addToSearchRequest('ccm_order_dir', $colsort->getColumnDefaultSortDirection());
             $this->fileList->addToSearchRequest('ccm_order_by', $colsort->getColumnKey());
         }
     }
     $keywords = htmlentities($req['fKeywords'], ENT_QUOTES, APP_CHARSET);
     if ($keywords != '') {
         $this->fileList->filterByKeywords($keywords);
     }
     if ($req['numResults']) {
         $this->fileList->setItemsPerPage(intval($req['numResults']));
     }
     if (isset($req['fsIDNone']) && $req['fsIDNone'] == 1 || is_array($req['fsID']) && in_array(-1, $req['fsID'])) {
         $this->fileList->filterByNoSet();
     } else {
         if (is_array($req['fsID'])) {
             foreach ($req['fsID'] as $fsID) {
                 $fs = FileSet::getByID($fsID);
                 $this->fileList->filterBySet($fs);
             }
         } elseif (isset($req['fsID']) && $req['fsID'] != '' && $req['fsID'] > 0) {
             $set = $req['fsID'];
             $fs = FileSet::getByID($set);
             $this->fileList->filterBySet($fs);
         }
     }
     if (isset($req['fType']) && $req['fType'] != '') {
         $type = $req['fType'];
         $this->fileList->filterByType($type);
     }
     if (isset($req['fExtension']) && $req['fExtension'] != '') {
         $ext = $_GET['fExtension'];
         $fileList->filterByExtension($ext);
     }
     $selectedSets = array();
     if (is_array($req['field'])) {
         foreach ($req['field'] as $i => $item) {
             $this->fields[] = $this->getField($item);
             // due to the way the form is setup, index will always be one more than the arrays
             if ($item != '') {
                 switch ($item) {
                     case "extension":
                         $extension = $req['extension'];
                         $this->fileList->filterByExtension($extension);
                         break;
                     case "type":
                         $type = $req['type'];
                         $this->fileList->filterByType($type);
                         break;
                     case "date_added":
                         $wdt = Loader::helper('form/date_time');
                         /* @var $wdt \Concrete\Core\Form\Service\Widget\DateTime */
                         $dateFrom = $wdt->translate('date_added_from', $req);
                         if ($dateFrom) {
                             $this->fileList->filterByDateAdded($dateFrom, '>=');
                         }
                         $dateTo = $wdt->translate('date_added_to', $req);
                         if ($dateTo) {
                             if (preg_match('/^(.+\\d+:\\d+):00$/', $dateTo, $m)) {
                                 $dateTo = $m[1] . ':59';
                             }
                             $this->fileList->filterByDateAdded($dateTo, '<=');
                         }
                         break;
                     case 'added_to':
                         $ocID = $req['ocIDSearchField'];
                         if ($ocID > 0) {
                             $this->fileList->filterByOriginalPageID($ocID);
                         }
                         break;
                     case "size":
                         $from = $req['size_from'];
                         $to = $req['size_to'];
                         $this->fileList->filterBySize($from, $to);
                         break;
                     default:
                         $akID = $item;
                         $fak = FileAttributeKey::get($akID);
                         $type = $fak->getAttributeType();
                         $cnt = $type->getController();
                         $cnt->setRequestArray($req);
                         $cnt->setAttributeKey($fak);
                         $cnt->searchForm($this->fileList);
                         break;
                 }
             }
         }
     }
     if (isset($req['numResults'])) {
         $this->fileList->setItemsPerPage(intval($req['numResults']));
     }
     $this->fileList->setPermissionsChecker(function ($file) {
         $cp = new \Permissions($file);
         return $cp->canViewFileInFileManager();
     });
     $handleName = "filter" . Loader::helper('text')->camelcase($this->attributeHandle);
     if (method_exists("Application\\Src\\AdvancedAttributeFilters", $handleName)) {
         \Application\Src\AdvancedAttributeFilters::$handleName($this, $this->fileList);
     }
     $ilr = new FileSearchResult($columns, $this->fileList, URL::to($this->getSearchURL()), $this->fields);
     $this->result = $ilr;
 }
Example #2
0
 public function setPermissionsChecker(Closure $checker)
 {
     return parent::setPermissionsChecker($checker);
 }