Esempio n. 1
0
 /**
  * Default run method for default 'write-typed' controller
  *
  * Save data from the posted form into the first parameter object using standard method.
  * Create a new instance of this object if no identifier was given.
  *
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @param $class_name string
  * @return string
  * @throws Exception
  */
 public function run(Parameters $parameters, $form, $files, $class_name)
 {
     $object = $parameters->getMainObject($class_name);
     Dao::begin();
     try {
         $builder = new Post_Files();
         $form = $builder->appendToForm($form, $files);
         $builder = new Object_Builder_Array();
         $builder->null_if_empty_sub_objects = true;
         $builder->build($form, $object);
         $write_objects = [];
         foreach ($builder->getBuiltObjects() as $write_object) {
             if ($write_object == $object || Dao::getObjectIdentifier($write_object)) {
                 $write_objects[] = $write_object;
             }
         }
         $write_error = false;
         foreach ($write_objects as $write_object) {
             if (!Dao::write($write_object)) {
                 $write_error = true;
                 break;
             }
         }
         $write_error ? Dao::rollback() : Dao::commit();
     } catch (Exception $exception) {
         Dao::rollback();
         throw $exception;
     }
     $parameters = $this->getViewParameters($parameters, $class_name, $write_error);
     return View::run($parameters, $form, $files, $class_name, Feature::F_WRITE);
 }
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @param $class_name string
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files, $class_name)
 {
     $replaced = $parameters->getMainObject();
     $objects = $parameters->getObjects();
     if ($id_replace_with = $parameters->getRawParameter('id_replace_with')) {
         $objects['replace_with'] = $replacement = Dao::read($id_replace_with, $class_name);
         Dao::begin();
         if ((new Delete_And_Replace())->deleteAndReplace($replaced, $replacement)) {
             Dao::commit();
             $objects['done'] = true;
         } else {
             Dao::rollback();
             $objects['error'] = true;
         }
     }
     return View::run($objects, $form, $files, $class_name, 'deleteAndReplace');
 }
Esempio n. 3
0
 /**
  * Imports a data array using settings
  *
  * $array is a reference to avoid array replication.
  * Beware : if $array begins with a 'Class_Name' row, this first row will be removed !
  * Beware : first row must contain property paths, and will be removed !
  *
  * @param $array array $value = string[$row_number][$column_number]
  */
 public function importArray(&$array)
 {
     Dao::begin();
     $class_name = self::getClassNameFromArray($array) ?: $this->class_name;
     if (isset($class_name)) {
         $this->class_name = $class_name;
     }
     list($this->properties_link, $this->properties_column) = self::getPropertiesLinkAndColumn($this->class_name, self::getPropertiesFromArray($array, $this->class_name));
     $key = key($array);
     foreach ($this->sortedClasses() as $class) {
         reset($array);
         while (key($array) !== $key) {
             next($array);
         }
         $this->importArrayClass($class, $array);
     }
     if ($this->simulation) {
         Dao::rollback();
     } else {
         Dao::commit();
     }
 }