/** * Fetch data for this collection. If your request is a POST, then we'll * get the data from the request. If it's not a POST, we ask the * fetchDataCallback for the initial data set. * * @param string $mode * @return array|mixed */ public function getData($mode = self::DATA_MODE_COLUMN_NAMES) { if (!$this->request->isPost()) { return call_user_func($this->fetchDataCallback); } else { return $this->getDataFromRequest($this->request->getPost(), $mode); } }
/** * @return bool|int */ public function getId() { $id = $this->getIdFromSignedCookie(); if (false === $id) { $ipAddress = $this->request->getClientIp(); $geocoderResult = null; if ($this->geocoder) { try { $geocoderResult = $this->geocoder->geocode($ipAddress)->first(); } catch (NoResultException $e) { } } $id = $this->dbGateway->insertUserInformation($ipAddress, $_SERVER['HTTP_USER_AGENT'], php_sapi_name(), $geocoderResult); $this->writeSignedCookie($id); } return $id; }
/** * Using the supplied \Dewdrop\Fields and \Dewdrop\Db\Select, modify the * Select to include only the current page with the correct number of * records. The DB driver is used to ensure we can get the total number * of records that _would_ have been returned had no pagination been applied * after the query has been executed (using whatever facility is provided * for that use in the specific RDBMS). * * @param Fields $fields * @param Select $select * @return Select * @throws Exception */ public function modifySelect(Fields $fields, Select $select) { if ($this->request->getQuery($this->prefix . 'disable-pagination')) { $this->disable(); } $driver = $select->getAdapter()->getDriver(); $this->page = (int) $this->request->getQuery($this->prefix . 'listing-page', 1); $driver->prepareSelectForTotalRowCalculation($select); if (!$this->enabled) { return $select; } return $select->limit($this->getPageSize(), $this->getPageSize() * ($this->page - 1)); }
/** * Using the supplied \Dewdrop\Fields and \Dewdrop\Db\Select, modify the * Select to include only the current page with the correct number of * records. The DB driver is used to ensure we can get the total number * of records that _would_ have been returned had no pagination been applied * after the query has been executed (using whatever facility is provided * for that use in the specific RDBMS). * * @param Fields $fields * @param Select $select * @return Select * @throws Exception */ public function modifySelect(Fields $fields, Select $select) { if (!$this->isEnabled()) { return $select; } $column = $select->quoteWithAlias($this->field->getTable()->getTableName(), $this->field->getName()); $this->showingDeletedRecords = (bool) $this->request->getQuery($this->getQueryParameterName()); if ($this->isShowingDeletedRecords()) { return $select->where("{$column} = true"); } else { return $select->where("{$column} = false"); } }
/** * Given the supplied $fields and \Dewdrop\Request object, find the field * referenced in the query string and apply its sort callback to the query. * * @param Fields $fields * @param Select $select * @throws \Dewdrop\Fields\Exception * @return Select */ public function modifySelect(Fields $fields, Select $select) { $this->sortedField = null; $this->sortedDirection = null; /* @var $field FieldInterface */ foreach ($fields->getSortableFields() as $field) { if ($field->getQueryStringId() === urlencode($this->request->getQuery($this->prefix . 'sort'))) { if ('ASC' === $this->defaultDirection) { $dir = 'DESC' === strtoupper($this->request->getQuery($this->prefix . 'dir')) ? 'DESC' : 'ASC'; } else { $dir = 'ASC' === strtoupper($this->request->getQuery($this->prefix . 'dir')) ? 'ASC' : 'DESC'; } $select = call_user_func($this->getFieldAssignment($field), $select, $dir); if (!$select instanceof Select) { throw new Exception('Your SelectSort callback must return the modified Select object.'); } $this->sortedField = $field; $this->sortedDirection = $dir; return $select; } } // Sort by the first visible field that is also sortable, if no other sort was performed foreach ($fields->getVisibleFields() as $field) { if ($field->isSortable() && (null === $this->defaultField || $this->defaultField === $field)) { $this->sortedField = $field; $this->sortedDirection = $this->defaultDirection; return call_user_func($this->getFieldAssignment($field), $select, $this->defaultDirection); } } return $select; }
public function testIsPostWorksWhenMethodIsNotPost() { $request = new Request(array(), array(), 'GET'); $this->assertFalse($request->isPost()); }