@@ -30,318 +30,318 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class Logger |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * @param PdoDatabase $database |
|
| 35 | - * @param Request $object |
|
| 36 | - */ |
|
| 37 | - public static function emailConfirmed(PdoDatabase $database, Request $object) |
|
| 38 | - { |
|
| 39 | - self::createLogEntry($database, $object, "Email Confirmed", null, User::getCommunity()); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param PdoDatabase $database |
|
| 44 | - * @param DataObject $object |
|
| 45 | - * @param string $logAction |
|
| 46 | - * @param null|string $comment |
|
| 47 | - * @param User $user |
|
| 48 | - * |
|
| 49 | - * @throws Exception |
|
| 50 | - */ |
|
| 51 | - private static function createLogEntry( |
|
| 52 | - PdoDatabase $database, |
|
| 53 | - DataObject $object, |
|
| 54 | - $logAction, |
|
| 55 | - $comment = null, |
|
| 56 | - $user = null |
|
| 57 | - ) { |
|
| 58 | - if ($user == null) { |
|
| 59 | - $user = User::getCurrent($database); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $objectType = get_class($object); |
|
| 63 | - if (strpos($objectType, 'Waca\\DataObjects\\') !== false) { |
|
| 64 | - $objectType = str_replace('Waca\\DataObjects\\', '', $objectType); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - $log = new Log(); |
|
| 68 | - $log->setDatabase($database); |
|
| 69 | - $log->setAction($logAction); |
|
| 70 | - $log->setObjectId($object->getId()); |
|
| 71 | - $log->setObjectType($objectType); |
|
| 72 | - $log->setUser($user); |
|
| 73 | - $log->setComment($comment); |
|
| 74 | - $log->save(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - #region Users |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param PdoDatabase $database |
|
| 81 | - * @param User $user |
|
| 82 | - */ |
|
| 83 | - public static function newUser(PdoDatabase $database, User $user) |
|
| 84 | - { |
|
| 85 | - self::createLogEntry($database, $user, 'Registered', null, User::getCommunity()); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param PdoDatabase $database |
|
| 90 | - * @param User $object |
|
| 91 | - */ |
|
| 92 | - public static function approvedUser(PdoDatabase $database, User $object) |
|
| 93 | - { |
|
| 94 | - self::createLogEntry($database, $object, "Approved"); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param PdoDatabase $database |
|
| 99 | - * @param User $object |
|
| 100 | - * @param string $comment |
|
| 101 | - */ |
|
| 102 | - public static function declinedUser(PdoDatabase $database, User $object, $comment) |
|
| 103 | - { |
|
| 104 | - self::createLogEntry($database, $object, "Declined", $comment); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param PdoDatabase $database |
|
| 109 | - * @param User $object |
|
| 110 | - * @param string $comment |
|
| 111 | - */ |
|
| 112 | - public static function suspendedUser(PdoDatabase $database, User $object, $comment) |
|
| 113 | - { |
|
| 114 | - self::createLogEntry($database, $object, "Suspended", $comment); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @param PdoDatabase $database |
|
| 119 | - * @param User $object |
|
| 120 | - * @param string $comment |
|
| 121 | - */ |
|
| 122 | - public static function demotedUser(PdoDatabase $database, User $object, $comment) |
|
| 123 | - { |
|
| 124 | - self::createLogEntry($database, $object, "Demoted", $comment); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param PdoDatabase $database |
|
| 129 | - * @param User $object |
|
| 130 | - */ |
|
| 131 | - public static function promotedUser(PdoDatabase $database, User $object) |
|
| 132 | - { |
|
| 133 | - self::createLogEntry($database, $object, "Promoted"); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param PdoDatabase $database |
|
| 138 | - * @param User $object |
|
| 139 | - * @param string $comment |
|
| 140 | - */ |
|
| 141 | - public static function renamedUser(PdoDatabase $database, User $object, $comment) |
|
| 142 | - { |
|
| 143 | - self::createLogEntry($database, $object, "Renamed", $comment); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param PdoDatabase $database |
|
| 148 | - * @param User $object |
|
| 149 | - */ |
|
| 150 | - public static function userPreferencesChange(PdoDatabase $database, User $object) |
|
| 151 | - { |
|
| 152 | - self::createLogEntry($database, $object, "Prefchange"); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param PdoDatabase $database |
|
| 157 | - * @param User $object |
|
| 158 | - * @param string $reason |
|
| 159 | - * @param array $added |
|
| 160 | - * @param array $removed |
|
| 161 | - */ |
|
| 162 | - public static function userRolesEdited(PdoDatabase $database, User $object, $reason, $added, $removed) |
|
| 163 | - { |
|
| 164 | - $logData = serialize(array( |
|
| 165 | - 'added' => $added, |
|
| 166 | - 'removed' => $removed, |
|
| 167 | - 'reason' => $reason, |
|
| 168 | - )); |
|
| 169 | - |
|
| 170 | - self::createLogEntry($database, $object, "RoleChange", $logData); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - #endregion |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @param PdoDatabase $database |
|
| 177 | - * @param SiteNotice $object |
|
| 178 | - */ |
|
| 179 | - public static function siteNoticeEdited(PdoDatabase $database, SiteNotice $object) |
|
| 180 | - { |
|
| 181 | - self::createLogEntry($database, $object, "Edited"); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - #region Welcome Templates |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param PdoDatabase $database |
|
| 188 | - * @param WelcomeTemplate $object |
|
| 189 | - */ |
|
| 190 | - public static function welcomeTemplateCreated(PdoDatabase $database, WelcomeTemplate $object) |
|
| 191 | - { |
|
| 192 | - self::createLogEntry($database, $object, "CreatedTemplate"); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param PdoDatabase $database |
|
| 197 | - * @param WelcomeTemplate $object |
|
| 198 | - */ |
|
| 199 | - public static function welcomeTemplateEdited(PdoDatabase $database, WelcomeTemplate $object) |
|
| 200 | - { |
|
| 201 | - self::createLogEntry($database, $object, "EditedTemplate"); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * @param PdoDatabase $database |
|
| 206 | - * @param WelcomeTemplate $object |
|
| 207 | - */ |
|
| 208 | - public static function welcomeTemplateDeleted(PdoDatabase $database, WelcomeTemplate $object) |
|
| 209 | - { |
|
| 210 | - self::createLogEntry($database, $object, "DeletedTemplate"); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - #endregion |
|
| 214 | - |
|
| 215 | - #region Bans |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @param PdoDatabase $database |
|
| 219 | - * @param Ban $object |
|
| 220 | - * @param string $reason |
|
| 221 | - */ |
|
| 222 | - public static function banned(PdoDatabase $database, Ban $object, $reason) |
|
| 223 | - { |
|
| 224 | - self::createLogEntry($database, $object, "Banned", $reason); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @param PdoDatabase $database |
|
| 229 | - * @param Ban $object |
|
| 230 | - * @param string $reason |
|
| 231 | - */ |
|
| 232 | - public static function unbanned(PdoDatabase $database, Ban $object, $reason) |
|
| 233 | - { |
|
| 234 | - self::createLogEntry($database, $object, "Unbanned", $reason); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - #endregion |
|
| 238 | - |
|
| 239 | - #region Requests |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @param PdoDatabase $database |
|
| 243 | - * @param Request $object |
|
| 244 | - * @param string $target |
|
| 245 | - */ |
|
| 246 | - public static function deferRequest(PdoDatabase $database, Request $object, $target) |
|
| 247 | - { |
|
| 248 | - self::createLogEntry($database, $object, "Deferred to $target"); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @param PdoDatabase $database |
|
| 253 | - * @param Request $object |
|
| 254 | - * @param integer $target |
|
| 255 | - * @param string $comment |
|
| 256 | - */ |
|
| 257 | - public static function closeRequest(PdoDatabase $database, Request $object, $target, $comment) |
|
| 258 | - { |
|
| 259 | - self::createLogEntry($database, $object, "Closed $target", $comment); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @param PdoDatabase $database |
|
| 264 | - * @param Request $object |
|
| 265 | - */ |
|
| 266 | - public static function reserve(PdoDatabase $database, Request $object) |
|
| 267 | - { |
|
| 268 | - self::createLogEntry($database, $object, "Reserved"); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @param PdoDatabase $database |
|
| 273 | - * @param Request $object |
|
| 274 | - */ |
|
| 275 | - public static function breakReserve(PdoDatabase $database, Request $object) |
|
| 276 | - { |
|
| 277 | - self::createLogEntry($database, $object, "BreakReserve"); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * @param PdoDatabase $database |
|
| 282 | - * @param Request $object |
|
| 283 | - */ |
|
| 284 | - public static function unreserve(PdoDatabase $database, Request $object) |
|
| 285 | - { |
|
| 286 | - self::createLogEntry($database, $object, "Unreserved"); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @param PdoDatabase $database |
|
| 291 | - * @param Comment $object |
|
| 292 | - * @param Request $request |
|
| 293 | - */ |
|
| 294 | - public static function editComment(PdoDatabase $database, Comment $object, Request $request) |
|
| 295 | - { |
|
| 296 | - self::createLogEntry($database, $request, "EditComment-r"); |
|
| 297 | - self::createLogEntry($database, $object, "EditComment-c"); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @param PdoDatabase $database |
|
| 302 | - * @param Request $object |
|
| 303 | - * @param User $target |
|
| 304 | - */ |
|
| 305 | - public static function sendReservation(PdoDatabase $database, Request $object, User $target) |
|
| 306 | - { |
|
| 307 | - self::createLogEntry($database, $object, "SendReserved"); |
|
| 308 | - self::createLogEntry($database, $object, "ReceiveReserved", null, $target); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * @param PdoDatabase $database |
|
| 313 | - * @param Request $object |
|
| 314 | - * @param string $comment |
|
| 315 | - */ |
|
| 316 | - public static function sentMail(PdoDatabase $database, Request $object, $comment) |
|
| 317 | - { |
|
| 318 | - self::createLogEntry($database, $object, "SentMail", $comment); |
|
| 319 | - } |
|
| 320 | - #endregion |
|
| 321 | - |
|
| 322 | - #region Email templates |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * @param PdoDatabase $database |
|
| 326 | - * @param EmailTemplate $object |
|
| 327 | - */ |
|
| 328 | - public static function createEmail(PdoDatabase $database, EmailTemplate $object) |
|
| 329 | - { |
|
| 330 | - self::createLogEntry($database, $object, "CreatedEmail"); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * @param PdoDatabase $database |
|
| 335 | - * @param EmailTemplate $object |
|
| 336 | - */ |
|
| 337 | - public static function editedEmail(PdoDatabase $database, EmailTemplate $object) |
|
| 338 | - { |
|
| 339 | - self::createLogEntry($database, $object, "EditedEmail"); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - #endregion |
|
| 343 | - |
|
| 344 | - #region Display |
|
| 345 | - |
|
| 346 | - #endregion |
|
| 33 | + /** |
|
| 34 | + * @param PdoDatabase $database |
|
| 35 | + * @param Request $object |
|
| 36 | + */ |
|
| 37 | + public static function emailConfirmed(PdoDatabase $database, Request $object) |
|
| 38 | + { |
|
| 39 | + self::createLogEntry($database, $object, "Email Confirmed", null, User::getCommunity()); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param PdoDatabase $database |
|
| 44 | + * @param DataObject $object |
|
| 45 | + * @param string $logAction |
|
| 46 | + * @param null|string $comment |
|
| 47 | + * @param User $user |
|
| 48 | + * |
|
| 49 | + * @throws Exception |
|
| 50 | + */ |
|
| 51 | + private static function createLogEntry( |
|
| 52 | + PdoDatabase $database, |
|
| 53 | + DataObject $object, |
|
| 54 | + $logAction, |
|
| 55 | + $comment = null, |
|
| 56 | + $user = null |
|
| 57 | + ) { |
|
| 58 | + if ($user == null) { |
|
| 59 | + $user = User::getCurrent($database); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + $objectType = get_class($object); |
|
| 63 | + if (strpos($objectType, 'Waca\\DataObjects\\') !== false) { |
|
| 64 | + $objectType = str_replace('Waca\\DataObjects\\', '', $objectType); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + $log = new Log(); |
|
| 68 | + $log->setDatabase($database); |
|
| 69 | + $log->setAction($logAction); |
|
| 70 | + $log->setObjectId($object->getId()); |
|
| 71 | + $log->setObjectType($objectType); |
|
| 72 | + $log->setUser($user); |
|
| 73 | + $log->setComment($comment); |
|
| 74 | + $log->save(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + #region Users |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param PdoDatabase $database |
|
| 81 | + * @param User $user |
|
| 82 | + */ |
|
| 83 | + public static function newUser(PdoDatabase $database, User $user) |
|
| 84 | + { |
|
| 85 | + self::createLogEntry($database, $user, 'Registered', null, User::getCommunity()); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param PdoDatabase $database |
|
| 90 | + * @param User $object |
|
| 91 | + */ |
|
| 92 | + public static function approvedUser(PdoDatabase $database, User $object) |
|
| 93 | + { |
|
| 94 | + self::createLogEntry($database, $object, "Approved"); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param PdoDatabase $database |
|
| 99 | + * @param User $object |
|
| 100 | + * @param string $comment |
|
| 101 | + */ |
|
| 102 | + public static function declinedUser(PdoDatabase $database, User $object, $comment) |
|
| 103 | + { |
|
| 104 | + self::createLogEntry($database, $object, "Declined", $comment); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param PdoDatabase $database |
|
| 109 | + * @param User $object |
|
| 110 | + * @param string $comment |
|
| 111 | + */ |
|
| 112 | + public static function suspendedUser(PdoDatabase $database, User $object, $comment) |
|
| 113 | + { |
|
| 114 | + self::createLogEntry($database, $object, "Suspended", $comment); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @param PdoDatabase $database |
|
| 119 | + * @param User $object |
|
| 120 | + * @param string $comment |
|
| 121 | + */ |
|
| 122 | + public static function demotedUser(PdoDatabase $database, User $object, $comment) |
|
| 123 | + { |
|
| 124 | + self::createLogEntry($database, $object, "Demoted", $comment); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param PdoDatabase $database |
|
| 129 | + * @param User $object |
|
| 130 | + */ |
|
| 131 | + public static function promotedUser(PdoDatabase $database, User $object) |
|
| 132 | + { |
|
| 133 | + self::createLogEntry($database, $object, "Promoted"); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param PdoDatabase $database |
|
| 138 | + * @param User $object |
|
| 139 | + * @param string $comment |
|
| 140 | + */ |
|
| 141 | + public static function renamedUser(PdoDatabase $database, User $object, $comment) |
|
| 142 | + { |
|
| 143 | + self::createLogEntry($database, $object, "Renamed", $comment); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param PdoDatabase $database |
|
| 148 | + * @param User $object |
|
| 149 | + */ |
|
| 150 | + public static function userPreferencesChange(PdoDatabase $database, User $object) |
|
| 151 | + { |
|
| 152 | + self::createLogEntry($database, $object, "Prefchange"); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param PdoDatabase $database |
|
| 157 | + * @param User $object |
|
| 158 | + * @param string $reason |
|
| 159 | + * @param array $added |
|
| 160 | + * @param array $removed |
|
| 161 | + */ |
|
| 162 | + public static function userRolesEdited(PdoDatabase $database, User $object, $reason, $added, $removed) |
|
| 163 | + { |
|
| 164 | + $logData = serialize(array( |
|
| 165 | + 'added' => $added, |
|
| 166 | + 'removed' => $removed, |
|
| 167 | + 'reason' => $reason, |
|
| 168 | + )); |
|
| 169 | + |
|
| 170 | + self::createLogEntry($database, $object, "RoleChange", $logData); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + #endregion |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @param PdoDatabase $database |
|
| 177 | + * @param SiteNotice $object |
|
| 178 | + */ |
|
| 179 | + public static function siteNoticeEdited(PdoDatabase $database, SiteNotice $object) |
|
| 180 | + { |
|
| 181 | + self::createLogEntry($database, $object, "Edited"); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + #region Welcome Templates |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param PdoDatabase $database |
|
| 188 | + * @param WelcomeTemplate $object |
|
| 189 | + */ |
|
| 190 | + public static function welcomeTemplateCreated(PdoDatabase $database, WelcomeTemplate $object) |
|
| 191 | + { |
|
| 192 | + self::createLogEntry($database, $object, "CreatedTemplate"); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param PdoDatabase $database |
|
| 197 | + * @param WelcomeTemplate $object |
|
| 198 | + */ |
|
| 199 | + public static function welcomeTemplateEdited(PdoDatabase $database, WelcomeTemplate $object) |
|
| 200 | + { |
|
| 201 | + self::createLogEntry($database, $object, "EditedTemplate"); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * @param PdoDatabase $database |
|
| 206 | + * @param WelcomeTemplate $object |
|
| 207 | + */ |
|
| 208 | + public static function welcomeTemplateDeleted(PdoDatabase $database, WelcomeTemplate $object) |
|
| 209 | + { |
|
| 210 | + self::createLogEntry($database, $object, "DeletedTemplate"); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + #endregion |
|
| 214 | + |
|
| 215 | + #region Bans |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @param PdoDatabase $database |
|
| 219 | + * @param Ban $object |
|
| 220 | + * @param string $reason |
|
| 221 | + */ |
|
| 222 | + public static function banned(PdoDatabase $database, Ban $object, $reason) |
|
| 223 | + { |
|
| 224 | + self::createLogEntry($database, $object, "Banned", $reason); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @param PdoDatabase $database |
|
| 229 | + * @param Ban $object |
|
| 230 | + * @param string $reason |
|
| 231 | + */ |
|
| 232 | + public static function unbanned(PdoDatabase $database, Ban $object, $reason) |
|
| 233 | + { |
|
| 234 | + self::createLogEntry($database, $object, "Unbanned", $reason); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + #endregion |
|
| 238 | + |
|
| 239 | + #region Requests |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @param PdoDatabase $database |
|
| 243 | + * @param Request $object |
|
| 244 | + * @param string $target |
|
| 245 | + */ |
|
| 246 | + public static function deferRequest(PdoDatabase $database, Request $object, $target) |
|
| 247 | + { |
|
| 248 | + self::createLogEntry($database, $object, "Deferred to $target"); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @param PdoDatabase $database |
|
| 253 | + * @param Request $object |
|
| 254 | + * @param integer $target |
|
| 255 | + * @param string $comment |
|
| 256 | + */ |
|
| 257 | + public static function closeRequest(PdoDatabase $database, Request $object, $target, $comment) |
|
| 258 | + { |
|
| 259 | + self::createLogEntry($database, $object, "Closed $target", $comment); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @param PdoDatabase $database |
|
| 264 | + * @param Request $object |
|
| 265 | + */ |
|
| 266 | + public static function reserve(PdoDatabase $database, Request $object) |
|
| 267 | + { |
|
| 268 | + self::createLogEntry($database, $object, "Reserved"); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @param PdoDatabase $database |
|
| 273 | + * @param Request $object |
|
| 274 | + */ |
|
| 275 | + public static function breakReserve(PdoDatabase $database, Request $object) |
|
| 276 | + { |
|
| 277 | + self::createLogEntry($database, $object, "BreakReserve"); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * @param PdoDatabase $database |
|
| 282 | + * @param Request $object |
|
| 283 | + */ |
|
| 284 | + public static function unreserve(PdoDatabase $database, Request $object) |
|
| 285 | + { |
|
| 286 | + self::createLogEntry($database, $object, "Unreserved"); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @param PdoDatabase $database |
|
| 291 | + * @param Comment $object |
|
| 292 | + * @param Request $request |
|
| 293 | + */ |
|
| 294 | + public static function editComment(PdoDatabase $database, Comment $object, Request $request) |
|
| 295 | + { |
|
| 296 | + self::createLogEntry($database, $request, "EditComment-r"); |
|
| 297 | + self::createLogEntry($database, $object, "EditComment-c"); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @param PdoDatabase $database |
|
| 302 | + * @param Request $object |
|
| 303 | + * @param User $target |
|
| 304 | + */ |
|
| 305 | + public static function sendReservation(PdoDatabase $database, Request $object, User $target) |
|
| 306 | + { |
|
| 307 | + self::createLogEntry($database, $object, "SendReserved"); |
|
| 308 | + self::createLogEntry($database, $object, "ReceiveReserved", null, $target); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * @param PdoDatabase $database |
|
| 313 | + * @param Request $object |
|
| 314 | + * @param string $comment |
|
| 315 | + */ |
|
| 316 | + public static function sentMail(PdoDatabase $database, Request $object, $comment) |
|
| 317 | + { |
|
| 318 | + self::createLogEntry($database, $object, "SentMail", $comment); |
|
| 319 | + } |
|
| 320 | + #endregion |
|
| 321 | + |
|
| 322 | + #region Email templates |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * @param PdoDatabase $database |
|
| 326 | + * @param EmailTemplate $object |
|
| 327 | + */ |
|
| 328 | + public static function createEmail(PdoDatabase $database, EmailTemplate $object) |
|
| 329 | + { |
|
| 330 | + self::createLogEntry($database, $object, "CreatedEmail"); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * @param PdoDatabase $database |
|
| 335 | + * @param EmailTemplate $object |
|
| 336 | + */ |
|
| 337 | + public static function editedEmail(PdoDatabase $database, EmailTemplate $object) |
|
| 338 | + { |
|
| 339 | + self::createLogEntry($database, $object, "EditedEmail"); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + #endregion |
|
| 343 | + |
|
| 344 | + #region Display |
|
| 345 | + |
|
| 346 | + #endregion |
|
| 347 | 347 | } |
@@ -10,16 +10,16 @@ |
||
| 10 | 10 | |
| 11 | 11 | interface ITypeAheadHelper |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @param string $class CSS class to apply this typeahead to. |
|
| 15 | - * @param callable $generator Generator function taking no arguments to return an array of strings. |
|
| 16 | - * |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - public function defineTypeAheadSource($class, callable $generator); |
|
| 13 | + /** |
|
| 14 | + * @param string $class CSS class to apply this typeahead to. |
|
| 15 | + * @param callable $generator Generator function taking no arguments to return an array of strings. |
|
| 16 | + * |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + public function defineTypeAheadSource($class, callable $generator); |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @return string HTML fragment containing a JS block for typeaheads. |
|
| 23 | - */ |
|
| 24 | - public function getTypeAheadScriptBlock(); |
|
| 21 | + /** |
|
| 22 | + * @return string HTML fragment containing a JS block for typeaheads. |
|
| 23 | + */ |
|
| 24 | + public function getTypeAheadScriptBlock(); |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -17,15 +17,15 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | interface IEmailHelper |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Sends an email to the specified email address. |
|
| 22 | - * |
|
| 23 | - * @param string $to |
|
| 24 | - * @param string $subject |
|
| 25 | - * @param string $content |
|
| 26 | - * @param array $headers Extra headers to include |
|
| 27 | - * |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 30 | - public function sendMail($to, $subject, $content, $headers = array()); |
|
| 20 | + /** |
|
| 21 | + * Sends an email to the specified email address. |
|
| 22 | + * |
|
| 23 | + * @param string $to |
|
| 24 | + * @param string $subject |
|
| 25 | + * @param string $content |
|
| 26 | + * @param array $headers Extra headers to include |
|
| 27 | + * |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | + public function sendMail($to, $subject, $content, $headers = array()); |
|
| 31 | 31 | } |
| 32 | 32 | \ No newline at end of file |
@@ -15,39 +15,39 @@ |
||
| 15 | 15 | |
| 16 | 16 | interface IOAuthHelper |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @return stdClass |
|
| 20 | - * |
|
| 21 | - * @throws Exception |
|
| 22 | - * @throws CurlException |
|
| 23 | - */ |
|
| 24 | - public function getRequestToken(); |
|
| 18 | + /** |
|
| 19 | + * @return stdClass |
|
| 20 | + * |
|
| 21 | + * @throws Exception |
|
| 22 | + * @throws CurlException |
|
| 23 | + */ |
|
| 24 | + public function getRequestToken(); |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @param string $requestToken |
|
| 28 | - * |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - public function getAuthoriseUrl($requestToken); |
|
| 26 | + /** |
|
| 27 | + * @param string $requestToken |
|
| 28 | + * |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + public function getAuthoriseUrl($requestToken); |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param string $oauthRequestToken |
|
| 35 | - * @param string $oauthRequestSecret |
|
| 36 | - * @param string $oauthVerifier |
|
| 37 | - * |
|
| 38 | - * @return stdClass |
|
| 39 | - * @throws CurlException |
|
| 40 | - * @throws Exception |
|
| 41 | - */ |
|
| 42 | - public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier); |
|
| 33 | + /** |
|
| 34 | + * @param string $oauthRequestToken |
|
| 35 | + * @param string $oauthRequestSecret |
|
| 36 | + * @param string $oauthVerifier |
|
| 37 | + * |
|
| 38 | + * @return stdClass |
|
| 39 | + * @throws CurlException |
|
| 40 | + * @throws Exception |
|
| 41 | + */ |
|
| 42 | + public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param string $oauthAccessToken |
|
| 46 | - * @param string $oauthAccessSecret |
|
| 47 | - * |
|
| 48 | - * @return JWT |
|
| 49 | - * @throws CurlException |
|
| 50 | - * @throws Exception |
|
| 51 | - */ |
|
| 52 | - public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret); |
|
| 44 | + /** |
|
| 45 | + * @param string $oauthAccessToken |
|
| 46 | + * @param string $oauthAccessSecret |
|
| 47 | + * |
|
| 48 | + * @return JWT |
|
| 49 | + * @throws CurlException |
|
| 50 | + * @throws Exception |
|
| 51 | + */ |
|
| 52 | + public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret); |
|
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -12,30 +12,30 @@ |
||
| 12 | 12 | |
| 13 | 13 | interface IBanHelper |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Summary of nameIsBanned |
|
| 17 | - * |
|
| 18 | - * @param string $name The name to test if is banned. |
|
| 19 | - * |
|
| 20 | - * @return Ban |
|
| 21 | - */ |
|
| 22 | - public function nameIsBanned($name); |
|
| 15 | + /** |
|
| 16 | + * Summary of nameIsBanned |
|
| 17 | + * |
|
| 18 | + * @param string $name The name to test if is banned. |
|
| 19 | + * |
|
| 20 | + * @return Ban |
|
| 21 | + */ |
|
| 22 | + public function nameIsBanned($name); |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Summary of emailIsBanned |
|
| 26 | - * |
|
| 27 | - * @param string $email |
|
| 28 | - * |
|
| 29 | - * @return Ban |
|
| 30 | - */ |
|
| 31 | - public function emailIsBanned($email); |
|
| 24 | + /** |
|
| 25 | + * Summary of emailIsBanned |
|
| 26 | + * |
|
| 27 | + * @param string $email |
|
| 28 | + * |
|
| 29 | + * @return Ban |
|
| 30 | + */ |
|
| 31 | + public function emailIsBanned($email); |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Summary of ipIsBanned |
|
| 35 | - * |
|
| 36 | - * @param string $ip |
|
| 37 | - * |
|
| 38 | - * @return Ban |
|
| 39 | - */ |
|
| 40 | - public function ipIsBanned($ip); |
|
| 33 | + /** |
|
| 34 | + * Summary of ipIsBanned |
|
| 35 | + * |
|
| 36 | + * @param string $ip |
|
| 37 | + * |
|
| 38 | + * @return Ban |
|
| 39 | + */ |
|
| 40 | + public function ipIsBanned($ip); |
|
| 41 | 41 | } |
@@ -10,12 +10,12 @@ |
||
| 10 | 10 | |
| 11 | 11 | interface IBlacklistHelper |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist |
|
| 15 | - * |
|
| 16 | - * @param string $username |
|
| 17 | - * |
|
| 18 | - * @return bool |
|
| 19 | - */ |
|
| 20 | - public function isBlacklisted($username); |
|
| 13 | + /** |
|
| 14 | + * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist |
|
| 15 | + * |
|
| 16 | + * @param string $username |
|
| 17 | + * |
|
| 18 | + * @return bool |
|
| 19 | + */ |
|
| 20 | + public function isBlacklisted($username); |
|
| 21 | 21 | } |
| 22 | 22 | \ No newline at end of file |
@@ -15,77 +15,77 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | class UserSearchHelper extends SearchHelperBase |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * UserSearchHelper constructor. |
|
| 20 | - * |
|
| 21 | - * @param PdoDatabase $database |
|
| 22 | - */ |
|
| 23 | - public function __construct(PdoDatabase $database) |
|
| 24 | - { |
|
| 25 | - parent::__construct($database, 'user', User::class); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Initiates a search for requests |
|
| 30 | - * |
|
| 31 | - * @param PdoDatabase $database |
|
| 32 | - * |
|
| 33 | - * @return UserSearchHelper |
|
| 34 | - */ |
|
| 35 | - public static function get(PdoDatabase $database) |
|
| 36 | - { |
|
| 37 | - $helper = new UserSearchHelper($database); |
|
| 38 | - |
|
| 39 | - return $helper; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param string $status |
|
| 44 | - * |
|
| 45 | - * @return $this |
|
| 46 | - */ |
|
| 47 | - public function byStatus($status) |
|
| 48 | - { |
|
| 49 | - $this->whereClause .= ' AND status = ?'; |
|
| 50 | - $this->parameterList[] = $status; |
|
| 51 | - |
|
| 52 | - return $this; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function statusIn($statuses) { |
|
| 56 | - $this->inClause('status', $statuses); |
|
| 57 | - |
|
| 58 | - return $this; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param string $role |
|
| 63 | - * |
|
| 64 | - * @return $this |
|
| 65 | - */ |
|
| 66 | - public function byRole($role) |
|
| 67 | - { |
|
| 68 | - $this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user'; |
|
| 69 | - $this->whereClause .= ' AND r.role = ?'; |
|
| 70 | - $this->parameterList[] = $role; |
|
| 71 | - |
|
| 72 | - return $this; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param DateTime $instant |
|
| 77 | - * |
|
| 78 | - * @return $this |
|
| 79 | - */ |
|
| 80 | - public function lastActiveBefore(DateTime $instant){ |
|
| 81 | - $this->whereClause .= ' AND origin.lastactive < ?'; |
|
| 82 | - $this->parameterList[] = $instant->format("Y-m-d H:i:s"); |
|
| 83 | - |
|
| 84 | - return $this; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function getRoleMap(&$roleMap){ |
|
| 88 | - $query = <<<SQL |
|
| 18 | + /** |
|
| 19 | + * UserSearchHelper constructor. |
|
| 20 | + * |
|
| 21 | + * @param PdoDatabase $database |
|
| 22 | + */ |
|
| 23 | + public function __construct(PdoDatabase $database) |
|
| 24 | + { |
|
| 25 | + parent::__construct($database, 'user', User::class); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Initiates a search for requests |
|
| 30 | + * |
|
| 31 | + * @param PdoDatabase $database |
|
| 32 | + * |
|
| 33 | + * @return UserSearchHelper |
|
| 34 | + */ |
|
| 35 | + public static function get(PdoDatabase $database) |
|
| 36 | + { |
|
| 37 | + $helper = new UserSearchHelper($database); |
|
| 38 | + |
|
| 39 | + return $helper; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param string $status |
|
| 44 | + * |
|
| 45 | + * @return $this |
|
| 46 | + */ |
|
| 47 | + public function byStatus($status) |
|
| 48 | + { |
|
| 49 | + $this->whereClause .= ' AND status = ?'; |
|
| 50 | + $this->parameterList[] = $status; |
|
| 51 | + |
|
| 52 | + return $this; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function statusIn($statuses) { |
|
| 56 | + $this->inClause('status', $statuses); |
|
| 57 | + |
|
| 58 | + return $this; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param string $role |
|
| 63 | + * |
|
| 64 | + * @return $this |
|
| 65 | + */ |
|
| 66 | + public function byRole($role) |
|
| 67 | + { |
|
| 68 | + $this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user'; |
|
| 69 | + $this->whereClause .= ' AND r.role = ?'; |
|
| 70 | + $this->parameterList[] = $role; |
|
| 71 | + |
|
| 72 | + return $this; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param DateTime $instant |
|
| 77 | + * |
|
| 78 | + * @return $this |
|
| 79 | + */ |
|
| 80 | + public function lastActiveBefore(DateTime $instant){ |
|
| 81 | + $this->whereClause .= ' AND origin.lastactive < ?'; |
|
| 82 | + $this->parameterList[] = $instant->format("Y-m-d H:i:s"); |
|
| 83 | + |
|
| 84 | + return $this; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function getRoleMap(&$roleMap){ |
|
| 88 | + $query = <<<SQL |
|
| 89 | 89 | SELECT /* UserSearchHelper/roleMap */ |
| 90 | 90 | r.user user |
| 91 | 91 | , group_concat(r.role SEPARATOR ', ') roles |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | GROUP BY r.user |
| 95 | 95 | SQL; |
| 96 | 96 | |
| 97 | - $statement = $this->database->prepare($query); |
|
| 98 | - $statement->execute($this->parameterList); |
|
| 97 | + $statement = $this->database->prepare($query); |
|
| 98 | + $statement->execute($this->parameterList); |
|
| 99 | 99 | |
| 100 | - $roleMap = array(); |
|
| 101 | - foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 102 | - $roleMap[$row['user']] = $row['roles']; |
|
| 103 | - } |
|
| 100 | + $roleMap = array(); |
|
| 101 | + foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 102 | + $roleMap[$row['user']] = $row['roles']; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return $this; |
|
| 106 | - } |
|
| 105 | + return $this; |
|
| 106 | + } |
|
| 107 | 107 | } |
@@ -77,14 +77,14 @@ |
||
| 77 | 77 | * |
| 78 | 78 | * @return $this |
| 79 | 79 | */ |
| 80 | - public function lastActiveBefore(DateTime $instant){ |
|
| 80 | + public function lastActiveBefore(DateTime $instant) { |
|
| 81 | 81 | $this->whereClause .= ' AND origin.lastactive < ?'; |
| 82 | 82 | $this->parameterList[] = $instant->format("Y-m-d H:i:s"); |
| 83 | 83 | |
| 84 | 84 | return $this; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function getRoleMap(&$roleMap){ |
|
| 87 | + public function getRoleMap(&$roleMap) { |
|
| 88 | 88 | $query = <<<SQL |
| 89 | 89 | SELECT /* UserSearchHelper/roleMap */ |
| 90 | 90 | r.user user |
@@ -52,7 +52,8 @@ discard block |
||
| 52 | 52 | return $this; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public function statusIn($statuses) { |
|
| 55 | + public function statusIn($statuses) |
|
| 56 | + { |
|
| 56 | 57 | $this->inClause('status', $statuses); |
| 57 | 58 | |
| 58 | 59 | return $this; |
@@ -77,14 +78,16 @@ discard block |
||
| 77 | 78 | * |
| 78 | 79 | * @return $this |
| 79 | 80 | */ |
| 80 | - public function lastActiveBefore(DateTime $instant){ |
|
| 81 | + public function lastActiveBefore(DateTime $instant) |
|
| 82 | + { |
|
| 81 | 83 | $this->whereClause .= ' AND origin.lastactive < ?'; |
| 82 | 84 | $this->parameterList[] = $instant->format("Y-m-d H:i:s"); |
| 83 | 85 | |
| 84 | 86 | return $this; |
| 85 | 87 | } |
| 86 | 88 | |
| 87 | - public function getRoleMap(&$roleMap){ |
|
| 89 | + public function getRoleMap(&$roleMap) |
|
| 90 | + { |
|
| 88 | 91 | $query = <<<SQL |
| 89 | 92 | SELECT /* UserSearchHelper/roleMap */ |
| 90 | 93 | r.user user |
@@ -15,200 +15,200 @@ |
||
| 15 | 15 | |
| 16 | 16 | abstract class SearchHelperBase |
| 17 | 17 | { |
| 18 | - /** @var PdoDatabase */ |
|
| 19 | - protected $database; |
|
| 20 | - /** @var array */ |
|
| 21 | - protected $parameterList = array(); |
|
| 22 | - /** @var null|int */ |
|
| 23 | - private $limit = null; |
|
| 24 | - /** @var null|int */ |
|
| 25 | - private $offset = null; |
|
| 26 | - private $orderBy = null; |
|
| 27 | - /** |
|
| 28 | - * @var string The where clause. |
|
| 29 | - * |
|
| 30 | - * (the 1=1 condition will be optimised out of the query by the query planner, and simplifies our code here). Note |
|
| 31 | - * that we use positional parameters instead of named parameters because we don't know many times different options |
|
| 32 | - * will be called (looking at excluding() here, but there's the option for others). |
|
| 33 | - */ |
|
| 34 | - protected $whereClause = ' WHERE 1 = 1'; |
|
| 35 | - /** @var string */ |
|
| 36 | - protected $table; |
|
| 37 | - protected $joinClause = ''; |
|
| 38 | - private $targetClass; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * SearchHelperBase constructor. |
|
| 42 | - * |
|
| 43 | - * @param PdoDatabase $database |
|
| 44 | - * @param string $table |
|
| 45 | - * @param $targetClass |
|
| 46 | - * @param null|string $order Order by clause, excluding ORDER BY. |
|
| 47 | - */ |
|
| 48 | - protected function __construct(PdoDatabase $database, $table, $targetClass, $order = null) |
|
| 49 | - { |
|
| 50 | - $this->database = $database; |
|
| 51 | - $this->table = $table; |
|
| 52 | - $this->orderBy = $order; |
|
| 53 | - $this->targetClass = $targetClass; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Finalises the database query, and executes it, returning a set of objects. |
|
| 58 | - * |
|
| 59 | - * @return DataObject[] |
|
| 60 | - */ |
|
| 61 | - public function fetch() |
|
| 62 | - { |
|
| 63 | - $statement = $this->getData(); |
|
| 64 | - |
|
| 65 | - /** @var DataObject[] $returnedObjects */ |
|
| 66 | - $returnedObjects = $statement->fetchAll(PDO::FETCH_CLASS, $this->targetClass); |
|
| 67 | - foreach ($returnedObjects as $req) { |
|
| 68 | - $req->setDatabase($this->database); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - return $returnedObjects; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Finalises the database query, and executes it, returning only the requested column. |
|
| 76 | - * |
|
| 77 | - * @param string $column The required column |
|
| 78 | - * @return array |
|
| 79 | - */ |
|
| 80 | - public function fetchColumn($column){ |
|
| 81 | - $statement = $this->getData(array($column)); |
|
| 82 | - |
|
| 83 | - return $statement->fetchAll(PDO::FETCH_COLUMN); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - public function fetchMap($column){ |
|
| 87 | - $statement = $this->getData(array('id', $column)); |
|
| 88 | - |
|
| 89 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 90 | - $map = array(); |
|
| 91 | - |
|
| 92 | - foreach ($data as $row) { |
|
| 93 | - $map[$row['id']] = $row[$column]; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return $map; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param int $count Returns the record count of the result set |
|
| 101 | - * |
|
| 102 | - * @return $this |
|
| 103 | - */ |
|
| 104 | - public function getRecordCount(&$count) |
|
| 105 | - { |
|
| 106 | - $query = 'SELECT /* SearchHelper */ COUNT(*) FROM ' . $this->table . ' origin '; |
|
| 107 | - $query .= $this->joinClause . $this->whereClause; |
|
| 108 | - |
|
| 109 | - $statement = $this->database->prepare($query); |
|
| 110 | - $statement->execute($this->parameterList); |
|
| 111 | - |
|
| 112 | - $count = $statement->fetchColumn(0); |
|
| 113 | - $statement->closeCursor(); |
|
| 114 | - |
|
| 115 | - return $this; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Limits the results |
|
| 120 | - * |
|
| 121 | - * @param integer $limit |
|
| 122 | - * @param integer|null $offset |
|
| 123 | - * |
|
| 124 | - * @return $this |
|
| 125 | - * |
|
| 126 | - */ |
|
| 127 | - public function limit($limit, $offset = null) |
|
| 128 | - { |
|
| 129 | - $this->limit = $limit; |
|
| 130 | - $this->offset = $offset; |
|
| 131 | - |
|
| 132 | - return $this; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - private function applyLimit() |
|
| 136 | - { |
|
| 137 | - $clause = ''; |
|
| 138 | - if ($this->limit !== null) { |
|
| 139 | - $clause = ' LIMIT ?'; |
|
| 140 | - $this->parameterList[] = $this->limit; |
|
| 141 | - |
|
| 142 | - if ($this->offset !== null) { |
|
| 143 | - $clause .= ' OFFSET ?'; |
|
| 144 | - $this->parameterList[] = $this->offset; |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return $clause; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - private function applyOrder() |
|
| 152 | - { |
|
| 153 | - if ($this->orderBy !== null) { |
|
| 154 | - return ' ORDER BY ' . $this->orderBy; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - return ''; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param array $columns |
|
| 162 | - * |
|
| 163 | - * @return PDOStatement |
|
| 164 | - */ |
|
| 165 | - private function getData($columns = array('*')) |
|
| 166 | - { |
|
| 167 | - $query = $this->buildQuery($columns); |
|
| 168 | - $query .= $this->applyOrder(); |
|
| 169 | - $query .= $this->applyLimit(); |
|
| 170 | - |
|
| 171 | - $statement = $this->database->prepare($query); |
|
| 172 | - $statement->execute($this->parameterList); |
|
| 173 | - |
|
| 174 | - return $statement; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param array $columns |
|
| 179 | - * |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - protected function buildQuery($columns) |
|
| 183 | - { |
|
| 184 | - $colData = array(); |
|
| 185 | - foreach ($columns as $c) { |
|
| 186 | - $colData[] = 'origin.' . $c; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $query = 'SELECT /* SearchHelper */ ' . implode(', ', $colData) . ' FROM ' . $this->table . ' origin '; |
|
| 190 | - $query .= $this->joinClause . $this->whereClause; |
|
| 191 | - |
|
| 192 | - return $query; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - public function inIds($idList) { |
|
| 196 | - $this->inClause('id', $idList); |
|
| 197 | - return $this; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - protected function inClause($column, $values) { |
|
| 201 | - if (count($values) === 0) { |
|
| 202 | - return; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // Urgh. OK. You can't use IN() with parameters directly, so let's munge something together. |
|
| 206 | - $valueCount = count($values); |
|
| 207 | - |
|
| 208 | - // Firstly, let's create a string of question marks, which will do as positional parameters. |
|
| 209 | - $inSection = str_repeat('?,', $valueCount - 1) . '?'; |
|
| 210 | - |
|
| 211 | - $this->whereClause .= " AND {$column} IN ({$inSection})"; |
|
| 212 | - $this->parameterList = array_merge($this->parameterList, $values); |
|
| 213 | - } |
|
| 18 | + /** @var PdoDatabase */ |
|
| 19 | + protected $database; |
|
| 20 | + /** @var array */ |
|
| 21 | + protected $parameterList = array(); |
|
| 22 | + /** @var null|int */ |
|
| 23 | + private $limit = null; |
|
| 24 | + /** @var null|int */ |
|
| 25 | + private $offset = null; |
|
| 26 | + private $orderBy = null; |
|
| 27 | + /** |
|
| 28 | + * @var string The where clause. |
|
| 29 | + * |
|
| 30 | + * (the 1=1 condition will be optimised out of the query by the query planner, and simplifies our code here). Note |
|
| 31 | + * that we use positional parameters instead of named parameters because we don't know many times different options |
|
| 32 | + * will be called (looking at excluding() here, but there's the option for others). |
|
| 33 | + */ |
|
| 34 | + protected $whereClause = ' WHERE 1 = 1'; |
|
| 35 | + /** @var string */ |
|
| 36 | + protected $table; |
|
| 37 | + protected $joinClause = ''; |
|
| 38 | + private $targetClass; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * SearchHelperBase constructor. |
|
| 42 | + * |
|
| 43 | + * @param PdoDatabase $database |
|
| 44 | + * @param string $table |
|
| 45 | + * @param $targetClass |
|
| 46 | + * @param null|string $order Order by clause, excluding ORDER BY. |
|
| 47 | + */ |
|
| 48 | + protected function __construct(PdoDatabase $database, $table, $targetClass, $order = null) |
|
| 49 | + { |
|
| 50 | + $this->database = $database; |
|
| 51 | + $this->table = $table; |
|
| 52 | + $this->orderBy = $order; |
|
| 53 | + $this->targetClass = $targetClass; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Finalises the database query, and executes it, returning a set of objects. |
|
| 58 | + * |
|
| 59 | + * @return DataObject[] |
|
| 60 | + */ |
|
| 61 | + public function fetch() |
|
| 62 | + { |
|
| 63 | + $statement = $this->getData(); |
|
| 64 | + |
|
| 65 | + /** @var DataObject[] $returnedObjects */ |
|
| 66 | + $returnedObjects = $statement->fetchAll(PDO::FETCH_CLASS, $this->targetClass); |
|
| 67 | + foreach ($returnedObjects as $req) { |
|
| 68 | + $req->setDatabase($this->database); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + return $returnedObjects; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Finalises the database query, and executes it, returning only the requested column. |
|
| 76 | + * |
|
| 77 | + * @param string $column The required column |
|
| 78 | + * @return array |
|
| 79 | + */ |
|
| 80 | + public function fetchColumn($column){ |
|
| 81 | + $statement = $this->getData(array($column)); |
|
| 82 | + |
|
| 83 | + return $statement->fetchAll(PDO::FETCH_COLUMN); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + public function fetchMap($column){ |
|
| 87 | + $statement = $this->getData(array('id', $column)); |
|
| 88 | + |
|
| 89 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 90 | + $map = array(); |
|
| 91 | + |
|
| 92 | + foreach ($data as $row) { |
|
| 93 | + $map[$row['id']] = $row[$column]; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return $map; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param int $count Returns the record count of the result set |
|
| 101 | + * |
|
| 102 | + * @return $this |
|
| 103 | + */ |
|
| 104 | + public function getRecordCount(&$count) |
|
| 105 | + { |
|
| 106 | + $query = 'SELECT /* SearchHelper */ COUNT(*) FROM ' . $this->table . ' origin '; |
|
| 107 | + $query .= $this->joinClause . $this->whereClause; |
|
| 108 | + |
|
| 109 | + $statement = $this->database->prepare($query); |
|
| 110 | + $statement->execute($this->parameterList); |
|
| 111 | + |
|
| 112 | + $count = $statement->fetchColumn(0); |
|
| 113 | + $statement->closeCursor(); |
|
| 114 | + |
|
| 115 | + return $this; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Limits the results |
|
| 120 | + * |
|
| 121 | + * @param integer $limit |
|
| 122 | + * @param integer|null $offset |
|
| 123 | + * |
|
| 124 | + * @return $this |
|
| 125 | + * |
|
| 126 | + */ |
|
| 127 | + public function limit($limit, $offset = null) |
|
| 128 | + { |
|
| 129 | + $this->limit = $limit; |
|
| 130 | + $this->offset = $offset; |
|
| 131 | + |
|
| 132 | + return $this; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + private function applyLimit() |
|
| 136 | + { |
|
| 137 | + $clause = ''; |
|
| 138 | + if ($this->limit !== null) { |
|
| 139 | + $clause = ' LIMIT ?'; |
|
| 140 | + $this->parameterList[] = $this->limit; |
|
| 141 | + |
|
| 142 | + if ($this->offset !== null) { |
|
| 143 | + $clause .= ' OFFSET ?'; |
|
| 144 | + $this->parameterList[] = $this->offset; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return $clause; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + private function applyOrder() |
|
| 152 | + { |
|
| 153 | + if ($this->orderBy !== null) { |
|
| 154 | + return ' ORDER BY ' . $this->orderBy; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + return ''; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param array $columns |
|
| 162 | + * |
|
| 163 | + * @return PDOStatement |
|
| 164 | + */ |
|
| 165 | + private function getData($columns = array('*')) |
|
| 166 | + { |
|
| 167 | + $query = $this->buildQuery($columns); |
|
| 168 | + $query .= $this->applyOrder(); |
|
| 169 | + $query .= $this->applyLimit(); |
|
| 170 | + |
|
| 171 | + $statement = $this->database->prepare($query); |
|
| 172 | + $statement->execute($this->parameterList); |
|
| 173 | + |
|
| 174 | + return $statement; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param array $columns |
|
| 179 | + * |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + protected function buildQuery($columns) |
|
| 183 | + { |
|
| 184 | + $colData = array(); |
|
| 185 | + foreach ($columns as $c) { |
|
| 186 | + $colData[] = 'origin.' . $c; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $query = 'SELECT /* SearchHelper */ ' . implode(', ', $colData) . ' FROM ' . $this->table . ' origin '; |
|
| 190 | + $query .= $this->joinClause . $this->whereClause; |
|
| 191 | + |
|
| 192 | + return $query; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + public function inIds($idList) { |
|
| 196 | + $this->inClause('id', $idList); |
|
| 197 | + return $this; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + protected function inClause($column, $values) { |
|
| 201 | + if (count($values) === 0) { |
|
| 202 | + return; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // Urgh. OK. You can't use IN() with parameters directly, so let's munge something together. |
|
| 206 | + $valueCount = count($values); |
|
| 207 | + |
|
| 208 | + // Firstly, let's create a string of question marks, which will do as positional parameters. |
|
| 209 | + $inSection = str_repeat('?,', $valueCount - 1) . '?'; |
|
| 210 | + |
|
| 211 | + $this->whereClause .= " AND {$column} IN ({$inSection})"; |
|
| 212 | + $this->parameterList = array_merge($this->parameterList, $values); |
|
| 213 | + } |
|
| 214 | 214 | } |
@@ -77,13 +77,13 @@ |
||
| 77 | 77 | * @param string $column The required column |
| 78 | 78 | * @return array |
| 79 | 79 | */ |
| 80 | - public function fetchColumn($column){ |
|
| 80 | + public function fetchColumn($column) { |
|
| 81 | 81 | $statement = $this->getData(array($column)); |
| 82 | 82 | |
| 83 | 83 | return $statement->fetchAll(PDO::FETCH_COLUMN); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - public function fetchMap($column){ |
|
| 86 | + public function fetchMap($column) { |
|
| 87 | 87 | $statement = $this->getData(array('id', $column)); |
| 88 | 88 | |
| 89 | 89 | $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
@@ -77,13 +77,15 @@ discard block |
||
| 77 | 77 | * @param string $column The required column |
| 78 | 78 | * @return array |
| 79 | 79 | */ |
| 80 | - public function fetchColumn($column){ |
|
| 80 | + public function fetchColumn($column) |
|
| 81 | + { |
|
| 81 | 82 | $statement = $this->getData(array($column)); |
| 82 | 83 | |
| 83 | 84 | return $statement->fetchAll(PDO::FETCH_COLUMN); |
| 84 | 85 | } |
| 85 | 86 | |
| 86 | - public function fetchMap($column){ |
|
| 87 | + public function fetchMap($column) |
|
| 88 | + { |
|
| 87 | 89 | $statement = $this->getData(array('id', $column)); |
| 88 | 90 | |
| 89 | 91 | $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
@@ -192,12 +194,14 @@ discard block |
||
| 192 | 194 | return $query; |
| 193 | 195 | } |
| 194 | 196 | |
| 195 | - public function inIds($idList) { |
|
| 197 | + public function inIds($idList) |
|
| 198 | + { |
|
| 196 | 199 | $this->inClause('id', $idList); |
| 197 | 200 | return $this; |
| 198 | 201 | } |
| 199 | 202 | |
| 200 | - protected function inClause($column, $values) { |
|
| 203 | + protected function inClause($column, $values) |
|
| 204 | + { |
|
| 201 | 205 | if (count($values) === 0) { |
| 202 | 206 | return; |
| 203 | 207 | } |
@@ -13,87 +13,87 @@ |
||
| 13 | 13 | |
| 14 | 14 | class LogSearchHelper extends SearchHelperBase |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * LogSearchHelper constructor. |
|
| 18 | - * |
|
| 19 | - * @param PdoDatabase $database |
|
| 20 | - */ |
|
| 21 | - protected function __construct(PdoDatabase $database) |
|
| 22 | - { |
|
| 23 | - parent::__construct($database, 'log', Log::class, 'timestamp DESC'); |
|
| 24 | - } |
|
| 16 | + /** |
|
| 17 | + * LogSearchHelper constructor. |
|
| 18 | + * |
|
| 19 | + * @param PdoDatabase $database |
|
| 20 | + */ |
|
| 21 | + protected function __construct(PdoDatabase $database) |
|
| 22 | + { |
|
| 23 | + parent::__construct($database, 'log', Log::class, 'timestamp DESC'); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Initiates a search for requests |
|
| 28 | - * |
|
| 29 | - * @param PdoDatabase $database |
|
| 30 | - * |
|
| 31 | - * @return LogSearchHelper |
|
| 32 | - */ |
|
| 33 | - public static function get(PdoDatabase $database) |
|
| 34 | - { |
|
| 35 | - $helper = new LogSearchHelper($database); |
|
| 26 | + /** |
|
| 27 | + * Initiates a search for requests |
|
| 28 | + * |
|
| 29 | + * @param PdoDatabase $database |
|
| 30 | + * |
|
| 31 | + * @return LogSearchHelper |
|
| 32 | + */ |
|
| 33 | + public static function get(PdoDatabase $database) |
|
| 34 | + { |
|
| 35 | + $helper = new LogSearchHelper($database); |
|
| 36 | 36 | |
| 37 | - return $helper; |
|
| 38 | - } |
|
| 37 | + return $helper; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Filters the results by user |
|
| 42 | - * |
|
| 43 | - * @param int $userId |
|
| 44 | - * |
|
| 45 | - * @return $this |
|
| 46 | - */ |
|
| 47 | - public function byUser($userId) |
|
| 48 | - { |
|
| 49 | - $this->whereClause .= ' AND user = ?'; |
|
| 50 | - $this->parameterList[] = $userId; |
|
| 40 | + /** |
|
| 41 | + * Filters the results by user |
|
| 42 | + * |
|
| 43 | + * @param int $userId |
|
| 44 | + * |
|
| 45 | + * @return $this |
|
| 46 | + */ |
|
| 47 | + public function byUser($userId) |
|
| 48 | + { |
|
| 49 | + $this->whereClause .= ' AND user = ?'; |
|
| 50 | + $this->parameterList[] = $userId; |
|
| 51 | 51 | |
| 52 | - return $this; |
|
| 53 | - } |
|
| 52 | + return $this; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Filters the results by log action |
|
| 57 | - * |
|
| 58 | - * @param string $action |
|
| 59 | - * |
|
| 60 | - * @return $this |
|
| 61 | - */ |
|
| 62 | - public function byAction($action) |
|
| 63 | - { |
|
| 64 | - $this->whereClause .= ' AND action = ?'; |
|
| 65 | - $this->parameterList[] = $action; |
|
| 55 | + /** |
|
| 56 | + * Filters the results by log action |
|
| 57 | + * |
|
| 58 | + * @param string $action |
|
| 59 | + * |
|
| 60 | + * @return $this |
|
| 61 | + */ |
|
| 62 | + public function byAction($action) |
|
| 63 | + { |
|
| 64 | + $this->whereClause .= ' AND action = ?'; |
|
| 65 | + $this->parameterList[] = $action; |
|
| 66 | 66 | |
| 67 | - return $this; |
|
| 68 | - } |
|
| 67 | + return $this; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Filters the results by object type |
|
| 72 | - * |
|
| 73 | - * @param string $objectType |
|
| 74 | - * |
|
| 75 | - * @return $this |
|
| 76 | - */ |
|
| 77 | - public function byObjectType($objectType) |
|
| 78 | - { |
|
| 79 | - $this->whereClause .= ' AND objecttype = ?'; |
|
| 80 | - $this->parameterList[] = $objectType; |
|
| 70 | + /** |
|
| 71 | + * Filters the results by object type |
|
| 72 | + * |
|
| 73 | + * @param string $objectType |
|
| 74 | + * |
|
| 75 | + * @return $this |
|
| 76 | + */ |
|
| 77 | + public function byObjectType($objectType) |
|
| 78 | + { |
|
| 79 | + $this->whereClause .= ' AND objecttype = ?'; |
|
| 80 | + $this->parameterList[] = $objectType; |
|
| 81 | 81 | |
| 82 | - return $this; |
|
| 83 | - } |
|
| 82 | + return $this; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Filters the results by object type |
|
| 87 | - * |
|
| 88 | - * @param integer $objectId |
|
| 89 | - * |
|
| 90 | - * @return $this |
|
| 91 | - */ |
|
| 92 | - public function byObjectId($objectId) |
|
| 93 | - { |
|
| 94 | - $this->whereClause .= ' AND objectid = ?'; |
|
| 95 | - $this->parameterList[] = $objectId; |
|
| 85 | + /** |
|
| 86 | + * Filters the results by object type |
|
| 87 | + * |
|
| 88 | + * @param integer $objectId |
|
| 89 | + * |
|
| 90 | + * @return $this |
|
| 91 | + */ |
|
| 92 | + public function byObjectId($objectId) |
|
| 93 | + { |
|
| 94 | + $this->whereClause .= ' AND objectid = ?'; |
|
| 95 | + $this->parameterList[] = $objectId; |
|
| 96 | 96 | |
| 97 | - return $this; |
|
| 98 | - } |
|
| 97 | + return $this; |
|
| 98 | + } |
|
| 99 | 99 | } |
| 100 | 100 | \ No newline at end of file |