예제 #1
0
 public static function actionUserRolesSelector($name, CModel $model)
 {
     $values = CStaffManager::getAllUserRolesList();
     $selectValues = CStaffManager::getAccessLevelsList();
     $selectValues[0] = " -- Нет доступа --";
     $submodelName = "";
     if (strpos($name, "[") !== false) {
         $submodelName = substr($name, 0, strpos($name, "["));
         $name = substr($name, strpos($name, "[") + 1);
         $name = substr($name, 0, strlen($name) - 1);
         $model = $model->{$submodelName};
     }
     $roles = $model->{$name};
     foreach ($values as $key => $value) {
         $level = 0;
         $hasRole = false;
         if ($roles->hasElement($key)) {
             $hasRole = true;
             $level = ACCESS_LEVEL_READ_OWN_ONLY;
             $role = $roles->getItem($key);
             /**
             * Конкретному пользователю можно запретить
             * доступ к конкретной задаче
             *
                             if ($role->level > 0) {
                $level = $role->level;
                             }
             */
             $level = $role->level;
         }
         //
         $inputName = $model::getClassName();
         if ($submodelName !== "") {
             $inputName .= "[" . $submodelName . "]";
         }
         $inputName .= "[" . $name . "][" . $key . "]";
         echo '<div class="control-group form-inline">';
         echo '<label class="control-label">' . $value . '</label>';
         echo '<div class="controls">';
         echo '<select name="' . $inputName . '" asu-attr="role_' . $key . '">';
         foreach ($selectValues as $selectKey => $selectValue) {
             echo '<option value="' . $selectKey . '" ';
             if ($level == $selectKey) {
                 echo 'selected';
             }
             echo '>' . $selectValue . '</option>';
         }
         echo '</select>';
         if (get_class($model) == "CUser") {
             echo '&nbsp;<label class="checkbox">';
             echo '<input type="checkbox" class="roleDisabler" asu-attr="disabler_' . $key . '" ';
             if (!$hasRole) {
                 echo 'checked';
             }
             echo ' value="' . $key . '">Наследовать из групп';
             echo '</label>';
         }
         echo '</div>';
         echo '</div>';
     }
 }