I think the datamapper is working right now...
authorCameron Ball <cameron@getapproved.com.au>
Tue, 25 Nov 2014 02:16:21 +0000 (10:16 +0800)
committerCameron Ball <cameron@getapproved.com.au>
Tue, 25 Nov 2014 02:16:21 +0000 (10:16 +0800)
DataAccess/DataMapper/DataMapper.php
Services/Uploads/UserSession.php [deleted file]

index 24a7d5a..fd9c242 100644 (file)
@@ -57,22 +57,31 @@ class DataMapper implements IDataMapper
     {\r
         $queries = AbstractPopulationHelper::generateUpdateSaveQuery($this->_maps, $entity, $entity->getId(), $this->_db);\r
         $mergeMap = array();\r
-        \r
-        echo 'pre flattened: <br />';\r
-        echo '<pre>';\r
-        print_r($queries);\r
-        echo '</pre>';\r
-        \r
         $flattened = array();\r
-        $flattened_tables = array();\r
+\r
         foreach($queries as $index => $query)\r
         {\r
             $this_table = $query['table'];\r
             $this_columns = $query['columns'];\r
-            $flatten = true;\r
+            \r
+            if(!array_key_exists($index, $mergeMap)) {\r
+                $prepared = isset($query['prepared']) ? $query['prepared'] : null;\r
+                $id = isset($query['id']) ? $query['id'] : null;\r
+\r
+                $flattened[] = array(\r
+                    'columns' => $this_columns,\r
+                    'table' => $this_table,\r
+                    'prepared' => $prepared,\r
+                    'id' => $id\r
+                );\r
+            }\r
+            \r
             for($i = $index+1; $i<count($queries); $i++)\r
             {\r
-                if($queries[$i]['table'] == $this_table && !in_array($queries[$i]['table'], $flattened_tables) && !isset($query['id'])) //only merge create queries, updates are fine to run multiple times\r
+                if(\r
+                    $queries[$i]['table'] == $this_table &&\r
+                    !array_key_exists($i, $mergeMap) &&\r
+                    !isset($query['id'])) //only merge create queries, updates are fine to run multiple times\r
                 {\r
                     //XXX: This whole biz is tricky. Basically the problem is that when creating a new simfile,\r
                     //the datamapper spews out a bunch of create queries. When parsing a simfile for example, there can\r
@@ -82,34 +91,13 @@ class DataMapper implements IDataMapper
                     //check if the arrays are equal as well, which is what this does.\r
                     if($this_columns === $queries[$i]['columns'])\r
                     {\r
-                        $this_columns = array_merge($this_columns, $queries[$i]['columns']);\r
                         //need to keep track of what we merged as future queries might reference the old ids.\r
                         $mergeMap[$i] = $index;\r
-                    } else {\r
-                        //we need to add these unmerged ones here as further down we record that anything to\r
-                        //do with this table has been sorted out.\r
-//                        $prepared = isset($queries[$i]['prepared']) ? $queries[$i]['prepared'] : null;\r
-//                        $id = isset($queries[$i]['id']) ? $queries[$i]['id'] : null;\r
-//                        $flattened[] = array('columns' => $queries[$i]['columns'], 'table' => $queries[$i]['table'], 'prepared' => $prepared, 'id' => $id);\r
-                        $flatten = false;\r
                     }\r
                 }\r
             }\r
-            \r
-            if(!in_array($this_table, $flattened_tables))\r
-            {\r
-                if($flatten) $flattened_tables[] = $this_table;\r
-                $prepared = isset($query['prepared']) ? $query['prepared'] : null;\r
-                $id = isset($query['id']) ? $query['id'] : null;\r
-                $flattened[] = array('columns' => $this_columns, 'table' => $this_table, 'prepared' => $prepared, 'id' => $id);\r
-            }\r
         }\r
         \r
-        echo 'flattened: <br />';\r
-        echo '<pre>';\r
-        print_r($flattened);\r
-        echo '</pre>';\r
-        \r
         $queries = array();\r
                 \r
         foreach($flattened as $info)\r
diff --git a/Services/Uploads/UserSession.php b/Services/Uploads/UserSession.php
deleted file mode 100644 (file)
index ec941e6..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-
-namespace Services;
-
-use Services\IUserSession;
-use Services\Http\IHttpRequest;
-use DataAccess\IUserRepository;
-
-class UserSession implements IUserSession
-{
-    private $_httpRequest;
-    private $_userRepository;
-    private $_currentUser;
-    
-    public function __construct(IHttpRequest $httpRequest, IUserRepository $userRepository)
-    {
-        $this->_httpRequest = $httpRequest;
-        $this->_userRepository = $userRepository;
-    }
-    
-    public function getCurrentUser() {
-        if(empty($this->_currentUser))
-        {
-            $request = $this->_httpRequest->isGet() ? $this->_httpRequest->get() 
-                                                    : json_decode($this->_httpRequest->getBody(), true);
-
-            $token = isset($request['token']) ? $request['token'] : null;
-            $this->_currentUser = $this->_userRepository->findByAuthToken($token);
-        }
-        
-        return $this->_currentUser;
-    }
-}
-