/** * Fetch a single row from this listing by using the supplied ID value to * match against the listing's primary key field. * * @param Fields $fields * @param mixed $id * @return \Dewdrop\Db\Row */ public function fetchRow(Fields $fields, $id) { $select = $this->getModifiedSelect($fields); $quotedPrimaryKey = $select->quoteWithAlias($this->primaryKey->getTable()->getTableName(), $this->primaryKey->getName()); $select->where("{$quotedPrimaryKey} = ?", $id); return $this->select->getAdapter()->fetchRow($select); }
/** * Populate the primary key value from the supplied row (already saved in * the RowEditor) up to the linked field in this object. For example, say * you'd configured a link like this in your RowEditor: * * <pre> * $rowEditor->linkByField('addresses', $this->orderModel->field('address_id')); * </pre> * * Then, when this method was called, you'd get a row from the addresses * table that had already been saved by the row editor. And, using that row, * this method would set the value of the orderModel's address_id field * to the primary key of the addresses row. * * @param Row $row * @return \Dewdrop\Fields\RowEditor\Link\Field */ public function populateValueFromSavedRow(Row $row) { $references = $this->field->getTable()->getMetadata('references'); foreach ($references as $foreignKey => $referencedColumnAndTable) { if ($foreignKey === $this->field->getName()) { $referencedColumn = $referencedColumnAndTable['column']; $this->field->setValue($row[$referencedColumn]); } } return $this; }
/** * 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"); } }
/** * Provide a default sorting strategy for reference columns. * * @param DbField $field * @param Select $select * @param string $direction * @return Select * @throws Select\SelectException */ public function sortDbReference(DbField $field, Select $select, $direction) { $optionPairs = $field->getOptionPairs(); $tableName = $optionPairs->getTableName(); try { $titleColumn = $optionPairs->detectTitleColumn(); } catch (TitleColumnNotDetectedException $e) { $titleColumn = $field->getName(); } if ($titleColumn instanceof Expr) { $orderSpec = "{$titleColumn} {$direction}"; } else { $orderSpec = new Expr("{$select->quoteWithAlias($tableName, $titleColumn)} {$direction}"); } return $select->order($orderSpec); }
/** * A default implementation for most database fields. * * @param DbField $field * @param Select $select * @param string $direction * @return Select */ public function sortDbDefault(DbField $field, $select, $direction) { return $select->order("{$field->getName()} {$direction}"); }
/** * A fall back method for timestamp fields. Will convert the DB value to a * Unix timestamp and then format it with PHP's date() function. (How * retro!) You can customize the format with setDateFormat(). * * @param FieldInterface $field * @param array $rowData * @return string */ protected function renderDbTimestamp(DbField $field, array $rowData) { $value = $rowData[$field->getName()]; $timestamp = strtotime($value); return $this->view->escapeHtml(date($this->dateFormat . ' ' . $this->timeFormat, $timestamp)); }
/** * A fall back method for timestamp fields. Will convert the DB value to a * Unix timestamp and then format it with PHP's date() function. (How * retro!) You can customize the format with setDateFormat(). * * @param DbField $field * @param array $rowData * @return string */ protected function renderDbTimestamp(DbField $field, array $rowData) { $value = $rowData[$field->getName()]; $timestamp = strtotime($value); if ($timestamp) { return date($this->dateFormat . ' ' . $this->timeFormat, $timestamp); } else { return ''; } }
/** * A fall back method for timestamp fields. Will convert the DB value to a * Unix timestamp and then format it with PHP's date() function. (How * retro!) You can customize the format with setDateFormat(). * * @param FieldInterface $field * @param array $rowData * @return string */ protected function renderDbTimestamp(DbField $field, array $rowData) { $value = $rowData[$field->getName()]; $timestamp = strtotime($value); // Hack for handling GMT offsets in WordPress. if ($timestamp && function_exists('get_option')) { $timezoneString = get_option('timezone_string'); if ($timezoneString) { $offset = timezone_offset_get(new DateTimeZone($timezoneString), date_create($value)); $timestamp += $offset; } } if ($timestamp) { return $this->view->escapeHtml(date($this->dateFormat . ' ' . $this->timeFormat, $timestamp)); } else { return ''; } }
/** * Add a field, optionally changing its control name to disambiguate it * from other fields with the same control name on this page. * * @param DbField $field * @param string $groupName * @return \Dewdrop\Fields\Edit */ public function add(DbField $field, $groupName = null) { if (null === $groupName) { $this->fields[$field->getControlName()] = $field; } else { $fieldIndex = $groupName . ':' . $field->getName(); $field->setControlName($fieldIndex); $this->fields[$fieldIndex] = $field; } $this->inputFilter->add($field->getInputFilter()); return $this; }