Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 /**
  * 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);
     }
 }
Exemplo n.º 4
0
 /**
  * Apply the supplied default values to the row, skipping any fields
  * that already have a value.
  *
  * @param Row $row
  * @param array $defaults
  * @return $this
  * @throws \Dewdrop\Exception
  */
 public function applyDefaultsToRow(Row $row, array $defaults)
 {
     foreach ($defaults as $key => $value) {
         if (!$row->get($key)) {
             if ($value instanceof FieldInterface) {
                 $value = $value->getValue();
             }
             $row->set($key, $value);
         }
     }
     return $this;
 }