Example #1
0
 /**
  * Run the macroView over the model (which is an array)
  * and use the detailView on each item.
  *
  * @param One_Model& $model
  * @param string $topViewName
  * @param string $detailViewName
  * @return string
  */
 public function map($model, $topViewName, $detailViewName = 'default')
 {
     if (!is_array($model)) {
         return 'Error in one:map ' . $topViewName . ' : model is not an array.';
     }
     $view = new One_View($model, 'macro' . '/' . $topViewName);
     $view->setModel($model);
     $view->set('detailView', $detailViewName);
     return $view->show();
 }
Example #2
0
 /**
  * Determine what type of widget the DOMElement is and load it's conditions
  *
  * @param One_Form_Container_Abstract $container
  * @param DOMElement $element
  * @param string $widgetClass
  * @return One_Form_Widget_Abstract
  */
 protected static function determineWidget($container, $element, $widgetClass)
 {
     $id = $element->hasAttribute('id') ? $element->getAttribute('id') : $element->getAttribute('attribute');
     $name = $element->hasAttribute('name') ? $element->getAttribute('name') : $element->getAttribute('attribute');
     $label = $element->hasAttribute('label') ? $element->getAttribute('label') : $element->getAttribute('attribute');
     $attributes = array();
     $rawAttributes = $element->attributes;
     for ($i = 0; $i < $rawAttributes->length; $i++) {
         $attribute = $rawAttributes->item($i);
         $attributes[$attribute->localName] = $attribute->value;
     }
     if (false === isset($attributes['language'])) {
         $attributes['language'] = strtolower(One_Config::get('app.language'));
     }
     $widget = new $widgetClass($id, $name, $label, $attributes);
     if ($element->hasAttribute('optionsFrom') && method_exists($widget, 'setOptions')) {
         $parts = explode(':', $element->getAttribute('optionsFrom'));
         if (2 == count($parts)) {
             $session = One_Repository::getSession();
             $sessionCacheName = md5($id . '#' . $name . '#' . $element->getAttribute('optionsFrom'));
             if (false === $element->hasAttribute('cacheOptions') || $element->hasAttribute('cacheOptions') && false === $session->varExists($sessionCacheName, 'One_Form_Cache')) {
                 $optView = new One_View($parts[0], $parts[1]);
                 try {
                     $rawOptions = trim($optView->show());
                     $options = json_decode($rawOptions, 1);
                     if (false === is_array($options)) {
                         $options = array();
                     }
                     $widget->setOptions($options);
                     if ($element->hasAttribute('cacheOptions')) {
                         $session->set($sessionCacheName, $options, 'One_Form_Cache');
                     }
                 } catch (Exception $e) {
                     //					echo $e->getMessage();
                     //					exit;
                 }
             } else {
                 $options = $session->get($sessionCacheName, 'One_Form_Cache');
                 $widget->setOptions($options);
             }
         }
     }
     self::loadConstraints($element, $widget);
     $container->addWidget($widget);
     return $widget;
 }