first test
[m6w6/pq-gateway] / lib / pq / Mapper / Property / All.php
index b53efdd44979c5726979513faa61a23dcbfe4415..49fb0a622b4310a9ed410ee316362b62aeb6658c 100644 (file)
@@ -11,12 +11,22 @@ use UnexpectedValueException;
 class All implements RefPropertyInterface
 {
        use RefProperty;
-       
+
+       /**
+        * Create a child rows mapping
+        * @param Mapper $mapper
+        * @param string $property
+        */
        function __construct(Mapper $mapper, $property) {
                $this->mapper = $mapper;
                $this->property = $property;
        }
-       
+
+       /**
+        * Read the child objects
+        * @param Row $row
+        * @param object $objectToUpdate
+        */
        function read(Row $row, $objectToUpdate) {
                $val = $this->extract($objectToUpdate);
                if (!isset($val)) {
@@ -27,6 +37,12 @@ class All implements RefPropertyInterface
                }
        }
 
+       /**
+        * Write the child rows
+        * @param object $object
+        * @param Row $rowToUpdate
+        * @return callable deferred callback
+        */
        function write($object, Row $rowToUpdate) {
                $property = $this->findRefProperty($object);
                $map = $this->mapper->mapOf($this->refClass);
@@ -39,23 +55,14 @@ class All implements RefPropertyInterface
                                $map->unmap($ref);
                        }
                };
-               
-               if (!$this->container->getObjects()->rowId($rowToUpdate, true)) {
-                       return [$this, "write"];
-               } else {
-                       /* $object = User */
-                       /* $refs = array(Email) */
-                       /* $property = Property\Ref(Email::$user)->to(User)->by("email_user") */
-                       /* now update array(Email) with id of User, i.e. $ref->user_id = $object->id */
-                       $map = $this->mapper->mapOf($this->refClass);
-                       $refs = $this->extract($object);
-                       foreach ($refs as $ref) {
-                               $property->assign($ref, $object);
-                               $map->unmap($ref);
-                       }
-               }
        }
 
+       /**
+        * Find the referring property that references $object on our foreign key
+        * @param object $object
+        * @return RefPropertyInterface[]
+        * @throws UnexpectedValueException
+        */
        private function findRefProperty($object) {
                $map = $this->mapper->mapOf($this->refClass);
                $property = array_filter($map->getProperties(), function($property) use($object) {
@@ -72,24 +79,4 @@ class All implements RefPropertyInterface
                }
                return current($property);
        }
-
-       function read2(RowGateway $row) {
-               #echo __METHOD__." ".$this;
-               $ref = $this->getRefMap()->ref($row, $this->refName);
-               $value = $this->mapper->map($ref, $this->refClass);
-               return [$this->property => $value];
-       }
-       
-       function write2($object) {
-               #echo __METHOD__." ".$this;
-               $value = $this->extract($object);
-               foreach ($value as $ref) {
-                       $this->mapper->queue(function() use(&$object, &$ref) {
-                               $map = $this->getRefMap()->getRefMapping($this->refName);
-                               $map->assign($ref, $object);
-                               $this->mapper->unmap($ref, $this->getRefMap());
-                       });
-               }
-               return [];
-       }
-}
\ No newline at end of file
+}