protected static function begin($class, $params, array $options = []) { $defaults = ['class' => null, 'method' => null, 'filters' => []]; $options += $defaults; $chain = new FilterCollection($options); $next = $chain->rewind(); return call_user_func($next, $class, $params, $chain); }
public function __construct() { $this->_CI =& get_instance(); $filters = new FilterCollection(); $filters->initBySession(); $this->_hotels = new HotelColl(); $this->_hotels->setFilters($filters); $this->_hotels->setHotels(); }
/** * Binds form data to filters, and then adds those filters to a new instance of FilterCollection, * discarding the original and any filters that do not have values * * @param array $data * @param FilterCollection $filters * * @return FilterCollection */ public function bindData(array $data, FilterCollection $filters) { $boundFilters = new FilterCollection(); foreach ($data as $key => $value) { if ($filters->exists($key) && $value) { $filter = $filters[$key]; $filter->setValue($value); $boundFilters->add($filter); } } return $boundFilters; }
/** * @param array $filters * @throws \Searchperience\Common\Exception\UnexpectedValueException * @return FilterCollection */ public function createFromFilterArguments($filters) { if (!$this->validateFilterArguments($filters)) { throw new \Searchperience\Common\Exception\UnexpectedValueException(''); } $result = new FilterCollection(); foreach ($filters as $filterName => $filterValue) { $filterName = ucfirst($filterName); $filterClassName = $this->getFilterClassName($filterName); if (class_exists($filterClassName)) { $filter = $this->initFilter($filterClassName, $filterValue); $result->addFilter($filter); } else { throw new \Searchperience\Common\Exception\UnexpectedValueException('Filter not exists: ' . $filterName); } } return $result; }
/** * Do the actual conversion * * @param mixed $input * * @return mixed $output */ public function convert($input) { $objImpl = class_implements($this->getObject()); $subjImpl = class_implements($this->getSubject()); $available = array('Converter\\Area\\AreaInterface', 'Converter\\Calendar\\CalendarInterface', 'Converter\\Color\\ColorInterface', 'Converter\\Currency\\CurrencyInterface', 'Converter\\DateTime\\DateTimeInterface', 'Converter\\Force\\ForceInterface', 'Converter\\Geo\\GeoInterface', 'Converter\\Length\\LengthInterface', 'Converter\\Temperature\\TemperatureInterface', 'Converter\\Volume\\VolumeInterface', 'Converter\\TestInterface'); $keys = array_intersect($available, $objImpl); $keys = array_values($keys); if (1 < count($keys)) { throw new Exception\ConversionSpaceMismatchException('The Object has multiple Types'); } if (1 > count($keys)) { throw new Exception\ConversionSpaceMismatchException('The Object has no Type'); } if (!isset($subjImpl[$keys[0]])) { throw new Exception\ConversionSpaceMismatchException('The Object and the Subject are of different Types'); } // Do the actual conversion applying filters along the way $defaultMeasure = $this->getObject()->toDefault($input); $defaultMeasure = $this->filters->apply($defaultMeasure); return $this->getSubject()->fromDefault($defaultMeasure); }
public function testClientReceivingFilterCollection() { $filters = new FilterCollection(); $filters->append('string.toupper'); $this->assertSame('T', stream_get_contents($this->client->receiveStream(1, $filters)), 'Wrong contents echoed.'); }
/** * @param int $accountId * @return FilterCollection */ function &SelectFilters($accountId, $useCache = false) { $filters = null; $_sql = $this->_commandCreator->SelectFilters($accountId); $_cacher =& CObjectCache::CreateInstance(); if ($useCache && $_cacher->Has('sql=' . $_sql)) { $filters =& $_cacher->Get('sql=' . $_sql); } else { if ($this->_dbConnection->Execute($_sql, true)) { $filters = new FilterCollection(); while (false !== ($row = $this->_dbConnection->GetNextRecord())) { $filter = new Filter(); $filter->Id = $row->id_filter; $filter->IdAcct = $accountId; $filter->Field = $row->field; $filter->Condition = $row->condition; $filter->Filter = $row->filter; $filter->Action = $row->action; $filter->IdFolder = $row->id_folder; $filter->Applied = $row->applied; $filters->Add($filter); unset($filter); } if ($useCache) { $_cacher->Set('sql=' . $_sql, $filters); } } } return $filters; }
public function view_hotel_portfolio_list($pageNum = NULL) { if (!$this->securitypolicy->validateAccessRight(4, 'read')) { $this->_redirectInvalidAccess(); } $filters = new FilterCollection(); $portfolios = new PortfolioColl(); # Reinitialize used filters if ($this->input->post('filter-used')) { foreach ($this->input->post('filter-used') as $filterClassName => $filtersUsed) { foreach ($filtersUsed as $index => $filterUsed) { switch ($filterClassName) { case "PrtfoFltr": $filter = new PrtfoFltr(); $data = is_int($filterUsed) ? array('id' => $filterUsed) : array('name' => $filterUsed); $filterToRemove = $this->input->post('remove-filter'); $remove = false; if (isset($filterToRemove[$filterClassName][0])) { if ($filterToRemove[$filterClassName][0] == $index) { $remove = true; } } if (!$remove) { $filter->setFilter($data); $filters->add($filter); } break; } } } } # Initialize new filters if ($this->input->post('submit-portfolio') && $this->input->post('hotel-portfolio')) { $filter = new PrtfoFltr(); $filter->setFilter(array('name' => $this->input->post('hotel-portfolio'))); $filters->add($filter); } # Add filters to the portfolio collection if ($filters->count() > 0) { $this->_viewData['filters'] = $filters; foreach ($filters as $filter) { $portfolios->addFilter($filter); } } # Pagination $pageNum = isset($pageNum) ? $pageNum : '1'; $currentPage = $pageNum; $startItem = $currentPage * 10 - $this->_pagination; $portfolios->setStartItem($startItem); $portfolios->setOffsetCount($this->_pagination); $portfolios->setAll(); # Setting pagination $this->_viewData['portfolios'] = $portfolios; $this->_viewData['pagination'] = $this->_pagination; $this->_viewData['pages'] = ceil($portfolios->getTotalResults() / $this->_pagination); $this->_viewData['page'] = $currentPage; # Portfolio deletion message if ($this->_viewData['status'] == 'success' && $this->session->userdata('previous-action') == 'remove_portfolio') { $this->_viewData['showmsg'] = true; } $this->load->view('hotel_mngt_hotel_portfolio_list', $this->_viewData); }