public function search($params) { $query = Board::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'threads' => $this->threads, 'posts' => $this->posts]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Activates the Board for the current User. This means the selected board is made * available globally via cookies and(or) sessions */ public function actionActivate() { $session = Yii::$app->session; $request = Yii::$app->request; $activeBoardId = $request->get('id'); $session->set('currentBoardId', $activeBoardId); $boardRecord = Board::getActiveboard(); $session->setFlash('success', 'Board activated: ' . $boardRecord->title); Yii::$app->params['title'] = $boardRecord->title; $this->goHome(); }
public function buildSubBoards($id = 0, $parentName = '子板块') { $subBoards = Board::findAll(['parent_id' => $id], 'sort_num desc'); $totalRecords = count($subBoards); if ($totalRecords == 0) { return; } $html = ''; $parentBoard = $this->getCachedBoards()[$id]; $columnsCount = intval($parentBoard['columns']); if ($parentName == null) { $parentName = $parentBoard['name']; } $html .= '<div class="tbox border">'; $html .= '<div class="hd" style="border-bottom:none;"><h2>' . $parentName . '</h2></div>'; $html .= '<table class="table" style="margin-bottom:0px;">'; if ($columnsCount > 1) { $html .= $this->getMoreColumn($subBoards, $totalRecords, $columnsCount); } else { $html .= $this->getOneColumn($subBoards, $totalRecords); } $html .= '</table>'; $html .= '</div>'; return $html; }
/** * * todo: as of 20-Apr-2015 this method is not used, perhaps it could be removed * * @return \yii\db\ActiveRecord */ public function getBoard() { return $this->hasOne(Board::className(), ['id' => 'board_id'])->one(); }
/** * Finds the Board model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $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 static function createCache() { $newLine = "\r\n"; $content = '<?php' . $newLine; $channels = Board::find()->all(); foreach ($channels as $row) { $id = $row['id']; $content .= '$cachedBoards[' . $row['id'] . ']=[' . $newLine; $content .= Board::getCacheItem('id', $row, true); $content .= Board::getCacheItem('parent_id', $row, true); $parentIds = Board::getParentIds($id); $content .= Board::getCacheItemValue('parent_ids', implode(',', $parentIds)); $content .= Board::getCacheItem('name', $row); $content .= Board::getCacheItem('icon', $row); $content .= Board::getCacheItem('description', $row); $content .= Board::getCacheItem('rule', $row); $content .= Board::getCacheItem('columns', $row, true); $content .= Board::getCacheItem('sort_num', $row, true); $content .= Board::getCacheItem('redirect_url', $row); $content .= Board::getCacheItem('target', $row); $content .= Board::getCacheItemValue('level', count($parentIds) - 1, true); $content .= "];" . $newLine; } $dataRoot = \Yii::getAlias('@data'); TFileHelper::writeFile([$dataRoot, 'cache', 'cachedBoards.php'], $content); }
/** * Returns a list of all users who are associated with the current active board. */ public static function getBoardUsers() { return self::find()->where(Board::getActiveboard()->id . ' in (board_id)')->all(); }
public function actionNewPost() { if (!YiiForum::checkAuth('post_add')) { return $this->noPermission(); } YiiForum::checkIsGuest(); $post = new Post(); $threadId = YiiForum::getGetValue('threadid'); $data = YiiForum::getPostValue('Post'); if ($data == null) { $thread = Thread::findOne(['id' => $threadId]); $locals = []; $locals['thread'] = $thread; $locals['currentBoard'] = $this->getBoard($thread['board_id']); $locals['model'] = $post; return $this->render('new-post', $locals); } $boardId = $data['board_id']; $threadId = $data['thread_id']; $threadTitle = $data['thread_title']; $post->thread_id = $threadId; $post->user_id = YiiForum::getIdentity()->id; $post->user_name = YiiForum::getIdentity()->username; $post->title = isset($data['title']) ? $data['title'] : ''; $post->body = $data['body']; $post->create_time = TTimeHelper::getCurrentTime(); $post->modify_time = TTimeHelper::getCurrentTime(); $post->supports = 0; $post->againsts = 0; $post->floor = 0; $post->note = ''; if ($post->save()) { Thread::updateLastData($threadId); Board::updateLastData($boardId, $threadId, $threadTitle, false); } return $this->redirect(['view', 'id' => $threadId]); }
public function getBoard($id, $fromCache = True) { if ($fromCache) { $cahcedBoards = $this->getCachedBoards(); return $cahcedBoards[$id]; } return Board::findOne(['id' => $id]); }