Пример #1
0
 /**
  * Creates a new operation
  * @param string $assignTo The slug of the auth item to assign this to after saving, if any.
  */
 public function actionCreate($assignTo = null)
 {
     $model = new AAuthOperation();
     $this->performAjaxValidation($model);
     if (isset($_POST['AAuthOperation'])) {
         $model->attributes = $_POST['AAuthOperation'];
         if ($model->save()) {
             Yii::app()->user->setFlash("success", "<h3>Operation added successfully</h3>");
             if ($assignTo !== null) {
                 $parent = AAuthItem::model()->findBySlug($assignTo);
                 if (is_object($parent)) {
                     Yii::app()->authManager->addItemChild($parent->name, $model->name);
                     switch (get_class($parent)) {
                         case "AAuthOperation":
                             $this->redirect(array("operation/view", "slug" => $parent->slug));
                             break;
                         case "AAuthTask":
                             $this->redirect(array("task/view", "slug" => $parent->slug));
                             break;
                         case "AAuthRole":
                             $this->redirect(array("role/view", "slug" => $parent->slug));
                             break;
                     }
                 }
             }
             $this->redirect(array("view", "slug" => $model->slug));
         }
     }
     $this->render("create", array("model" => $model));
 }
Пример #2
0
 /**
  * Returns the static model of the specified AR class.
  * @param string $className the class name to instantiate
  * @return AAuthTask the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
Пример #3
0
 /**
  * Gets a summary of the access rights for this item
  * @return string the access summary html
  */
 public function getSummary()
 {
     $summary = array();
     $all = $this->getChildren();
     if (!count($all)) {
         return "<li>" . $this->description . "<br /></li>";
     }
     foreach ($all as $item) {
         if ($item->type == self::AUTH_OPERATION) {
             $line = "<li>" . $item->description . "<br /></li>";
         } else {
             $children = Yii::app()->authManager->getItemChildren($item->name);
             if (count($children)) {
                 $line = "<li>" . $item->description . "<br /><ul>";
                 foreach ($children as $child) {
                     $line .= AAuthItem::model()->findByPk($child->name)->getSummary();
                 }
                 $line .= "</ul>";
             } else {
                 $line = "<li>" . $item->description . "<br />";
             }
             $line .= "</li>";
         }
         $summary[] = $line;
     }
     return "<li>" . $this->description . "<br /><ul style='padding-left:10px;'>" . implode("\n", $summary) . "</ul><br /></li>";
 }
Пример #4
0
    them.</p>

<div class='grid_6 alpha'>
    <h4>Selected Operations</h4>

    <p>These operations belong to this task.</p>
    <?php 
$csrfData = json_encode(array(Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken));
$ajax = CHtml::ajax(array("url" => array("setOperations", "slug" => $model->slug), "type" => "POST", "data" => 'js:(function(){
									var data = ' . $csrfData . ';
									data.operations = $("#selectedOperations").sortable("toArray");
									return data;
								}())', "success" => "function(res){\r\n\t\t\t\t\t\t\t\t\t\$('#unselectedOperations li.ui-state-highlight').\r\n\t\t\t\t\t\t\t\t\t\tremoveClass('ui-state-highlight').\r\n\t\t\t\t\t\t\t\t\t\taddClass('ui-state-default');\r\n\t\t\t\t\t\t\t\t\t\$('#selectedOperations li.ui-state-default').\r\n\t\t\t\t\t\t\t\t\t\tremoveClass('ui-state-default').\r\n\t\t\t\t\t\t\t\t\t\taddClass('ui-state-highlight');\r\n\t\t\t\t\t\t\t\t}"));
$selectedOperations = array();
foreach ($model->getChildren(AAuthItem::AUTH_OPERATION) as $item) {
    $item = AAuthItem::model()->findByPk($item->name);
    $selectedOperations[$item->name] = CHtml::link($item->name, array("operation/view", "name" => $item->name), array("title" => $item->description));
}
$unselectedOperations = array();
foreach (AAuthOperation::model()->findAll() as $item) {
    if (isset($selectedOperations[$item->name])) {
        continue;
    }
    $unselectedOperations[$item->name] = CHtml::link($item->name, array("operation/view", "name" => $item->name), array("title" => $item->description));
}
$this->widget('zii.widgets.jui.CJuiSortable', array('id' => "selectedOperations", 'itemTemplate' => '<li id="{id}" class="ui-state-highlight"><span class="ui-icon ui-icon-arrowthick-2-e-w left"></span>&nbsp;&nbsp;{content}</li>', 'items' => $selectedOperations, 'options' => array('connectWith' => '#unselectedOperations', 'update' => 'js:function(event,ui){ ' . $ajax . ' }', 'delay' => 300)));
?>
</div>
<div class='grid_6 omega'>
    <h4>Unselected Operations</h4>