/** @inheritdoc */ public function __construct(RenderInterface $renderer, QueryInterface $query, Record $entity, Navigation $structure) { $this->name = $structure->Name; $this->id .= $structure->Url != '' ? '_' . $structure->Url : '_' . $structure->Name; $this->structure = $structure; $this->entity = $entity; $rows = $query->entity(Material::class)->where(Material::F_PARENT, $entity->id)->where(Material::F_DELETION, true)->fields(Material::F_PRIMARY); if (count($rows)) { $this->size = $query->entity(NavigationMaterial::class)->where(NavigationMaterial::F_MATERIALID, $rows)->where(NavigationMaterial::F_STRUCTUREID, $structure->id)->where(NavigationMaterial::F_ACTIVE, true)->count(); } // Get data about current tab $fieldWithMaterialCount = $query->entity(NavigationField::class)->join('field')->where('field_Type', 6)->where(NavigationField::F_STRUCTURE, $this->structure->id)->count(); $localizedFieldsCount = $query->entity(NavigationField::class)->join('field')->where('field_local', 1)->where(NavigationField::F_STRUCTURE, $this->structure->id)->count(); // If in this tab exists only material type field or don't exists localized fields if ($fieldWithMaterialCount > 0 || $localizedFieldsCount == 0) { // Create default sub tab $this->subTabs[] = new MaterialTableLocalized($renderer, $query, $entity, $structure, ''); // If in this tab exists not material type fields and this fields localized then include their } else { //if (($fieldWithMaterialCount == 0) && ($localizedFieldsCount > 0)) // Iterate available locales if we have localized fields foreach (SamsonLocale::$locales as $locale) { // Create child tab $subTab = new MaterialTableLocalized($renderer, $query, $entity, $structure, $locale); $this->subTabs[] = $subTab; } } // Call parent constructor to define all class fields parent::__construct($renderer, $query, $entity); }
/** * Get material entity by URL(s). * * @param QueryInterface $query Object for performing database queries * @param array|string $url Material URL or collection of material URLs * @param self|array|null $return Variable where request result would be returned * @return bool|self True if material entities has been found */ public static function byUrl(QueryInterface $query, $url, &$return = array()) { // Get entities by filtered identifiers $return = $query->entity(get_called_class())->where('Url', $url)->where('Active', 1)->first(); // If only one argument is passed - return null, otherwise bool return func_num_args() > 2 ? $return !== null : $return; }
/** * Render entities collection * @return array Asynchronous response array */ public function __async_collection($page = 1) { // Create entities collection from defined parameters $entitiesCollection = new $this->collectionClass($this, $this->query->entity($this->entity), new Pager($page, $this->pageSize, $this->id . '/collection')); // Generate Asynchronous response array return array_merge(array('status' => 1), $entitiesCollection->toView('collection_')); }
/** * Find additional field value database record by its material and field identifiers. * This is generic method that should be used in nested classes to find its * records by some its primary key value. * * @param QueryInterface $query Query object instance * @param string $materialID Material identifier * @param string $fieldID Additional field identifier * @param mixed $return Variable to return found database record * @param string $locale Locale identifier * @return bool|null|self Field instance or null if 3rd parameter not passed */ public static function byFieldIDAndMaterialID(QueryInterface $query, $materialID, $fieldID, &$return = null, $locale = null) { $return = $query->entity(get_called_class())->where(Material::F_PRIMARY, $materialID)->where(Field::F_PRIMARY, $fieldID)->where(self::F_LOCALE, $locale)->where(Material::F_DELETION, 1)->exec(); // If only one argument is passed - return null, otherwise bool return func_num_args() > 3 ? sizeof($return) : $return; }
/** * Generic collection constructor * * @param RenderInterface $renderer View render object * @param QueryInterface $query Query object */ public function __construct(RenderInterface $renderer, QueryInterface $query, PagerInterface $pager) { // Call parent initialization parent::__construct($renderer, $query->entity('\\samson\\activerecord\\material'), $pager); }
/** * Find additional field database record by Name or ID. * This is generic method that should be used in nested classes to find its * records by some its primary key value. * * @param QueryInterface $query Query object instance * @param string $nameOrID Additional field name or identifier * @param self $return Variable to return found database record * *@return bool|null|self Field instance or null if 3rd parameter not passed */ public static function byNameOrID(QueryInterface $query, $nameOrID, self &$return = null) { // Create id or URL condition $idOrUrl = new Condition('OR'); $idOrUrl->add('FieldID', $nameOrID)->add('Name', $nameOrID); // Perform query $return = $query->entity(get_called_class())->whereCondition($idOrUrl)->first(); // If only one argument is passed - return null, otherwise bool return func_num_args() > 1 ? $return == null : $return; }