Exemplo n.º 1
0
<?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();
Exemplo n.º 2
0
 /**
  * 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);
 }