| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @property integer $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @property CPagination $pagination | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @property integer $count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @property array $items | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @property integer $page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @property boolean $private | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class Forum extends CModel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     private $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     private $items = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     private $page = 0; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private $pagination; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private $count; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     private $private = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function attributeNames() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     public function getId() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         return (int)$this->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function getPagination() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         return $this->pagination; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function getCount() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         return $this->count; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function getItems() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return $this->items; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |        | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function setId($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->id = (int)$id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function setPage($page) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->page = $page; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public function setPrivate($private) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $this->private = (bool)$private; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public function fetchItems() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $player = Yii::app()->player->model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $limit = Yii::app()->params['listPerPage']; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $fetchPrivates = $this->id !== $player->in_club ? ' AND private=0' : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->count = Yii::app()->db->createCommand() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             ->select('COUNT(*) AS count') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             ->from('forum') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             ->where('club_id = :id'.$fetchPrivates, [':id'=>$this->id]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             ->queryScalar(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $res = Yii::app()->db->createCommand() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             ->select('*') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             ->from('forum') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             ->where('club_id = :id'.$fetchPrivates, [':id'=>$this->id]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             ->order('id DESC') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             ->limit($limit, ($this->page * $limit) - $limit) // the trick is here! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             ->queryAll(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $this->pagination = new CPagination($this->count); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->pagination->setPageSize(Yii::app()->params['listPerPage']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $this->items = $res; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |     public function save($post, $isMentor = false) | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |         if (!$isMentor) { | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |             $post = trim($post); | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |             $post = strip_tags($post); | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |             $post = htmlspecialchars($post); | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |             $post = substr($post, 0, 800); | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |         if (!$post) { | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |             return false; | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |         $player = Yii::app()->player->model; | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |         $uid = $isMentor ? 1 : $player->uid; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |         $user = $isMentor ? 'Áron bá' : $player->user; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |         if ($uid > 1 && $player->in_club != $this->id) { | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |             return false; //nem klubtag, nem mentor | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |         $parameters = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |             'club_id'=>$this->id, | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |             'uid'=>$uid, | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |             'user'=>$user, | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |             'body'=>$post, | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |             'private'=>$this->private | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |             ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |         Yii::app()->db->createCommand() | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |                 ->insert('forum', $parameters); | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |         $parameters['created'] = 'most'; | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |         array_unshift($this->items, $parameters); | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |         return true; | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     public function delete($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         if (!$id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $player = Yii::app()->player->model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         if ($player->in_club != $this->id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |             return false; //nem klubtag, nem mentor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         Yii::app()->db->createCommand()->delete( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |             'forum', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |             'id=:id AND uid=:uid', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |             [':id'=>(int)$id, ':uid'=>Yii::app()->player->model->uid] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 141 |  |  | } | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 142 |  |  |  | 
            
                        
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.