Example #1
0
 /**
  * Get an OptionGroups object for this field.  Allows you to easily
  * fetch key-value option pairs for foreign keys.
  *
  * @return \Dewdrop\Fields\OptionGroups
  */
 public function getOptionGroups()
 {
     if (null === $this->optionGroups) {
         $this->optionGroups = new OptionGroups($this->table->getAdapter());
         $ref = $this->getOptionPairsReference();
         if ($ref) {
             $this->optionGroups->setOptions(['tableName' => $ref['table'], 'valueColumn' => $ref['column'], 'optionPairs' => $this->getOptionPairs()]);
         }
     }
     return $this->optionGroups;
 }
Example #2
0
 /**
  * Augment the provided Select object with all the EAV attribute values from this
  * definition.
  *
  * @param Select $select
  * @return Select
  * @throws Select
  */
 public function augmentSelect(Select $select)
 {
     $db = $this->table->getAdapter();
     $id = current($this->table->getPrimaryKey());
     $rootTableAlias = $select->quoteWithAlias($this->table->getTableName(), $id);
     foreach ($this->getAttributes() as $attribute) {
         $alias = 'eav_' . $attribute['attribute_id'];
         $table = $this->table->getTableName() . $this->valueTablePrefix . $attribute['backend_type'];
         $select->joinLeft([$alias => $table], $db->quoteInto("{$alias}.{$id} = {$rootTableAlias} AND {$alias}.attribute_id = ?", $attribute['attribute_id']), [$alias => 'value']);
     }
     return $select;
 }
Example #3
0
 /**
  * Attempt to get a reasonable reference title column for many-to-many
  * values retrieved in augmentSelect().  Will use name or title, if available,
  * and then fall back to the first column in the reference table.  You can
  * override this behavior with setReferenceTitleColumn().
  *
  * @return Expr|string
  * @throws Exception
  */
 private function findReferenceTitleColumn()
 {
     if ($this->referenceTitleColumn) {
         return $this->referenceTitleColumn;
     }
     $metadata = $this->sourceTable->getAdapter()->getTableMetadata($this->getReferenceTableName());
     $columns = array_keys($metadata['columns']);
     if (in_array('name', $columns)) {
         return 'name';
     } elseif (in_array('title', $columns)) {
         return 'title';
     } else {
         return array_shift($columns);
     }
 }
Example #4
0
 /**
  * Provide the table for which we're generated a listing Select.
  *
  * @param Table $table
  */
 public function __construct(Table $table)
 {
     $this->table = $table;
     $this->db = $this->table->getAdapter();
 }
Example #5
0
 /**
  * Assemble the WHERE clause for the update method using the primary key
  * column's from the associated table.
  *
  * @return string
  */
 private function assembleUpdateWhereClause()
 {
     $pkey = $this->table->getPrimaryKey();
     $db = $this->table->getAdapter();
     $where = array();
     foreach ($pkey as $column) {
         $quotedColumn = $db->quoteIdentifier($column);
         $where[] = $db->quoteInto("{$quotedColumn} = ?", $this->data[$column]);
     }
     return implode(' AND ', $where);
 }