Example #1
0
 /**
  * @param $view_name     string   the view name is the associated data class name
  * @param $feature_names string[] feature and inherited feature which view will be searched
  * @param $template      string   if a specific template is set, the view named with it will be
  *                       searched into the view / feature namespace first
  * @return callable
  */
 private static function getView($view_name, $feature_names, $template = null)
 {
     $view_engine_name = get_class(View::current());
     $view_engine_name = Namespaces::shortClassName(Namespaces::of($view_engine_name));
     if (isset($template)) {
         foreach ([$view_engine_name . '_View', 'View'] as $suffix) {
             foreach ($feature_names as $feature_name) {
                 list($class, $method) = Getter::get($view_name, $feature_name, Names::methodToClass($template) . '_' . $suffix, 'php');
                 if (isset($class)) {
                     break 2;
                 }
             }
         }
     }
     if (!isset($class)) {
         foreach ([$view_engine_name . '_View', 'View'] as $suffix) {
             foreach ($feature_names as $feature_name) {
                 list($class, $method) = Getter::get($view_name, $feature_name, $suffix, 'php');
                 if (isset($class)) {
                     break 2;
                 }
             }
         }
     }
     if (!isset($class)) {
         list($class, $method) = [__CLASS__ . BS . $view_engine_name . BS . 'Default_View', 'run'];
     }
     /** @noinspection PhpUndefinedVariableInspection if $class is set, then $method is set too */
     return [$class, $method];
 }
Example #2
0
 /**
  * @param $template_file string
  * @param $parameters    array
  * @param $feature_name string
  * @return string
  */
 protected function executeTemplate($template_file, $parameters, $feature_name)
 {
     if (isset($parameters[Template::TEMPLATE])) {
         unset($parameters[Template::TEMPLATE]);
     }
     if (isset($parameters[Template::TEMPLATE_CLASS])) {
         $template_class = $parameters[Template::TEMPLATE_CLASS];
     } elseif (isset($parameters[Template::TEMPLATE_NAMESPACE])) {
         $template_class = $parameters[Template::TEMPLATE_NAMESPACE] . BS . 'Html_Template';
         unset($parameters[Template::TEMPLATE_NAMESPACE]);
     } else {
         $template_class = Template::class;
     }
     /** @var $template Template */
     $template = Builder::create($template_class, [reset($parameters), $template_file, $feature_name]);
     $template->setParameters($parameters);
     $current = Framework\View::current();
     if ($current instanceof Engine && ($css = $current->getCss())) {
         $template->setCss($css);
     }
     return $template->parse();
 }
Example #3
0
 /**
  * @param $conditions string[] the key is the name of the condition, the value is the name of the
  *   value that enables the condition
  * @param $filters string[] the key is the name of the filter, the value is the name of the form
  *   element containing its value
  * @return string
  */
 public function buildObject($conditions = null, $filters = null)
 {
     $class_name = $this->type->asString();
     // visible input
     $input = new Input(null, strval($this->value));
     $input->setAttribute('autocomplete', 'off');
     $input->setAttribute('data-combo-class', Names::classToSet($class_name));
     if (!$this->readonly) {
         if ($filters) {
             $html_filters = [];
             $old_name = $this->name;
             foreach ($filters as $filter_name => $filter_value) {
                 $this->name = $filter_value;
                 $name = $this->getFieldName('', false);
                 $html_filters[] = $filter_name . '=' . $name;
             }
             $this->name = $old_name;
             $input->setAttribute('data-combo-filters', join(',', $html_filters));
         }
         if ($conditions) {
             $html_conditions = [];
             $old_name = $this->name;
             foreach ($conditions as $condition_name => $condition_value) {
                 $this->name = $condition_name;
                 $name = $this->getFieldName('', false);
                 $html_conditions[] = $name . '=' . $condition_value;
             }
             $this->name = $old_name;
             $input->setAttribute('data-conditions', join(';', $html_conditions));
         }
         $input->addClass('autowidth');
         $input->addClass('combo');
         // id input
         $id_input = new Input($this->getFieldName('id_'), $this->value ? Dao::getObjectIdentifier($this->value) : '');
         $id_input->setAttribute('type', 'hidden');
         $id_input->addClass('id');
         // 'add' / 'edit' anchor
         $fill_combo = isset($this->template) ? ['fill_combo' => $this->template->getFormId() . DOT . $this->getFieldName('id_', false)] : '';
         $edit = new Anchor(View::current()->link($this->value ? get_class($this->value) : $class_name, Feature::F_ADD, null, $fill_combo), 'edit');
         $edit->addClass('edit');
         $edit->setAttribute('target', Target::BLANK);
         $edit->setAttribute('title', '|Edit ¦' . Names::classToDisplay($class_name) . '¦|');
         // 'more' button
         $more = new Button('more');
         $more->addClass('more');
         $more->setAttribute('tabindex', -1);
         $this->setOnChangeAttribute($id_input);
         return $id_input . $input . $more . $edit;
     }
     return $input;
 }