Пример #1
0
 protected static function swapModelWeightOperation()
 {
     $model_class_name = POSTAccess::getRequiredPostValue('_class_name');
     // TODO: constant for field name
     \OLOG\CheckClassInterfaces::exceptionIfClassNotImplementsInterface($model_class_name, \OLOG\Model\InterfaceWeight::class);
     $model_id = POSTAccess::getRequiredPostValue('_id');
     // TODO: constant for field name
     $context_fields_names_str = POSTAccess::getRequiredPostValue(CRUDTableWidgetWeight::FORMFIELD_CONTEXT_FIELDS_NAME);
     $context_fields_names_arr = explode(',', $context_fields_names_str);
     $context_arr = [];
     foreach ($context_fields_names_arr as $context_field_name) {
         $context_arr[$context_field_name] = NullablePostFields::optionalFieldValue($context_field_name);
     }
     /** @var InterfaceWeight $obj */
     $obj = CRUDObjectLoader::createAndLoadObject($model_class_name, $model_id);
     $obj->swapWeights($context_arr);
     \OLOG\Redirects::redirectToSelf();
 }
Пример #2
0
 protected static function saveEditorFormOperation($url_to_redirect_after_save = '', $redirect_get_params_arr = [])
 {
     $model_class_name = POSTAccess::getRequiredPostValue(self::FIELD_CLASS_NAME);
     $object_id = self::saveOrUpdateObjectFromFormData();
     if ($url_to_redirect_after_save != '') {
         $obj = CRUDObjectLoader::createAndLoadObject($model_class_name, $object_id);
         $redirect_url = $url_to_redirect_after_save;
         $redirect_url = CRUDCompiler::compile($redirect_url, ['this' => $obj]);
         $params_arr = [];
         foreach ($redirect_get_params_arr as $param => $value) {
             $params_arr[$param] = CRUDCompiler::compile($value, ['this' => $obj]);
         }
         if (!empty($redirect_get_params_arr)) {
             $redirect_url = $url_to_redirect_after_save . '?' . http_build_query($params_arr);
         }
         \OLOG\Redirects::redirect($redirect_url);
     }
     // keep get form
     \OLOG\Redirects::redirectToSelf();
 }