Find groups

@param   array  $filters
@return  mixed
498433
static function find($filters = array())
	{
		$db = \App::get('db');

		// Type 0 - System Group
		// Type 1 - HUB Group
		// Type 2 - Project Group
		// Type 3 - Partner "Special" Group
		// Type 4 - Course group
		$gTypes = array('all', 'system', 'hub', 'project', 'super', 'course', '0', '1', '2', '3', '4');

		$types = !empty($filters['type']) ? $filters['type'] : array('all');

		foreach ($types as $type)
		{
			if (!in_array($type, $gTypes))
			{
				return false;
			}
		}

		$where = array();

		if (!in_array('all', $types))
		{
			$t = implode(",", $types);

			//replace group type names with group type id
			$t = str_replace('hub', 1, $t);
			$t = str_replace('project', 2, $t);
			$t = str_replace('super', 3, $t);
			$t = str_replace('course', 4, $t);
			$t = str_replace('system', 0, $t);

			$where[] = 'type IN (' . $t . ')';
		}

		if (isset($filters['search']) && $filters['search'] != '')
		{
			if (is_numeric($filters['search']))
			{
				$where[] = "gidNumber=" . $db->quote($filters['search']);
			}
			else
			{
				$where[] = "(LOWER(description) LIKE " . $db->quote('%' . strtolower($filters['search']) . '%') . " OR LOWER(cn) LIKE " . $db->quote('%' . strtolower($filters['search']) . '%') . ")";
			}
		}

		if (isset($filters['index']) && $filters['index'] != '')
		{
			$where[] = "(LOWER(description) LIKE " . $db->quote(strtolower($filters['index']) . '%') . ")";
		}

		if (isset($filters['authorized']) && $filters['authorized'] === 'admin')
		{
			if (isset($filters['discoverability']) && $filters['discoverability'] != '')
			{
				switch ($filters['discoverability'])
				{
					case 0:
						$where[] = "discoverability=0";
						break;
					case 1:
						$where[] = "discoverability=1";
						break;
				}
			}
		}
		else
		{
			$where[] = "discoverability=0";
		}

		if (isset($filters['policy']) && $filters['policy'])
		{
			switch ($filters['policy'])
			{
				case 'closed':
					$where[] = "join_policy=3";
					break;
				case 'invite':
					$where[] = "join_policy=2";
					break;
				case 'restricted':
					$where[] = "join_policy=1";
					break;
				case 'open':
				default:
					$where[] = "join_policy=0";
					break;
			}
		}

		if (isset($filters['published']) && $filters['published'] != '')
		{
			$where[] = "published=" . $db->quote($filters['published']);
		}

		if (isset($filters['approved']) && $filters['approved'] != '')
		{
			$where[] = "approved=" . $db->quote($filters['approved']);
		}

		if (isset($filters['created']) && $filters['created'] != '')
		{
			if ($filters['created'] == 'pastday')
			{
				$pastDay = date("Y-m-d H:i:s", strtotime('-1 DAY'));
				$where[] = "created >= " . $db->quote($pastDay);
			}
		}


		if (empty($filters['fields']))
		{
			$filters['fields'][] = 'cn';
		}

		$field = implode(',', $filters['fields']);

		$query = "SELECT $field FROM `#__xgroups`";
		if (count($where) > 0)
		{
			$query .= " WHERE " . implode(" AND ", $where);
		}

		if (isset($filters['sortby']) && $filters['sortby'] != '')
		{
			$query .= " ORDER BY ";

			switch ($filters['sortby'])
			{
				case 'alias':
					$query .= 'cn ASC';
					break;
				case 'title':
					$query .= 'description ASC';
					break;
				default:
					$query .= $filters['sortby'];
					break;
			}
		}

		if (isset($filters['limit']) && $filters['limit'] != 'all')
		{
			$query .= " LIMIT " . $filters['start'] . "," . $filters['limit'];
		}

		$query .= ";";

		$db->setQuery($query);

		if (!in_array('COUNT(*)', $filters['fields']))
		{
			$result = $db->loadObjectList();
		}
		else
		{
			$result = $db->loadResult();
		}

		if (empty($result))
		{
			return false;
		}

		return $result;
	}
365006
public function getFilter($filter)
    {
        $result = null;

        if(isset($this->__filters[$filter])) {
            $result = $this->__filters[$filter];
         }

        return $result;
    }
715799
public function setFilters($filters)
    {
        if ($filters === null)
            $filters = [];
        else if (!is_array($filters))
            throw new \Exception('Filters should be null or array');

        foreach ($filters as $column => $filter) {
            $found = [];
            foreach ($this->getColumns() as $id => $params) {
                if ($id == $column) {
                    foreach ($filter as $name => $value) {
                        if (in_array($name, $params['filters']))
                            $found[$name] = $value;
                    }
                    break;
                }
            }

            if (count($found) > 0)
                $filters[$column] = $found;
            else
                unset($filters[$column]);
        }

        $this->filters = $filters;
        return $this;
    }
384345
public static function aggregate($filters, $aggregation, $options = null)
    {
        if (is_string($options)) {
            $options = ['group' => $options];
        }
        return static::query()->where($filters)->options($options)->aggregate($aggregation);
    }
687362
public static function decodeFilters(array $filters)
    {
        $decodedFilters = [];
        foreach ($filters as $property => $value) {
            $decodedFilters[] = ['value' => $value, 'property' => $property];
        }

        return $decodedFilters;
    }
23987
public function findParents(array $filters = [], array $options = [])
    {
        $options = array_replace(
            [
                'returnFirstResult' => false,
                'indexById'         => false
            ],
            $options
        );
        $parents = $this->getAllParents($options);

        if ($parents && $filters) {
            $result = [];

            /** @var NodeInterface $parent */
            foreach ($parents as $i => $parent) {
                foreach ($filters as $f => $v) {
                    $method = 'get' . ucfirst($f);

                    if (!method_exists($parent, $method) || $parent->$method() !== $v) {
                        continue 2;
                    }
                }

                if ($options['indexById']) {
                    $result[$i] = $parent;
                } else {
                    $result[] = $parent;
                }
            }
        } else {
            $result = $parents;
        }

        return $options['returnFirstResult'] && $result ?
            array_values($result)[0] :
            $result;
    }
307799
public function listListings(array $filters = [])
    {
        $query = '';

        if ($this->config->products) {
            $filters['product__id'] = $this->config->products;
        }

        if ($filters) {
            $query = '?' . preg_replace('/%5B[0-9]+%5D/simU', '', http_build_query($filters));
        }

        $body = $this->sendRequest('GET', '/listings' . $query);

        /** @var Listing[] $models */
        $models = Model::modelize('listings', json_decode($body));
        foreach ($models as $index => $model) {
            $models[$index]->requestProcessor = $this;
        }

        return $models;
    }
985283
public function getRecords($filters = array())
	{
		$entries = self::all();

		$c = $entries->getTableName();
		$e = '#__extensions';

		$entries
			->select($c . '.*,' . $e . '.name')
			->join($e, $e . '.element', $c . '.component', 'inner')
			->whereEquals($e . '.type', 'component');

		if (isset($filters['component']) && $filters['component'])
		{
			$entries->whereEquals($e . '.element', $filters['component']);
		}

		return $entries
			->ordered($c . '.component', 'asc')
			->rows();
	}
1017707
public function findChildren(array $filters = [], array $options = [])
    {
        $options = array_replace(
            [
                'returnFirstResult'     => false
            ],
            $options
        );

        if (empty($filters)) {
            $result = array_values($this->_nodes);
        } else if (count($filters) === 1
            && isset($filters['id'])
        ) {
            $result = $this->hasNode($filters['id']) ?
                [$this->getNode($filters['id'])] :
                [];
        } else {
            $result = [];

            /** @var NodeInterface $child */
            foreach ($this->getNodes() as $child) {
                foreach ($filters as $f => $v) {
                    $method = 'get'.ucfirst($f);

                    if (!method_exists($child, $method) || $child->$method() !== $v) {
                        continue 2;
                    }
                }

                $result[] = $child;
            }
        }

        return $options['returnFirstResult'] && $result ?
            $result[0] :
            $result;
    }
858921
public function filter($filters)
    {
        $filtered = [];
        foreach ($this->objectArr as $obj) {
            $success = true;
            foreach ($filters as $prop => $value) {
                if ($obj->$prop !== $value) {
                    $success = false;
                    break;
                }
            }
            if ($success) {
                $filtered[] = $obj;
            }
        }
        return $filtered;
    }
1226445
public static function getCategories($filter = array())
    {
        $filter = Filter::create($filter);
        return self::getCollection('/categories' . $filter->toQuery(), 'Category');
    }
1262745
protected function parseFilterGroups(array $filter_groups)
    {
        $return = [];

        foreach($filter_groups as $group) {
            if (!array_key_exists('filters', $group)) {
                throw new InvalidArgumentException('Filter group does not have the \'filters\' key.');
            }

            $filters = array_map(function($filter){
                if (!isset($filter['not'])) {
                    $filter['not'] = false;
                }

                return $filter;
            }, $group['filters']);

            $return[] = [
                'filters' => $filters,
                'or' => isset($group['or']) ? $group['or'] : false
            ];
        }

        return $return;
    }
33073
protected function getFilterParams(array &$filters, $filter)
    {
        $fragments = preg_split('%;%', $filter, -1, PREG_SPLIT_NO_EMPTY);

        $name = array_shift($fragments);
        $params = [];

        foreach ($fragments as $param) {
            list($key, $value)  = explode('=', $param);
            $params[$key] = $value;
        }

        $filters[$name] = $params;
    }
1052485
public function filter(array $filters)
	{
		foreach ($filters as $filter) {
			if ($filter->isValueSet()) {
				if ($filter->hasConditionCallback()) {
					Callback::invokeArgs(
						$filter->getConditionCallback(),
						[$this->data_source, $filter->getValue()]
					);
				} else {
					if ($filter instanceof Filter\FilterText) {
						$this->applyFilterText($filter);
					} elseif ($filter instanceof Filter\FilterMultiSelect) {
						$this->applyFilterMultiSelect($filter);
					} elseif ($filter instanceof Filter\FilterSelect) {
						$this->applyFilterSelect($filter);
					} elseif ($filter instanceof Filter\FilterDate) {
						$this->applyFilterDate($filter);
					} elseif ($filter instanceof Filter\FilterDateRange) {
						$this->applyFilterDateRange($filter);
					} elseif ($filter instanceof Filter\FilterRange) {
						$this->applyFilterRange($filter);
					}
				}
			}
		}

		return $this;
	}
1256419
public function list(array $filters = [])
    {
        $data = [
            'filters' => json_encode($filters),
        ];

        $url = $this->url.'?'.http_build_query($data);

        return $this->curl->get($url);
    }
323560
protected function checkGroups(array $groups)
    {
        $checkedGroups = array();
        foreach ($groups as $group) {
            if (true === is_string($group) && false === in_array($group, $checkedGroups)) {
                $checkedGroups[] = (string)$group;
            }
        }
        return $checkedGroups;
    }
1039024
public function addFilters(array $filters)
    {
        foreach ($filters as $filter) {
            if ($filter === null) {
                continue;
            }

            $this->addFilter($filter);
        }

        return $this;
    }