示例#1
0
 /**
  * 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);
 }
示例#2
0
 /**
  * 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");
     }
 }
示例#4
0
 /**
  * Handle the model (\Dewdrop\Db\Table) objects for the supplied newly added
  * DB field.  We allow custom model names for situations where you need to
  * add fields from two different instances of the same model (e.g. you have
  * an two Addresses model instances on your fields set because you have both
  * a billing and a shipping address).
  *
  * @param DbField $field
  * @param string $modelName
  * @throws Exception
  */
 protected function handleModelsForDbField(DbField $field, $modelName)
 {
     $fieldTable = $field->getTable();
     $groupName = $field->getGroupName();
     if (null === $modelName && isset($this->modelInstances[$groupName]) && $this->modelInstances[$groupName] !== $fieldTable) {
         throw new Exception('When adding fields from two instances of the same model, you must specify ' . 'an alternate model name as the second paramter to add().');
     }
     if (null === $modelName) {
         $modelName = $groupName;
     }
     if (isset($this->modelsByName[$modelName]) && $this->modelsByName[$modelName] !== $fieldTable) {
         throw new Exception("The name '{$modelName}' has already been used with another model instance. " . 'Please make sure to use model names consistently when adding fields.');
     }
     $this->modelInstances[$groupName] = $fieldTable;
     $this->modelsByName[$modelName] = $fieldTable;
     // Update the field's control name so that generated IDs, etc., use the new name
     if ($modelName !== $groupName) {
         $field->setGroupName($modelName);
     }
 }