| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Copyright (c) 2013 Janos Szurovecz | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * this software and associated documentation files (the "Software"), to deal in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * the Software without restriction, including without limitation the rights to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * of the Software, and to permit persons to whom the Software is furnished to do | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * so, subject to the following conditions: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * The above copyright notice and this permission notice shall be included in all | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * copies or substantial portions of the Software. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * SOFTWARE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | namespace predaddy\presentation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use precore\lang\Object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use precore\lang\ObjectInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use precore\util\Objects; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * Represents an ordering for the given property with the given direction. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @author Janos Szurovecz <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | class Order extends Object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @var Direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     private $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     private $property; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @param Direction $direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param string $property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public function __construct(Direction $direction, $property) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->direction = $direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->property = $property; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @return Direction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function getDirection() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         return $this->direction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     public function getProperty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         return $this->property; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     public function equals(ObjectInterface $object = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         if ($object === $this) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         /* @var $object Order */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         return $object !== null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             && $this->getClassName() === $object->getClassName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             && $this->direction->equals($object->direction) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             && $this->property === $object->property; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |     public function toString() | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |         return Objects::toStringHelper($this) | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |             ->add($this->property) | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |             ->add($this->direction) | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |             ->toString(); | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 92 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |  |