public function actionUserblog($catid = 0, $userid = 0) { $category = []; $dataProvider = new ActiveDataProvider(['query' => BlogRecords::find()->where(['author_id' => $userid, 'category_id' => $catid]), 'pagination' => array('pageSize' => 12), 'sort' => ['defaultOrder' => ['date' => SORT_DESC]]]); if ($catid != 0) { $category = BlogCategories::findOne(['id' => $catid]); } return $this->render('userblog', ['records' => $dataProvider, 'pagination' => $dataProvider->pagination, 'category' => $category]); }
/** * 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; }