/** * Retrieve the value of this field for the associated row, if available. * * @throws Exception * @return mixed */ public function getValue() { if (!$this->row) { throw new Exception("Attempting to retrieve value for {$this->name} field with no row assigned."); } return $this->row->get($this->name); }
/** * Load the initial value for the supplied attribute name. If the supplied * row is new (i.e. no primary key value), then we use the default value * for the attribute. Otherwise, we query that appropriate value table. * * @param Row $row * @param string $name */ public function loadInitialValue(Row $row, $name) { $db = $this->table->getAdapter(); $attribute = $this->getAttribute($name); if ($row->isNew()) { return $attribute['default_value']; } else { $valueTable = $this->getBackendTypeTableName($attribute['backend_type']); $stmt = $db->select()->from($valueTable, array('value'))->where('attribute_id = ?', $attribute['attribute_id']); foreach ($this->table->getPrimaryKey() as $keyColumn) { $keyQuoted = $db->quoteIdentifier("{$valueTable}.{$keyColumn}"); $stmt->where("{$keyQuoted} = ?", $row->get($keyColumn)); } return $db->fetchOne($stmt); } }
/** * Assign the provided row object to the named model. This will iterate * over all the fields and call setRow() on each one associated with * the named model so that their values can be set and retrieved for * editing. * * @throws \Dewdrop\Fields\Exception * @param string $modelName * @param Row $row * @return RowEditor */ public function setRow($modelName, Row $row) { $model = $this->getModel($modelName); if ($model !== $row->getTable()) { throw new Exception('The row should be from the same table instance.'); } foreach ($this->fields as $field) { if ($field instanceof DbField && $field->getTable() === $model) { $field->setRow($row); } } if ($this->deleteField) { $this->deleteField->setRow($row); } if (array_key_exists($modelName, $this->defaultsByModelName)) { $this->applyDefaultsToRow($row, $this->defaultsByModelName[$modelName]); } $this->rowsByName[$modelName] = $row; return $this; }
/** * Using the supplied source table row, retrieve the initial value for * this relationship. This is typically called by \Dewdrop\Db\Row when * get() is first called for this relationship. * * @param Row $row * @return array */ public function loadInitialValue(Row $row) { $value = $row->get($this->getSourceColumnName()); // If the anchor column has no value, we can assume this relationship has no value if (!$value) { return array(); } $db = $row->getTable()->getAdapter(); $stmt = $db->select(); $whereName = $db->quoteIdentifier("{$this->xrefTableName}.{$this->getXrefAnchorColumnName()}"); $stmt->from($this->xrefTableName, array($this->getXrefReferenceColumnName()))->where("{$whereName} = ?", $value); return $db->fetchCol($stmt); }
public function assembleUserMessage(Row $user) { $lists = []; if ($this->changes->hasAdditions()) { $lists[] = $this->addVerb . ' ' . $this->assembleList($this->changes->getAdditions()); } if ($this->changes->hasRemovals()) { $lists[] = $this->removeVerb . ' ' . $this->assembleList($this->changes->getRemovals()); } $lists = implode(' and ', $lists); return "{$user->shortcode()} {$lists} on {$this->field->getLabel()} for {$this->subject->shortcode()}."; }