本文整理汇总了PHP中Roles::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::getId方法的具体用法?PHP Roles::getId怎么用?PHP Roles::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roles
的用法示例。
在下文中一共展示了Roles::getId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_parent_users_by_iduser
/**
* function to get the parent users by iduser
* @param integer $iduser
* @return array if record found else return false
*/
public function get_parent_users_by_iduser($iduser = '')
{
$parent_users = array();
if ($_SESSION["do_user"]->iduser > 0) {
$iduser = $_SESSION["do_user"]->iduser;
$role_id = $_SESSION["do_user"]->idrole;
} else {
$this->getId($iduser);
$role_id = $this->role_id;
}
$do_role = new Roles();
$do_role->getId($role_id);
$parent_role = $do_role->parentrole;
$explode_parent_roles = explode("::", $parent_role);
$paresed_roles = '';
if (count($explode_parent_roles) > 0) {
foreach ($explode_parent_roles as $parent_roles) {
$users = array();
if ($paresed_roles == '') {
$paresed_roles = $parent_roles;
} else {
$paresed_roles = $paresed_roles . '::' . $parent_roles;
}
$users = $this->get_user_by_parentrole($paresed_roles);
$parent_users = array_merge($parent_users, $users);
}
}
if (count($parent_users) > 0) {
return array_diff(array_unique($parent_users), array($iduser));
} else {
return false;
}
}
示例2: _save
/**
* @param \Roles $role
* @param $error
* @return bool|\Roles
* @throws \Exception
*/
protected function _save(\Roles $role, &$error)
{
$current_status = $role->getStatus();
$data = $this->post('role', 'ARRAY', []);
$role->hydrate($data);
if (!isset($data['admin_access'])) {
$role->setAdminAccess(0);
}
$parentId = $this->post('role_parent', 'INT', 0);
if ($parentId == 0) {
$parent = \Roles::retrieveRoot();
} else {
$parent = \Roles::retrieveById($parentId);
if (!$parent) {
$error['parent'] = array(t('Role parent not found with id:' . $parentId));
return false;
}
}
$is_new = $role->isNew();
$role->beginTransaction();
try {
if ($is_new) {
//always save
$role->setParentId($parent->getId());
$role->setStatus($parent->getStatus());
$role->insertAsLastChildOf($parent);
//dispatch event
$this->dispatch('onCreateNewRole', new CMSBackendEvent($this, ['role' => $role]));
} else {
$currentParent = $role->getParent();
if ($parent->getId() == $role->getId()) {
//something fucked
$error['parent'] = t('Could not move to child of itself!');
}
if ($currentParent->getId() != $parent->getId()) {
//move tree
$role->moveToLastChildOf($parent);
$role->setParentId($parent->getId());
$role->setStatus($parent->getStatus());
if (!$role->save()) {
//save information first
$this->dispatch('onUpdateRole', new CMSBackendEvent($this, ['role' => $role]));
if (!$role->isValid()) {
$failures = $role->getValidationFailures();
foreach ($failures as $failure) {
$error[$failure->getColumn()] = $failure->getMessage();
}
}
}
} else {
//simply save information
if ($role->save()) {
//dispatch event update
$this->dispatch('onUpdateRole', new CMSBackendEvent($this, ['role' => $role]));
} else {
if (!$role->isValid()) {
$failures = $role->getValidationFailures();
foreach ($failures as $failure) {
$error[$failure->getColumn()] = $failure->getMessage();
}
}
}
if (!empty($error)) {
$role->rollBack();
return false;
}
}
//end simply save information
if ($current_status != $role->getStatus() && $role->getStatus() == \Roles::STATUS_INACTIVE) {
//change status to INACTIVE
$role->changeDescendantsStatus(\Roles::STATUS_INACTIVE);
}
}
if ($role->isValid()) {
$role->commit();
return $role;
}
$role->rollBack();
} catch (\Exception $e) {
$role->rollBack();
throw $e;
}
$failures = $role->getValidationFailures();
foreach ($failures as $failure) {
$error[$failure->getColumn()] = $failure->getMessage();
}
return false;
}