/**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsContentCategories()
 {
     return $this->hasMany(CmsContentCategory::className(), ['parent_id' => 'id']);
 }
Exemplo n.º 2
0
 /**
  * get the complete media category tree as SimpleMediaCategory instances tree
  * 
  * @return \schallschlucker\simplecms\models\SimpleMediaCategory
  */
 public function getCategoryTree()
 {
     $allRowsArray = CmsContentCategory::find()->orderBy('id ASC')->asArray(true)->all();
     $associativeArray = [];
     foreach ($allRowsArray as $fieldArray) {
         /* @var $fieldArray array */
         $simpleMediaCategoryRoot = new SimpleMediaCategory();
         $simpleMediaCategoryRoot->initFromArray($fieldArray);
         $associativeArray[$fieldArray['id']] = $simpleMediaCategoryRoot;
     }
     unset($allRowsArray);
     // init root item
     if (!isset($associativeArray[MediaController::$ROOT_MEDIA_CATEGORY_ID])) {
         throw new \Exception("category root item could not be found for id = " . MediaController::$ROOT_MEDIA_CATEGORY_ID . ". Cannot build category tree");
     }
     $simpleMediaCategoryRoot = $associativeArray[MediaController::$ROOT_MEDIA_CATEGORY_ID];
     $this->fillCategoryTreeRecursive($simpleMediaCategoryRoot, $associativeArray);
     return $simpleMediaCategoryRoot;
 }