Beispiel #1
0
 /**
  * Adds properties of the class name into $properties
  *
  * Please always call this instead of adding properties manually : it manages 'link'
  * class annotations.
  *
  * @param $path       string
  * @param $class_name string
  * @param $join_mode  string
  */
 private function addProperties($path, $class_name, $join_mode = null)
 {
     $class = new Link_Class($class_name);
     $this->properties[$class_name] = $class->getProperties([T_EXTENDS, T_USE]);
     $linked_class_name = $class->getAnnotation('link')->value;
     if ($linked_class_name) {
         $this->addLinkedClass($path, $class, $linked_class_name, $join_mode);
     }
 }
Beispiel #2
0
 /**
  * @param $object   object
  * @param $property Reflection_Property
  * @param $map      object[]
  */
 private function writeMap($object, Reflection_Property $property, $map)
 {
     // old map
     $class = new Link_Class(get_class($object));
     $composite_property_name = $class->getAnnotation('link')->value ? $class->getCompositeProperty()->name : null;
     $old_object = Search_Object::create(Link_Class::linkedClassNameOf($object));
     $this->setObjectIdentifier($old_object, $this->getObjectIdentifier($object, $composite_property_name));
     $aop_getter_ignore = Getter::$ignore;
     Getter::$ignore = false;
     $old_map = $property->getValue($old_object);
     Getter::$ignore = $aop_getter_ignore;
     // map properties : write each of them
     $insert_builder = new Map_Insert($property);
     $id_set = [];
     foreach ($map as $element) {
         $id = $this->getObjectIdentifier($element) ?: $this->getObjectIdentifier($this->write($element));
         if (!isset($old_map[$id])) {
             $query = $insert_builder->buildQuery($object, $element);
             $this->connection->query($query);
         } else {
             $id_set[$id] = true;
         }
     }
     // remove old unused elements
     $delete_builder = new Map_Delete($property);
     foreach ($old_map as $old_element) {
         $id = $this->getObjectIdentifier($old_element);
         if (!isset($id_set[$id])) {
             $query = $delete_builder->buildQuery($object, $old_element);
             $this->connection->query($query);
         }
     }
 }
Beispiel #3
0
 /**
  * @param $class_name string
  * @param $search     array
  * @return array
  */
 private function createArrayReference($class_name, $search)
 {
     $array = isset($search) ? [Builder::fromArray($class_name, $search)] : null;
     $class = new Link_Class($class_name);
     $link_class = $class->getAnnotation('link')->value;
     if ($link_class) {
         $object = reset($array);
         $link_search = Builder::create($link_class);
         $composite_property_name = $class->getCompositeProperty()->name;
         foreach (array_keys($class->getLinkedProperties()) as $property_name) {
             if (isset($search[$property_name])) {
                 $link_search->{$property_name} = $search[$property_name];
             }
         }
         $object->{$composite_property_name} = Dao::searchOne($link_search) ?: $link_search;
     }
     return $array;
 }
Beispiel #4
0
 /**
  * Build SQL WHERE section for an object
  *
  * @param $path        string Base property path pointing to the object
  * @param $object      object The value is an object, which will be used for search
  * @return string
  */
 private function buildObject($path, $object)
 {
     $class = new Link_Class(get_class($object));
     $id = $this->sql_link->getObjectIdentifier($object, $class->getAnnotation('link')->value ? $class->getCompositeProperty()->name : null);
     if ($id) {
         // object is linked to stored data : search with object identifier
         return $this->buildValue($path, $id, $path == 'id' ? '' : 'id_');
     }
     // object is a search object : each property is a search entry, and must join table
     $this->joins->add($path);
     $array = [];
     $class = new Reflection_Class(get_class($object));
     foreach ($class->accessProperties() as $property_name => $property) {
         if (isset($object->{$property_name})) {
             $sub_path = $property_name;
             $array[$sub_path] = $object->{$property_name};
         }
     }
     $sql = $this->buildArray($path, $array, 'AND');
     if (!$sql) {
         $sql = 'FALSE';
     }
     return $sql;
 }