Advertisement
fernandezekiel

Untitled

Apr 11th, 2013
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /**
  5.  * Description of RestrictedController
  6.  *
  7.  * @author Web Developer
  8.  */
  9. class RestrictedController extends Controller{
  10.     //put your code here
  11.     public function actions() {
  12.         return array(
  13.             'admin' => array(
  14.                 'class' => 'ext.restricted.components.actions.admin',
  15.                 'modelClass'=>ucfirst($this->getId()),
  16.                 ),
  17.         );
  18.     }
  19.    
  20.     public function loadModel($id=null, $modelClass = null, $action = null) {
  21.         if($modelClass == null){
  22.             $modelClass = ucfirst($this->getId());
  23.         }
  24.        
  25.         if ($action == null){
  26.             $action = Yii::app()->controller->action->id;
  27.         }
  28.        
  29.         if (is_string($modelClass)) {
  30.             $model = $modelClass::model();
  31.         } else if ($modelClass instanceof CActiveRecord) {
  32.             $model = $modelClass;
  33.         }
  34.        
  35.         $model->hideSoftDeleted = false;
  36.         //$model->enableFiltering = false;
  37.        
  38.         $model = $model->findByPk($id);
  39.         if ($model == null) {
  40.              
  41.             Yii::app()->user->setFlash('danger', 'Page does not exist!');
  42.             Yii::app()->request->redirect(Yii::app()->getRequest()->getUrlReferrer());
  43.             // echo Yii::app()->getRequest()->getUrlReferrer();
  44.             //Yii::app()->end();
  45.         }
  46.         $accessTerms = $model->accessTerms;
  47.         $authItem = RestrictedActiveRecord::createAuthItem($action, $accessTerms['ownAccessTerm'], get_class($model));
  48.        
  49.        
  50.         if($model::mayGenerally($model, $action)){
  51.             Yii::app()->user->setFlash('info', "You may generally $action this item " . get_class($model));
  52.            // Yii::app()->end();
  53.         }
  54.         else if ($model->owner_id != Yii::app()->user->id && Yii::app()->user->checkAccess($authItem)) {
  55.  
  56.             Yii::app()->user->setFlash('danger', 'You are not permitted to view this ' . get_class($model));
  57.             $this->redirect(Yii::app()->getRequest()->getUrlReferrer());
  58.         }
  59.        
  60.        if ($model->deleted){
  61.            Yii::app()->user->setFlash('warning', "this $modelClass is no longer active (deleted)");
  62.        }
  63.        
  64.         return $model;
  65.        
  66.     }
  67. }
  68.  
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement