コード例 #1
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");
 }
コード例 #2
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);
 }
コード例 #3
0
ファイル: SharpEntitiesList.php プロジェクト: dvlpp/sharp
 public function getSortedColumn()
 {
     return $this->params->getSortedColumn();
 }