예제 #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);
 }
예제 #2
0
파일: Logger.php 프로젝트: TuxBoy/Demo-saf
 /**
  * Stop logging : write end date-time and duration
  */
 public function stop()
 {
     $this->antiloop--;
     if (!$this->antiloop) {
         $this->log_entry->stop();
         Dao::write($this->log_entry);
     }
 }
예제 #3
0
파일: Tests.php 프로젝트: TuxBoy/Demo-saf
 public function testWriteAnnotations()
 {
     $tests = new Tests();
     $tests->data = 'test';
     Dao::write($tests, [Dao::only(['data'])]);
     Dao::delete($tests);
     $this->assume(__METHOD__, $tests->data, 'test+locbefore(data)+disbefore(data)+locafter(data)+disafter(data)');
 }
예제 #4
0
파일: Counter.php 프로젝트: TuxBoy/Demo-saf
 /**
  * Load a counter linked to the class of an object from default data link and increment it
  *
  * @param $object     object The object to use to format the counter
  * @param $identifier string The identifier of the counter ; default is get_class($object)
  * @return string The new counter value
  */
 public static function increment($object, $identifier = null)
 {
     Dao::begin();
     if (empty($identifier)) {
         $identifier = Builder::current()->sourceClassName(get_class($object));
     }
     $counter = Dao::searchOne(['identifier' => $identifier], get_called_class()) ?: new Counter($identifier);
     $next_value = $counter->next($object);
     Dao::write($counter);
     Dao::commit();
     return $next_value;
 }
예제 #5
0
파일: Logger.php 프로젝트: TuxBoy/Demo-saf
 /**
  * @param $object Framework\Logger
  */
 public function onLoggerStop(Framework\Logger $object)
 {
     if ($this->log_flag) {
         Dao::begin();
         foreach (Dao::search(['log' => Func::isNull()], Compiler_Log::class) as $logger) {
             /** @var $logger Compiler_Log */
             $logger->log = $object->log_entry;
             Dao::write($logger, [Dao::only(['log'])]);
         }
         $this->log_flag = false;
         Dao::commit();
     }
 }
예제 #6
0
 /**
  * To use this :
  * - Create your own writeSubClassNames() method
  * - Your method has no parameters
  * - Your method returns nothing
  * - Call return writeSub('sub_class_names', 'super_class_name') using your two properties names
  *
  * @param $sub   string sub property name ie 'sub_class_names'
  * @param $super string super property name ie 'super_class_name'
  */
 private function writeSub($sub, $super)
 {
     $written = [];
     // update $super_property into new $sub_properties
     foreach ($this->{$sub} as $sub) {
         if (!Dao::is($this, $sub->{$super})) {
             $sub->{$super} = $this;
             Dao::write($sub, [Dao::only($super)]);
         }
         $written[Dao::getObjectIdentifier($sub)] = true;
     }
     // empty $super_property from removed $sub_properties
     $subs = Dao::search([$super => $this], Link_Class::linkedClassNameOf($this));
     foreach ($subs as $sub) {
         if (!isset($written[Dao::getObjectIdentifier($sub)])) {
             $sub->{$super} = null;
             Dao::write($sub, [Dao::only($super)]);
         }
     }
 }
예제 #7
0
 /**
  * If $save_name is set : saves the Data_List_Settings object into the Settings set
  * If $save_name is not set : saves the Data_List_Settings object for current user and session
  *
  * @param $save_name string
  */
 public function save($save_name = null)
 {
     if (isset($save_name)) {
         $this->name = $save_name;
         $setting = new Setting($this->class_name . DOT . static::customId() . DOT . $save_name);
         $setting = Dao::searchOne($setting) ?: $setting;
         $setting->value = $this;
         Dao::write($setting);
     } elseif ($this) {
         Dao::write($this->setting);
     }
 }
예제 #8
0
 /**
  * Register with current environment using login and password
  *
  * @param $form string[] The form content
  * @return User user
  */
 public static function register($form)
 {
     return Dao::write(self::arrayToUser($form));
 }
예제 #9
0
 /**
  * @param $row                     array
  * @param $class                   Import_Class
  * @param $class_properties_column integer[]|string[]
  * @return object
  */
 private function writeNewObject($row, Import_Class $class, $class_properties_column)
 {
     $object = Builder::create($class->class_name);
     foreach (array_keys($class->identify_properties) as $property_name) {
         $object->{$property_name} = $row[$class_properties_column[$property_name]];
     }
     foreach (array_keys($class->write_properties) as $property_name) {
         $object->{$property_name} = $row[$class_properties_column[$property_name]];
     }
     if ($this->simulation) {
         $this->simulateNew($class, $object);
     }
     Dao::write($object);
     return $object;
 }
예제 #10
0
 /**
  * Translates a text using current language and an optionnal given context
  *
  * @param $text    string
  * @param $context string
  * @return string
  */
 public function translate($text, $context = '')
 {
     if (!trim($text) || is_numeric($text)) {
         return $text;
     } elseif (strpos($text, DOT) !== false) {
         $translation = [];
         foreach (explode(DOT, $text) as $sentence) {
             $translation[] = $this->translate($sentence, $context);
         }
         return join(DOT, $translation);
     } elseif (!isset($this->cache[$text]) || !isset($this->cache[$text][$context])) {
         if (substr($text, -1) === AT) {
             $str_uri = true;
             $text = substr($text, 0, -1);
         } else {
             $str_uri = false;
         }
         $search = new Translation($text, $this->language, $context);
         $translations = Dao::search($search);
         foreach ($translations as $translation) {
             if ($translation->text === $text) {
                 break;
             }
         }
         while ($search->context && !isset($translation)) {
             $i = strrpos($search->context, DOT);
             $search->context = $i ? substr($search->context, 0, $i) : '';
             $translations = Dao::search($search);
             foreach ($translations as $translation) {
                 if ($translation->text === $text) {
                     break;
                 }
             }
         }
         if (!isset($translation) && strpos($text, ', ')) {
             $translation_parts = [];
             foreach (explode(', ', $text) as $text_part) {
                 $translation_parts[] = $this->translate($text_part, $context);
             }
             $translation = new Translation($text, $this->language, $context, join(', ', $translation_parts));
         }
         if (!isset($translation)) {
             $translation = $search;
             $translation->text = str_replace('_', SP, strtolower($translation->text));
             $translation->translation = '';
             Dao::write($translation);
         }
         $translation = $translation ? $translation->translation : $text;
         if ($str_uri) {
             $text .= AT;
             $translation = strUri($translation);
         }
         $this->cache[$text][$context] = $translation;
     }
     $translation = $this->cache[$text][$context];
     return empty($translation) ? $text : (strIsCapitals($text[0]) ? ucfirsta($translation) : $translation);
 }
예제 #11
0
파일: Archive.php 프로젝트: TuxBoy/Demo-saf
 /**
  * @param $email Email
  */
 public function save(Email $email)
 {
     Dao::write($email);
 }