/** * 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)); }
/** * 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); }
<?php use radium\models\Configurations; $slug = isset($slug) ? $slug : ''; $configuration = isset($configuration) ? $configuration : null; if (is_null($configuration) && !empty($slug)) { $configuration = Configurations::load($slug); } if (!$configuration) { return; } switch ($configuration->type) { case 'navigation': echo $this->Navigation->render($configuration->val()); break; case 'ini': case 'json': case 'neon': case 'array': echo $this->widget->render(array('radium/data' => array('data' => $configuration->val(null, array('flat' => true))))); break; case 'list': echo '<div class="well">'; echo $this->widget->render(array('radium/list' => array('data' => $configuration->val(null, array('flat' => true))))); echo '</div>'; break; case 'string': echo '<p class="well">' . $configuration->value . '</p>'; break; case 'boolean': $val = $configuration->val();
/** * fetches the associated configuration record * * If current record has a configuration id set, it will load the corresponding record, * but if it is not set, it will try to load a configuration by slug, with the following * format: `<modelname>.<slug>`. * * @param object $entity current instance * @param string $field what field (in case of array) to return * @param array $options an array of options currently supported are * - `raw` : returns Configuration object directly * - `default` : what to return, if nothing is found * - `flat` : to flatten the result, if object/array-ish, defaults to false * @return mixed configuration value */ public function configuration($entity, $field = null, array $options = array()) { $defaults = array('raw' => false); $options += $defaults; $load = empty($entity->config_id) ? sprintf('%s.%s', strtolower(static::meta('name')), $entity->slug) : $entity->config_id; $config = Configurations::load($load); if (!$config) { return null; } return $options['raw'] ? $config : $config->val($field, $options); }
/** * 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); }
public function settings() { $settings = Configurations::settings(); return compact('settings'); }
case 'select': $method = Inflector::underscore(Inflector::pluralize($field)); $options = array('type' => 'select', 'class' => "form-control {$field}", 'data-switch' => $field, 'list' => $model::$method()); if (isset($schema[$field]['null']) && $schema[$field]['null'] === true) { $options['empty'] = true; } if (in_array($field, $readonly)) { $options['type'] = 'text'; $options['value'] = $model::$method($this->scaffold->object->{$field}); $options['disabled'] = 'disabled'; $options['class'] .= ' uneditable-input'; } echo $this->form->field($field, $options); break; case 'configuration': $options = array('type' => 'select', 'class' => "form-control {$field}", 'data-switch' => 'configuration', 'list' => Configurations::find('list')); if (isset($schema[$field]['null']) && $schema[$field]['null'] === true) { $options['empty'] = true; } if (in_array($field, $readonly)) { $options['disabled'] = 'disabled'; $options['class'] .= ' uneditable-input'; } if ($field == 'config_id') { $options['label'] = 'Configuration'; } echo $this->form->field($field, $options); break; case 'ini': $options = array('type' => 'textarea', 'class' => 'form-control autogrow', 'rows' => 10); if (in_array($field, $readonly)) {