public function actionListajax() { //echo "<pre>";var_dump($_REQUEST);exit; $pageStart = isset($_REQUEST["iDisplayStart"]) ? intval($_REQUEST["iDisplayStart"]) : 0; $pageLen = isset($_REQUEST["iDisplayLength"]) ? intval($_REQUEST["iDisplayLength"]) : 10; $orderCol = isset($_REQUEST["iSortCol_0"]) ? intval($_REQUEST["iSortCol_0"]) : 0; $orderDir = isset($_REQUEST["sSortDir_0"]) && in_array($_REQUEST["sSortDir_0"], array("asc", "desc")) ? $_REQUEST["sSortDir_0"] : "asc"; $searchContent = isset($_REQUEST["sSearch"]) ? $_REQUEST["sSearch"] : ""; // column name $colNames = User::model()->attributeNames(); $totalNum = User::model()->count(); $numAfterFilter = User::model()->count(); $criteria = new CDbCriteria(); $criteria->select = '*'; // 只选择 'title' 列 if (!empty($searchContent)) { $criteria->condition = "uname like '%{$searchContent}%' or email like '%{$searchContent}%'"; } $criteria->limit = $pageLen; $criteria->offset = $pageStart; $criteria->order = $colNames[$orderCol] . " " . $orderDir; $actionInfos = User::model()->findAll($criteria); //var_dump($actionInfos);exit; $entitys = array(); foreach ($actionInfos as $v) { $t = Role::model()->find("rid={$v['rid']}"); $data = array(0 => $v['uid'], 1 => $v['uname'], 2 => $v['email'], 3 => $t['rname'], 4 => '<a class="btn btn-sm red" href="/main/user/edit?id=' . $v["uid"] . '"><i class="fa fa-edit"></i></a> ' . '<a class="delete btn btn-sm red" data-id="' . $v["uid"] . '"><i class="fa fa-times"></i></a>'); $entitys[] = $data; } $retData = array("sEcho" => intval($_REQUEST['sEcho']), "iTotalRecords" => $totalNum, "iTotalDisplayRecords" => $numAfterFilter, "aaData" => $entitys); echo json_encode($retData); }
public function getRoles($originalSorting = false) { $uid = $this->id; if (!$uid) { return [$this->role]; } ## get roles $roles = Role::model()->with('userRoles')->findAll(ActiveRecord::formatCriteria(['condition' => '|user_id| = :p', 'order' => '|is_default_role|', 'params' => [':p' => $uid]])); $roles = ActiveRecord::toArray($roles); if (empty($roles)) { return false; } $idx = 0; foreach ($roles as $k => $role) { ## find current role index if ($role['role_name'] == Yii::app()->user->getState('role') && $idx == 0) { $idx = $k; } } if ($originalSorting) { return $roles; } $role = array_splice($roles, $idx, 1); array_unshift($roles, $role[0]); $this->roles = $roles; return $roles; }
public function run() { $model = new UserForm(); if (($post = $this->request->getPost('UserForm', false)) !== false) { $model->attributes = $post; if ($model->save()) { $this->response(200, '更新用户成功'); } else { $this->response(500, '更新用户失败'); } $this->app->end(); } else { if (($id = $this->request->getQuery('id', 0)) != false) { if (($user = User::model()->findByPk($id)) != false) { $model->attributes = ['id' => $user->id, 'username' => $user->username, 'realname' => $user->realname, 'nickname' => $user->nickname, 'email' => $user->email, 'state' => $user->state]; $auth = $this->app->getAuthManager(); $roles = $auth->getRoleByUserId($id); $role = []; foreach ($roles as $item) { $role[] = $item->getId(); } $groups = $auth->getGroupByUserId($id); $group = []; foreach ($groups as $item) { $group[] = $item->getId(); } $this->render('edit', ['model' => $model, 'role' => $role, 'group' => $group, 'roleList' => Role::model()->findAll(), 'groupList' => Group::model()->findAll()]); $this->app->end(); } } } $this->response(404, '参数错误'); }
public function init() { parent::init(); $cs = Yii::app()->clientScript; $pt = Yii::app()->homeUrl; $cs->registerScriptFile($pt . 'js/tinymce/tinymce.min.js', CClientScript::POS_END); $this->role = Role::model()->findByPk(Yii::app()->user->role); }
public function getRoles() { $roles = array('all' => 'All', 'guest' => 'Guest', 'loggedIn' => 'Logged In', 'super' => 'Super'); if (Yii::app()->hasModule('role')) { return array_merge($roles, CHtml::listData(Role::model()->findAll(), 'name', 'name')); } return $roles; }
public function actionView($menu_id) { $model = MenuSection::model(); $links = $model->findAllByAttributes(['menu_id' => $menu_id]); $roles = Role::model()->findAll(); foreach ($roles as $ind => $role) { $roles[$role->name] = $role->description; } $this->render('view', ['links' => $links, 'roles' => $roles, 'meta' => $model->meta()]); }
public function actionDel() { $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : ''; if ($id != '') { $ret = Role::model()->deleteByPk($id); RoleAction::model()->deleteAll('rid=:rid', array(':rid' => $id)); var_dump($ret); } else { echo "fail"; } }
public function loadModel() { if ($this->_model === null) { if (isset($_GET['id'])) { $this->_model = Role::model()->findbyPk($_GET['id']); } if ($this->_model === null) { throw new CHttpException(404, Yii::t('App', 'The requested page does not exist.')); } } return $this->_model; }
public static function initRoles() { $roleArray = array('superman', 'teacher', 'student'); foreach ($roleArray as $value) { $roleInfo = Role::model()->find("rname=:rname", array(":rname" => $value)); if (!empty($roleInfo)) { continue; } else { $role = new Role(); $role->rname = $value; $role->save(); } } }
public static function is($role) { $userId = Yii::app()->user->id; if (!$userId) { return false; } $isRole = in_array($role, User::model()->findByPk($userId)->roles); $roleObj = Role::model()->findByAttributes(array('name' => $role)); if (!$roleObj) { // throw new CHttpException(500, 'No role named ' . $role . ' exists!'); return false; } $isActive = $roleObj->active; return $isRole && $isActive; }
public function actionLoadParties() { $data = "<option value=''></option>"; $accounttype = isset($_POST['accounttype'])?$_POST['accounttype']:null; if(empty($accounttype)) { $this->returnJsonResponseII($data); } $tmparray = array(); if($accounttype === Helper::CONST_Receivables) { $rolename = Helper::CONST_Customer; } else { $rolename = Helper::CONST_Contractor; } $role = Role::model()->getRoleByName($rolename); if(empty($role)) { $this->returnJsonResponseII($data); } $role_id = $role->id; $criteria = new CDbCriteria; $criteria = Yii::app()->controller->getPeopleCriteria($role_id, false); $tmparray = Person::model()->findAll($criteria); //$data = CHtml::listData($tmparray, 'id', 'name'); $i = 0; foreach($tmparray as $single) { $tmp = "<option "; if($i === 0) { $tmp .= " selected = 'selected'"; } $i++; $tmp .= " value='" . $single->id ."'>" . $single->name . "</option>"; $data .= $tmp; } $this->returnJsonResponseII($data); }
public function save() { try { if ($this->id) { $model = Role::model()->findByPk($this->id); if (empty($model)) { throw new CDbException('参数出错', 1, []); } } else { $model = new Role(); } $model->attributes = ['name' => $this->name, 'description' => $this->description, 'status' => $this->status]; if ($model->save() === false) { throw new CDbException('更新用户出错', 2, $model->getErrors()); } } catch (CDbException $e) { $this->addErrors($e->errorInfo); return false; } return true; }
public function getFewRecordsTitle($attrName, $attrValue) { if ($attrName == 'roles') { $builtInRoles = Role::builtInRoles(); if (isset($builtInRoles[$attrValue])) { return $builtInRoles[$attrValue]; } else { $role = Role::model()->findByAttributes(array('name' => $attrValue)); if ($role) { return $role->title; } else { return parent::getFewRecordsTitle($attrName, $attrValue); } } } elseif ($attrName == 'login') { $user = User::getByLogin($attrValue); if ($user) { return $user->getFullname(); } else { return parent::getFewRecordsTitle($attrName, $attrValue); } } else { return parent::getFewRecordsTitle($attrName, $attrValue); } }
/** * Create Role root - Original Role for System * * Role name: root * Create automatic: Yes */ public function createRoleOrigin() { $root = Role::model()->findByPk(1); if (empty($root)) { $listRole = $this->_originRole(); $data = array(); try { foreach ($listRole as $value) { $role = new Role('setup'); $role->setAttributes($value); $role->save(); } $this->redirect($this->addRootOrigin()); } catch (Exception $ex) { $data['roles'] = array_keys($listRole); $data['errmsg'] = $ex->getMessage(); } $this->render('role', $data); } else { $this->redirect($this->addRootOrigin()); } }
* @link http://yupe.ru **/ $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', ['action' => Yii::app()->createUrl($this->route), 'method' => 'get', 'type' => 'vertical', 'htmlOptions' => ['class' => 'well']]); ?> <fieldset> <div class="row"> <div class="col-sm-3"> <?php echo $form->textFieldGroup($model, 'id', ['widgetOptions' => ['htmlOptions' => ['class' => 'popover-help', 'data-original-title' => $model->getAttributeLabel('id'), 'data-content' => $model->getAttributeDescription('id')]]]); ?> </div> <div class="col-sm-3"> <?php echo $form->dropDownListGroup($model, 'user_id', ['widgetOptions' => ['data' => CHtml::listData(User::model()->findAll(), 'id', 'first_name')]]); ?> </div> <div class="col-sm-3"> <?php echo $form->dropDownListGroup($model, 'role_id', ['widgetOptions' => ['data' => CHtml::listData(Role::model()->findAll(), 'id', 'name')]]); ?> </div> </div> </fieldset> <?php $this->widget('bootstrap.widgets.TbButton', ['context' => 'primary', 'encodeLabel' => false, 'buttonType' => 'submit', 'label' => '<i class="fa fa-search"> </i> ' . Yii::t('UserModule.user', 'Искать Должность')]); ?> <?php $this->endWidget();
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $model->scenario = 'scenarioUpdate'; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $pre_selected_roles = $model->getExistingRolesOfUser($model->id); $model->_selected_roles = $pre_selected_roles; if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $transaction = Yii::app()->db->beginTransaction(); try { if ($model->save()) { $model->deleteRolesOfUser($model->id); if ($model->assignRolesToUser($model->id)) { $transaction->commit(); $this->redirect(array('view', 'id' => $model->id)); } else { $transaction->rollBack(); } } } catch (Exception $e) { $transaction->rollBack(); } } if (Role::model()->count('active = 1') > 0) { $this->render('update', array('model' => $model)); } else { throw new CHttpException('', 'Primero debes ' . CHtml::link('crear', array('role/create')) . ' o ' . CHtml::link('activar ', array('role/admin')) . 'algún rol' . '.'); } }
public function userHasThisRole($role_id) { $role = Role::model()->findByPk($role_id); if (empty($role->users)) { return false; } else { return true; } }
<?php $form = $this->beginWidget('CActiveForm', array('id' => 'user-form', 'enableAjaxValidation' => false)); ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <div class="row"> <?php echo $form->labelEx($model, 'role_id'); ?> <?php echo $form->dropDownList($model, 'role_id', CHtml::listData(Role::model()->findAll(array('order' => 'name')), 'id', 'name')); ?> <?php echo $form->error($model, 'role_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'username'); ?> <?php echo $form->textField($model, 'username', array('size' => 60, 'maxlength' => 255)); ?> <?php echo $form->error($model, 'username');
public function getFirstOrNewPerson($rolename = Helper::COSNT_Customer, $searchname = null) { $persons = array(); $rsltrolename = null; switch(strtolower($rolename)) { case strtolower(Helper::CONST_Manager): $persons = Yii::app()->user->companymanagers; break; case strtolower(Helper::CONST_Employee): $persons = Yii::app()->user->companyemployees; break; case strtolower(Helper::CONST_Contractor): $persons = Yii::app()->user->companycontractors; break; case strtolower(Helper::CONST_Supplier): $persons = Yii::app()->user->companysuppliers; break; case strtolower(Helper::CONST_Customer): default: $persons = Yii::app()->user->companycustomers; break; } $person = new Person; if(!empty($persons)) { if(empty($searchname)) { $person_ids = array_keys($persons); } else { $person_ids = array_keys(array_map('strtolower', $persons), strtolower($searchname)); } $person_id = (!empty($person_ids)?$person_ids[0]:0); $person = Person::model()->findByPk($person_id); if(empty($person)) $person = new Person; } $role = Role::model()->getRoleByName($rolename); if(!empty($role)) { $person->rolename = $role->role; $person->role_id = $role->id; } return $person; }
public function actionDelrole() { $roleid = $_GET['roleid']; if ($roleid) { $result = UserRole::model()->deleteAll("RoleID=:roleid", array(":roleid" => $roleid)); $result = Role::model()->deleteByPk($roleid); } echo json_encode($result); }
?> <?php echo $form->checkBox($model, 'guest'); ?> <?php echo $form->labelEx($model, 'guest'); ?> <?php echo $form->error($model, 'guest'); ?> </div> <div id="roles" class="row nm_row"> <?php echo CHtml::checkBoxList('Access[roles]', array_map('Awecms::getPrimaryKey', $model->roles), CHtml::listData(Role::model()->findAll(), 'id', 'name'), array('attributeitem' => 'id')); ?> </div> <div class="row"> <?php /* echo $form->labelEx($model, 'rule'); ?> <?php echo CHtml::activeDropDownList($model, 'rule', array( 'allow' => Yii::t('app', 'Allow'), 'deny' => Yii::t('app', 'Deny'), )); ?> <?php echo $form->error($model, 'rule'); */
* @author Brett O'Donnell <*****@*****.**> * @author Zain Ul abidin <*****@*****.**> * @copyright 2013 Mr PHP * @link https://github.com/cornernote/yii-dressing * @license BSD-3-Clause https://raw.github.com/cornernote/yii-dressing/master/license.txt */ $this->pageTitle = $this->getName() . ' ' . Yii::t('dressing', ucfirst($task)); $role = $id ? Role::model()->findByPk($id) : new Role('search'); /** @var YdActiveForm $form */ $form = $this->beginWidget('dressing.widgets.YdActiveForm', array('id' => 'role-' . $task . '-form', 'type' => 'horizontal', 'action' => array('/role/delete', 'id' => $id, 'task' => $task, 'confirm' => 1))); echo $this->getGridIdHiddenFields($id); echo $form->beginModalWrap(); echo $form->errorSummary($role); echo '<fieldset>'; echo '<legend>' . Yii::t('dressing', 'Selected Records') . '</legend>'; $roles = Role::model()->findAll('t.id IN (' . implode(',', YdHelper::getGridIds($id)) . ')'); if ($roles) { echo '<ul>'; foreach ($roles as $role) { echo '<li>'; echo $role->getName(); echo '</li>'; } echo '</ul>'; } echo '</fieldset>'; echo $form->endModalWrap(); echo '<div class="' . $form->getSubmitRowClass() . '">'; $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('dressing', 'Confirm ' . ucfirst($task)), 'htmlOptions' => array('class' => 'pull-right'))); echo '</div>'; $this->endWidget();
<div class="row"> <div class="col-sm-7"> <div class="form-group"> <?php echo $form->hiddenField($model, 'user_id'); $this->widget('zii.widgets.jui.CJuiAutoComplete', array('name' => 'user_id', 'source' => CController::createUrl('/teacher/autoComplete'), 'options' => ['minLength' => '2', 'select' => 'js:function( event, ui ) { $("#user_id").val( ui.item.label ); $("#RoleToUser_user_id").val( ui.item.value ); return false; }'], 'htmlOptions' => ['onfocus' => 'js: this.value = null; $("#user_id").val(null); $("#RoleToUser_user_id").val(null);', 'class' => 'input-xxlarge search-query popover-help form-control', 'placeholder' => "Введите имя сотрудника"])); ?> </div> </div> </div> <div class="row"> <div class="col-sm-7"> <?php echo $form->dropDownListGroup($model, 'role_id', ['widgetOptions' => ['data' => CHtml::listData(Role::model()->findAll(), 'id', 'name'), 'htmlOptions' => ['empty' => '--выберите--', 'encode' => false]]]); ?> </div> </div> <?php $this->widget('bootstrap.widgets.TbButton', ['buttonType' => 'submit', 'context' => 'primary', 'label' => Yii::t('UserModule.user', 'Сохранить Должность и продолжить')]); ?> <?php $this->widget('bootstrap.widgets.TbButton', ['buttonType' => 'submit', 'htmlOptions' => ['name' => 'submit-type', 'value' => 'index'], 'label' => Yii::t('UserModule.user', 'Сохранить Должность и закрыть')]); ?> <?php $this->endWidget();
<h1><span class="fa fa-user"></span> User<hr></h1> <ul class="breadcrumb" style="background-color:#F8F8F8;"> <li><a href="<?php echo Yii::app()->createUrl('site/admin'); ?> "><span class="fa fa-dashboard"></span> Dashboard</a></li> <li><a href="<?php echo Yii::app()->createUrl('user/admin'); ?> "><span class="fa fa-user"></span> User</a></li> <li class="active"><span class="fa fa-cog"></span> Manage</li> </ul><hr> <a href="<?php echo Yii::app()->createUrl('user/create'); ?> " class="btn btn-default"><span class="fa fa-plus"></span> Create</a> <?php $this->widget('booster.widgets.TbGridView', array('id' => 'user-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('name' => 'id', 'htmlOptions' => array('style' => 'width:80px;')), 'username', 'password', array('name' => 'role_id', 'value' => '$data->role->role_name', 'filter' => CHtml::listData(Role::model()->findAll(array('order' => 'id')), 'id', 'role_name')), 'last_login', array('class' => 'booster.widgets.TbButtonColumn', 'htmlOptions' => array('style' => 'width:80px;'))))); ?>
public function actionUpdateRole($id) { $student = Student::model()->findByAttributes(array('id_user' => $id)); if (!$student) { $student = false; } $valid = true; if (isset($_POST['Student'])) { $student->attributes = $_POST['Student']; if ($_POST['Role'][3] == 1) { $valid = $valid && $student->save(); } } if (isset($_POST['Role']) && !empty($_POST['Role']) && $valid) { foreach ($_POST['Role'] as $key => $role) { $arrRol[] = $key; } if (RoleToUser::model()->changeRole($id, $arrRol)) { $this->redirect(array('allusers')); } } $roles = Role::model()->findAll(); $user = User::model()->findByPk($id); $this->render('update', array('user' => $user, 'roles' => $roles, 'student' => $student)); }
<?php @(include_once '../settings/autoload.php'); Role::model()->clearCache(); echo 'done...';
public function getPrimaryRole() { return Role::model()->find(array('with' => array('users'), 'condition' => 'users.id=:user_id', 'params' => array(':user_id' => $this->id), 'order' => 't.priority DESC')); }
<?php $form = $this->beginWidget('booster.widgets.TbActiveForm', array('id' => 'user-form', 'enableAjaxValidation' => false)); ?> <p class="help-block">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <?php echo $form->textFieldGroup($model, 'username', array('widgetOptions' => array('htmlOptions' => array('class' => 'span5', 'maxlength' => 64)))); ?> <?php echo $form->passwordFieldGroup($model, 'password', array('widgetOptions' => array('htmlOptions' => array('class' => 'span5', 'maxlength' => 128)))); ?> <?php echo $form->dropDownListGroup($model, 'role_id', array('wrapperHtmlOptions' => array('class' => 'col-sm-5'), 'widgetOptions' => array('data' => CHtml::listData(Role::model()->findAll(array('order' => 'role_name ASC')), 'id', 'role_name'), 'htmlOptions' => array('empty' => 'Choose')))); ?> <div class="form-actions"> <?php $this->widget('booster.widgets.TbButton', array('buttonType' => 'submit', 'context' => 'primary', 'label' => $model->isNewRecord ? 'Create' : 'Save')); ?> </div> <?php $this->endWidget();
public static function listRole() { $list = CHtml::listData(Role::model()->findAll(), 'id', 'role_description'); return $list; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Role the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Role::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }