Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Description of RestrictedController
- *
- * @author Web Developer
- */
- class RestrictedController extends Controller{
- //put your code here
- public function actions() {
- return array(
- 'admin' => array(
- 'class' => 'ext.restricted.components.actions.admin',
- 'modelClass'=>ucfirst($this->getId()),
- ),
- );
- }
- public function loadModel($id=null, $modelClass = null, $action = null) {
- if($modelClass == null){
- $modelClass = ucfirst($this->getId());
- }
- if ($action == null){
- $action = Yii::app()->controller->action->id;
- }
- if (is_string($modelClass)) {
- $model = $modelClass::model();
- } else if ($modelClass instanceof CActiveRecord) {
- $model = $modelClass;
- }
- $model->hideSoftDeleted = false;
- //$model->enableFiltering = false;
- $model = $model->findByPk($id);
- if ($model == null) {
- Yii::app()->user->setFlash('danger', 'Page does not exist!');
- Yii::app()->request->redirect(Yii::app()->getRequest()->getUrlReferrer());
- // echo Yii::app()->getRequest()->getUrlReferrer();
- //Yii::app()->end();
- }
- $accessTerms = $model->accessTerms;
- $authItem = RestrictedActiveRecord::createAuthItem($action, $accessTerms['ownAccessTerm'], get_class($model));
- if($model::mayGenerally($model, $action)){
- Yii::app()->user->setFlash('info', "You may generally $action this item " . get_class($model));
- // Yii::app()->end();
- }
- else if ($model->owner_id != Yii::app()->user->id && Yii::app()->user->checkAccess($authItem)) {
- Yii::app()->user->setFlash('danger', 'You are not permitted to view this ' . get_class($model));
- $this->redirect(Yii::app()->getRequest()->getUrlReferrer());
- }
- if ($model->deleted){
- Yii::app()->user->setFlash('warning', "this $modelClass is no longer active (deleted)");
- }
- return $model;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement