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;
 }
 /**
  * Getter for the language object for an object that has translations
  * I impemented it a a static method because it would be redundantly declared
  * in any multilanguage DataObject
  *
  * @param HasManyList $componentset has_many relation to be searched for the right translation
  * @param string      $locale       locale eg. de_DE, en_NZ, ...
  *
  * @return DataObject|false
  * 
  * @author Roland Lehmann <*****@*****.**>
  * @since 03.01.2012
  */
 public static function getLanguage($componentset, $locale = false)
 {
     $lang = false;
     if ($locale == false) {
         $locale = Translatable::get_current_locale();
     }
     if ($componentset->find('Locale', $locale)) {
         $lang = $componentset->find('Locale', $locale);
     } elseif (SilvercartConfig::useDefaultLanguageAsFallback()) {
         if ($componentset->find('Locale', SilvercartConfig::DefaultLanguage())) {
             $lang = $componentset->find('Locale', SilvercartConfig::DefaultLanguage());
         }
     }
     return $lang;
 }
 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);
     }
     if ($join) {
         throw new \InvalidArgumentException('The $join argument has been removed. Use leftJoin($table, $joinClause) instead.');
     }
     // If we haven't been written yet, we can't save these relations, so use a list that handles this case
     if (!$this->ID) {
         if (!isset($this->unsavedRelations[$componentName])) {
             $this->unsavedRelations[$componentName] = UnsavedRelationList::create($this->class, $componentName, $componentClass);
         }
         return $this->unsavedRelations[$componentName];
     }
     $joinField = $this->getRemoteJoinField($componentName, 'has_many');
     $result = HasManyList::create($componentClass, $joinField);
     if ($this->model) {
         $result->setDataModel($this->model);
     }
     $result = $result->forForeignID($this->ID);
     $result = $result->where($filter)->limit($limit)->sort($sort);
     return $result;
 }
 /**
  * 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;
 }
 public function __construct($parentClassName)
 {
     parent::__construct('Comment', 'ParentID');
     // Ensure underlying DataQuery globally references the class filter
     $this->dataQuery->setQueryParam('Foreign.Class', $parentClassName);
     // For queries with multiple foreign IDs (such as that generated by
     // DataList::relation) the filter must be generalised to filter by subclasses
     $classNames = Convert::raw2sql(ClassInfo::subclassesFor($parentClassName));
     $this->dataQuery->where(sprintf("\"BaseClass\" IN ('%s')", implode("', '", $classNames)));
 }
 /**
  * Create a new PolymorphicHasManyList relation list.
  *
  * @param string $dataClass The class of the DataObjects that this will list.
  * @param string $foreignField The name of the composite foreign relation field. Used
  * to generate the ID and Class foreign keys.
  * @param string $foreignClass Name of the class filter this relation is filtered against
  */
 function __construct($dataClass, $foreignField, $foreignClass)
 {
     // Set both id foreign key (as in HasManyList) and the class foreign key
     parent::__construct($dataClass, "{$foreignField}ID");
     $this->classForeignKey = "{$foreignField}Class";
     // Ensure underlying DataQuery globally references the class filter
     $this->dataQuery->setQueryParam('Foreign.Class', $foreignClass);
     // For queries with multiple foreign IDs (such as that generated by
     // DataList::relation) the filter must be generalised to filter by subclasses
     $classNames = Convert::raw2sql(ClassInfo::subclassesFor($foreignClass));
     $this->dataQuery->where(sprintf("\"{$this->classForeignKey}\" IN ('%s')", implode("', '", $classNames)));
 }
예제 #8
0
 /**
  * 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;
 }
    /**
     * Returns a one-to-many relation as a HasManyList
     *
     * @param string $componentName Name of the component
     * @param string|null $filter Deprecated. A filter to be inserted into the WHERE clause
     * @param string|null|array $sort Deprecated. 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 Deprecated, use leftJoin($table, $joinClause) instead
     * @param string|null|array $limit Deprecated. 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 = null, $sort = null, $join = null, $limit = null)
    {
        $result = null;
        if (!($componentClass = $this->hasManyComponent($componentName))) {
            user_error("DataObject::getComponents(): Unknown 1-to-many component '{$componentName}'" . " on class '{$this->class}'", E_USER_ERROR);
        }
        if ($join) {
            throw new \InvalidArgumentException('The $join argument has been removed. Use leftJoin($table, $joinClause) instead.');
        }
        if ($filter !== null || $sort !== null || $limit !== null) {
            Deprecation::notice('4.0', 'The $filter, $sort and $limit parameters for DataObject::getComponents() 
				have been deprecated. Please manipluate the returned list directly.', Deprecation::SCOPE_GLOBAL);
        }
        // If we haven't been written yet, we can't save these relations, so use a list that handles this case
        if (!$this->ID) {
            if (!isset($this->unsavedRelations[$componentName])) {
                $this->unsavedRelations[$componentName] = new UnsavedRelationList($this->class, $componentName, $componentClass);
            }
            return $this->unsavedRelations[$componentName];
        }
        // Determine type and nature of foreign relation
        $joinField = $this->getRemoteJoinField($componentName, 'has_many', $polymorphic);
        if ($polymorphic) {
            $result = PolymorphicHasManyList::create($componentClass, $joinField, $this->class);
        } else {
            $result = HasManyList::create($componentClass, $joinField);
        }
        if ($this->model) {
            $result->setDataModel($this->model);
        }
        return $result->forForeignID($this->ID)->where($filter)->limit($limit)->sort($sort);
    }
 /**
  * Create a DataObject from the given SQL row
  *
  * @param array $row
  * @return DataObject
  */
 protected function createDataObject($row)
 {
     $item = parent::createDataObject($row);
     $item->setWidgetEditor($this->_widgetEditor);
     return $item;
 }
 /**
  * Returns a one-to-many relation as a HasManyList
  *
  * @param string $componentName Name of the component
  * @return HasManyList The components of the one-to-many relationship.
  */
 public function getComponents($componentName)
 {
     $result = null;
     $componentClass = $this->hasManyComponent($componentName);
     if (!$componentClass) {
         throw new InvalidArgumentException(sprintf("DataObject::getComponents(): Unknown 1-to-many component '%s' on class '%s'", $componentName, $this->class));
     }
     // If we haven't been written yet, we can't save these relations, so use a list that handles this case
     if (!$this->ID) {
         if (!isset($this->unsavedRelations[$componentName])) {
             $this->unsavedRelations[$componentName] = new UnsavedRelationList($this->class, $componentName, $componentClass);
         }
         return $this->unsavedRelations[$componentName];
     }
     // Determine type and nature of foreign relation
     $joinField = $this->getRemoteJoinField($componentName, 'has_many', $polymorphic);
     /** @var HasManyList $result */
     if ($polymorphic) {
         $result = PolymorphicHasManyList::create($componentClass, $joinField, $this->class);
     } else {
         $result = HasManyList::create($componentClass, $joinField);
     }
     if ($this->model) {
         $result->setDataModel($this->model);
     }
     return $result->setDataQueryParam($this->getInheritableQueryParams())->forForeignID($this->ID);
 }
 public function __construct($dataClass, $foreignKey)
 {
     parent::__construct($dataClass, $foreignKey);
 }