Example #1
0
 public function prepare($db, $data)
 {
     $this->data = $data;
     if ($this->is_admin_form) {
         $this->action = sprintf($this->action, $this->data->val($this->id));
         $this->del_url = sprintf($this->del_url, $this->data->val($this->id));
     }
     foreach ($this->fields as $field) {
         if (isset($field->name)) {
             $field->value = $this->data->val($field->name);
             if ($field->type == 'select' && !isset($field->select_data)) {
                 $field->select_data = ModelBase::select($db, $field->select_table, null, null, null, null, $field->select_label_field);
             } elseif ($field->type == 'foreign_key_link') {
                 $entity = new ModelBase($db);
                 $entity->table_name = $field->link_table;
                 $filter = sprintf('%s = ?', $field->link_id_field);
                 $entity->loadSingleFiltered($filter, [$this->data->val($field->name)]);
                 $field->link_label = $entity->val($field->link_label_field);
                 $field->link_url = sprintf($field->link_template, $entity->val($field->link_id_field));
             }
         }
     }
 }