| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Declares a condition that determines whether an email can be sent to a given recipient | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @method UserDefinedForm_EmailRecipient Parent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @property Enum ConditionOption | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @property Varchar ConditionValue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @method EditableFormField ConditionField | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class UserDefinedForm_EmailRecipientCondition extends DataObject | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * List of options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     private static $condition_options = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         "IsBlank" => "Is blank", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         "IsNotBlank" => "Is not blank", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         "Equals" => "Equals", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         "NotEquals" => "Doesn't equal", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         "ValueLessThan" => "Less than", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         "ValueLessThanEqual" => "Less than or equal", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         "ValueGreaterThan" => "Greater than", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         "ValueGreaterThanEqual" => "Greater than or equal" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     private static $db = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         'ConditionOption' => 'Enum("IsBlank,IsNotBlank,Equals,NotEquals,ValueLessThan,ValueLessThanEqual,ValueGreaterThan,ValueGreaterThanEqual")', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         'ConditionValue' => 'Varchar' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     private static $has_one = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         'Parent' => 'UserDefinedForm_EmailRecipient', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         'ConditionField' => 'EditableFormField' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 1 |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 1 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 1 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 1 |  |      * Determine if this rule matches the given condition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 1 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  |      * @param $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 1 |  |      * @return bool|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  |      * @throws LogicException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |     public function matches($data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  |         $fieldName = $this->ConditionField()->Name; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 1 |  |         $fieldValue = isset($data[$fieldName]) ? $data[$fieldName] : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $conditionValue = $this->ConditionValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $result = null; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         switch ($this->ConditionOption) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             case 'IsBlank': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                 $result = empty($fieldValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             case 'IsNotBlank': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 $result = !empty($fieldValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             case 'ValueLessThan': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 $result = ($fieldValue < $conditionValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             case 'ValueLessThanEqual': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 $result = ($fieldValue <= $conditionValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             case 'ValueGreaterThan': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 $result = ($fieldValue > $conditionValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             case 'ValueGreaterThanEqual': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 $result = ($fieldValue >= $conditionValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             case 'NotEquals': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             case 'Equals': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 $result = is_array($fieldValue) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                     ? in_array($conditionValue, $fieldValue) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                     : $fieldValue == $conditionValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 if ($this->ConditionOption == 'NotEquals') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                     $result = !($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 throw new LogicException("Unhandled rule {$this->ConditionOption}"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                 break; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * Return whether a user can create an object of this type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @param Member $member | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @param array $context Virtual parameter to allow context to be passed in to check | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 103 |  | View Code Duplication |     public function canCreate($member = null) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         // Check parent page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $parent = $this->getCanCreateContext(func_get_args()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         if ($parent) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             return $parent->canEdit($member); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         // Fall back to secure admin permissions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         return parent::canCreate($member); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * Helper method to check the parent for this object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @param array $args List of arguments passed to canCreate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * @return SiteTree Parent page instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 121 |  | View Code Duplication |     protected function getCanCreateContext($args) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         // Inspect second parameter to canCreate for a 'Parent' context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         if (isset($args[1]['Parent'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             return $args[1]['Parent']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         // Hack in currently edited page if context is missing | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         if (Controller::has_curr() && Controller::curr() instanceof CMSMain) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 1 |  |             return Controller::curr()->currentPage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         // No page being edited | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * @param Member | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     public function canView($member = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         return $this->Parent()->canView($member); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * @param Member | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     public function canEdit($member = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         return $this->Parent()->canEdit($member); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |      * @param Member | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |      * @return boolean | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 160 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 161 |  |  |     public function canDelete($member = null) | 
            
                                                        
            
                                    
            
            
                | 162 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 163 |  |  |         return $this->canEdit($member); | 
            
                                                        
            
                                    
            
            
                | 164 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 165 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 166 |  |  |  | 
            
                        
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.