コード例 #1
0
ファイル: Navigation.php プロジェクト: bruensicke/radium
 /**
  * Renders a group of navigations defined as Configurations.
  *
  * A Configuration with a type ´navigation´ must follow this naming conventions:
  * nav.{name of navigation group}.{name of navigation}
  * e.g. nav.sidebar.main, nav.sidebar.mailplugin, ...
  *
  * $this->Navigation->group('sidebar') will render all Configurations with a slug starting with
  * ´nav.sidebar.´ that are of type `navigation`. In addition it renders all navigations based
  * on files from all loaded libraries, that have files at {:library}/data/nav/{:name}.foo.neon
  *
  * @param string $name part of a navigation slug
  * @param array $options additional options:
  *        - `pattern`: pattern of slug to search configurations of, defaults to `nav.{:name}.`
  *        - `seperator`: glue-character to implode all navigations together with
  *        - `db`: set to false to avoid database-based rendering of navigations (configurations)
  *        - `files`: set to false to avoid file-based rendering of navigations
  * @return string all navigations
  */
 public function group($name, array $options = array())
 {
     $defaults = array('pattern' => 'nav.{:name}.', 'seperator' => "\n", 'files' => true, 'db' => true);
     $options += $defaults;
     $search = String::insert($options['pattern'], compact('name'));
     $result = array();
     if ($options['db']) {
         $configs = Configurations::search($search);
         if ($configs) {
             foreach ($configs as $nav) {
                 $result[] = $this->render($nav);
             }
         }
     }
     if (!$options['files']) {
         return implode($options['seperator'], $result);
     }
     $conditions = array('slug' => $name);
     $files = Neon::find(array('source' => 'nav', 'key' => 'slug'), 'all', compact('conditions'));
     if ($files) {
         foreach ($files as $file => $nav) {
             $caption = Inflector::humanize(str_replace(sprintf('%s.', $name), '', $file));
             $result[] = $this->render($nav, compact('caption'));
         }
     }
     return implode($options['seperator'], $result);
 }
コード例 #2
0
ファイル: BaseModel.php プロジェクト: bruensicke/radium
 /**
  * allows for data-retrieval of entities via file-based access
  *
  * In case you want to provide default file-data without inserting them into the database, you
  * would need to create files based on model-name in a path like that
  * `{:library}/data/{:class}/{:id}.neon` or `{:library}/data/{:class}/{:slug}.neon`
  *
  * In that case, an entity requested by id or slug would be loaded from file instead. Please pay
  * attention, though that not all options are implemented, such as extended conditions, order,
  * limit or page. This is meant to enable basic loading of id- or slug-based entity lookups.
  *
  * @see radium\util\Neon::file()
  * @see radium\util\File::contents()
  * @param string $type The find type, which is looked up in `Model::$_finders`. By default it
  *        accepts `all`, `first`, `list` and `count`,
  * @param array $options Options for the query. By default, accepts:
  *        - `conditions`: The conditional query elements, e.g.
  *                 `'conditions' => array('published' => true)`
  *        - `fields`: The fields that should be retrieved. When set to `null`, defaults to
  *             all fields.
  *        - `order`: The order in which the data will be returned, e.g. `'order' => 'ASC'`.
  *        - `limit`: The maximum number of records to return.
  *        - `page`: For pagination of data.
  * @return mixed
  */
 public static function find($type, array $options = array())
 {
     $result = parent::find($type, $options);
     $neon = static::meta('neon');
     if ($neon && (!$result || !count($result))) {
         return Neon::find(get_called_class(), $type, $options);
     }
     return $result;
 }