Example #1
0
 /**
  * Updates an existing Forum model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id, $action = 'dashboard')
 {
     $model = $this->findModel($id);
     $newBoard = new Board();
     if ($newBoard->load(Yii::$app->request->post())) {
         $newBoard->forum_id = $model->id;
         if ($newBoard->save()) {
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Create successfully.'));
         } else {
             Yii::$app->getSession()->setFlash('error', 'Server error.');
         }
     }
     Yii::setAlias('@upload', '@webroot/uploads/forum/icon/');
     if (Yii::$app->request->isPost && !empty($_FILES)) {
         $extension = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
         $fileName = $model->id . '_' . time() . rand(1, 10000) . '.' . $extension;
         Image::thumbnail($_FILES['file']['tmp_name'], 160, 160)->save(Yii::getAlias('@upload') . $fileName, ['quality' => 80]);
         //delete old icon
         $file_exists = file_exists(Yii::getAlias('@upload') . $model->forum_icon);
         if ($file_exists && strpos($model->forum_icon, 'default') === false) {
             @unlink(Yii::getAlias('@upload') . $model->forum_icon);
         }
         $model->forum_icon = $fileName;
         $model->update();
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate() && $model->save()) {
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Save successfully.'));
         }
     }
     return $this->render('update', ['model' => $model, 'newBoard' => $newBoard, 'action' => $action]);
 }
Example #2
0
 /**
  * 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.');
     }
 }
Example #3
0
                                    </a>
                                </div>
                                <dl style="margin-bottom:0">
                                    <dt><?php 
            echo Html::a(Html::encode($subBoard['name']), ['/forum/board/view', 'id' => $subBoard['id']]);
            ?>
</dt>
                                    <dd><?php 
            echo Html::encode($subBoard['description']);
            ?>
</dd>
                                </dl>
                            </td>
                            <td class="hidden-xs" style="width:100px;">
                                <i class="glyphicon glyphicon-comment"></i> <?php 
            echo Board::getThreadCount($subBoard['id']);
            ?>
 
                            </td>
                            <td class="hidden-xs" style="width:150px;">
                                <i class="glyphicon glyphicon-user"></i> <?php 
            echo $lastThread['username'];
            ?>
 <br>
                                <i class="glyphicon glyphicon-time"></i> <?php 
            echo Yii::$app->formatter->asRelativeTime($lastThread['created_at']);
            ?>
                            </td>
                        </tr>
                    <?php 
        }
Example #4
0
        ?>
">
                                </a>
                            </div>
                            <dl style="margin-bottom:0">
                                <dt><?php 
        echo Html::a(Html::encode($subBoard['name']), ['/forum/board/view', 'id' => $subBoard['id']]);
        ?>
</dt>
                                <dd><?php 
        echo Html::encode($subBoard['description']);
        ?>
</dd>
                            </dl>
                        </td>
                        <td class="smallFont" style="vertical-align:middle;width:220px;">
                            <?php 
        echo Board::getLastThread($subBoard['id'])['username'];
        ?>
                        </td>
                    </tr>
                <?php 
    }
    ?>
            <?php 
}
?>
        </tbody>
    </table>
</div>
Example #5
0
 /**
  * @return yii\db\ActiveQuery
  */
 public function getBoards()
 {
     return Board::find()->where('forum_id = :forum_id && (parent_id = :BOARD || parent_id = :CATEGORY)', [':forum_id' => $this->id, ':BOARD' => Board::AS_BOARD, ':CATEGORY' => Board::AS_CATEGORY])->all();
 }