| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | require_once 'Phwittr/Config.php'; |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | class Phwittr_Following |
|---|
| 26 | { |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | protected $_userId; |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | public function __construct($userId) |
|---|
| 64 | { |
|---|
| 65 | Phwittr_Config::configurePieceORM(); |
|---|
| 66 | |
|---|
| 67 | $this->_userId = $userId; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | public function addFriend($targetUserId) |
|---|
| 80 | { |
|---|
| 81 | if ($targetUserId == $this->_userId) { |
|---|
| 82 | return false; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | $follower = Piece_ORM::createObject('Followers'); |
|---|
| 86 | |
|---|
| 87 | $follower->userId = $this->_userId; |
|---|
| 88 | $follower->followId = $targetUserId; |
|---|
| 89 | $follower->createdAt = date('Y-m-d H:i:s'); |
|---|
| 90 | |
|---|
| 91 | $mapper = Piece_ORM::getMapper('Followers'); |
|---|
| 92 | $result = $mapper->insert($follower); |
|---|
| 93 | |
|---|
| 94 | if ($result) { |
|---|
| 95 | return true; |
|---|
| 96 | } else { |
|---|
| 97 | return false; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | public function removeFriend($targetUserId) |
|---|
| 111 | { |
|---|
| 112 | $follower = Piece_ORM::createObject('Followers'); |
|---|
| 113 | $follower->userId = $this->_userId; |
|---|
| 114 | $follower->followId = $targetUserId; |
|---|
| 115 | |
|---|
| 116 | $mapper = Piece_ORM::getMapper('Followers'); |
|---|
| 117 | $result = $mapper->delete($follower); |
|---|
| 118 | |
|---|
| 119 | if ($result) { |
|---|
| 120 | return true; |
|---|
| 121 | } else { |
|---|
| 122 | return false; |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | public function listFriends() |
|---|
| 135 | { |
|---|
| 136 | $user = Piece_ORM::createObject('Users'); |
|---|
| 137 | $user->id = $this->_userId; |
|---|
| 138 | |
|---|
| 139 | $mapper = Piece_ORM::getMapper('Users'); |
|---|
| 140 | return $mapper->findAllByIdForListFriends($user); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | public function listFollowers() |
|---|
| 152 | { |
|---|
| 153 | $user = Piece_ORM::createObject('Users'); |
|---|
| 154 | $user->id = $this->_userId; |
|---|
| 155 | |
|---|
| 156 | $mapper = Piece_ORM::getMapper('Users'); |
|---|
| 157 | return $mapper->findAllByIdForListFollowers($user); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | public function isFriend($userName) |
|---|
| 170 | { |
|---|
| 171 | $criteria = new stdClass(); |
|---|
| 172 | $criteria->id = $this->_userId; |
|---|
| 173 | $criteria->targetUserName = $userName; |
|---|
| 174 | |
|---|
| 175 | $mapper = Piece_ORM::getMapper('Users'); |
|---|
| 176 | $user = $mapper->findByIdAndTargetUserNameUserNameForUserIsFriend($criteria); |
|---|
| 177 | var_dump($user); |
|---|
| 178 | |
|---|
| 179 | if ($user) { |
|---|
| 180 | return true; |
|---|
| 181 | } else { |
|---|
| 182 | return false; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | ?> |
|---|