/**
  * Creates collection of items.
  *
  * Override it if you need to implement
  * derived collection that requires specific initialization.
  *
  * @param array $items
  *
  * @return static
  */
 protected function createCollection(array $items)
 {
     $collection = new static();
     $itemsRef =& $collection->items();
     $itemsRef = $items;
     return $collection;
 }
Example #2
0
 /**
  * Loads a config file or array.
  *
  * @param    mixed    $file         string file | config array
  * @param    mixed    $group        null for no group, true for group is filename, false for not storing in the master config
  * @return   array                  the (loaded) config array
  */
 public static function load($file, $group = null)
 {
     $config = array();
     if (is_array($file)) {
         $config = $file;
     } elseif (is_string($file)) {
         $info = pathinfo($file);
         $type = 'json';
         if (isset($info['extension'])) {
             $type = $info['extension'];
         }
         $loadMethod = 'read' . ucfirst($type);
         if (method_exists(get_called_class(), $loadMethod)) {
             $config = static::$loadMethod($file);
         } else {
             throw new \Exception(sprintf('Invalid config type "%s".', $type));
         }
     } else {
         throw new \Exception('Invalid config specified.');
     }
     if ($group === null) {
         static::$items = array_merge(static::$items, $config);
     } else {
         if (!isset(static::$items[$group])) {
             static::$items[$group] = array();
         }
         static::$items[$group] = array_merge(static::$items[$group], $config);
     }
     return $config;
 }
Example #3
0
 public static function load($file, $group = null, $reload = false)
 {
     if (!is_array($file) && array_key_exists($file, static::$loaded_files) and !$reload) {
         return false;
     }
     $config = array();
     if (is_array($file)) {
         $config = $file;
     } elseif ($paths = \Fuel::find_file('config', $file, '.php', true)) {
         // Reverse the file list so that we load the core configs first and
         // the app can override anything.
         $paths = array_reverse($paths);
         foreach ($paths as $path) {
             $config = \Fuel::load($path) + $config;
         }
     }
     if ($group === null) {
         static::$items = $reload ? $config : static::$items + $config;
     } else {
         $group = $group === true ? $file : $group;
         if (!isset(static::$items[$group]) or $reload) {
             static::$items[$group] = array();
         }
         static::$items[$group] = static::$items[$group] + $config;
     }
     if (!is_array($file)) {
         static::$loaded_files[$file] = true;
     }
     return $config;
 }
Example #4
0
 public static function load($file)
 {
     if (file_exists($file) === false) {
         return false;
     }
     static::$items = array_merge(static::$items, require $file);
     return true;
 }
Example #5
0
 public static function load()
 {
     if (file_exists(PATH . 'config.php') === false) {
         return false;
     }
     static::$items = (require PATH . 'config.php');
     return true;
 }
Example #6
0
 /**
  * Returns an array of menu items grouped by menu.
  *
  * @param   array  $config  An array of configuration options.
  *
  * @return  array
  *
  * @since   1.6
  */
 public static function menuitems($config = array())
 {
     if (empty(static::$items)) {
         $menus = static::menus();
         $db = JFactory::getDbo();
         $query = $db->getQuery(true)->select('a.id AS value, a.title AS text, a.level, a.menutype')->from('#__menu AS a')->where('a.parent_id > 0')->where('a.client_id = 0');
         // Filter on the published state
         if (isset($config['published'])) {
             if (is_numeric($config['published'])) {
                 $query->where('a.published = ' . (int) $config['published']);
             } elseif ($config['published'] === '') {
                 $query->where('a.published IN (0,1)');
             }
         }
         $query->order('a.lft');
         $db->setQuery($query);
         $items = $db->loadObjectList();
         // Collate menu items based on menutype
         $lookup = array();
         foreach ($items as &$item) {
             if (!isset($lookup[$item->menutype])) {
                 $lookup[$item->menutype] = array();
             }
             $lookup[$item->menutype][] =& $item;
             $item->text = str_repeat('- ', $item->level) . $item->text;
         }
         static::$items = array();
         $user = JFactory::getUser();
         $aclcheck = !empty($config['checkacl']) ? (int) $config['checkacl'] : 0;
         foreach ($menus as &$menu) {
             if ($aclcheck) {
                 $action = $aclcheck == $menu->id ? 'edit' : 'create';
                 if (!$user->authorise('core.' . $action, 'com_menus.menu.' . $menu->id)) {
                     continue;
                 }
             }
             // Start group:
             $optGroup = new stdClass();
             $optGroup->value = '<OPTGROUP>';
             $optGroup->text = $menu->text;
             static::$items[] = $optGroup;
             // Special "Add to this Menu" option:
             static::$items[] = JHtml::_('select.option', $menu->value . '.1', JText::_('JLIB_HTML_ADD_TO_THIS_MENU'));
             // Menu items:
             if (isset($lookup[$menu->value])) {
                 foreach ($lookup[$menu->value] as &$item) {
                     static::$items[] = JHtml::_('select.option', $menu->value . '.' . $item->value, $item->text);
                 }
             }
             // Finish group:
             $closeOptGroup = new stdClass();
             $closeOptGroup->value = '</OPTGROUP>';
             $closeOptGroup->text = $menu->text;
             static::$items[] = $closeOptGroup;
         }
     }
     return static::$items;
 }
Example #7
0
 /**
  * Loads a config file.
  *
  * @param    mixed    $file         string file | config array | Config_Interface instance
  * @param    mixed    $group        null for no group, true for group is filename, false for not storing in the master config
  * @param    bool     $reload       true to force a reload even if the file is already loaded
  * @param    bool     $overwrite    true for array_merge, false for \Arr::merge
  * @return   array                  the (loaded) config array
  */
 public static function load($file, $group = null, $reload = false, $overwrite = false)
 {
     if (!$reload and !is_array($file) and !is_object($file) and array_key_exists($file, static::$loaded_files)) {
         $group === true and $group = $file;
         if ($group === null or $group === false or !isset(static::$items[$group])) {
             return false;
         }
         return static::$items[$group];
     }
     $config = array();
     if (is_array($file)) {
         $config = $file;
     } elseif (is_string($file)) {
         $info = pathinfo($file);
         $type = 'php';
         if (isset($info['extension'])) {
             $type = $info['extension'];
             // Keep extension when it's an absolute path, because the finder won't add it
             if ($file[0] !== '/' and $file[1] !== ':') {
                 $file = substr($file, 0, -(strlen($type) + 1));
             }
         }
         $class = '\\Config_' . ucfirst($type);
         if (class_exists($class)) {
             static::$loaded_files[$file] = true;
             $file = new $class($file);
         } else {
             throw new \FuelException(sprintf('Invalid config type "%s".', $type));
         }
     }
     if ($file instanceof Config_Interface) {
         try {
             $config = $file->load($overwrite, !$reload);
         } catch (\ConfigException $e) {
             $config = array();
         }
         $group = $group === true ? $file->group() : $group;
     }
     if ($group === null) {
         static::$items = $reload ? $config : ($overwrite ? array_merge(static::$items, $config) : \Arr::merge(static::$items, $config));
         static::$itemcache = array();
     } else {
         $group = $group === true ? $file : $group;
         if (!isset(static::$items[$group]) or $reload) {
             static::$items[$group] = array();
         }
         static::$items[$group] = $overwrite ? array_merge(static::$items[$group], $config) : \Arr::merge(static::$items[$group], $config);
         $group .= '.';
         foreach (static::$itemcache as $key => $value) {
             if (strpos($key, $group) === 0) {
                 unset(static::$itemcache[$key]);
             }
         }
     }
     return $config;
 }
Example #8
0
 /**
  * Load a complete config file to merge with the config class's items.
  * Only support for php files that return an array:
  * <code>
  * <?php
  * return array(
  *      'key' = 'item',
  *      'key2' = [
  *          'key' => 'item'
  *      ]
  * );
  * </code>
  *
  * @param $file
  * @throws \InvalidArgumentException
  * @throws \Exception
  * @static
  * @access public
  * @return void
  */
 public static function loadFile($file)
 {
     if (Helpers::fileExists($file) === false) {
         throw new \InvalidArgumentException(sprintf('File [%s] is not found or readable.', $file));
     }
     if (strtolower(pathinfo($file)['extension']) == 'php') {
         $data = (require_once $file);
         if (is_array($data) == false && $data instanceof \Travsersable == false) {
             throw new \Exception('Supplied file for loading should return an array.');
         }
     }
     static::$items = array_merge(static::$items, $data);
 }
Example #9
0
 public static function newKuesioner($data)
 {
     $k = new static();
     $k->title = $data['title'];
     $k->user_id = auth()->user()->id;
     $k->gelombang_id = Gelombang::getActive()->id;
     $k->save();
     $i = 1;
     foreach ($data['pertanyaan'] as $q) {
         $p = new KuesionerItem();
         $p->label = $q;
         $p->type = 'input';
         $p->priority = $i;
         $k->items()->save($p);
         $i++;
     }
 }
 /**
  * Get a list of the available content language items.
  *
  * @param   boolean  $all        True to include All (*)
  * @param   boolean  $translate  True to translate All
  *
  * @return  string
  *
  * @see     JFormFieldContentLanguage
  * @since   1.6
  */
 public static function existing($all = false, $translate = false)
 {
     if (empty(static::$items)) {
         // Get the database object and a new query object.
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('a.lang_code AS value, a.title AS text, a.title_native')->from('#__languages AS a')->where('a.published >= 0')->order('a.title');
         // Set the query and load the options.
         $db->setQuery($query);
         static::$items = $db->loadObjectList();
         if ($all) {
             array_unshift(static::$items, new JObject(array('value' => '*', 'text' => $translate ? JText::alt('JALL', 'language') : 'JALL_LANGUAGE')));
         }
     }
     return static::$items;
 }
Example #11
0
 /**
  * Returns an array of menu items grouped by menu.
  *
  * @param   array  $config  An array of configuration options.
  *
  * @return  array
  *
  * @since   1.6
  */
 public static function menuitems($config = array())
 {
     if (empty(static::$items)) {
         $menus = static::menus();
         $db = JFactory::getDbo();
         $query = $db->getQuery(true)->select('a.id AS value, a.title AS text, a.level, a.menutype')->from('#__menu AS a')->where('a.parent_id > 0')->where('a.client_id = 0');
         // Filter on the published state
         if (isset($config['published'])) {
             if (is_numeric($config['published'])) {
                 $query->where('a.published = ' . (int) $config['published']);
             } elseif ($config['published'] === '') {
                 $query->where('a.published IN (0,1)');
             }
         }
         $query->order('a.lft');
         $db->setQuery($query);
         $items = $db->loadObjectList();
         // Collate menu items based on menutype
         $lookup = array();
         foreach ($items as &$item) {
             if (!isset($lookup[$item->menutype])) {
                 $lookup[$item->menutype] = array();
             }
             $lookup[$item->menutype][] =& $item;
             $item->text = str_repeat('- ', $item->level) . $item->text;
         }
         static::$items = array();
         foreach ($menus as &$menu) {
             // Start group:
             static::$items[] = JHtml::_('select.optgroup', $menu->text);
             // Special "Add to this Menu" option:
             static::$items[] = JHtml::_('select.option', $menu->value . '.1', JText::_('JLIB_HTML_ADD_TO_THIS_MENU'));
             // Menu items:
             if (isset($lookup[$menu->value])) {
                 foreach ($lookup[$menu->value] as &$item) {
                     static::$items[] = JHtml::_('select.option', $menu->value . '.' . $item->value, $item->text);
                 }
             }
             // Finish group:
             static::$items[] = JHtml::_('select.optgroup', $menu->text);
         }
     }
     return static::$items;
 }
Example #12
0
 /**
  * Loads a config file.
  *
  * @param    mixed    $file         string file | config array | Config_Interface instance
  * @param    mixed    $group        null for no group, true for group is filename, false for not storing in the master config
  * @param    bool     $overwrite    true for array_merge, false for \Arr::merge
  * @return   array                  the (loaded) config array
  */
 public static function load($file, $group = null, $reload = false, $overwrite = false)
 {
     if (!$reload and !is_array($file) and !is_object($file) and array_key_exists($file, static::$loaded_files)) {
         return false;
     }
     $config = array();
     if (is_array($file)) {
         $config = $file;
     } elseif (is_string($file)) {
         $info = pathinfo($file);
         $type = isset($info['extension']) ? $info['extension'] : 'php';
         $file = $info['filename'];
         $class = '\\Config_' . ucfirst($type);
         if (class_exists($class)) {
             static::$loaded_files[$file] = true;
             $file = new $class($file);
         } else {
             throw new \FuelException(sprintf('Invalid config type "%s".', $type));
         }
     }
     if ($file instanceof Config_Interface) {
         try {
             $config = $file->load($overwrite);
         } catch (\ConfigException $e) {
             $config = array();
         }
         $group = $group === true ? $file->group() : $group;
     }
     if ($group === null) {
         static::$items = $reload ? $config : ($overwrite ? array_merge(static::$items, $config) : \Arr::merge(static::$items, $config));
     } else {
         $group = $group === true ? $file : $group;
         if (!isset(static::$items[$group]) or $reload) {
             static::$items[$group] = array();
         }
         static::$items[$group] = $overwrite ? array_merge(static::$items[$group], $config) : \Arr::merge(static::$items[$group], $config);
     }
     return $config;
 }
Example #13
0
File: RBAC.php Project: romeoz/rock
 public function refresh()
 {
     static::$items = [];
     static::$assignments = [];
 }
Example #14
0
 public function removeAll()
 {
     static::$items = static::$roles = static::$permissions = null;
     $this->saveToFile([], $this->path);
     return true;
 }
Example #15
0
 /**
  * @param $filepath Charge le fichier de configuration spécifié et définit $items
  */
 public static function load($filepath)
 {
     static::$items = (include ROOT . '/app/config/' . $filepath . '.config.php');
 }
Example #16
0
 public static function set($key, $value = null)
 {
     static::$items = arraySet(static::$vars, $key, $value);
 }
Example #17
0
 public static function load($newItems)
 {
     static::$items = array_merge(static::$items, $newItems);
 }
Example #18
0
 protected function load()
 {
     //@TODO cache
     if (!($dataItems = (new Query())->from($this->itemsTable)->orderBy(['order_index' => SORT_DESC])->indexBy('name')->all($this->connection))) {
         throw new RBACException('Items is empty.');
     }
     static::$items = $dataItems;
     $alias = Query::alias($this->rolesTable, $this->rolesTable);
     //@TODO cache
     if (!($dataRolesItems = (new Query())->select(SelectBuilder::selects([['roles' => ['name', 'type', 'description', 'data']], ['access_items' => ['name', 'type', 'description', 'data'], 'items']]))->from($this->rolesItemsTable)->innerJoin($this->itemsTable, "{$this->rolesItemsTable}.item = {$this->itemsTable}.name")->innerJoin($this->rolesTable, "{$this->rolesItemsTable}.role = {$alias}.name")->andWhere(["{$alias}.[[type]]" => RBACInterface::TYPE_ROLE])->orderBy(["{$alias}.[[order_index]]" => SORT_DESC])->asSubattributes()->all($this->connection))) {
         return;
     }
     $result = [];
     foreach ($dataRolesItems as $value) {
         if (isset($result[$value['name']])) {
             $result[$value['name']]['items'] = array_merge($result[$value['name']]['items'], (array) $value['items']['name']);
             continue;
         }
         $value['items'] = [$value['items']['name']];
         $result[$value['name']] = $value;
     }
     static::$items = ArrayHelper::toType(ArrayHelper::filterRecursive($result + static::$items, function ($value, $key) {
         return !in_array($key, ['name'], true);
     }));
 }
Example #19
0
 /**
  * Initiate and check user authentication, the method will try to detect current 
  * cookie for this session and verify the cookie with the database, it has to 
  * be verify so that no one else could try to copy the same cookie configuration 
  * and use it as their own.
  * 
  * @TODO need to use User-Agent as one of the hash value 
  * 
  * @static
  * @access	private
  * @return	bool
  */
 public static function _init()
 {
     \Config::load('app', true);
     \Config::load('crypt', true);
     if (!is_null(static::$acl)) {
         return;
     }
     $users = \Cookie::get('_users');
     if (!is_null($users)) {
         $users = unserialize(\Crypt::decode($users));
         static::$items = (array) $users;
     } else {
         static::_unregister();
         return true;
     }
     static::$acl = new \Hybrid\Acl();
     $config = \Config::get('app.user_table', array());
     foreach ($config as $key => $value) {
         if (!!property_exists('\\Hybrid\\Acl_User', "_{$key}")) {
             $property = '_' . $key;
             static::${$property} = $value;
             \Config::set("app.user_table.{$key}", $value);
         }
     }
     static::$_optionals = \Config::get('app.user_table.optionals', static::$_optionals);
     foreach (static::$_optionals as $field) {
         if (is_string($field) and !isset(static::$items[$field])) {
             static::$items[$field] = '';
         }
     }
     switch ($users->method) {
         case 'normal':
             /*
              * SELECT `users`.*, `users_auths`.`password`, `users_twitter`.`id` AS `twitter_id` 
              * FROM `users` 
              * INNER JOIN `users_auths` ON (`users_auths`.`user_id`=`users`.`id`) 
              * LEFT JOIN `users_twitters` ON (`users_twitters`.`user_id`=`users`.`id`)   
              * WHERE `users`.`id`=%d  */
             $results = \DB::select('users.*')->from('users')->where('users.id', '=', static::$items['id'])->limit(1);
             if (static::$_use_auth === true) {
                 $results->select('users_auths.password')->join('users_auths')->on('users_auths.user_id', '=', 'users.id');
             }
             if (static::$_use_meta === true) {
                 $results->select('users_meta.*')->join('users_meta')->on('users_meta.user_id', '=', 'users.id');
             }
             if (static::$_use_twitter === true) {
                 $results->select(array('users_twitters.id', 'twitter_id'))->join('users_twitters', 'left')->on('users_twitters.user_id', '=', 'users.id');
             }
             $result = $results->as_object()->execute();
             break;
         case 'twitter_oauth':
             /**
              * @todo: Twitter OAuth integration
              */
             /* $result = \DB::select('users.*', 'users_auths.password', array('twitters.id', 'twitter_id'))->from('users')
             	  ->join('users_auths')
             	  ->on('users_auths.id', '=', 'users.id')
             	  ->join('twitters')
             	  ->on('users.id', '=', 'twitters.user_id')
             	  ->where('twitters.id', '=', $twitter_oauth->id)
             	  ->execute(); */
             break;
     }
     if ($result->count() < 1) {
         static::_unregister(true);
         return true;
     } else {
         $user = $result->current();
         if ($user->status !== 'verified') {
             // only verified user can login to this application
             static::_unregister();
             return true;
         }
         // we validate the hash to add security to this application
         $hash = $user->user_name . $user->password;
         if (static::$items['_hash'] !== static::add_salt($hash)) {
             static::_unregister();
             return true;
         }
         static::$items['id'] = $user->id;
         static::$items['user_name'] = $user->user_name;
         static::$items['roles'] = $users->roles;
         static::$items['password'] = $user->password;
         foreach (static::$_optionals as $property) {
             if (\property_exists($user, $property)) {
                 static::$items[$property] = $user->{$property};
             }
         }
         // if user already link their account with twitter, map the relationship
         if (property_exists($user, 'twitter_id')) {
             static::$items['twitter'] = $user->twitter_id;
         }
     }
     return true;
 }