当前位置: 首页>>代码示例>>PHP>>正文


PHP Roles::retrieveRoot方法代码示例

本文整理汇总了PHP中Roles::retrieveRoot方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::retrieveRoot方法的具体用法?PHP Roles::retrieveRoot怎么用?PHP Roles::retrieveRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Roles的用法示例。


在下文中一共展示了Roles::retrieveRoot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: begin

 public function begin()
 {
     $root = \Roles::retrieveRoot();
     $this->roles = $root->getDescendants();
 }
开发者ID:hosivan90,项目名称:toxotes,代码行数:5,代码来源:SelectRoleParent.php

示例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;
 }
开发者ID:hosivan90,项目名称:toxotes,代码行数:94,代码来源:Role.php


注:本文中的Roles::retrieveRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。