Completed
Branch dependabot/npm_and_yarn/wordpr... (0475b3)
by
unknown
14:52 queued 12:42
created
strategies/EE_Restriction_Generator_Event_Related_Public.strategy.php 2 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -17,72 +17,72 @@
 block discarded – undo
17 17
 class EE_Restriction_Generator_Event_Related_Public extends EE_Restriction_Generator_Base
18 18
 {
19 19
 
20
-    /**
21
-     * Path to the event model from the model this restriction generator will be applied to;
22
-     * including the event model itself. Eg "Ticket.Datetime.Event"
23
-     * @var string
24
-     */
25
-    protected $_path_to_event_model;
26
-    /**
27
-     *
28
-     * @param string $path_to_event_model
29
-     */
30
-    public function __construct($path_to_event_model)
31
-    {
32
-        if (substr($path_to_event_model, -1, 1) != '.') {
33
-            $path_to_event_model .= '.';
34
-        }
35
-        $this->_path_to_event_model = $path_to_event_model;
36
-    }
37
-    /**
38
-     *
39
-     * @return \EE_Default_Where_Conditions
40
-     */
41
-    protected function _generate_restrictions()
42
-    {
43
-        // if there are no standard caps for this model, then for now all we know
44
-        // if they need the default cap to access this
45
-        if (! $this->model()->cap_slug()) {
46
-            return array(
47
-                self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions()
48
-            );
49
-        }
20
+	/**
21
+	 * Path to the event model from the model this restriction generator will be applied to;
22
+	 * including the event model itself. Eg "Ticket.Datetime.Event"
23
+	 * @var string
24
+	 */
25
+	protected $_path_to_event_model;
26
+	/**
27
+	 *
28
+	 * @param string $path_to_event_model
29
+	 */
30
+	public function __construct($path_to_event_model)
31
+	{
32
+		if (substr($path_to_event_model, -1, 1) != '.') {
33
+			$path_to_event_model .= '.';
34
+		}
35
+		$this->_path_to_event_model = $path_to_event_model;
36
+	}
37
+	/**
38
+	 *
39
+	 * @return \EE_Default_Where_Conditions
40
+	 */
41
+	protected function _generate_restrictions()
42
+	{
43
+		// if there are no standard caps for this model, then for now all we know
44
+		// if they need the default cap to access this
45
+		if (! $this->model()->cap_slug()) {
46
+			return array(
47
+				self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions()
48
+			);
49
+		}
50 50
 
51
-        $event_model = EEM_Event::instance();
52
-        return array(
53
-            // first: basically access to non-defaults is essentially controlled by which events are accessible
54
-            // if they don't have the basic event cap, they can only read things for published events
55
-            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(
56
-                $this->addPublishedPostConditions(
57
-                    array(),
58
-                    true,
59
-                    $this->_path_to_event_model
60
-                )
61
-            ),
62
-            // if they don't have the others event cap, they can't access others' non-default items
63
-            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions(
64
-                array(
65
-                    'OR*' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions(
66
-                        array(
67
-                            $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
68
-                        ),
69
-                        true,
70
-                        $this->_path_to_event_model
71
-                    )
72
-                )
73
-            ),
74
-            // if they have basic and others, but not private, they can't access others' private non-default items
75
-            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions(
76
-                array(
77
-                    'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions(
78
-                        array(
79
-                            $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
80
-                        ),
81
-                        false,
82
-                        $this->_path_to_event_model
83
-                    )
84
-                )
85
-            ),
86
-        );
87
-    }
51
+		$event_model = EEM_Event::instance();
52
+		return array(
53
+			// first: basically access to non-defaults is essentially controlled by which events are accessible
54
+			// if they don't have the basic event cap, they can only read things for published events
55
+			EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(
56
+				$this->addPublishedPostConditions(
57
+					array(),
58
+					true,
59
+					$this->_path_to_event_model
60
+				)
61
+			),
62
+			// if they don't have the others event cap, they can't access others' non-default items
63
+			EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions(
64
+				array(
65
+					'OR*' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions(
66
+						array(
67
+							$this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
68
+						),
69
+						true,
70
+						$this->_path_to_event_model
71
+					)
72
+				)
73
+			),
74
+			// if they have basic and others, but not private, they can't access others' private non-default items
75
+			EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions(
76
+				array(
77
+					'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions(
78
+						array(
79
+							$this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
80
+						),
81
+						false,
82
+						$this->_path_to_event_model
83
+					)
84
+				)
85
+			),
86
+		);
87
+	}
88 88
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     {
43 43
         // if there are no standard caps for this model, then for now all we know
44 44
         // if they need the default cap to access this
45
-        if (! $this->model()->cap_slug()) {
45
+        if ( ! $this->model()->cap_slug()) {
46 46
             return array(
47 47
                 self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions()
48 48
             );
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
                 )
61 61
             ),
62 62
             // if they don't have the others event cap, they can't access others' non-default items
63
-            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions(
63
+            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_others') => new EE_Default_Where_Conditions(
64 64
                 array(
65
-                    'OR*' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions(
65
+                    'OR*'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_others') => $this->addPublishedPostConditions(
66 66
                         array(
67
-                            $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
67
+                            $this->_path_to_event_model.'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
68 68
                         ),
69 69
                         true,
70 70
                         $this->_path_to_event_model
@@ -72,11 +72,11 @@  discard block
 block discarded – undo
72 72
                 )
73 73
             ),
74 74
             // if they have basic and others, but not private, they can't access others' private non-default items
75
-            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions(
75
+            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_private') => new EE_Default_Where_Conditions(
76 76
                 array(
77
-                    'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions(
77
+                    'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_private') => $this->addPublishedPostConditions(
78 78
                         array(
79
-                            $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
79
+                            $this->_path_to_event_model.'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
80 80
                         ),
81 81
                         false,
82 82
                         $this->_path_to_event_model
Please login to merge, or discard this patch.
core/db_models/strategies/EE_Restriction_Generator_Public.strategy.php 2 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -12,74 +12,74 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Restriction_Generator_Public extends EE_Restriction_Generator_Base
14 14
 {
15
-    protected function _generate_restrictions()
16
-    {
17
-        // if there are no standard caps for this model, then for allow full access
18
-        if (! $this->model()->cap_slug()) {
19
-            return array(
20
-            );
21
-        }
15
+	protected function _generate_restrictions()
16
+	{
17
+		// if there are no standard caps for this model, then for allow full access
18
+		if (! $this->model()->cap_slug()) {
19
+			return array(
20
+			);
21
+		}
22 22
 
23
-        $restrictions = array();
24
-        // does the basic cap exist? (eg 'ee_read_registrations')
25
-        if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action())) {
26
-            if ($this->model() instanceof EEM_CPT_Base) {
27
-                $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions(
28
-                    $this->addPublishedPostConditions()
29
-                );
30
-            } elseif ($this->model() instanceof EEM_Soft_Delete_Base) {
31
-                $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions(
32
-                    array( $this->model()->deleted_field_name() => false )
33
-                );
34
-            } else {
35
-                // don't impose any restrictions if they don't have the basic reading cap
36
-            }
37
-            // does the others cap exist? (eg 'ee_read_others_registrations')
38
-            if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others')) {// both caps exist
39
-                if ($this->model() instanceof EEM_CPT_Base) {
40
-                    // then if they don't have the others cap, AT MOST show them their own and other published ones
41
-                    $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions(
42
-                        array(
43
-                            'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => $this->addPublishedPostConditions(
44
-                                array(
45
-                                    EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
46
-                                )
47
-                            )
48
-                        )
49
-                    );
50
-                } elseif ($this->model() instanceof EEM_Soft_Delete_Base) {
51
-                    // then if they don't have the other cap, AT MOST show them their own or non deleted ones
52
-                    $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions(
53
-                        array(
54
-                            'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => array(
55
-                                EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
56
-                                $this->model()->deleted_field_name() => false
57
-                            )
58
-                        )
59
-                    );
60
-                } else {
61
-                    // again, if they don't have the others cap, continue showing all because there are no inherently hidden ones
62
-                }
63
-                // does the private cap exist (eg 'ee_read_others_private_events')
64
-                if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_private') && $this->model() instanceof EEM_CPT_Base) {
65
-                    // if they have basic and others, but not private, restrict them to see theirs and others' that aren't private
66
-                    $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') ] = new EE_Default_Where_Conditions(
67
-                        array(
68
-                            'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') => $this->addPublishedPostConditions(
69
-                                array(
70
-                                    EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
71
-                                ),
72
-                                false,
73
-                                ''
74
-                            )
75
-                        )
76
-                    );
77
-                }
78
-            }
79
-        } else {
80
-            // there is no basic cap. So allow full access
81
-            $restrictions = array();
82
-        }
83
-        return $restrictions;
84
-    }
23
+		$restrictions = array();
24
+		// does the basic cap exist? (eg 'ee_read_registrations')
25
+		if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action())) {
26
+			if ($this->model() instanceof EEM_CPT_Base) {
27
+				$restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions(
28
+					$this->addPublishedPostConditions()
29
+				);
30
+			} elseif ($this->model() instanceof EEM_Soft_Delete_Base) {
31
+				$restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions(
32
+					array( $this->model()->deleted_field_name() => false )
33
+				);
34
+			} else {
35
+				// don't impose any restrictions if they don't have the basic reading cap
36
+			}
37
+			// does the others cap exist? (eg 'ee_read_others_registrations')
38
+			if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others')) {// both caps exist
39
+				if ($this->model() instanceof EEM_CPT_Base) {
40
+					// then if they don't have the others cap, AT MOST show them their own and other published ones
41
+					$restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions(
42
+						array(
43
+							'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => $this->addPublishedPostConditions(
44
+								array(
45
+									EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
46
+								)
47
+							)
48
+						)
49
+					);
50
+				} elseif ($this->model() instanceof EEM_Soft_Delete_Base) {
51
+					// then if they don't have the other cap, AT MOST show them their own or non deleted ones
52
+					$restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions(
53
+						array(
54
+							'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => array(
55
+								EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
56
+								$this->model()->deleted_field_name() => false
57
+							)
58
+						)
59
+					);
60
+				} else {
61
+					// again, if they don't have the others cap, continue showing all because there are no inherently hidden ones
62
+				}
63
+				// does the private cap exist (eg 'ee_read_others_private_events')
64
+				if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_private') && $this->model() instanceof EEM_CPT_Base) {
65
+					// if they have basic and others, but not private, restrict them to see theirs and others' that aren't private
66
+					$restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') ] = new EE_Default_Where_Conditions(
67
+						array(
68
+							'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') => $this->addPublishedPostConditions(
69
+								array(
70
+									EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
71
+								),
72
+								false,
73
+								''
74
+							)
75
+						)
76
+					);
77
+				}
78
+			}
79
+		} else {
80
+			// there is no basic cap. So allow full access
81
+			$restrictions = array();
82
+		}
83
+		return $restrictions;
84
+	}
85 85
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
     protected function _generate_restrictions()
16 16
     {
17 17
         // if there are no standard caps for this model, then for allow full access
18
-        if (! $this->model()->cap_slug()) {
18
+        if ( ! $this->model()->cap_slug()) {
19 19
             return array(
20 20
             );
21 21
         }
@@ -24,23 +24,23 @@  discard block
 block discarded – undo
24 24
         // does the basic cap exist? (eg 'ee_read_registrations')
25 25
         if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action())) {
26 26
             if ($this->model() instanceof EEM_CPT_Base) {
27
-                $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions(
27
+                $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action())] = new EE_Default_Where_Conditions(
28 28
                     $this->addPublishedPostConditions()
29 29
                 );
30 30
             } elseif ($this->model() instanceof EEM_Soft_Delete_Base) {
31
-                $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions(
32
-                    array( $this->model()->deleted_field_name() => false )
31
+                $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action())] = new EE_Default_Where_Conditions(
32
+                    array($this->model()->deleted_field_name() => false)
33 33
                 );
34 34
             } else {
35 35
                 // don't impose any restrictions if they don't have the basic reading cap
36 36
             }
37 37
             // does the others cap exist? (eg 'ee_read_others_registrations')
38
-            if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others')) {// both caps exist
38
+            if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action().'_others')) {// both caps exist
39 39
                 if ($this->model() instanceof EEM_CPT_Base) {
40 40
                     // then if they don't have the others cap, AT MOST show them their own and other published ones
41
-                    $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions(
41
+                    $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others')] = new EE_Default_Where_Conditions(
42 42
                         array(
43
-                            'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => $this->addPublishedPostConditions(
43
+                            'OR*'.EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others') => $this->addPublishedPostConditions(
44 44
                                 array(
45 45
                                     EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
46 46
                                 )
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
                     );
50 50
                 } elseif ($this->model() instanceof EEM_Soft_Delete_Base) {
51 51
                     // then if they don't have the other cap, AT MOST show them their own or non deleted ones
52
-                    $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions(
52
+                    $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others')] = new EE_Default_Where_Conditions(
53 53
                         array(
54
-                            'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => array(
54
+                            'OR*'.EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others') => array(
55 55
                                 EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
56 56
                                 $this->model()->deleted_field_name() => false
57 57
                             )
@@ -61,11 +61,11 @@  discard block
 block discarded – undo
61 61
                     // again, if they don't have the others cap, continue showing all because there are no inherently hidden ones
62 62
                 }
63 63
                 // does the private cap exist (eg 'ee_read_others_private_events')
64
-                if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_private') && $this->model() instanceof EEM_CPT_Base) {
64
+                if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action().'_private') && $this->model() instanceof EEM_CPT_Base) {
65 65
                     // if they have basic and others, but not private, restrict them to see theirs and others' that aren't private
66
-                    $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') ] = new EE_Default_Where_Conditions(
66
+                    $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_private')] = new EE_Default_Where_Conditions(
67 67
                         array(
68
-                            'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') => $this->addPublishedPostConditions(
68
+                            'OR*'.EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_private') => $this->addPublishedPostConditions(
69 69
                                 array(
70 70
                                     EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
71 71
                                 ),
Please login to merge, or discard this patch.
db_models/strategies/EE_Restriction_Generator_Default_Public.strategy.php 2 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -18,110 +18,110 @@
 block discarded – undo
18 18
 class EE_Restriction_Generator_Default_Public extends EE_Restriction_Generator_Base
19 19
 {
20 20
 /**
21
-     * Name of the field on this model (or a related model, including the model chain to it)
22
-     * that is a boolean indicating whether or not a model object is considered "Default" or not
23
-     * @var string
24
-     */
25
-    protected $_default_field_name;
21
+ * Name of the field on this model (or a related model, including the model chain to it)
22
+ * that is a boolean indicating whether or not a model object is considered "Default" or not
23
+ * @var string
24
+ */
25
+	protected $_default_field_name;
26 26
 
27
-    /**
28
-     * The model chain to follow to get to the event model, including the event model itself.
29
-     * Eg 'Ticket.Datetime.Event'
30
-     * @var string
31
-     */
32
-    protected $_path_to_event_model;
33
-    /**
34
-     *
35
-     * @param string $default_field_name the name of the field Name of the field on this model (or a related model, including the model chain to it)
36
-     * that is a boolean indicating whether or not a model object is considered "Default" or not
37
-     * @param string $path_to_event_model The model chain to follow to get to the event model, including the event model itself.
38
-     * Eg 'Ticket.Datetime.Event'
39
-     */
40
-    public function __construct($default_field_name, $path_to_event_model)
41
-    {
42
-        $this->_default_field_name = $default_field_name;
43
-        if (substr($path_to_event_model, -1, 1) != '.') {
44
-            $path_to_event_model .= '.';
45
-        }
46
-        $this->_path_to_event_model = $path_to_event_model;
47
-    }
27
+	/**
28
+	 * The model chain to follow to get to the event model, including the event model itself.
29
+	 * Eg 'Ticket.Datetime.Event'
30
+	 * @var string
31
+	 */
32
+	protected $_path_to_event_model;
33
+	/**
34
+	 *
35
+	 * @param string $default_field_name the name of the field Name of the field on this model (or a related model, including the model chain to it)
36
+	 * that is a boolean indicating whether or not a model object is considered "Default" or not
37
+	 * @param string $path_to_event_model The model chain to follow to get to the event model, including the event model itself.
38
+	 * Eg 'Ticket.Datetime.Event'
39
+	 */
40
+	public function __construct($default_field_name, $path_to_event_model)
41
+	{
42
+		$this->_default_field_name = $default_field_name;
43
+		if (substr($path_to_event_model, -1, 1) != '.') {
44
+			$path_to_event_model .= '.';
45
+		}
46
+		$this->_path_to_event_model = $path_to_event_model;
47
+	}
48 48
 
49
-    /**
50
-     * @return EE_Default_Where_Conditions
51
-     * @throws EE_Error
52
-     */
53
-    protected function _generate_restrictions()
54
-    {
55
-        // if there are no standard caps for this model, then for now all we know
56
-        // if they need the default cap to access this
57
-        if (!$this->model()->cap_slug()) {
58
-            return array(
59
-                self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions()
60
-            );
61
-        }
49
+	/**
50
+	 * @return EE_Default_Where_Conditions
51
+	 * @throws EE_Error
52
+	 */
53
+	protected function _generate_restrictions()
54
+	{
55
+		// if there are no standard caps for this model, then for now all we know
56
+		// if they need the default cap to access this
57
+		if (!$this->model()->cap_slug()) {
58
+			return array(
59
+				self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions()
60
+			);
61
+		}
62 62
 
63
-        $event_model = EEM_Event::instance();
63
+		$event_model = EEM_Event::instance();
64 64
 
65
-        $restrictions = array(
66
-            // first: basically access to non-defaults is essentially controlled by which events are accessible
67
-            // if they don't have the basic event cap, they can't access ANY non-default items
68
-            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(array(
69
-                'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => $this->addPublishedPostConditions(
70
-                    array(
71
-                        $this->_default_field_name             => true,
72
-                    ),
73
-                    true,
74
-                    $this->_path_to_event_model
75
-                )
76
-            )),
77
-            // if they don't have the others event cap, they can only access their own, others' that are for published events, or defaults
78
-            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions(
79
-                array(
80
-                    'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions(
81
-                        array(
82
-                            $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
83
-                            $this->_default_field_name => true,
84
-                        ),
85
-                        true,
86
-                        $this->_path_to_event_model
87
-                    )
88
-                )
89
-            ),
90
-            // if they have basic and others, but not private, they can access default, their own, and others' that aren't private
91
-            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private')   => new EE_Default_Where_Conditions(
92
-                array(
93
-                    'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions(
94
-                        array(
95
-                            $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
96
-                            $this->_default_field_name => true
97
-                        ),
98
-                        false,
99
-                        $this->_path_to_event_model
100
-                    )
101
-                )
102
-            ),
103
-            // second: access to defaults is controlled by the default capabilities
104
-            // if they don't have the basic default capability, restrict access to only non-default items
105
-            EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_default') => new EE_Default_Where_Conditions(
106
-                array( $this->_default_field_name => false )
107
-            ),
108
-        );
109
-        if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others_default')) {
110
-            // if they don't have the "others" default capability, restrict access to only their default ones, and non-default ones
111
-            $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') ] = new EE_Default_Where_Conditions(
112
-                array(
113
-                    // if they don't have the others default cap, they can't access others default items (but they can access
114
-                    // their own default items, and non-default items)
115
-                    'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') => array(
116
-                        'AND' => array(
117
-                            EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
118
-                            $this->_default_field_name => true
119
-                        ),
120
-                        $this->_default_field_name => false
121
-                    )
122
-                )
123
-            );
124
-        }
125
-        return $restrictions;
126
-    }
65
+		$restrictions = array(
66
+			// first: basically access to non-defaults is essentially controlled by which events are accessible
67
+			// if they don't have the basic event cap, they can't access ANY non-default items
68
+			EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(array(
69
+				'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => $this->addPublishedPostConditions(
70
+					array(
71
+						$this->_default_field_name             => true,
72
+					),
73
+					true,
74
+					$this->_path_to_event_model
75
+				)
76
+			)),
77
+			// if they don't have the others event cap, they can only access their own, others' that are for published events, or defaults
78
+			EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions(
79
+				array(
80
+					'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions(
81
+						array(
82
+							$this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
83
+							$this->_default_field_name => true,
84
+						),
85
+						true,
86
+						$this->_path_to_event_model
87
+					)
88
+				)
89
+			),
90
+			// if they have basic and others, but not private, they can access default, their own, and others' that aren't private
91
+			EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private')   => new EE_Default_Where_Conditions(
92
+				array(
93
+					'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions(
94
+						array(
95
+							$this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
96
+							$this->_default_field_name => true
97
+						),
98
+						false,
99
+						$this->_path_to_event_model
100
+					)
101
+				)
102
+			),
103
+			// second: access to defaults is controlled by the default capabilities
104
+			// if they don't have the basic default capability, restrict access to only non-default items
105
+			EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_default') => new EE_Default_Where_Conditions(
106
+				array( $this->_default_field_name => false )
107
+			),
108
+		);
109
+		if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others_default')) {
110
+			// if they don't have the "others" default capability, restrict access to only their default ones, and non-default ones
111
+			$restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') ] = new EE_Default_Where_Conditions(
112
+				array(
113
+					// if they don't have the others default cap, they can't access others default items (but they can access
114
+					// their own default items, and non-default items)
115
+					'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') => array(
116
+						'AND' => array(
117
+							EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
118
+							$this->_default_field_name => true
119
+						),
120
+						$this->_default_field_name => false
121
+					)
122
+				)
123
+			);
124
+		}
125
+		return $restrictions;
126
+	}
127 127
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     {
55 55
         // if there are no standard caps for this model, then for now all we know
56 56
         // if they need the default cap to access this
57
-        if (!$this->model()->cap_slug()) {
57
+        if ( ! $this->model()->cap_slug()) {
58 58
             return array(
59 59
                 self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions()
60 60
             );
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
             // first: basically access to non-defaults is essentially controlled by which events are accessible
67 67
             // if they don't have the basic event cap, they can't access ANY non-default items
68 68
             EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(array(
69
-                'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => $this->addPublishedPostConditions(
69
+                'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => $this->addPublishedPostConditions(
70 70
                     array(
71 71
                         $this->_default_field_name             => true,
72 72
                     ),
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
                 )
76 76
             )),
77 77
             // if they don't have the others event cap, they can only access their own, others' that are for published events, or defaults
78
-            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions(
78
+            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_others') => new EE_Default_Where_Conditions(
79 79
                 array(
80
-                    'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions(
80
+                    'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_others') => $this->addPublishedPostConditions(
81 81
                         array(
82
-                            $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
82
+                            $this->_path_to_event_model.'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
83 83
                             $this->_default_field_name => true,
84 84
                         ),
85 85
                         true,
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
                 )
89 89
             ),
90 90
             // if they have basic and others, but not private, they can access default, their own, and others' that aren't private
91
-            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private')   => new EE_Default_Where_Conditions(
91
+            EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_private')   => new EE_Default_Where_Conditions(
92 92
                 array(
93
-                    'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions(
93
+                    'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_private') => $this->addPublishedPostConditions(
94 94
                         array(
95
-                            $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
95
+                            $this->_path_to_event_model.'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder,
96 96
                             $this->_default_field_name => true
97 97
                         ),
98 98
                         false,
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
             ),
103 103
             // second: access to defaults is controlled by the default capabilities
104 104
             // if they don't have the basic default capability, restrict access to only non-default items
105
-            EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_default') => new EE_Default_Where_Conditions(
106
-                array( $this->_default_field_name => false )
105
+            EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_default') => new EE_Default_Where_Conditions(
106
+                array($this->_default_field_name => false)
107 107
             ),
108 108
         );
109
-        if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others_default')) {
109
+        if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action().'_others_default')) {
110 110
             // if they don't have the "others" default capability, restrict access to only their default ones, and non-default ones
111
-            $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') ] = new EE_Default_Where_Conditions(
111
+            $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others_default')] = new EE_Default_Where_Conditions(
112 112
                 array(
113 113
                     // if they don't have the others default cap, they can't access others default items (but they can access
114 114
                     // their own default items, and non-default items)
115
-                    'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') => array(
115
+                    'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others_default') => array(
116 116
                         'AND' => array(
117 117
                             EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder,
118 118
                             $this->_default_field_name => true
Please login to merge, or discard this patch.
core/domain/entities/editor/BlockInterface.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -22,70 +22,70 @@
 block discarded – undo
22 22
 interface BlockInterface
23 23
 {
24 24
 
25
-    const NAME_SPACE = 'eventespresso';
26
-
27
-    /**
28
-     * Perform any early setup required by the block
29
-     * including setting the block type and supported post types
30
-     *
31
-     * @return void
32
-     */
33
-    public function initialize();
34
-
35
-
36
-    /**
37
-     * @return string
38
-     */
39
-    public function blockType();
40
-
41
-
42
-    /**
43
-     * AssetRegister that this editor block uses for asset registration
44
-     *
45
-     * @return BlockAssetManagerInterface
46
-     */
47
-    public function assetManager();
48
-
49
-
50
-    /**
51
-     * Registers the Editor Block with WP core;
52
-     * Returns the registered block type on success, or false on failure.
53
-     *
54
-     * @return WP_Block_Type|false
55
-     */
56
-    public function registerBlock();
57
-
58
-
59
-    /**
60
-     * Un-registers the Editor Block with WP core;
61
-     * Returns the registered block type on success, or false on failure.
62
-     *
63
-     * @return WP_Block_Type|false
64
-     */
65
-    public function unRegisterBlock();
66
-
67
-
68
-    /**
69
-     * returns an array of fully qualified class names
70
-     * for RouteMatchSpecificationInterface objects
71
-     * that specify routes that the block should be loaded for.
72
-     *
73
-     * @return array
74
-     */
75
-    public function supportedRoutes();
76
-
77
-
78
-    /**
79
-     * @return array
80
-     */
81
-    public function getEditorContainer();
82
-
83
-
84
-    /**
85
-     * returns the rendered HTML for the block
86
-     *
87
-     * @param array $attributes
88
-     * @return string
89
-     */
90
-    public function renderBlock(array $attributes = array());
25
+	const NAME_SPACE = 'eventespresso';
26
+
27
+	/**
28
+	 * Perform any early setup required by the block
29
+	 * including setting the block type and supported post types
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public function initialize();
34
+
35
+
36
+	/**
37
+	 * @return string
38
+	 */
39
+	public function blockType();
40
+
41
+
42
+	/**
43
+	 * AssetRegister that this editor block uses for asset registration
44
+	 *
45
+	 * @return BlockAssetManagerInterface
46
+	 */
47
+	public function assetManager();
48
+
49
+
50
+	/**
51
+	 * Registers the Editor Block with WP core;
52
+	 * Returns the registered block type on success, or false on failure.
53
+	 *
54
+	 * @return WP_Block_Type|false
55
+	 */
56
+	public function registerBlock();
57
+
58
+
59
+	/**
60
+	 * Un-registers the Editor Block with WP core;
61
+	 * Returns the registered block type on success, or false on failure.
62
+	 *
63
+	 * @return WP_Block_Type|false
64
+	 */
65
+	public function unRegisterBlock();
66
+
67
+
68
+	/**
69
+	 * returns an array of fully qualified class names
70
+	 * for RouteMatchSpecificationInterface objects
71
+	 * that specify routes that the block should be loaded for.
72
+	 *
73
+	 * @return array
74
+	 */
75
+	public function supportedRoutes();
76
+
77
+
78
+	/**
79
+	 * @return array
80
+	 */
81
+	public function getEditorContainer();
82
+
83
+
84
+	/**
85
+	 * returns the rendered HTML for the block
86
+	 *
87
+	 * @param array $attributes
88
+	 * @return string
89
+	 */
90
+	public function renderBlock(array $attributes = array());
91 91
 }
Please login to merge, or discard this patch.
core/domain/entities/route_match/RouteMatchSpecification.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -24,17 +24,17 @@
 block discarded – undo
24 24
 abstract class RouteMatchSpecification implements RouteMatchSpecificationInterface
25 25
 {
26 26
 
27
-    /**
28
-     * @var RequestInterface $request
29
-     */
30
-    protected $request;
27
+	/**
28
+	 * @var RequestInterface $request
29
+	 */
30
+	protected $request;
31 31
 
32
-    /**
33
-     * RouteMatch constructor.
34
-     * @param RequestInterface $request
35
-     */
36
-    public function __construct(RequestInterface $request)
37
-    {
38
-        $this->request = $request;
39
-    }
32
+	/**
33
+	 * RouteMatch constructor.
34
+	 * @param RequestInterface $request
35
+	 */
36
+	public function __construct(RequestInterface $request)
37
+	{
38
+		$this->request = $request;
39
+	}
40 40
 }
Please login to merge, or discard this patch.
core/domain/entities/route_match/RouteMatchSpecificationDecorator.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -13,18 +13,18 @@
 block discarded – undo
13 13
 abstract class RouteMatchSpecificationDecorator implements RouteMatchSpecificationInterface
14 14
 {
15 15
 
16
-    /**
17
-     * @var RouteMatchSpecificationInterface $specification
18
-     */
19
-    protected $specification;
16
+	/**
17
+	 * @var RouteMatchSpecificationInterface $specification
18
+	 */
19
+	protected $specification;
20 20
 
21
-    /**
22
-     * RouteMatchSpecificationDecorator constructor.
23
-     *
24
-     * @param RouteMatchSpecificationInterface $specification
25
-     */
26
-    public function __construct(RouteMatchSpecificationInterface $specification)
27
-    {
28
-        $this->specification = $specification;
29
-    }
21
+	/**
22
+	 * RouteMatchSpecificationDecorator constructor.
23
+	 *
24
+	 * @param RouteMatchSpecificationInterface $specification
25
+	 */
26
+	public function __construct(RouteMatchSpecificationInterface $specification)
27
+	{
28
+		$this->specification = $specification;
29
+	}
30 30
 }
Please login to merge, or discard this patch.
core/services/editor/BlockManager.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@
 block discarded – undo
18 18
 abstract class BlockManager
19 19
 {
20 20
 
21
-    /**
22
-     * @var CollectionInterface|BlockInterface[] $blocks
23
-     */
24
-    protected $blocks;
25
-
26
-    /**
27
-     * @var RequestInterface $request
28
-     */
29
-    protected $request;
30
-
31
-
32
-
33
-    /**
34
-     * BlockManager constructor.
35
-     *
36
-     * @param BlockCollection   $blocks
37
-     * @param RequestInterface  $request
38
-     */
39
-    public function __construct(
40
-        BlockCollection $blocks,
41
-        RequestInterface $request
42
-    ) {
43
-        $this->blocks            = $blocks;
44
-        $this->request           = $request;
45
-        add_action($this->initHook(), array($this, 'initialize'));
46
-    }
47
-
48
-
49
-    /**
50
-     *  Returns the name of a hookpoint to be used to call initialize()
51
-     *
52
-     * @return string
53
-     */
54
-    abstract public function initHook();
55
-
56
-
57
-    /**
58
-     * Perform any early setup required for block editors to functions
59
-     *
60
-     * @return void
61
-     */
62
-    abstract public function initialize();
21
+	/**
22
+	 * @var CollectionInterface|BlockInterface[] $blocks
23
+	 */
24
+	protected $blocks;
25
+
26
+	/**
27
+	 * @var RequestInterface $request
28
+	 */
29
+	protected $request;
30
+
31
+
32
+
33
+	/**
34
+	 * BlockManager constructor.
35
+	 *
36
+	 * @param BlockCollection   $blocks
37
+	 * @param RequestInterface  $request
38
+	 */
39
+	public function __construct(
40
+		BlockCollection $blocks,
41
+		RequestInterface $request
42
+	) {
43
+		$this->blocks            = $blocks;
44
+		$this->request           = $request;
45
+		add_action($this->initHook(), array($this, 'initialize'));
46
+	}
47
+
48
+
49
+	/**
50
+	 *  Returns the name of a hookpoint to be used to call initialize()
51
+	 *
52
+	 * @return string
53
+	 */
54
+	abstract public function initHook();
55
+
56
+
57
+	/**
58
+	 * Perform any early setup required for block editors to functions
59
+	 *
60
+	 * @return void
61
+	 */
62
+	abstract public function initialize();
63 63
 }
Please login to merge, or discard this patch.
core/services/route_match/RouteMatchSpecificationCollection.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -16,36 +16,36 @@
 block discarded – undo
16 16
 class RouteMatchSpecificationCollection extends Collection
17 17
 {
18 18
 
19
-    const COLLECTION_NAME = 'route_match_specifications';
20
-
21
-
22
-    /**
23
-     * RouteMatchSpecificationCollection constructor
24
-     *
25
-     * @throws InvalidInterfaceException
26
-     */
27
-    public function __construct()
28
-    {
29
-        parent::__construct(
30
-            'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface',
31
-            RouteMatchSpecificationCollection::COLLECTION_NAME
32
-        );
33
-    }
34
-
35
-
36
-    /**
37
-     * getIdentifier
38
-     * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
39
-     * If no $identifier is supplied, then the  fully qualified class name is used
40
-     *
41
-     * @param        $object
42
-     * @param  mixed $identifier
43
-     * @return bool
44
-     */
45
-    public function getIdentifier($object, $identifier = null)
46
-    {
47
-        return ! empty($identifier)
48
-            ? $identifier
49
-            : get_class($object);
50
-    }
19
+	const COLLECTION_NAME = 'route_match_specifications';
20
+
21
+
22
+	/**
23
+	 * RouteMatchSpecificationCollection constructor
24
+	 *
25
+	 * @throws InvalidInterfaceException
26
+	 */
27
+	public function __construct()
28
+	{
29
+		parent::__construct(
30
+			'EventEspresso\core\domain\entities\route_match\RouteMatchSpecificationInterface',
31
+			RouteMatchSpecificationCollection::COLLECTION_NAME
32
+		);
33
+	}
34
+
35
+
36
+	/**
37
+	 * getIdentifier
38
+	 * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
39
+	 * If no $identifier is supplied, then the  fully qualified class name is used
40
+	 *
41
+	 * @param        $object
42
+	 * @param  mixed $identifier
43
+	 * @return bool
44
+	 */
45
+	public function getIdentifier($object, $identifier = null)
46
+	{
47
+		return ! empty($identifier)
48
+			? $identifier
49
+			: get_class($object);
50
+	}
51 51
 }
Please login to merge, or discard this patch.
core/services/collections/Collection.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     protected function setCollectionInterface($collection_interface)
68 68
     {
69
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
69
+        if ( ! (interface_exists($collection_interface) || class_exists($collection_interface))) {
70 70
             throw new InvalidInterfaceException($collection_interface);
71 71
         }
72 72
         $this->collection_interface = $collection_interface;
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
     protected function setCollectionIdentifier()
112 112
     {
113 113
         // hash a few collection details
114
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
114
+        $identifier = md5(spl_object_hash($this).$this->collection_interface.time());
115 115
         // grab a few characters from the start, middle, and end of the hash
116 116
         $id = array();
117 117
         for ($x = 0; $x < 19; $x += 9) {
118 118
             $id[] = substr($identifier, $x, 3);
119 119
         }
120
-        $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id));
120
+        $this->collection_identifier = $this->collection_name.'-'.strtoupper(implode('-', $id));
121 121
     }
122 122
 
123 123
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function add($object, $identifier = null)
137 137
     {
138
-        if (! $object instanceof $this->collection_interface) {
138
+        if ( ! $object instanceof $this->collection_interface) {
139 139
             throw new InvalidEntityException($object, $this->collection_interface);
140 140
         }
141 141
         if ($this->contains($object)) {
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      */
352 352
     public function indexOf($object)
353 353
     {
354
-        if (! $this->contains($object)) {
354
+        if ( ! $this->contains($object)) {
355 355
             return false;
356 356
         }
357 357
         foreach ($this as $index => $obj) {
@@ -420,9 +420,9 @@  discard block
 block discarded – undo
420 420
             $remaining_objects = $this->slice($index, $this->count() - $index);
421 421
             foreach ($remaining_objects as $key => $remaining_object) {
422 422
                 // we need to grab the identifiers for each object and use them as keys
423
-                $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
423
+                $remaining_objects[$remaining_object->getInfo()] = $remaining_object;
424 424
                 // and then remove the object from the current tracking array
425
-                unset($remaining_objects[ $key ]);
425
+                unset($remaining_objects[$key]);
426 426
                 // and then remove it from the Collection
427 427
                 $this->detach($remaining_object);
428 428
             }
@@ -446,17 +446,17 @@  discard block
 block discarded – undo
446 446
      */
447 447
     public function insertAt($objects, $index)
448 448
     {
449
-        if (! is_array($objects)) {
449
+        if ( ! is_array($objects)) {
450 450
             $objects = array($objects);
451 451
         }
452 452
         // check to ensure that objects don't already exist in the collection
453 453
         foreach ($objects as $key => $object) {
454 454
             if ($this->contains($object)) {
455
-                unset($objects[ $key ]);
455
+                unset($objects[$key]);
456 456
             }
457 457
         }
458 458
         // do we have any objects left?
459
-        if (! $objects) {
459
+        if ( ! $objects) {
460 460
             return;
461 461
         }
462 462
         // detach any objects at or past this index
Please login to merge, or discard this patch.
Indentation   +500 added lines, -500 removed lines patch added patch discarded remove patch
@@ -19,504 +19,504 @@
 block discarded – undo
19 19
 class Collection extends SplObjectStorage implements CollectionInterface
20 20
 {
21 21
 
22
-    /**
23
-     * a unique string for identifying this collection
24
-     *
25
-     * @type string $collection_identifier
26
-     */
27
-    protected $collection_identifier;
28
-
29
-
30
-    /**
31
-     * an interface (or class) name to be used for restricting the type of objects added to the storage
32
-     * this should be set from within the child class constructor
33
-     *
34
-     * @type string $interface
35
-     */
36
-    protected $collection_interface;
37
-
38
-    /**
39
-     * a short dash separated string describing the contents of this collection
40
-     * used as the base for the $collection_identifier
41
-     * defaults to the class short name if not set
42
-     *
43
-     * @type string $collection_identifier
44
-     */
45
-    protected $collection_name;
46
-
47
-
48
-    /**
49
-     * Collection constructor
50
-     *
51
-     * @param string $collection_interface
52
-     * @param string $collection_name
53
-     * @throws InvalidInterfaceException
54
-     */
55
-    public function __construct($collection_interface, $collection_name = '')
56
-    {
57
-        $this->setCollectionInterface($collection_interface);
58
-        $this->setCollectionName($collection_name);
59
-        $this->setCollectionIdentifier();
60
-    }
61
-
62
-
63
-    /**
64
-     * setCollectionInterface
65
-     *
66
-     * @param  string $collection_interface
67
-     * @throws InvalidInterfaceException
68
-     */
69
-    protected function setCollectionInterface($collection_interface)
70
-    {
71
-        if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
72
-            throw new InvalidInterfaceException($collection_interface);
73
-        }
74
-        $this->collection_interface = $collection_interface;
75
-    }
76
-
77
-
78
-    /**
79
-     * @return string
80
-     */
81
-    public function collectionName()
82
-    {
83
-        return $this->collection_name;
84
-    }
85
-
86
-
87
-    /**
88
-     * @param string $collection_name
89
-     */
90
-    protected function setCollectionName($collection_name)
91
-    {
92
-        $this->collection_name = ! empty($collection_name)
93
-            ? sanitize_key($collection_name)
94
-            : basename(str_replace('\\', '/', get_class($this)));
95
-    }
96
-
97
-
98
-    /**
99
-     * @return string
100
-     */
101
-    public function collectionIdentifier()
102
-    {
103
-        return $this->collection_identifier;
104
-    }
105
-
106
-
107
-    /**
108
-     * creates a very readable unique 9 character identifier like:  CF2-532-DAC
109
-     * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
110
-     *
111
-     * @return void
112
-     */
113
-    protected function setCollectionIdentifier()
114
-    {
115
-        // hash a few collection details
116
-        $identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
117
-        // grab a few characters from the start, middle, and end of the hash
118
-        $id = array();
119
-        for ($x = 0; $x < 19; $x += 9) {
120
-            $id[] = substr($identifier, $x, 3);
121
-        }
122
-        $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id));
123
-    }
124
-
125
-
126
-    /**
127
-     * add
128
-     * attaches an object to the Collection
129
-     * and sets any supplied data associated with the current iterator entry
130
-     * by calling EE_Object_Collection::set_identifier()
131
-     *
132
-     * @param        $object
133
-     * @param  mixed $identifier
134
-     * @return bool
135
-     * @throws InvalidEntityException
136
-     * @throws DuplicateCollectionIdentifierException
137
-     */
138
-    public function add($object, $identifier = null)
139
-    {
140
-        if (! $object instanceof $this->collection_interface) {
141
-            throw new InvalidEntityException($object, $this->collection_interface);
142
-        }
143
-        if ($this->contains($object)) {
144
-            throw new DuplicateCollectionIdentifierException($identifier);
145
-        }
146
-        $this->attach($object);
147
-        $this->setIdentifier($object, $identifier);
148
-        return $this->contains($object);
149
-    }
150
-
151
-
152
-    /**
153
-     * getIdentifier
154
-     * if no $identifier is supplied, then the spl_object_hash() is used
155
-     *
156
-     * @param        $object
157
-     * @param  mixed $identifier
158
-     * @return bool
159
-     */
160
-    public function getIdentifier($object, $identifier = null)
161
-    {
162
-        return ! empty($identifier)
163
-            ? $identifier
164
-            : spl_object_hash($object);
165
-    }
166
-
167
-
168
-    /**
169
-     * setIdentifier
170
-     * Sets the data associated with an object in the Collection
171
-     * if no $identifier is supplied, then the spl_object_hash() is used
172
-     *
173
-     * @param        $object
174
-     * @param  mixed $identifier
175
-     * @return bool
176
-     */
177
-    public function setIdentifier($object, $identifier = null)
178
-    {
179
-        $identifier = $this->getIdentifier($object, $identifier);
180
-        $this->rewind();
181
-        while ($this->valid()) {
182
-            if ($object === $this->current()) {
183
-                $this->setInfo($identifier);
184
-                $this->rewind();
185
-                return true;
186
-            }
187
-            $this->next();
188
-        }
189
-        return false;
190
-    }
191
-
192
-
193
-    /**
194
-     * get
195
-     * finds and returns an object in the Collection based on the identifier that was set using addObject()
196
-     * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
197
-     *
198
-     * @param mixed $identifier
199
-     * @return mixed
200
-     */
201
-    public function get($identifier)
202
-    {
203
-        $this->rewind();
204
-        while ($this->valid()) {
205
-            if ($identifier === $this->getInfo()) {
206
-                $object = $this->current();
207
-                $this->rewind();
208
-                return $object;
209
-            }
210
-            $this->next();
211
-        }
212
-        return null;
213
-    }
214
-
215
-
216
-    /**
217
-     * has
218
-     * returns TRUE or FALSE
219
-     * depending on whether the object is within the Collection
220
-     * based on the supplied $identifier
221
-     *
222
-     * @param  mixed $identifier
223
-     * @return bool
224
-     */
225
-    public function has($identifier)
226
-    {
227
-        $this->rewind();
228
-        while ($this->valid()) {
229
-            if ($identifier === $this->getInfo()) {
230
-                $this->rewind();
231
-                return true;
232
-            }
233
-            $this->next();
234
-        }
235
-        return false;
236
-    }
237
-
238
-
239
-    /**
240
-     * hasObject
241
-     * returns TRUE or FALSE depending on whether the supplied object is within the Collection
242
-     *
243
-     * @param $object
244
-     * @return bool
245
-     */
246
-    public function hasObject($object)
247
-    {
248
-        return $this->contains($object);
249
-    }
250
-
251
-
252
-    /**
253
-     * hasObjects
254
-     * returns true if there are objects within the Collection, and false if it is empty
255
-     *
256
-     * @return bool
257
-     */
258
-    public function hasObjects()
259
-    {
260
-        return $this->count() !== 0;
261
-    }
262
-
263
-
264
-    /**
265
-     * isEmpty
266
-     * returns true if there are no objects within the Collection, and false if there are
267
-     *
268
-     * @return bool
269
-     */
270
-    public function isEmpty()
271
-    {
272
-        return $this->count() === 0;
273
-    }
274
-
275
-
276
-    /**
277
-     * remove
278
-     * detaches an object from the Collection
279
-     *
280
-     * @param $object
281
-     * @return bool
282
-     */
283
-    public function remove($object)
284
-    {
285
-        $this->detach($object);
286
-        return true;
287
-    }
288
-
289
-
290
-    /**
291
-     * setCurrent
292
-     * advances pointer to the object whose identifier matches that which was provided
293
-     *
294
-     * @param mixed $identifier
295
-     * @return boolean
296
-     */
297
-    public function setCurrent($identifier)
298
-    {
299
-        $this->rewind();
300
-        while ($this->valid()) {
301
-            if ($identifier === $this->getInfo()) {
302
-                return true;
303
-            }
304
-            $this->next();
305
-        }
306
-        return false;
307
-    }
308
-
309
-
310
-    /**
311
-     * setCurrentUsingObject
312
-     * advances pointer to the provided object
313
-     *
314
-     * @param $object
315
-     * @return boolean
316
-     */
317
-    public function setCurrentUsingObject($object)
318
-    {
319
-        $this->rewind();
320
-        while ($this->valid()) {
321
-            if ($this->current() === $object) {
322
-                return true;
323
-            }
324
-            $this->next();
325
-        }
326
-        return false;
327
-    }
328
-
329
-
330
-    /**
331
-     * Returns the object occupying the index before the current object,
332
-     * unless this is already the first object, in which case it just returns the first object
333
-     *
334
-     * @return mixed
335
-     */
336
-    public function previous()
337
-    {
338
-        $index = $this->indexOf($this->current());
339
-        if ($index === 0) {
340
-            return $this->current();
341
-        }
342
-        $index--;
343
-        return $this->objectAtIndex($index);
344
-    }
345
-
346
-
347
-    /**
348
-     * Returns the index of a given object, or false if not found
349
-     *
350
-     * @see http://stackoverflow.com/a/8736013
351
-     * @param $object
352
-     * @return boolean|int|string
353
-     */
354
-    public function indexOf($object)
355
-    {
356
-        if (! $this->contains($object)) {
357
-            return false;
358
-        }
359
-        foreach ($this as $index => $obj) {
360
-            if ($obj === $object) {
361
-                return $index;
362
-            }
363
-        }
364
-        return false;
365
-    }
366
-
367
-
368
-    /**
369
-     * Returns the object at the given index
370
-     *
371
-     * @see http://stackoverflow.com/a/8736013
372
-     * @param int $index
373
-     * @return mixed
374
-     */
375
-    public function objectAtIndex($index)
376
-    {
377
-        $iterator = new LimitIterator($this, $index, 1);
378
-        $iterator->rewind();
379
-        return $iterator->current();
380
-    }
381
-
382
-
383
-    /**
384
-     * Returns the sequence of objects as specified by the offset and length
385
-     *
386
-     * @see http://stackoverflow.com/a/8736013
387
-     * @param int $offset
388
-     * @param int $length
389
-     * @return array
390
-     */
391
-    public function slice($offset, $length)
392
-    {
393
-        $slice = array();
394
-        $iterator = new LimitIterator($this, $offset, $length);
395
-        foreach ($iterator as $object) {
396
-            $slice[] = $object;
397
-        }
398
-        return $slice;
399
-    }
400
-
401
-
402
-    /**
403
-     * Inserts an object at a certain point
404
-     *
405
-     * @see http://stackoverflow.com/a/8736013
406
-     * @param mixed $object A single object
407
-     * @param int   $index
408
-     * @param mixed $identifier
409
-     * @return bool
410
-     * @throws DuplicateCollectionIdentifierException
411
-     * @throws InvalidEntityException
412
-     */
413
-    public function insertObjectAt($object, $index, $identifier = null)
414
-    {
415
-        // check to ensure that objects don't already exist in the collection
416
-        if ($this->has($identifier)) {
417
-            throw new DuplicateCollectionIdentifierException($identifier);
418
-        }
419
-        // detach any objects at or past this index
420
-        $remaining_objects = array();
421
-        if ($index < $this->count()) {
422
-            $remaining_objects = $this->slice($index, $this->count() - $index);
423
-            foreach ($remaining_objects as $key => $remaining_object) {
424
-                // we need to grab the identifiers for each object and use them as keys
425
-                $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
426
-                // and then remove the object from the current tracking array
427
-                unset($remaining_objects[ $key ]);
428
-                // and then remove it from the Collection
429
-                $this->detach($remaining_object);
430
-            }
431
-        }
432
-        // add the new object we're splicing in
433
-        $this->add($object, $identifier);
434
-        // attach the objects we previously detached
435
-        foreach ($remaining_objects as $key => $remaining_object) {
436
-            $this->add($remaining_object, $key);
437
-        }
438
-        return $this->contains($object);
439
-    }
440
-
441
-
442
-    /**
443
-     * Inserts an object (or an array of objects) at a certain point
444
-     *
445
-     * @see http://stackoverflow.com/a/8736013
446
-     * @param mixed $objects A single object or an array of objects
447
-     * @param int   $index
448
-     */
449
-    public function insertAt($objects, $index)
450
-    {
451
-        if (! is_array($objects)) {
452
-            $objects = array($objects);
453
-        }
454
-        // check to ensure that objects don't already exist in the collection
455
-        foreach ($objects as $key => $object) {
456
-            if ($this->contains($object)) {
457
-                unset($objects[ $key ]);
458
-            }
459
-        }
460
-        // do we have any objects left?
461
-        if (! $objects) {
462
-            return;
463
-        }
464
-        // detach any objects at or past this index
465
-        $remaining = array();
466
-        if ($index < $this->count()) {
467
-            $remaining = $this->slice($index, $this->count() - $index);
468
-            foreach ($remaining as $object) {
469
-                $this->detach($object);
470
-            }
471
-        }
472
-        // add the new objects we're splicing in
473
-        foreach ($objects as $object) {
474
-            $this->attach($object);
475
-        }
476
-        // attach the objects we previously detached
477
-        foreach ($remaining as $object) {
478
-            $this->attach($object);
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     * Removes the object at the given index
485
-     *
486
-     * @see http://stackoverflow.com/a/8736013
487
-     * @param int $index
488
-     */
489
-    public function removeAt($index)
490
-    {
491
-        $this->detach($this->objectAtIndex($index));
492
-    }
493
-
494
-
495
-    /**
496
-     * detaches ALL objects from the Collection
497
-     */
498
-    public function detachAll()
499
-    {
500
-        $this->rewind();
501
-        while ($this->valid()) {
502
-            $object = $this->current();
503
-            $this->next();
504
-            $this->detach($object);
505
-        }
506
-    }
507
-
508
-
509
-    /**
510
-     * unsets and detaches ALL objects from the Collection
511
-     */
512
-    public function trashAndDetachAll()
513
-    {
514
-        $this->rewind();
515
-        while ($this->valid()) {
516
-            $object = $this->current();
517
-            $this->next();
518
-            $this->detach($object);
519
-            unset($object);
520
-        }
521
-    }
22
+	/**
23
+	 * a unique string for identifying this collection
24
+	 *
25
+	 * @type string $collection_identifier
26
+	 */
27
+	protected $collection_identifier;
28
+
29
+
30
+	/**
31
+	 * an interface (or class) name to be used for restricting the type of objects added to the storage
32
+	 * this should be set from within the child class constructor
33
+	 *
34
+	 * @type string $interface
35
+	 */
36
+	protected $collection_interface;
37
+
38
+	/**
39
+	 * a short dash separated string describing the contents of this collection
40
+	 * used as the base for the $collection_identifier
41
+	 * defaults to the class short name if not set
42
+	 *
43
+	 * @type string $collection_identifier
44
+	 */
45
+	protected $collection_name;
46
+
47
+
48
+	/**
49
+	 * Collection constructor
50
+	 *
51
+	 * @param string $collection_interface
52
+	 * @param string $collection_name
53
+	 * @throws InvalidInterfaceException
54
+	 */
55
+	public function __construct($collection_interface, $collection_name = '')
56
+	{
57
+		$this->setCollectionInterface($collection_interface);
58
+		$this->setCollectionName($collection_name);
59
+		$this->setCollectionIdentifier();
60
+	}
61
+
62
+
63
+	/**
64
+	 * setCollectionInterface
65
+	 *
66
+	 * @param  string $collection_interface
67
+	 * @throws InvalidInterfaceException
68
+	 */
69
+	protected function setCollectionInterface($collection_interface)
70
+	{
71
+		if (! (interface_exists($collection_interface) || class_exists($collection_interface))) {
72
+			throw new InvalidInterfaceException($collection_interface);
73
+		}
74
+		$this->collection_interface = $collection_interface;
75
+	}
76
+
77
+
78
+	/**
79
+	 * @return string
80
+	 */
81
+	public function collectionName()
82
+	{
83
+		return $this->collection_name;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param string $collection_name
89
+	 */
90
+	protected function setCollectionName($collection_name)
91
+	{
92
+		$this->collection_name = ! empty($collection_name)
93
+			? sanitize_key($collection_name)
94
+			: basename(str_replace('\\', '/', get_class($this)));
95
+	}
96
+
97
+
98
+	/**
99
+	 * @return string
100
+	 */
101
+	public function collectionIdentifier()
102
+	{
103
+		return $this->collection_identifier;
104
+	}
105
+
106
+
107
+	/**
108
+	 * creates a very readable unique 9 character identifier like:  CF2-532-DAC
109
+	 * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC
110
+	 *
111
+	 * @return void
112
+	 */
113
+	protected function setCollectionIdentifier()
114
+	{
115
+		// hash a few collection details
116
+		$identifier = md5(spl_object_hash($this) . $this->collection_interface . time());
117
+		// grab a few characters from the start, middle, and end of the hash
118
+		$id = array();
119
+		for ($x = 0; $x < 19; $x += 9) {
120
+			$id[] = substr($identifier, $x, 3);
121
+		}
122
+		$this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id));
123
+	}
124
+
125
+
126
+	/**
127
+	 * add
128
+	 * attaches an object to the Collection
129
+	 * and sets any supplied data associated with the current iterator entry
130
+	 * by calling EE_Object_Collection::set_identifier()
131
+	 *
132
+	 * @param        $object
133
+	 * @param  mixed $identifier
134
+	 * @return bool
135
+	 * @throws InvalidEntityException
136
+	 * @throws DuplicateCollectionIdentifierException
137
+	 */
138
+	public function add($object, $identifier = null)
139
+	{
140
+		if (! $object instanceof $this->collection_interface) {
141
+			throw new InvalidEntityException($object, $this->collection_interface);
142
+		}
143
+		if ($this->contains($object)) {
144
+			throw new DuplicateCollectionIdentifierException($identifier);
145
+		}
146
+		$this->attach($object);
147
+		$this->setIdentifier($object, $identifier);
148
+		return $this->contains($object);
149
+	}
150
+
151
+
152
+	/**
153
+	 * getIdentifier
154
+	 * if no $identifier is supplied, then the spl_object_hash() is used
155
+	 *
156
+	 * @param        $object
157
+	 * @param  mixed $identifier
158
+	 * @return bool
159
+	 */
160
+	public function getIdentifier($object, $identifier = null)
161
+	{
162
+		return ! empty($identifier)
163
+			? $identifier
164
+			: spl_object_hash($object);
165
+	}
166
+
167
+
168
+	/**
169
+	 * setIdentifier
170
+	 * Sets the data associated with an object in the Collection
171
+	 * if no $identifier is supplied, then the spl_object_hash() is used
172
+	 *
173
+	 * @param        $object
174
+	 * @param  mixed $identifier
175
+	 * @return bool
176
+	 */
177
+	public function setIdentifier($object, $identifier = null)
178
+	{
179
+		$identifier = $this->getIdentifier($object, $identifier);
180
+		$this->rewind();
181
+		while ($this->valid()) {
182
+			if ($object === $this->current()) {
183
+				$this->setInfo($identifier);
184
+				$this->rewind();
185
+				return true;
186
+			}
187
+			$this->next();
188
+		}
189
+		return false;
190
+	}
191
+
192
+
193
+	/**
194
+	 * get
195
+	 * finds and returns an object in the Collection based on the identifier that was set using addObject()
196
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
197
+	 *
198
+	 * @param mixed $identifier
199
+	 * @return mixed
200
+	 */
201
+	public function get($identifier)
202
+	{
203
+		$this->rewind();
204
+		while ($this->valid()) {
205
+			if ($identifier === $this->getInfo()) {
206
+				$object = $this->current();
207
+				$this->rewind();
208
+				return $object;
209
+			}
210
+			$this->next();
211
+		}
212
+		return null;
213
+	}
214
+
215
+
216
+	/**
217
+	 * has
218
+	 * returns TRUE or FALSE
219
+	 * depending on whether the object is within the Collection
220
+	 * based on the supplied $identifier
221
+	 *
222
+	 * @param  mixed $identifier
223
+	 * @return bool
224
+	 */
225
+	public function has($identifier)
226
+	{
227
+		$this->rewind();
228
+		while ($this->valid()) {
229
+			if ($identifier === $this->getInfo()) {
230
+				$this->rewind();
231
+				return true;
232
+			}
233
+			$this->next();
234
+		}
235
+		return false;
236
+	}
237
+
238
+
239
+	/**
240
+	 * hasObject
241
+	 * returns TRUE or FALSE depending on whether the supplied object is within the Collection
242
+	 *
243
+	 * @param $object
244
+	 * @return bool
245
+	 */
246
+	public function hasObject($object)
247
+	{
248
+		return $this->contains($object);
249
+	}
250
+
251
+
252
+	/**
253
+	 * hasObjects
254
+	 * returns true if there are objects within the Collection, and false if it is empty
255
+	 *
256
+	 * @return bool
257
+	 */
258
+	public function hasObjects()
259
+	{
260
+		return $this->count() !== 0;
261
+	}
262
+
263
+
264
+	/**
265
+	 * isEmpty
266
+	 * returns true if there are no objects within the Collection, and false if there are
267
+	 *
268
+	 * @return bool
269
+	 */
270
+	public function isEmpty()
271
+	{
272
+		return $this->count() === 0;
273
+	}
274
+
275
+
276
+	/**
277
+	 * remove
278
+	 * detaches an object from the Collection
279
+	 *
280
+	 * @param $object
281
+	 * @return bool
282
+	 */
283
+	public function remove($object)
284
+	{
285
+		$this->detach($object);
286
+		return true;
287
+	}
288
+
289
+
290
+	/**
291
+	 * setCurrent
292
+	 * advances pointer to the object whose identifier matches that which was provided
293
+	 *
294
+	 * @param mixed $identifier
295
+	 * @return boolean
296
+	 */
297
+	public function setCurrent($identifier)
298
+	{
299
+		$this->rewind();
300
+		while ($this->valid()) {
301
+			if ($identifier === $this->getInfo()) {
302
+				return true;
303
+			}
304
+			$this->next();
305
+		}
306
+		return false;
307
+	}
308
+
309
+
310
+	/**
311
+	 * setCurrentUsingObject
312
+	 * advances pointer to the provided object
313
+	 *
314
+	 * @param $object
315
+	 * @return boolean
316
+	 */
317
+	public function setCurrentUsingObject($object)
318
+	{
319
+		$this->rewind();
320
+		while ($this->valid()) {
321
+			if ($this->current() === $object) {
322
+				return true;
323
+			}
324
+			$this->next();
325
+		}
326
+		return false;
327
+	}
328
+
329
+
330
+	/**
331
+	 * Returns the object occupying the index before the current object,
332
+	 * unless this is already the first object, in which case it just returns the first object
333
+	 *
334
+	 * @return mixed
335
+	 */
336
+	public function previous()
337
+	{
338
+		$index = $this->indexOf($this->current());
339
+		if ($index === 0) {
340
+			return $this->current();
341
+		}
342
+		$index--;
343
+		return $this->objectAtIndex($index);
344
+	}
345
+
346
+
347
+	/**
348
+	 * Returns the index of a given object, or false if not found
349
+	 *
350
+	 * @see http://stackoverflow.com/a/8736013
351
+	 * @param $object
352
+	 * @return boolean|int|string
353
+	 */
354
+	public function indexOf($object)
355
+	{
356
+		if (! $this->contains($object)) {
357
+			return false;
358
+		}
359
+		foreach ($this as $index => $obj) {
360
+			if ($obj === $object) {
361
+				return $index;
362
+			}
363
+		}
364
+		return false;
365
+	}
366
+
367
+
368
+	/**
369
+	 * Returns the object at the given index
370
+	 *
371
+	 * @see http://stackoverflow.com/a/8736013
372
+	 * @param int $index
373
+	 * @return mixed
374
+	 */
375
+	public function objectAtIndex($index)
376
+	{
377
+		$iterator = new LimitIterator($this, $index, 1);
378
+		$iterator->rewind();
379
+		return $iterator->current();
380
+	}
381
+
382
+
383
+	/**
384
+	 * Returns the sequence of objects as specified by the offset and length
385
+	 *
386
+	 * @see http://stackoverflow.com/a/8736013
387
+	 * @param int $offset
388
+	 * @param int $length
389
+	 * @return array
390
+	 */
391
+	public function slice($offset, $length)
392
+	{
393
+		$slice = array();
394
+		$iterator = new LimitIterator($this, $offset, $length);
395
+		foreach ($iterator as $object) {
396
+			$slice[] = $object;
397
+		}
398
+		return $slice;
399
+	}
400
+
401
+
402
+	/**
403
+	 * Inserts an object at a certain point
404
+	 *
405
+	 * @see http://stackoverflow.com/a/8736013
406
+	 * @param mixed $object A single object
407
+	 * @param int   $index
408
+	 * @param mixed $identifier
409
+	 * @return bool
410
+	 * @throws DuplicateCollectionIdentifierException
411
+	 * @throws InvalidEntityException
412
+	 */
413
+	public function insertObjectAt($object, $index, $identifier = null)
414
+	{
415
+		// check to ensure that objects don't already exist in the collection
416
+		if ($this->has($identifier)) {
417
+			throw new DuplicateCollectionIdentifierException($identifier);
418
+		}
419
+		// detach any objects at or past this index
420
+		$remaining_objects = array();
421
+		if ($index < $this->count()) {
422
+			$remaining_objects = $this->slice($index, $this->count() - $index);
423
+			foreach ($remaining_objects as $key => $remaining_object) {
424
+				// we need to grab the identifiers for each object and use them as keys
425
+				$remaining_objects[ $remaining_object->getInfo() ] = $remaining_object;
426
+				// and then remove the object from the current tracking array
427
+				unset($remaining_objects[ $key ]);
428
+				// and then remove it from the Collection
429
+				$this->detach($remaining_object);
430
+			}
431
+		}
432
+		// add the new object we're splicing in
433
+		$this->add($object, $identifier);
434
+		// attach the objects we previously detached
435
+		foreach ($remaining_objects as $key => $remaining_object) {
436
+			$this->add($remaining_object, $key);
437
+		}
438
+		return $this->contains($object);
439
+	}
440
+
441
+
442
+	/**
443
+	 * Inserts an object (or an array of objects) at a certain point
444
+	 *
445
+	 * @see http://stackoverflow.com/a/8736013
446
+	 * @param mixed $objects A single object or an array of objects
447
+	 * @param int   $index
448
+	 */
449
+	public function insertAt($objects, $index)
450
+	{
451
+		if (! is_array($objects)) {
452
+			$objects = array($objects);
453
+		}
454
+		// check to ensure that objects don't already exist in the collection
455
+		foreach ($objects as $key => $object) {
456
+			if ($this->contains($object)) {
457
+				unset($objects[ $key ]);
458
+			}
459
+		}
460
+		// do we have any objects left?
461
+		if (! $objects) {
462
+			return;
463
+		}
464
+		// detach any objects at or past this index
465
+		$remaining = array();
466
+		if ($index < $this->count()) {
467
+			$remaining = $this->slice($index, $this->count() - $index);
468
+			foreach ($remaining as $object) {
469
+				$this->detach($object);
470
+			}
471
+		}
472
+		// add the new objects we're splicing in
473
+		foreach ($objects as $object) {
474
+			$this->attach($object);
475
+		}
476
+		// attach the objects we previously detached
477
+		foreach ($remaining as $object) {
478
+			$this->attach($object);
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 * Removes the object at the given index
485
+	 *
486
+	 * @see http://stackoverflow.com/a/8736013
487
+	 * @param int $index
488
+	 */
489
+	public function removeAt($index)
490
+	{
491
+		$this->detach($this->objectAtIndex($index));
492
+	}
493
+
494
+
495
+	/**
496
+	 * detaches ALL objects from the Collection
497
+	 */
498
+	public function detachAll()
499
+	{
500
+		$this->rewind();
501
+		while ($this->valid()) {
502
+			$object = $this->current();
503
+			$this->next();
504
+			$this->detach($object);
505
+		}
506
+	}
507
+
508
+
509
+	/**
510
+	 * unsets and detaches ALL objects from the Collection
511
+	 */
512
+	public function trashAndDetachAll()
513
+	{
514
+		$this->rewind();
515
+		while ($this->valid()) {
516
+			$object = $this->current();
517
+			$this->next();
518
+			$this->detach($object);
519
+			unset($object);
520
+		}
521
+	}
522 522
 }
Please login to merge, or discard this patch.