Ejemplo n.º 1
0
 public function actionView($userid = 0, $catid = 0, $viewid)
 {
     $category = [];
     $read = BlogRecords::findOne(['id' => $viewid]);
     if ($catid != 0) {
         $category = BlogCategories::findOne(['id' => $catid]);
     }
     return $this->render('view', ['record' => $read, 'userid' => $userid, 'category' => $category]);
 }
Ejemplo n.º 2
0
 /**
  * Generate categories tree
  * @param int $parent parend ID, default 0
  * @param int $user_id user ID, default 0
  * @return array recursive array tree
  */
 public static function getCategoriesTree($parent = 0, $user_id = 0)
 {
     $out = [];
     $categories = self::findAll(['parent_id' => $parent, 'user_id' => $user_id]);
     foreach ($categories as $category) {
         $count = BlogRecords::find()->where(['category_id' => $category->id, 'author_id' => $category->user_id])->count();
         $out[$category->id] = ['title' => $category->title, 'user_id' => $category->user_id, 'records_count' => (int) $count];
         $childs = self::getCategoriesTree($category->id, $user_id);
         if (!empty($childs)) {
             $out[$category->id]['childs'] = $childs;
         }
     }
     return $out;
 }