public function Elements() { $result = $this->getComponents('Widgets'); $list = new HasManyList('BaseElement', $result->getForeignKey()); $list->setDataModel($this->model); $list->sort('Sort ASC'); $list = $list->forForeignID($this->ID); return $list; }
public function Elements() { $result = $this->getComponents('Widgets'); if ($result instanceof UnsavedRelationList) { return array(); } $list = new HasManyList('BaseElement', $result->getForeignKey()); $list->setDataModel($this->model); $list->sort('Sort ASC'); $list = $list->forForeignID($this->ID); $list = $list->filter(array('Enabled' => 1)); return $list; }
/** * Returns all the {@link BaseElement} instances in this area, regardless if * they are enabled or not. * * @return HasManyList */ public function AllElements() { $result = $this->getComponents('Widgets'); if ($result instanceof UnsavedRelationList) { // Setup a proper UnsavedRelationList so that a page using this extension can be created // programmatically and have unsaved/saved BaseElement records attached to it. // NOTE(SilbinaryWolf): Able to set protected var 'dataClass' due to ViewableData using magic get/set for properties $result->dataClass = 'BaseElement'; // Change from 'Widget' to 'BaseElement' return $result; } $list = new HasManyList('BaseElement', $result->getForeignKey()); $list->setDataModel($this->model); $list->sort('Sort ASC'); $list = $list->forForeignID($this->ID); return $list; }
/** * Returns a one-to-many relation as a HasManyList * * @param string $componentName Name of the component * @param string $filter A filter to be inserted into the WHERE clause * @param string|array $sort A sort expression to be inserted into the ORDER BY clause. If omitted, the static field $default_sort on the component class will be used. * @param string $join A single join clause. This can be used for filtering, only 1 instance of each DataObject will be returned. * @param string|array $limit A limit expression to be inserted into the LIMIT clause * * @return HasManyList The components of the one-to-many relationship. */ public function getComponents($componentName, $filter = "", $sort = "", $join = "", $limit = null) { $result = null; if (!($componentClass = $this->has_many($componentName))) { user_error("DataObject::getComponents(): Unknown 1-to-many component '{$componentName}' on class '{$this->class}'", E_USER_ERROR); } $joinField = $this->getRemoteJoinField($componentName, 'has_many'); $result = new HasManyList($componentClass, $joinField); if ($this->model) { $result->setDataModel($this->model); } $result->setForeignID($this->ID); $result = $result->where($filter)->limit($limit)->sort($sort); if ($join) { $result = $result->join($join); } return $result; }