public function getIsEmpty() { $count = Categories::find()->where(['parent_id' => $this->id])->count(); if ($count == 0) { $count = Resources::find()->where(['category_id' => $this->id])->count(); } return $count == 0; }
/** ** Вывод списка страниц. Если задан $id категории - списка страниц категории */ public function actionList($id = 0) { $q = Resources::find(); if ($id > 0) { $q->where(['category_id' => $id]); } else { $q->joinWith('category')->where(['categories.handler' => $this->id]); } $dataProvider = new ActiveDataProvider(['query' => $q, 'pagination' => false]); return $this->render('list', ['category' => Categories::findOne($id), 'dataProvider' => $dataProvider, 'category_id' => $id]); }
public function actionList($id) { if ($id == 0) { throw new \yii\web\BadRequestHttpException("Неправильный запрос"); } $q = Resources::find()->where(['category_id' => $id]); $dataProvider = new ActiveDataProvider(['query' => $q]); $uploadModel = new FileUploadModel(); $uploadModel->id = $id; return $this->render('list', ['dataProvider' => $dataProvider, 'album' => Categories::findOne($id), 'uploadModel' => $uploadModel]); }
/** * Store a newly created ResourceLike in storage. * POST /resourceLikes * * @param Request $request * * @return Response */ public function store(Request $request) { if (sizeof(ResourceLike::$rules) > 0) { $this->validateRequestOrFail($request, ResourceLike::$rules); } $input = $request->all(); $resourceLikes = $this->resourceLikeRepository->create($input); $resource = Resources::find($input['postId']); if ($resource) { $resource->likes = $resource->likes + 1; $resource->update(); } else { return response()->json("Invalid Resources Id!", 400); } return response()->json($resource->likes); }
public static function findByAlias($alias, $cat_id = 0) { return Resources::find()->where(['alias' => $alias])->andWhere(['category_id' => $cat_id])->one(); }
public function share($id, Request $request) { $post_type = $request->input('postType'); switch ($post_type) { case 'Post': $post = Post::find($id); if ($post) { $post->share_count = $post->share_count + 1; $post->update(); return response()->json($post->share_count); } break; case 'iWomenPost': $post = IwomenPost::find($id); if ($post) { $post->share_count = $post->share_count + 1; $post->update(); return response()->json($post->share_count); } break; case 'Resources': $post = Resources::find($id); if ($post) { $post->share_count = $post->share_count + 1; $post->update(); return response()->json($post->share_count); } break; case 'SubResourceDetail': $post = SubResourceDetail::find($id); if ($post) { $post->share_count = $post->share_count + 1; $post->update(); return response()->json($post->share_count); } break; default: # code... break; } return response()->json("Successfully shared your post!"); }
/** * TODO */ public function actionIndex($id) { $album = $this->findAlbum($id); $images = Resources::find()->where(['category_id' => $id])->all(); return $this->render('index', ['album' => $album, 'images' => $images]); }