Completed
Branch CASC/store-to-db (67966b)
by
unknown
17:39 queued 08:43
created
core/services/orm/tree_traversal/ModelObjNodeTreeDTO.php 2 patches
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -22,151 +22,151 @@
 block discarded – undo
22 22
  */
23 23
 class ModelObjNodeTreeDTO
24 24
 {
25
-    const INDEX_PATH = 'ip';
26
-    const ROOTS = 'rts';
27
-    const MODEL = 'm';
28
-    const ITEMS = 'i';
29
-    const ID = 'id';
30
-    const RELATIONSHIPS = 'r';
31
-    const COUNT = 'c';
32
-    /**
33
-     * @var array with a special structure. Like the following:
34
-     * {
35
-     *  "index_path": [0,3,1,2],
36
-     *  "roots": [
37
-     *      {
38
-     *          "model": "Event",
39
-     *          "items": [
40
-     *              {
41
-     *                  "id": 123,
42
-     *                  "rels": [
43
-     *                      {
44
-     *                          "model": "Datetime"
45
-     *                          "count": 3
46
-     *                          "items": [
47
-     *                              {
48
-     *                                  "id": 456,
49
-     *                                  "rels": [
50
-     *                                      {
51
-     *                                          "model": "Datetime_Ticket",
52
-     *                                          "count": 1,
53
-     *                                          "items": [
54
-     *                                              {
55
-     *                                                  "id": 789,
56
-     *                                                  "rels": [
57
-     *                                                      {
58
-     *                                                          "model": "Extra_Meta",
59
-     *                                                          "count": 0,
60
-     *                                                          "items":[],
61
-     *                                                      }
62
-     *                                                      // ... other models that have foreign keys to Datetime_Ticket
63
-     *                                                  ]
64
-     *                                              }.
65
-     *                                          ]
66
-     *                                      },
67
-     *                                      // ... other models that have foreign keys to Datetime
68
-     *                                  ]
69
-     *                              },
70
-     *                              // ... 2 more datetimes (unless we haven't fetched them from the DB yet. The count
71
-     *                              // is useful here to know if we need to fetch more or not
72
-     *                          ]
73
-     *                      },
74
-     *                      //  ...other models that have foreign keys to events, including implicit join models
75
-     *                  ]
76
-     *              },
77
-     *              // ...other root events that we want to traverse
78
-     *          ],
79
-     *          /// ...other models with root nodes
80
-     *      }
81
-     */
82
-    protected $data;
25
+	const INDEX_PATH = 'ip';
26
+	const ROOTS = 'rts';
27
+	const MODEL = 'm';
28
+	const ITEMS = 'i';
29
+	const ID = 'id';
30
+	const RELATIONSHIPS = 'r';
31
+	const COUNT = 'c';
32
+	/**
33
+	 * @var array with a special structure. Like the following:
34
+	 * {
35
+	 *  "index_path": [0,3,1,2],
36
+	 *  "roots": [
37
+	 *      {
38
+	 *          "model": "Event",
39
+	 *          "items": [
40
+	 *              {
41
+	 *                  "id": 123,
42
+	 *                  "rels": [
43
+	 *                      {
44
+	 *                          "model": "Datetime"
45
+	 *                          "count": 3
46
+	 *                          "items": [
47
+	 *                              {
48
+	 *                                  "id": 456,
49
+	 *                                  "rels": [
50
+	 *                                      {
51
+	 *                                          "model": "Datetime_Ticket",
52
+	 *                                          "count": 1,
53
+	 *                                          "items": [
54
+	 *                                              {
55
+	 *                                                  "id": 789,
56
+	 *                                                  "rels": [
57
+	 *                                                      {
58
+	 *                                                          "model": "Extra_Meta",
59
+	 *                                                          "count": 0,
60
+	 *                                                          "items":[],
61
+	 *                                                      }
62
+	 *                                                      // ... other models that have foreign keys to Datetime_Ticket
63
+	 *                                                  ]
64
+	 *                                              }.
65
+	 *                                          ]
66
+	 *                                      },
67
+	 *                                      // ... other models that have foreign keys to Datetime
68
+	 *                                  ]
69
+	 *                              },
70
+	 *                              // ... 2 more datetimes (unless we haven't fetched them from the DB yet. The count
71
+	 *                              // is useful here to know if we need to fetch more or not
72
+	 *                          ]
73
+	 *                      },
74
+	 *                      //  ...other models that have foreign keys to events, including implicit join models
75
+	 *                  ]
76
+	 *              },
77
+	 *              // ...other root events that we want to traverse
78
+	 *          ],
79
+	 *          /// ...other models with root nodes
80
+	 *      }
81
+	 */
82
+	protected $data;
83 83
 
84
-    /**
85
-     * @since $VID:$
86
-     * @param EE_Base_Class[] $model_objs
87
-     */
88
-    public function initializeRootNodes($model_objs){
89
-        $this->data = [
90
-            self::INDEX_PATH => [0,0],
91
-            self::ROOTS => []
92
-        ];
93
-        foreach($model_objs as $model_obj) {
94
-            if (!$model_obj instanceof EE_Base_Class) {
95
-                throw new \InvalidArgumentException(esc_html__('You must initialize a ModelObjNodeTreeDTO with an array of EE_Base_Class.', 'event_espresso'));
96
-            }
97
-            if (!isset($this->data[ self::ROOTS ])){
98
-                $this->data[ self::ROOTS ][ $model_obj->get_model()->get_this_model_name() ] = [];
99
-            }
100
-            $this->data[self::ROOTS][$model_obj->get_model()->get_this_model_name()][] = [
101
-                self::ID => $model_obj->ID(),
102
-                self::RELATIONSHIPS => []
103
-            ];
104
-        }
105
-    }
84
+	/**
85
+	 * @since $VID:$
86
+	 * @param EE_Base_Class[] $model_objs
87
+	 */
88
+	public function initializeRootNodes($model_objs){
89
+		$this->data = [
90
+			self::INDEX_PATH => [0,0],
91
+			self::ROOTS => []
92
+		];
93
+		foreach($model_objs as $model_obj) {
94
+			if (!$model_obj instanceof EE_Base_Class) {
95
+				throw new \InvalidArgumentException(esc_html__('You must initialize a ModelObjNodeTreeDTO with an array of EE_Base_Class.', 'event_espresso'));
96
+			}
97
+			if (!isset($this->data[ self::ROOTS ])){
98
+				$this->data[ self::ROOTS ][ $model_obj->get_model()->get_this_model_name() ] = [];
99
+			}
100
+			$this->data[self::ROOTS][$model_obj->get_model()->get_this_model_name()][] = [
101
+				self::ID => $model_obj->ID(),
102
+				self::RELATIONSHIPS => []
103
+			];
104
+		}
105
+	}
106 106
 
107
-    /**
108
-     * @since $VID:$
109
-     * @param array $data
110
-     */
111
-    public function loadData(&$data)
112
-    {
113
-        $this->data = $data;
114
-    }
107
+	/**
108
+	 * @since $VID:$
109
+	 * @param array $data
110
+	 */
111
+	public function loadData(&$data)
112
+	{
113
+		$this->data = $data;
114
+	}
115 115
 
116
-    /**
117
-     * Returns a reference to the data (so it's not duplicated, because it could be really big).
118
-     * @since $VID:$
119
-     * @return array
120
-     */
121
-    public function &getData()
122
-    {
123
-        return $this->data;
124
-    }
116
+	/**
117
+	 * Returns a reference to the data (so it's not duplicated, because it could be really big).
118
+	 * @since $VID:$
119
+	 * @return array
120
+	 */
121
+	public function &getData()
122
+	{
123
+		return $this->data;
124
+	}
125 125
 
126
-    /**
127
-     * @since $VID:$
128
-     * @param EE_Base_Class $model_obj
129
-     */
130
-    public function addDiscoveredItem($model_obj){
131
-        // Figure out where our current spot in the tree.
132
-        $current_items_list = $this->getCurrentItemList();
126
+	/**
127
+	 * @since $VID:$
128
+	 * @param EE_Base_Class $model_obj
129
+	 */
130
+	public function addDiscoveredItem($model_obj){
131
+		// Figure out where our current spot in the tree.
132
+		$current_items_list = $this->getCurrentItemList();
133 133
 
134
-        // Ensure the data is of the correct type.
134
+		// Ensure the data is of the correct type.
135 135
 
136
-        // Add data that corresponds to it to that spot.
136
+		// Add data that corresponds to it to that spot.
137 137
 
138
-    }
138
+	}
139 139
 
140
-    /**
141
-     * Returns a list of indexes to follow.
142
-     * @since $VID:$
143
-     * @return array
144
-     */
145
-    protected function getIndexPath()
146
-    {
147
-        return $this->data[self::INDEX_PATH];
148
-    }
140
+	/**
141
+	 * Returns a list of indexes to follow.
142
+	 * @since $VID:$
143
+	 * @return array
144
+	 */
145
+	protected function getIndexPath()
146
+	{
147
+		return $this->data[self::INDEX_PATH];
148
+	}
149 149
 
150
-    /**
151
-     * @since $VID:$
152
-     */
153
-    public function getCurrentItemList()
154
-    {
155
-        $traverser = &$this->data[ self::ROOTS ];
156
-        foreach ($this->getIndexPath() as $index) {
157
-            if (isset($traverser[ $index ])) {
158
-                if (isset($traverser[ $index ][ self::ID ])) {
159
-                    $traverser = &$traverser[ $index ][ self::RELATIONSHIPS ];
160
-                } else {
161
-                    $traverser = &$traverser[ $index ][ self::ITEMS ];
162
-                }
150
+	/**
151
+	 * @since $VID:$
152
+	 */
153
+	public function getCurrentItemList()
154
+	{
155
+		$traverser = &$this->data[ self::ROOTS ];
156
+		foreach ($this->getIndexPath() as $index) {
157
+			if (isset($traverser[ $index ])) {
158
+				if (isset($traverser[ $index ][ self::ID ])) {
159
+					$traverser = &$traverser[ $index ][ self::RELATIONSHIPS ];
160
+				} else {
161
+					$traverser = &$traverser[ $index ][ self::ITEMS ];
162
+				}
163 163
 
164
-            } else {
165
-                throw new Exception(esc_html__('Index out of sync', 'event_espresso'));
166
-            }
167
-        }
168
-        return $traverser;
169
-    }
164
+			} else {
165
+				throw new Exception(esc_html__('Index out of sync', 'event_espresso'));
166
+			}
167
+		}
168
+		return $traverser;
169
+	}
170 170
 }
171 171
 // End of file ModelObjNodeTreeDTO.php
172 172
 // Location: EventEspresso\core\services\orm\tree_traversal/ModelObjNodeTreeDTO.php
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -85,17 +85,17 @@  discard block
 block discarded – undo
85 85
      * @since $VID:$
86 86
      * @param EE_Base_Class[] $model_objs
87 87
      */
88
-    public function initializeRootNodes($model_objs){
88
+    public function initializeRootNodes($model_objs) {
89 89
         $this->data = [
90
-            self::INDEX_PATH => [0,0],
90
+            self::INDEX_PATH => [0, 0],
91 91
             self::ROOTS => []
92 92
         ];
93
-        foreach($model_objs as $model_obj) {
94
-            if (!$model_obj instanceof EE_Base_Class) {
93
+        foreach ($model_objs as $model_obj) {
94
+            if ( ! $model_obj instanceof EE_Base_Class) {
95 95
                 throw new \InvalidArgumentException(esc_html__('You must initialize a ModelObjNodeTreeDTO with an array of EE_Base_Class.', 'event_espresso'));
96 96
             }
97
-            if (!isset($this->data[ self::ROOTS ])){
98
-                $this->data[ self::ROOTS ][ $model_obj->get_model()->get_this_model_name() ] = [];
97
+            if ( ! isset($this->data[self::ROOTS])) {
98
+                $this->data[self::ROOTS][$model_obj->get_model()->get_this_model_name()] = [];
99 99
             }
100 100
             $this->data[self::ROOTS][$model_obj->get_model()->get_this_model_name()][] = [
101 101
                 self::ID => $model_obj->ID(),
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      * @since $VID:$
128 128
      * @param EE_Base_Class $model_obj
129 129
      */
130
-    public function addDiscoveredItem($model_obj){
130
+    public function addDiscoveredItem($model_obj) {
131 131
         // Figure out where our current spot in the tree.
132 132
         $current_items_list = $this->getCurrentItemList();
133 133
 
@@ -152,13 +152,13 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function getCurrentItemList()
154 154
     {
155
-        $traverser = &$this->data[ self::ROOTS ];
155
+        $traverser = &$this->data[self::ROOTS];
156 156
         foreach ($this->getIndexPath() as $index) {
157
-            if (isset($traverser[ $index ])) {
158
-                if (isset($traverser[ $index ][ self::ID ])) {
159
-                    $traverser = &$traverser[ $index ][ self::RELATIONSHIPS ];
157
+            if (isset($traverser[$index])) {
158
+                if (isset($traverser[$index][self::ID])) {
159
+                    $traverser = &$traverser[$index][self::RELATIONSHIPS];
160 160
                 } else {
161
-                    $traverser = &$traverser[ $index ][ self::ITEMS ];
161
+                    $traverser = &$traverser[$index][self::ITEMS];
162 162
                 }
163 163
 
164 164
             } else {
Please login to merge, or discard this patch.