Beispiel #1
0
 /**
  * Applies filters to Citations model and returns applied filters
  * @param array  $filters array of POST values
  * @return	array sanitized and validated filter values
  */
 private function _filterHandler($filters = array(), $scope_id = 0)
 {
     $citations = \Components\Citations\Models\Citation::all();
     // require citations
     if (!$citations) {
         return false;
     }
     // get the ones for this group
     $citations->where('scope', '=', 'member');
     $citations->where('scope_id', '=', $scope_id);
     $citations->where('published', '!=', $citations::STATE_DELETED);
     // don't include deleted citations
     if (count($filters) > 0) {
         foreach ($filters as $filter => $value) {
             // sanitization
             $value = \Hubzero\Utility\Sanitize::clean($value);
             // we handle things differently in search and sorting
             if ($filter != 'search' && $filter != 'sort' && $filter != 'tag' && $value != "") {
                 switch ($filter) {
                     case 'author':
                         $citations->where('author', 'LIKE', "%{$value}%", 'and', 1);
                         break;
                     case 'publishedin':
                         $citations->where('date_publish', 'LIKE', "%{$value}-%");
                         break;
                     case 'year_start':
                         $citations->where('year', '>=', $value);
                         break;
                     case 'year_end':
                         $citations->where('year', '<=', $value);
                         break;
                     case 'filter':
                         if ($value == 'aff') {
                             $value = 1;
                         } else {
                             $value = 0;
                         }
                         $citations->where('affiliated', '=', $value);
                         break;
                     default:
                         $citations->where($filter, '=', $value);
                         break;
                 }
             }
             // end if not search & not sort & non-empty value
             // for searching
             if ($filter == "search" && $value != "") {
                 $terms = preg_split('/\\s+/', $value);
                 $value = \Hubzero\Utility\Sanitize::clean($value);
                 $term = $value;
                 $collection = array();
                 $columns = array('author', 'title', 'isbn', 'doi', 'publisher', 'abstract');
                 foreach ($columns as $column) {
                     foreach ($terms as $term) {
                         // copy the original item
                         $cite = clone $citations;
                         // do some searching
                         $cite->where($column, 'LIKE', "%{$term}%");
                         foreach ($cite as $c) {
                             // put for collection later
                             array_push($collection, $c->id);
                         }
                         // end foreach $cite
                     }
                     // end foreach terms
                 }
                 // end foreach columns
                 // remove duplicates
                 $collection = array_unique($collection);
                 // pull the appropriate ones.
                 $citations->whereIn('id', $collection);
             }
             // end searching
             // for tags
             if ($filter == "tag" && $value != "") {
                 $collection = array();
                 $cite = clone $citations;
                 foreach ($cite as $c) {
                     foreach ($c->tags as $tag) {
                         if ($tag->tag == $value) {
                             array_push($collection, $c->id);
                         }
                     }
                 }
                 // remove duplicates
                 $collection = array_unique($collection);
                 // get the tagged ones
                 $citations->whereIn('id', $collection);
             }
             // end if tags
             if ($filter == "sort" && $value != "") {
                 $clause = explode(" ", $value);
                 $citations->order($clause[0], $clause[1]);
             }
         }
         // end foreach filters as filter
         return array('citations' => $citations, 'filters' => $filters);
     } else {
         return array('citations' => $citations, 'filters' => array());
     }
 }
Beispiel #2
0
 /**
  * Applies filters to Citations model and returns applied filters
  * @param array  $filters array of POST values
  * @return	array sanitized and validated filter values
  */
 private function _filterHandler($filters = array(), $scope_id = 0)
 {
     $citations = \Components\Citations\Models\Citation::all();
     // require citations
     if (!$citations) {
         return false;
     }
     $filterCount = count($filters);
     // see if we have members too
     $config = json_decode($this->group->get('params'));
     $members = $this->group->members;
     // get the ones for this group
     if (isset($config->display) && $config->display == 'member') {
         // if all filter is applied
         if (array_key_exists('filter', $filters) && ($filters['filter'] == '' || $filters['filter'] == 'all')) {
             // get the ID's of the citations of members of the group
             $memberCitations = \Components\Citations\Models\Citation::all()->where('scope', '=', 'member')->whereIn('scope_id', $members)->where('published', '=', $citations::STATE_PUBLISHED);
             // don't include deleted citations
             // push them to an array
             $memberCites = array();
             foreach ($memberCitations as $mC) {
                 array_push($memberCites, $mC->id);
             }
             // Get the group's citations plus member citations.
             $citations->where('scope', '=', self::PLUGIN_SCOPE)->where('scope_id', '=', $scope_id)->orWhereIn('id', $memberCites)->where('published', '!=', $citations::STATE_DELETED);
             // don't include deleted citations
         } elseif (array_key_exists('filter', $filters) && $filters['filter'] == 'member') {
             $citations->where('scope', '=', 'member')->whereIn('scope_id', $members)->where('published', '=', $citations::STATE_PUBLISHED);
             // don't include deleted citations
         } else {
             // get the ID's of the citations of members of the group
             $memberCitations = \Components\Citations\Models\Citation::all()->where('scope', '=', 'member')->whereIn('scope_id', $members)->where('published', '=', $citations::STATE_PUBLISHED);
             // don't include deleted citations
             // push them to an array
             $memberCites = array();
             foreach ($memberCitations as $mC) {
                 array_push($memberCites, $mC->id);
             }
             // Get the group's citations plus member citations.
             $citations->where('scope', '=', self::PLUGIN_SCOPE)->where('scope_id', '=', $scope_id)->orWhereIn('id', $memberCites)->where('published', '!=', $citations::STATE_DELETED);
             // don't include deleted citations
         }
     } else {
         // display only group citations
         $citations->where('scope', '=', self::PLUGIN_SCOPE);
         $citations->where('scope_id', '=', $scope_id);
         $citations->where('published', '!=', $citations::STATE_DELETED);
         // don't include deleted citations
     }
     // apply filters on the set of citations
     if ($filterCount > 0) {
         foreach ($filters as $filter => $value) {
             // sanitization
             $value = \Hubzero\Utility\Sanitize::clean($value);
             // we handle things differently in search and sorting
             if ($filter != 'search' && $filter != 'sort' && $filter != 'tag' && $value != "" && $filter != 'filter') {
                 switch ($filter) {
                     case 'author':
                         $citations->where('author', 'LIKE', "%{$value}%", 'and', 1);
                         break;
                     case 'publishedin':
                         $citations->where('date_publish', 'LIKE', "%{$value}-%");
                         break;
                     case 'year_start':
                         $citations->where('year', '>=', $value);
                         break;
                     case 'year_end':
                         $citations->where('year', '<=', $value);
                         break;
                     default:
                         $citations->where($filter, '=', $value);
                         break;
                 }
             }
             // end if not search & not sort & non-empty value
             // for searching
             if ($filter == "search" && $value != "") {
                 $terms = preg_split('/\\s+/', $value);
                 $value = \Hubzero\Utility\Sanitize::clean($value);
                 $term = $value;
                 $collection = array();
                 $columns = array('author', 'title', 'isbn', 'doi', 'publisher', 'abstract');
                 foreach ($columns as $column) {
                     foreach ($terms as $term) {
                         // copy the original item
                         $cite = clone $citations;
                         // do some searching
                         $cite->where($column, 'LIKE', "%{$term}%");
                         foreach ($cite as $c) {
                             // put for collection later
                             array_push($collection, $c->id);
                         }
                         // end foreach $cite
                     }
                     // end foreach terms
                 }
                 // end foreach columns
                 // remove duplicates
                 $collection = array_unique($collection);
                 // pull the appropriate ones.
                 $citations->whereIn('id', $collection);
             }
             // end searching
             // for tags
             if ($filter == "tag" && $value != "") {
                 $collection = array();
                 $cite = clone $citations;
                 foreach ($cite as $c) {
                     foreach ($c->tags as $tag) {
                         if ($tag->tag == $value) {
                             array_push($collection, $c->id);
                         }
                     }
                 }
                 // remove duplicates
                 $collection = array_unique($collection);
                 // get the tagged ones
                 $citations->whereIn('id', $collection);
             }
             // end if tags
             if ($filter == "sort" && $value != "") {
                 $clause = explode(" ", $value);
                 $citations->order($clause[0], $clause[1]);
             }
         }
         // end foreach filters as filter
         return array('citations' => $citations, 'filters' => $filters);
     } else {
         return array('citations' => $citations, 'filters' => array());
     }
 }