<?php
class DefaultController extends FrontEndController {
public function accessRules() {
return CMap::mergeArray(array(
array('allow',
'actions' => array('index', 'recentTopics', 'participationTopics', 'userTopics'),
'users' => array('@'),
),
), parent::accessRules());
}
/**
* List of forums
*/
public function actionIndex() {
$model = false;
if (Yii::app()->user->checkAccess('forums.forum.createForum')) {
$model = new Forum('create');
if (isset($_POST[CHtml::modelName($model)])) {
$model->attributes = $_POST[CHtml::modelName($model)];
if ($model->validate()) {
if ($model->save()) {
Yii::app()->user->setAlert(Yii::t('Forums', 'Forum created'), 'success');
$this->refresh(array('index'));
}
}
}
}
$this->render('index', array(
'forums' => new CActiveDataProvider(Forum::model(), array('pagination' => false)),
'model' => $model,
));
}
/**
* Shows recently updated topics
*/
public function actionRecentTopics() {
$this->render('recent', array(
'topics' => new CActiveDataProvider(Topic::model(), array('criteria' => array(
// 'with' => array('section', 'section.forum'),
'order' => 't.updated_at',
))),
));
}
/**
* Shows topics I participated
*/
public function actionParticipationTopics() {
$this->render('participationTopics', array(
'topics' => new CActiveDataProvider(Topic::model(), array('criteria' => array(
'condition' => '(SELECT COUNT(*) FROM '.TopicPost::model()->tableName().' WHERE `topic_id` = `t`.`id` AND `author_id` = :user_id) > 0',
'params' => array(':user_id' => Yii::app()->user->record->id),
'order' => 't.updated_at',
))),
));
}
/**
* Shows topics I created
*/
public function actionUserTopics($user = null) {
if (empty($user))
$user = $this->webUser;
elseif (($user = User::model()->findByPk($user)) === null)
throw new CHttpException(404, 'Invalid User!');
$this->render('userTopics', array(
'user' => $user,
'topics' => new CActiveDataProvider(Topic::model(), array('criteria' => array(
'condition' => 'initiator_id = :initiator_id',
'params' => array(':initiator_id' => $user->id),
'order' => 't.updated_at',
))),
));
}
}