/** * TODO: In future models will have more relations which might not delete automatically. It should be tested properly * TODO: Files should be deleted too * Deletes all boards, threads and posts with 'is_deleted = 1', handles relation between them. * @return array with deleted rows */ public static function clean() { $itemsToDelete = ['boardsIds' => [], 'threadsIds' => [], 'postsIds' => [], 'postDataIds' => [], 'postMessageIds' => []]; Post::getDeletedRows($itemsToDelete); Thread::getDeletedRows($itemsToDelete); Board::getDeletedRows($itemsToDelete); self::getPostDataIds($itemsToDelete); self::getPostMessageIds($itemsToDelete); /** * Deletes post_message's related to threads and posts */ $deleted['post_messages'] = PostMessage::deleteAll(['in', 'id', array_unique($itemsToDelete['postMessageIds'])]); /** * Deletes threads and posts because of FK */ $deleted['threads'] = Thread::deleteAll(['in', 'id', array_unique($itemsToDelete['threadsIds'])]); /** * Deleted posts and threads related to post_data */ $deleted['post_data'] = PostData::deleteAll(['in', 'id', array_unique($itemsToDelete['postDataIds'])]); /** * Deleted boards */ $deleted['boards'] = Board::deleteAll(['in', 'id', array_unique($itemsToDelete['boardsIds'])]); $deleted['posts'] = $deleted['post_data'] - $deleted['threads']; $deleted['total'] = $deleted['boards'] + $deleted['threads'] + $deleted['posts'] + $deleted['post_data'] + $deleted['post_messages']; return $deleted; }
public function beforeAction($action) { $request = \Yii::$app->urlManager->parseRequest(\Yii::$app->request); $board = Board::findOne(['name' => $request[1]['name']]); $thread = isset($request[1]['threadNum']) ? Thread::findOne($request[1]['threadNum']) : null; $ban = new Ban($board, $thread); return $ban->check(); }
public static function getProfile($user_id) { $number_of_following = FollowEvent::countFollowing($user_id); $number_of_follower = FollowEvent::countFollower($user_id); $number_of_boards = Board::countBoardsByUserId($user_id); $number_of_posts = Post::countPostsByUserId($user_id); return array("number_of_posts" => $number_of_posts, "number_of_boards" => $number_of_boards, "number_of_follower" => $number_of_follower, "number_of_following" => $number_of_following); }
public static function getBoardById($board_id) { $result["board"] = Board::where('board_id', $board_id)->first(); $result["posts"] = UserPosts::where('board_id', $board_id)->get(); $result["board"]["cover_link"] = $result["posts"][0]["photo_link"]; $result["profile"]["number_of_posts"] = Post::where('board_id', $board_id)->count(); $result["profile"]["number_of_following"] = FollowEvent::countFollower($board_id); return $result; }
public function searchRecentBoard($params, $size) { $query = Board::find()->orderBy(['created_at' => SORT_DESC]); $dataProvider->sort->attributes['id'] = ['asc' => ['id' => SORT_ASC], 'desc' => ['id' => SORT_DESC]]; $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => $size]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } return $dataProvider; }
public function delMember($id) { if (!Auth::check()) { return redirect("/"); } $memberID = \Input::get('memberID'); $member = Membermanagement::find($memberID); $member->active = 1; $member->save(); $board = Board::find($id); $boardManager = $board->manager_id; $MemMa = Membermanagement::where('User_id', '=', $boardManager)->where('Board_id', '=', $id)->get(); $cards = Card::where('MemberManagement_id', '=', $member->id)->get(); foreach ($cards as $card) { $card->MemberManagement_id = $MemMa[0]->id; $card->save(); } return redirect("member/{$id}"); }
public function create(string $boardName, array $data) { /** @var Board $board */ if (!($board = Board::findOne(['name' => $boardName]))) { throw new UserException('Board was not found', 404); } $validationParams = $board->postsSettings->getValidationParams(); $thread = new Thread(['boardId' => $board->id]); $postData = new PostData(['validationParams' => $validationParams]); $uploadForm = new UploadForm(['files' => PostedFile::getPostedFiles($validationParams['maxFiles']), 'validationParams' => $validationParams]); $toLoad = [$thread, $postData]; $toValidate = [$thread, $postData, $uploadForm]; if (!ARExtended::loadMultiple($toLoad, $data) || !Model::validateMultiple($toValidate)) { throw new UserException('Failed to load/validate data', 400); } if (strlen($postData->messageText) == 0 && count($uploadForm->files)) { throw new UserException('Must be attached atleast 1 file or non-empty message', 400); } $toSave = [$postData, $thread, $uploadForm]; $postData->on(PostData::EVENT_AFTER_INSERT, function ($event) use($thread) { $thread->postDataId = $event->sender->id; }); $saved = true; foreach ($toSave as $model) { if (method_exists($model, 'save')) { $saved = $saved && $model->save(); if (!$saved) { break; } } } if (!$saved) { for ($i = count($toSave) - 1; $i >= 0; $i--) { method_exists($toSave[$i], 'delete') && $toSave[$i]->delete(); } throw new UserException('Failed to create thread', 500); } foreach ($uploadForm->getFileInfos() as $fileInfo) { $postData->link('fileInfos', $fileInfo); } $thread->link('board', $board); return $thread; }
public function init() { parent::init(); $this->user = \Yii::$app->user->identity; $actionParams = \Yii::$app->urlManager->parseRequest(\Yii::$app->request)[1]; if (!isset($actionParams['name'])) { return; } $name = $actionParams['name']; $board = Board::find()->where(['name' => $name])->one(); if (!$board) { return; } $this->boardRights = $this->user->getBoardRights($board->id)->one(); if (!isset($actionParams['threadNum'])) { return; } $threadNum = $actionParams['threadNum']; $thread = $board->getThreads()->where(['number' => $threadNum])->one(); $this->threadChatRights = $this->user->getThreadChatRights($thread->id)->one(); }
public function countBoard() { $count = count(Board::find()->all()); return $count; }
public function actionWriteBoard($data) { if (Yii::$app->request->isAjax && !Yii::$app->user->isGuest) { Yii::$app->response->format = Response::FORMAT_JSON; $object = json_decode($data); $content = Html::encode($object->msg); if (!empty(trim($object->msg))) { $board = new Board(); $board->content = $content; $board->posted_by = Yii::$app->user->identity->id; $board->save(); if ($board->save()) { return array('boardSave' => true); } } } }
/** * Deletes board * @param $name */ public function actionDelete($name) { $board = Board::find()->where(['name' => $name])->limit(1)->one(); if ($board) { $board->isDeleted = true; $board->save(); } \Yii::$app->response->setStatusCode(204); }
public function insert() { $allUser = User::all(); $params = ['body' => []]; for ($i = 0; $i < count($allUser); $i++) { SearchController::insertUser($allUser[$i]); } $allUser = Post::all(); $params = ['body' => []]; for ($i = 0; $i < count($allUser); $i++) { SearchController::insertPost($allUser[$i]); } $allUser = Board::all(); $params = ['body' => []]; for ($i = 0; $i < count($allUser); $i++) { SearchController::insertBoard($allUser[$i]); } }
public function getCurrentBoardCards() { $board = Board::with(['members'])->find(session()->get('idForGantt')); return $board->cards()->with([])->get(); }
public function removeCard() { if (!Auth::check()) { return redirect("/"); } $reCard = Card::find($cardId); $board = Board::find($reCard->Board_id); if (Auth::user()->id != $Board->manager_id) { return redirect("/"); } $cardId = Input::get('card'); $check = Checklist::where('Card_id', '=', $cardId); $check->delete(); $com = Comment::where('Card_id', '=', $cardId); $com->delete(); $reCard->delete(); return $cardId; }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($post_id) { // $post = $this->getPostDetail($post_id)[0]; $post_stat = $this->getPostDetail($post_id)[1]; if (Auth::check()) { $post["liked"] = LikeEvent::checkLiked($post["post_id"], Auth::user()->user_id); } $post["comments"] = Post::getCommentsByPostId($post_id); $post["likes"] = $post_stat["likes"]; $post["pins"] = $post_stat["pins"]; $post["boards"] = Board::getPostsInBoard($post["board_id"]); $post["places"] = Place::getPlaceById(Post::getPostById($post_id)['place_id']); $recommend = new RecommendController(); $post["recommend_posts"] = $recommend->getPost($post_id); return response()->json($post); }
public function getUser($user_name) { $user = User::getUserByName($user_name); if (Auth::check()) { $current_user_id = Auth::user()->user_id; $bool = FollowEvent::checkFollowed($current_user_id, $user["user_id"]); if ($bool == true) { $user["follow"] = "true"; } } $id = $user->user_id; $list = UserPosts::getPostByUserId($id); $profile = User::getProfile($id); $boards = Board::getPreviewBoardsByUserId($id); $followers = FollowEvent::getFollower($id); $following = FollowEvent::getFollowing($id); if ($user) { return response()->view('profile', ["user" => $user, "posts" => $list, "profile" => $profile, "boards" => $boards, "followers" => $followers, "followings" => $following]); } else { return response()->json("Not found"); } }
public static function getBoardById($board_id) { $board = Board::where("board_id", $board_id)->first(); $board["preview"] = Board::getPreviewBoard($board_id); return $board; }
/** * Finds the Board model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Board the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Board::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getDataMember() { if (!Auth::check()) { return redirect("/"); } $user = User::find(Auth::user()->id); $board = Board::with([])->find(session()->get('Board')); $data['user'] = $user; $data['board'] = $board; return $data; }
public function getBoard() { return $this->hasOne(Board::className(), ['id' => 'board_id']); }
public function __toString() { // TODO: Implement __toString() method. //Form: {{username}} {{action}} {{object}} //Nhuan likes your post //Tung follow you $noti = ""; $action = ""; $username = ""; $type = ""; if ($this["type"] == FOLLOW) { $action = " follow "; if ($this["objectType"] == USER) { $type = " you "; } else { $board_title = Board::getBoardById($this->objectID)["board_title"]; $type = " your board " . ' ' . $board_title; } } else { $type = "your post "; if ($this["type"] == LIKE) { $action = " liked "; } else { if ($this["type"] == COMMENT) { $action = " comment on "; } else { if ($this["type"] == PIN) { $action = " pinned "; } } } } if (isset($this["sender_id"])) { $username = User::getUserById($this["sender_id"])["name"]; } else { $username = $this["sender_string"]; } $noti = $username . $action . $type; return $noti; }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // $result = Board::getBoardById($id); return response()->json($result); }