Exemplo n.º 1
0
 /**
  * Generated a navigation list based on the given parameters.
  * If a string is given, it looks for a Configuration with this slug and takes the array in it to render.
  * If an array is given, it just renders the navigation with this array.
  *
  * The array should look like this:
  *
  *	Array (
  *		0 => Array (
  *			'name' => 'Users'   // optional(1), if not provided, humanized url will be used
  *			'icon' => 'user'    // optional, font-awesome icon name (without the trailing ´fa-´
  *			'url' =>  '/users'  // optional(1), if not provided, lower case ´name´ will be used (in this case /users)
  * 			'badge' => 4		// optional, will render a ´4´ in a blue circle behind the navigation name
  *		),
  *		1 => Array (
  *			'name' => 'Contents'
  * 			'badge' => array(			// badge can also be an array with additional data
  * 				'value' => '4', 		// mandatory
  * 				'color' => 'primary'    // optional, can be default (gray), primary (blue),
  * 										// success (green), info (turquoise), warning (yellow), danger (red)
  * 			)
  *		),
  *		2 => Array (					// this will render a expandable submenu ´Contents´
  *			'name' => 'Contents'		// with the items Posts and Images inside it.
  * 			'children' => Array(
  * 				[0] => Array (
  *					'name' => 'Posts'
  *					'icon' => 'page'
  *				),
  * 				[1] => Array (
  *					'name' => 'Images'
  *					'icon' => 'image'
  *				),
  * 			)
  *		)
  * 	)
  *
  * (1) either ´name´ or ´url´ must be provided
  *
  * @param string|array $nav slug or array containing the navigation items
  * @param array $options additional options:
  *        - `caption`: allows overwriting/setting caption of navigation
  * @return string HTML navigation list
  */
 public function render($nav, array $options = array())
 {
     $defaults = array('caption' => false);
     $options += $defaults;
     if (is_string($nav)) {
         return $this->render(Configurations::get($nav));
     }
     $navigation = array();
     if ($nav instanceof \lithium\data\Entity) {
         $navigation['caption'] = $nav->name;
         $nav = $nav->val();
     }
     if (!is_array($nav)) {
         return false;
     }
     if ($options['caption']) {
         $navigation['caption'] = $options['caption'];
     }
     foreach ($nav as $navitem) {
         $navitem = $this->_item($navitem);
         if (!empty($navitem['children'])) {
             foreach ($navitem['children'] as $id => $child) {
                 $child = $this->_item($child);
                 $navitem['children'][$id] = $child;
             }
         }
         $navigation['items'][] = $navitem;
     }
     return $this->_element('navigation', $navigation);
 }
Exemplo n.º 2
0
 /**
  * renders a list of widgets according to a defined structure
  *
  * {{{
  * contents/view
  * configurations/details
  * }}}
  *
  * {{{
  * contents/view
  * 	slug: foo
  * configurations/details
  * 	slug: bar
  * }}}
  *
  * {{{
  * contents/view
  * configuration_slug:
  * }}}
  *
  * {{{
  * -
  * 	widget: contents/view
  *  slug: foo
  *  target: a
  * -
  * 	widget: configurations/details
  *  slug: foo
  *  target: b
  * }}}
  *
  * @param array $widgets
  * @param array $options additional options:
  *              - `prefix`: a string that is prefixed in front of widget name
  *              - `pattern`: pattern of slug to search within configurations for
  *                           additional, defaults to `widget.{:name}`
  *              - `seperator`: Character to be used to join widgets, defaults to `\n`
  * @return bool|string
  */
 public function render($widgets = array(), array $options = array())
 {
     $defaults = array('seperator' => "\n", 'pattern' => 'widget.{:name}', 'prefix' => '');
     $options += $defaults;
     if (empty($widgets) && $this->_context->page) {
         $widgets = $this->_context->page->widgets();
     }
     $result = array();
     foreach ((array) $widgets as $key => $value) {
         $widget = is_array($value) || is_null($value) ? $key : $value;
         $data = is_array($value) ? $value : array();
         if (isset($data['widget'])) {
             $widget = $data['widget'];
         }
         $name = $options['prefix'] . $widget;
         $config = Configurations::get(String::insert($options['pattern'], compact('name')));
         $result[] = $config ? $this->render($config, $options) : $this->parse($name, $data, $options);
     }
     return implode($options['seperator'], array_filter($result));
 }
Exemplo n.º 3
0
 /**
  * generic method to retrieve a list or an entry of an array of a static property or a
  * configuration with given properties list
  *
  * This method is used to allow an easy addition of key/value pairs, mainly for usage
  * in a dropdown for a specific model.
  *
  * If you want to provide a list of available options, declare your properties in the same
  * manner as `$_types` or `$_status` or create a new configuration with a slug that follows
  * this structure: `{static::meta('sources')}.$property` (e.g. `content.types`).
  * This array is used, then.
  *
  * @see radium\models\BaseModel::types()
  * @see radium\models\BaseModel::status()
  * @param string $property name of property to look for.
  *               automatically prepended by an underscore: `_`. Must be static and public
  * @param string $type type to look for, optional
  * @return mixed all types with keys and their name, or value of `$type` if given
  */
 public static function _group($property, $type = null)
 {
     $field = sprintf('_%s', $property);
     $slug = sprintf('%s.%s', static::meta('source'), $property);
     if (!empty($type)) {
         $var =& static::${$field};
         $default = isset($var[$type]) ? $var[$type] : false;
     } else {
         $default = static::${$field};
     }
     return Configurations::get($slug, $default, array('field' => $type));
 }
Exemplo n.º 4
0
 /**
  * Retrieve information from Configurations
  *
  * @param string $type
  * @return mixed
  */
 public function get($name, $default = null, array $options = array())
 {
     $defaults = array('field' => null, 'status' => 'active');
     $options += $defaults;
     return Configurations::get($name, $default, $options);
 }