Example #1
0
 public function renderField()
 {
     if (!$this->is_display) {
         return '';
     }
     $format = $this->name_form . '[' . $this->name . ']';
     $id = $this->id ? $this->id : $this->name_form . '_' . $this->name;
     $string = '';
     $_data = array();
     $options = $this->options;
     $Model = null;
     if (count($options) == 0) {
         $Model = Service::get('database.manager')->model($this->name_model_relation, 't');
     }
     if (!$this->form->isNew()) {
         $definition = $this->definition;
         $model = $this->form->getModel();
         $name_primary = $model::primary;
         $_id = $model->{$name_primary};
         // Si se esta editando el registro
         // Si el modelo fue iniciado
         // Si la relacion es 'many-to-many-self-referencing'
         // Entontes, excluye del query el ID del registro actual.
         if ($Model && $this->type_relation == 'many-to-many-self-referencing') {
             $Model->where("t.{$name_primary}", '<>', $_id);
         }
         /**
          * @var $db DatabaseManager
          */
         $db = Service::get('database.manager');
         $ConnectionOptions = $db->getConnectionManager()->getConnectionOptions();
         // Busca los registros que han sido seleccionados
         $_opt = $db->getQueryBuilder()->select('*')->from("{$ConnectionOptions['prefix']}{$definition['tableManyToMany']}", 't')->where("t.{$definition['localField']}=:{$definition['localField']}")->setParameter(":{$definition['localField']}", $_id)->execute()->fetchAll();
         foreach ($_opt as $op) {
             $_data[] = $op[$definition['foreignField']];
         }
     }
     if ($Model) {
         $options = $Model->getForOptions();
     }
     foreach ($options as $_value => $_option) {
         $string .= '<label class="checkbox-inline">';
         $is_active = in_array($_value, $_data) ? true : false;
         $string .= \Kodazzi\Helper\FormHtml::checkbox($format . '[' . $_value . ']', $_value, $is_active, array('id' => $id . '_' . $_value, 'class' => $this->getClassCss(), 'disabled' => $this->isDisabled(), 'readonly' => $this->isReadonly()));
         $string .= $_option . ' </label>';
     }
     return $string;
 }
Example #2
0
 public function renderField()
 {
     if (!$this->is_display) {
         return '';
     }
     $format = $this->format ? $this->format : $this->name_form . '[' . $this->name . ']';
     $id = $this->id ? $this->id : $this->name_form . '_' . $this->name;
     if ($this->type_field_tag === 'check') {
         $label = $this->getValueLabel();
         $string = '';
         $string .= '<label>';
         $string .= \Kodazzi\Helper\FormHtml::checkbox($format, 1, (int) $this->value === 1 || $this->value === true ? true : false, array('id' => $id, 'class' => $this->getClassCss(), 'disabled' => $this->isDisabled(), 'readonly' => $this->isReadonly()));
         $string .= "{$label}";
         $string .= '</label>';
         return $string;
     }
 }