Esempio n. 1
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)]);
         }
     }
 }