/** * Attempt to apply some default filters to a generated options * statement. Dewdrop supported two similar conventions here: "active" * columns and "deleted" columns. If your options table has an "active" * column, only options for which "active" is true will be included. * If your options table has a "deleted" column, options with that * column set as true will be excluded. * * @param array $columns The columns portion of the table metadata. * @param Select $stmt * @return \Dewdrop\Db\Select */ protected function filterStmt($columns, Select $stmt) { if (array_key_exists('active', $columns)) { $column = $this->dbAdapter->quoteIdentifier("{$this->tableName}.active"); $stmt->where("{$column} = true"); } if (array_key_exists('deleted', $columns)) { $column = $this->dbAdapter->quoteIdentifier("{$this->tableName}.deleted"); $stmt->where("{$column} = false"); } return $stmt; }
/** * 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"); } }