public function execute(HTTPRequestCustom $request)
    {
        $id = $request->get_getint('id');
        $this->init();
        $extended_field = new ExtendedField();
        $extended_field->set_id($id);
        $exist_field = ExtendedFieldsDatabaseService::check_field_exist_by_id($extended_field);
        if ($exist_field) {
            $this->extended_field = ExtendedFieldsCache::load()->get_extended_field($id);
            $this->build_form($request);
        } else {
            $error_controller = PHPBoostErrors::unexisting_page();
            DispatchManager::redirect($error_controller);
        }
        $this->tpl = new StringTemplate('# INCLUDE MSG #
				# INCLUDE FORM #
				<script>
				jQuery(document).ready(function() {
				' . $this->get_events_select_type() . '});
				</script>');
        $this->tpl->add_lang($this->lang);
        $this->tpl->put_all(array('FIELD_TYPE' => $this->extended_field['field_type']));
        if ($this->submit_button->has_been_submited() && $this->form->validate()) {
            $extended_field = $this->save($id);
            $error = ExtendedFieldsService::get_error();
            if (!empty($error)) {
                $this->tpl->put('MSG', MessageHelper::display($error, MessageHelper::ERROR, 5));
            } else {
                AppContext::get_response()->redirect($this->form->get_value('referrer') ? $this->form->get_value('referrer') : AdminExtendedFieldsUrlBuilder::fields_list(), StringVars::replace_vars($this->lang['message.success.edit'], array('name' => $extended_field->get_name())));
            }
        }
        $this->tpl->put('FORM', $this->form->display());
        return new AdminExtendedFieldsDisplayResponse($this->tpl, $this->lang['extended-field-edit']);
    }
 public function execute(HTTPRequestCustom $request)
 {
     $id = $request->get_int('id', null);
     $code = -1;
     if ($id !== null) {
         $extended_field = new ExtendedField();
         $extended_field->set_id($id);
         $exist_field = ExtendedFieldsDatabaseService::check_field_exist_by_id($extended_field);
         if ($exist_field) {
             ExtendedFieldsService::delete_by_id($id);
             $code = $id;
         }
     }
     return new JSONResponse(array('code' => $code));
 }
 public static function __static()
 {
     self::$db_querier = PersistenceContext::get_querier();
 }
 /**
  * @desc Return informations for extended field by id or field name
  * @param object ExtendedField containing the id or the field name
  * @param const $sort SORT_BY_ID or SORT_BY_FIELD_NAME
  * $return Object ExtendedField containing the informations field
  */
 public static function data_field(ExtendedField $extended_field, $sort = self::SORT_BY_ID)
 {
     $field_name = $extended_field->get_field_name();
     $id = $extended_field->get_id();
     if ($sort == self::SORT_BY_ID && $id > 0) {
         $data = ExtendedFieldsDatabaseService::select_data_field_by_id($extended_field);
     } else {
         if ($sort == self::SORT_BY_FIELD_NAME && !empty($field_name)) {
             $data = ExtendedFieldsDatabaseService::select_data_field_by_field_name($extended_field);
         }
     }
     if (isset($data)) {
         $extended_field->set_name($data['name']);
         $extended_field->set_field_name($data['field_name']);
         $extended_field->set_position($data['position']);
         $extended_field->set_description($data['description']);
         $extended_field->set_field_type($data['field_type']);
         $extended_field->set_possible_values($data['possible_values']);
         $extended_field->set_default_value($data['default_value']);
         $extended_field->set_is_required($data['required']);
         $extended_field->set_display($data['display']);
         $extended_field->set_regex($data['regex']);
         $extended_field->set_is_freeze($data['freeze']);
         $extended_field->set_authorization($data['auth']);
     }
     return $extended_field;
 }