Просмотр файла vkclone-0.0.1/protected/modules/gallery/controllers/AlbumController.php

Размер файла: 1.99Kb
<?php
class AlbumController extends FrontEndController {
	public function behaviors() {
		return array(
			'crud' => array(
				'class' => 'application.components.CrudControllerBehavior',
				'modelClass' => 'GalleryAlbum',

				'updateSuccessfullAlert' => Yii::t('Gallery', 'Album settings changed'),
				'deleteSuccessfullAlert' => Yii::t('Gallery', 'Album deleted'),
				'deleteFailureAlert' => Yii::t('Gallery', 'Can not delete album'),

				'deleteContinueUrl' => array('default/index'),
			),
		);
	}

	public function accessRules() {
		return CMap::mergeArray(array(
			array('allow',
				'actions' => array('index'),
				'users' => array('@'),
			),
			array('allow',
				'actions' => array('update'),
				'roles' => array('gallery.album.updateAlbum', 'author' => array('author' => $this->crud->model->user->id)),
			),
			array('allow',
				'actions' => array('confirm', 'delete'),
				'roles' => array('gallery.album.deleteAlbum', 'author' => array('author' => $this->crud->model->user->id)),
			),
		), parent::accessRules());
	}

	public $album;

	public function filters() {
		return CMap::mergeArray(parent::filters(), array(
			// array('ext.RetrieveRecordFilter.RetrieveRecordFilter - index', 'param' => 'id', 'attribute' => 'album', 'model' => 'GalleryAlbum', 'message' => 'Invalid GalleryAlbum!', 'filter' => array($this, 'filterGalleryAlbum')),
			// 'owner + upload, edit, confirm, delete',
			'postOnly + delete',
		));
	}



	/**
	 * Shows album
	 */
	public function actionIndex() {
		$this->render('index', array(
			'album' => $this->crud->model,
			'photos' => new CActiveDataProvider(GalleryPhoto::model(), array(
				'criteria' => array(
					'condition' => 'album_id = :album_id',
					'params' => array(':album_id' => $this->crud->model->id),
				),
			)),
		));
	}

	// /**
	//  * Filters owner
	//  */
	// public function filterOwner($filterChain) {
	// 	if ($this->album->user_id == Yii::app()->user->record->id)
	// 		$filterChain->run();
	// 	else
	// 		$this->redirect(Yii::app()->homeUrl);
	// }

}