コード例 #1
0
ファイル: SharpEntitiesList.php プロジェクト: dvlpp/sharp
 public function createParams()
 {
     $this->params = new SharpEntitiesListParams();
     if ($this->currentSubListId) {
         $this->params->setCurrentSubListId($this->getCurrentSublistId());
     }
     // Manage column sort: first determine which column is sorted
     list($sortCol, $sortDir) = $this->retrieveSorting();
     foreach ($this->entity->list_template->columns as $colKey => $col) {
         if ($col->sortable && (!$sortCol || $colKey == $sortCol)) {
             $this->params->setSortedColumn($colKey);
             $this->params->setSortedDirection($sortDir);
             break;
         }
     }
     // Manage search
     $search = null;
     if ($this->entity->list_template->searchable && $this->request->has("search")) {
         $search = urldecode($this->request->get("search"));
     }
     // Manage advanced search
     if (!$search && $this->entity->advanced_search->data && $this->request->has("adv")) {
         $this->params->setAdvancedSearch(true);
         $search = [];
         foreach ($this->request->all() as $input => $value) {
             if (!starts_with($input, "adv_")) {
                 continue;
             }
             if (is_array($value) && !sizeof($value) || !is_array($value) && !strlen(trim($value))) {
                 continue;
             }
             if (is_array($value)) {
                 foreach ($value as $v) {
                     $search[substr($input, 4)][] = urldecode($v);
                 }
             } else {
                 $search[substr($input, 4)] = urldecode($value);
             }
         }
     }
     $this->params->setSearch($search);
     return $this->params;
 }
コード例 #2
0
ファイル: ExportCsvCommand.php プロジェクト: oimken/sharpzoo
 /**
  * Execute the entities list command, and return
  * a file name (if command type is "download"),
  * an array of data for a view (case "view"),
  * or nothing.
  *
  * @param \Dvlpp\Sharp\ListView\SharpEntitiesListParams $entitiesListParams
  * @return mixed
  */
 function execute(SharpEntitiesListParams $entitiesListParams)
 {
     $query = Giraffe::with('zookeeper')->where("zookeeper_id", $entitiesListParams->getCurrentSublistId());
     if ($entitiesListParams->getSearch()) {
         foreach ($entitiesListParams->getSearchTerms() as $term) {
             $query->where(function ($query) use($term) {
                 $query->orWhere("name", "like", $term)->orWhere('desc', 'like', $term);
             });
         }
     }
     if ($entitiesListParams->getSortedColumn()) {
         $query->orderBy($entitiesListParams->getSortedColumn(), $entitiesListParams->getSortedDirection());
     }
     $giraffes = $query->get();
     // Code omitted: generate a CSV file with $giraffes
     // ...
     return public_path("tmp/giraffes.csv");
 }
コード例 #3
0
ファイル: Repository.php プロジェクト: oimken/sharpzoo
 /**
  * Paginate instances.
  *
  * @param $count
  * @param \Dvlpp\Sharp\ListView\SharpEntitiesListParams $params
  * @return mixed
  */
 function paginate($count, SharpEntitiesListParams $params)
 {
     $giraffes = Giraffe::with('zookeeper')->where("lang", $this->lang)->where("zookeeper_id", $this->getCurrentSublistId());
     if ($params->getSearch()) {
         if ($params->isAdvancedSearch()) {
             foreach ($params->getSearch() as $field => $value) {
                 switch ($field) {
                     case "age":
                         $ageComp = $params->getAdvancedSearchValue("age_comp");
                         $giraffes->where("age", $ageComp, $value);
                         break;
                     case "name":
                         foreach (explode_search_words($value) as $term) {
                             $giraffes->where("name", "like", $term);
                         }
                         break;
                     case "particularities":
                         foreach ($value as $v) {
                             $giraffes->whereExists(function ($query) use($v) {
                                 $query->select('giraffe_id')->from('giraffes_particularities')->whereRaw('giraffes_particularities.giraffe_id = giraffes.id ' . 'AND giraffes_particularities.particularity_id=' . $v);
                             });
                         }
                 }
             }
         } else {
             // Quicksearch
             foreach (explode_search_words($params->getSearch()) as $term) {
                 $giraffes->where(function ($query) use($term) {
                     $query->orWhere("name", "like", $term)->orWhere('desc', 'like', $term);
                 });
             }
         }
     }
     if ($params->getSortedColumn()) {
         $giraffes->orderBy($params->getSortedColumn(), $params->getSortedDirection());
     }
     return $giraffes->paginate($count);
 }