View file vkclone-0.0.1/protected/modules/publics/controllers/PostController.php

File size: 1.47Kb
<?php
class PostController extends FrontEndController {
	public $public;
	public $post;

	public function behaviors() {
		return array(
			'crud' => array(
				'class' => 'application.components.CrudControllerBehavior',
				'modelClass' => 'PublicPost',

				'updateSuccessfullAlert' => Yii::t('Publics', 'Post has been changed'),
				'deleteSuccessfullAlert' => Yii::t('Publics', 'Post deleted'),
				'deleteFailureAlert' => Yii::t('Publics', 'Can not delete post'),

				'deleteContinueUrl' => function (PublicPost $post) { return array('public/index', 'id' => $post->public_id); },
			),
		);
	}

	public function accessRules() {
		return CMap::mergeArray(parent::accessRules(), array(
			array('allow',
				'actions' => array('update', 'confirm', 'delete'),
				'expression' => 'Yii::app()->controller->crud->model->public->checkAccess(PublicReader::MODERATOR)',
			),
		));
	}

	/**
	 * Updates post
	 */
	public function actionUpdate() {
		$model = $this->crud->model;
		$model->setScenario('update');
		$model->update_datetime = new CDbExpression('NOW()');
		$model->editor_id = $this->webUser->id;

		if (isset($_POST[CHtml::modelName($model)])) {
			$model->attributes = $_POST[CHtml::modelName($model)];
			if ($model->validate() && $model->save()) {
				Yii::app()->user->setAlert(Yii::t('Publics', 'Post has been changed'), 'success');
				$this->redirect(array('public/index', 'id' => $this->crud->model->public_id));
			}
		}

		$this->render('edit', array(
			'model' => $model,
		));
	}
}