/**
  * Check if the user is superuser
  *
  * @param type $user User information object.
  * @param Request $request Cake request object.
  * @return bool
  */
 public function authorize($user, Request $request)
 {
     $user = (array) $user;
     $superuserField = $this->config('superuser_field');
     if (Hash::check($user, $superuserField)) {
         return (bool) Hash::get($user, $superuserField);
     }
     return false;
 }
 /**
  * Match the current plugin/controller/action against loaded permissions
  * Set a default role if no role is provided
  *
  * @param array $user user data
  * @param Request $request request
  * @return bool
  */
 public function authorize($user, Request $request)
 {
     $roleField = $this->config('role_field');
     $role = $this->config('default_role');
     if (Hash::check($user, $roleField)) {
         $role = Hash::get($user, $roleField);
     }
     $allowed = $this->_checkRules($user, $role, $request);
     return $allowed;
 }
 /**
  * @param string $entityName
  * @param array $data
  * @return Entity\EntityInterface
  * @throws Exception\LogicException
  */
 public function getEntity($entityName, array $data = [])
 {
     $class = '';
     $classCandidates = [__NAMESPACE__ . '\\Entity\\' . trim($entityName, '\\'), __NAMESPACE__ . '\\Entity\\Subset\\' . trim($entityName, '\\')];
     foreach ($classCandidates as $classCandidate) {
         if (class_exists($classCandidate)) {
             $class = $classCandidate;
             break;
         }
     }
     if (!$class) {
         throw new LogicException("Entity \"{$entityName}\" is undefined.");
     }
     $entity = new $class();
     if (!$entity instanceof EntityInterface) {
         throw new LogicException("Class \"{$class}\" isn't an implement of EntityInterface.");
     }
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             $childEntityName = Inflector::singularize((string) Inflector::camelize($key));
             if (Hash::check($value, '{s}')) {
                 // has string key => entity.
                 $value = $this->getEntity($childEntityName, $value);
             } elseif (Hash::check($value, '{n}.{s}')) {
                 // has string key under number key => array of entities.
                 $children = [];
                 foreach ($value as $child) {
                     $children[] = $this->getEntity($childEntityName, $child);
                 }
                 $value = $children;
             } else {
                 // else => array of scalar.
             }
         }
         if (property_exists($entity, $key)) {
             $entity->{$key} = $value;
         }
     }
     return $entity;
 }
예제 #4
0
 /**
  * Check whether or not a field has an error attached to it
  *
  * @param string $field A dot separated path to check errors on.
  * @return bool Returns true if the errors for the field are not empty.
  */
 public function hasError($field)
 {
     if (empty($this->_context['errors'])) {
         return false;
     }
     return (bool) Hash::check($this->_context['errors'], $field);
 }
예제 #5
0
 /**
  * testCheck method
  *
  * @return void
  */
 public function testCheck()
 {
     $set = ['My Index 1' => ['First' => 'The first item']];
     $this->assertTrue(Hash::check($set, 'My Index 1.First'));
     $this->assertTrue(Hash::check($set, 'My Index 1'));
     $set = ['My Index 1' => ['First' => ['Second' => ['Third' => ['Fourth' => 'Heavy. Nesting.']]]]];
     $this->assertTrue(Hash::check($set, 'My Index 1.First.Second'));
     $this->assertTrue(Hash::check($set, 'My Index 1.First.Second.Third'));
     $this->assertTrue(Hash::check($set, 'My Index 1.First.Second.Third.Fourth'));
     $this->assertFalse(Hash::check($set, 'My Index 1.First.Seconds.Third.Fourth'));
 }
예제 #6
0
 public function processCount($oneEnd, $query)
 {
     $countTotalOnDay = [];
     foreach ($query as $key => $row) {
         $dateFormat = $row->date_result->i18nFormat('yyyy-MM-dd');
         if ($row->one_end == $oneEnd) {
             $countTotalOnDay[$dateFormat] = Hash::check($countTotalOnDay, $dateFormat) ? $countTotalOnDay[$dateFormat] + 1 : 1;
         }
     }
     $arrDurationPresent = [];
     $space = 0;
     foreach ($countTotalOnDay as $key => $value) {
         if ($value > 3) {
         } else {
             $space++;
             continue;
         }
         $arrDurationPresent[$space]['count'] = Hash::check($arrDurationPresent, "{$space}.count") ? $arrDurationPresent[$space]['count'] + 1 : 1;
         //$arrDurationPresent[$space]['date'][] = $key;
         $arrDurationPresent[$space]['index'] = $space;
         $space = 0;
     }
     $arrDurationPresent = Hash::sort($arrDurationPresent, '{n}.index', 'asc');
     return $arrDurationPresent;
 }
예제 #7
0
파일: Nav.php 프로젝트: UnionCMS/Core
 /**
  * Add a menu item.
  *
  * @param $menu
  * @param $path
  * @param array $options
  */
 public static function add($menu, $path, $options = [])
 {
     // Juggle argument for backward compatibility
     if (is_array($path)) {
         $options = $path;
         $path = $menu;
         $menu = self::activeMenu();
     } else {
         self::activeMenu($menu);
     }
     $pathE = explode('.', $path);
     $pathE = array_splice($pathE, 0, count($pathE) - 2);
     $parent = join('.', $pathE);
     if (!empty($parent) && !Hash::check(self::$_items[$menu], $parent)) {
         $title = Inflector::humanize(end($pathE));
         $opt = ['title' => $title];
         self::_setupOptions($opt);
         self::add($parent, $opt);
     }
     self::_setupOptions($options);
     $current = Hash::extract(self::$_items[$menu], $path);
     if (!empty($current)) {
         self::_replace(self::$_items[$menu], $path, $options);
     } else {
         self::$_items[$menu] = Hash::insert(self::$_items[$menu], $path, $options);
     }
 }
 /**
  * Checks if a particular option is available.
  *
  * @param string $path
  *
  * @return bool
  */
 public function hasJraOption($path)
 {
     return Hash::check($this->getJraOptions(), $path);
 }