Пример #1
0
 /**
  * Add the EAV values for all attributes to the provided Select.
  *
  * @param Select $select
  * @return Select
  */
 public function augmentSelect(Select $select)
 {
     if ($this->table->hasEav()) {
         $this->table->getEav()->augmentSelect($select);
     }
     return $select;
 }
Пример #2
0
 /**
  * Augment the provided Select by adding a comma-separated list of
  * many-to-many values for all relationships in this field provider.
  *
  * @param Select $select
  * @return Select
  */
 public function augmentSelect(Select $select)
 {
     /* @var $relationship Relationship */
     foreach ($this->table->getManyToManyRelationships() as $name => $relationship) {
         $relationship->augmentSelect($select, $name);
     }
     return $select;
 }
Пример #3
0
 public function __construct(Row $subject, Table $valueTable, ManyToManyField $field, array $originalValue = null)
 {
     $this->subject = $subject;
     $this->field = $field;
     $this->originalValue = $originalValue;
     $this->valueShortcodeName = $valueTable->getActivityLogHandler()->getName();
     $this->changes = new Changes($originalValue, $this->field->getValue());
 }
Пример #4
0
 /**
  * Provide a row that can be linked to all the fields from the supplied
  * table.  If the query string variable has a value, we'll attempt to get
  * the row from the table's find() method.  Otherwise, we'll create a new
  * row.
  *
  * @param Table $table
  * @return \Dewdrop\Db\Row
  */
 public function link(Table $table)
 {
     $value = $this->request->getQuery($this->variableName);
     if ($value) {
         $row = $table->find($value);
     } else {
         $row = $table->createRow();
     }
     return $row;
 }
Пример #5
0
 public function __construct(Table $table, ActivityLog $activityLog = null, Inflector $inflector = null)
 {
     $this->table = $table;
     $this->inflector = $inflector ?: Pimple::getResource('inflector');
     $tableName = $table->getTableName();
     $inflectedName = $this->inflector->singularize($this->inflector->hyphenize($tableName));
     if (!$tableName) {
         $className = get_class($table);
         throw new Exception("Cannot create activity log handle for {$className} because no table name is set.");
     }
     $this->setActivityLog($activityLog ?: Pimple::getResource('activity-log'))->setName($inflectedName)->setModel($table)->addAlias($tableName);
     parent::__construct();
 }
Пример #6
0
 /**
  * Allow each field provider on the Table to augment the Select object.
  * This is how many-to-many and EAV fields get their values folded into a
  * listing query.
  *
  * @param Select $select
  * @return Select
  */
 private function selectFieldProviderValues(Select $select)
 {
     /* @var $provider ProviderInterface */
     foreach ($this->table->getFieldProviders() as $provider) {
         $provider->augmentSelect($select);
     }
     return $select;
 }
Пример #7
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;
 }
Пример #8
0
 /**
  * Provide a row that can be linked to all the fields from the supplied
  * table.  If the field has a value, we'll look up the row using the table's
  * find() method.  Otherwise, we'll create a new row.  Note that an exception
  * is throw if you attempt to use this linker with a field that doesn't
  * itself have a row associated with it already.  Often you'll link to the
  * first row using a \Dewdrop\Fields\RowEditor\Link\QueryString rule and
  * then string Field linker on after that.
  *
  * @throws \Dewdrop\Fields\Exception
  * @param Table $table
  * @return \Dewdrop\Db\Row
  */
 public function link(Table $table)
 {
     if (!$this->field->hasRow()) {
         $this->field->setRow($this->rowEditor->getRow($this->field->getGroupName()));
     }
     $value = $this->field->getValue();
     if ($value) {
         $row = $table->find($value);
     } else {
         $row = $table->createRow();
     }
     return $row;
 }
Пример #9
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);
     }
 }
Пример #10
0
 /**
  * On a POST request, validate the user's input.  If valid, save using the
  * RowEditor, set a success message and then redirect.  Should also behave
  * reasonably well when used as an endpoint for an XHR by returning a success
  * message and the new primary key value.
  *
  * @param ResponseHelper $responseHelper
  */
 public function process(ResponseHelper $responseHelper)
 {
     if ($this->request->isPost()) {
         $this->invalidSubmission = !$this->rowEditor->isValid($this->request->getPost());
         if (!$this->invalidSubmission) {
             $title = strtolower($this->model->getSingularTitle());
             if (!$this->request->isAjax()) {
                 if ($this->isNew) {
                     $responseHelper->setSuccessMessage("Successfully saved new {$title}.");
                 } else {
                     $responseHelper->setSuccessMessage("Successfully saved changes to {$title}.");
                 }
             }
             $this->rowEditor->save();
             if (!$this->request->isAjax()) {
                 $this->redirect($responseHelper);
             }
         }
     }
 }
Пример #11
0
 /**
  * Check to see if this field is a foreign key.  Calling isType('reference')
  * will automatically delegate to this method.
  *
  * @return boolean
  */
 protected function isTypeReference()
 {
     return (bool) $this->table->getMetadata('references', $this->name);
 }
Пример #12
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);
 }
Пример #13
0
 /**
  * Set the titles for this collection using the titles from a Table object.
  *
  * @param Table $table
  * @return $this
  */
 public function setTitlesFromTable(Table $table)
 {
     $this->title = $table->getPluralTitle();
     $this->singularTitle = $table->getSingularTitle();
     $this->pluralTitle = $table->getPluralTitle();
     return $this;
 }
Пример #14
0
 /**
  * A shortcut for linkByQueryString() that uses Table object get the model
  * and query string param name.
  *
  * @param Table $table
  * @return RowEditor
  * @throws Exception
  */
 public function linkTableByQueryString(Table $table)
 {
     $primaryKey = $table->getPrimaryKey();
     if (1 !== count($primaryKey)) {
         throw new Exception('Can only use linkTableByQueryString() when a single primary key column is present.');
     }
     return $this->linkByQueryString($table->getTableName(), current($primaryKey));
 }
Пример #15
0
 /**
  * Get a list of the field names available from this provider.
  *
  * @return array
  */
 public function getAllNames()
 {
     return array_keys($this->table->getMetadata('columns'));
 }