Complex classes like UserCoreModel often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UserCoreModel, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | class UserCoreModel extends Model |
||
| 27 | { |
||
| 28 | const CACHE_GROUP = 'db/sys/mod/user'; |
||
| 29 | const CACHE_TIME = 604800; |
||
| 30 | |||
| 31 | const OFFLINE_STATUS = 0; |
||
| 32 | const ONLINE_STATUS = 1; |
||
| 33 | const BUSY_STATUS = 2; |
||
| 34 | const AWAY_STATUS = 3; |
||
| 35 | |||
| 36 | /** @var string */ |
||
| 37 | protected $sCurrentDate; |
||
| 38 | |||
| 39 | /** @var string */ |
||
| 40 | protected $iProfileId; |
||
| 41 | |||
| 42 | public function __construct() |
||
| 49 | |||
| 50 | public static function checkGroup() |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Login method for Members and Affiliate, but not for Admins since it has another method PH7\AdminModel::adminLogin() even more secure. |
||
| 70 | * |
||
| 71 | * @param string $sEmail Not case sensitive since on lot of mobile devices (such as iPhone), the first letter is uppercase. |
||
| 72 | * @param string $sPassword |
||
| 73 | * @param string $sTable Default DbTableName::MEMBER |
||
| 74 | * |
||
| 75 | * @return bool|string (boolean "true" or string "message") |
||
| 76 | */ |
||
| 77 | public function login($sEmail, $sPassword, $sTable = DbTableName::MEMBER) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Set Log Session. |
||
| 102 | * |
||
| 103 | * @param string $sEmail |
||
| 104 | * @param string $sUsername |
||
| 105 | * @param string $sFirstName |
||
| 106 | * @param string $sTable |
||
| 107 | * @param string $sTable Default DbTableName::MEMBER |
||
| 108 | * |
||
| 109 | * @return void |
||
| 110 | */ |
||
| 111 | public function sessionLog($sEmail, $sUsername, $sFirstName, $sTable = DbTableName::MEMBER) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Read Profile Data. |
||
| 127 | * |
||
| 128 | * @param int $iProfileId The user ID |
||
| 129 | * @param string $sTable Default DbTableName::MEMBER |
||
| 130 | * |
||
| 131 | * @return stdClass|bool The data of a member if exists, FALSE otherwise. |
||
| 132 | */ |
||
| 133 | public function readProfile($iProfileId, $sTable = DbTableName::MEMBER) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Get the total number of members. |
||
| 153 | * |
||
| 154 | * @param string $sTable Default DbTableName::MEMBER |
||
| 155 | * @param int $iDay Default '0' |
||
| 156 | * @param string $sGender Values available 'all', 'male', 'female'. 'couple' is only available to Members. Default 'all' |
||
| 157 | * |
||
| 158 | * @return int Total Users |
||
| 159 | */ |
||
| 160 | public function total($sTable = DbTableName::MEMBER, $iDay = 0, $sGender = 'all') |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Update profile data. |
||
| 189 | * |
||
| 190 | * @param string $sSection |
||
| 191 | * @param string $sValue |
||
| 192 | * @param int $iProfileId Profile ID |
||
| 193 | * @param string $sTable Default DbTableName::MEMBER |
||
| 194 | * |
||
| 195 | * @return void |
||
| 196 | */ |
||
| 197 | public function updateProfile($sSection, $sValue, $iProfileId, $sTable = DbTableName::MEMBER) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Update Privacy setting data. |
||
| 206 | * |
||
| 207 | * @param string $sSection |
||
| 208 | * @param string $sValue |
||
| 209 | * @param int $iProfileId Profile ID |
||
| 210 | * |
||
| 211 | * @return void |
||
| 212 | */ |
||
| 213 | public function updatePrivacySetting($sSection, $sValue, $iProfileId) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Change password of a member. |
||
| 220 | * |
||
| 221 | * @param string $sEmail |
||
| 222 | * @param string $sNewPassword |
||
| 223 | * @param string $sTable |
||
| 224 | * |
||
| 225 | * @return bool |
||
| 226 | */ |
||
| 227 | public function changePassword($sEmail, $sNewPassword, $sTable) |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Set a new hash validation. |
||
| 240 | * |
||
| 241 | * @param int $iProfileId |
||
| 242 | * @param string $sHash |
||
| 243 | * @param string $sTable |
||
| 244 | * |
||
| 245 | * @return bool |
||
| 246 | */ |
||
| 247 | public function setNewHashValidation($iProfileId, $sHash, $sTable) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Check the hash validation. |
||
| 260 | * |
||
| 261 | * @param string $sEmail |
||
| 262 | * @param string $sHash |
||
| 263 | * @param string $sTable |
||
| 264 | * |
||
| 265 | * @return bool |
||
| 266 | */ |
||
| 267 | public function checkHashValidation($sEmail, $sHash, $sTable) |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Search users. |
||
| 281 | * |
||
| 282 | * @param array $aParams |
||
| 283 | * @param bool $bCount |
||
| 284 | * @param int $iOffset |
||
| 285 | * @param int $iLimit |
||
| 286 | * |
||
| 287 | * @return array|int Object for the users list returned or integer for the total number users returned. |
||
| 288 | */ |
||
| 289 | public function search(array $aParams, $bCount, $iOffset, $iLimit) |
||
| 290 | { |
||
| 291 | $bCount = (bool)$bCount; |
||
| 292 | $iOffset = (int)$iOffset; |
||
| 293 | $iLimit = (int)$iLimit; |
||
| 294 | |||
| 295 | $bIsMail = !empty($aParams[SearchQueryCore::EMAIL]) && Str::noSpaces($aParams[SearchQueryCore::EMAIL]); |
||
| 296 | $bIsFirstName = !$bIsMail && !empty($aParams[SearchQueryCore::FIRST_NAME]) && Str::noSpaces($aParams[SearchQueryCore::FIRST_NAME]); |
||
| 297 | $bIsMiddleName = !$bIsMail && !empty($aParams[SearchQueryCore::MIDDLE_NAME]) && Str::noSpaces($aParams[SearchQueryCore::MIDDLE_NAME]); |
||
| 298 | $bIsLastName = !$bIsMail && !empty($aParams[SearchQueryCore::LAST_NAME]) && Str::noSpaces($aParams[SearchQueryCore::LAST_NAME]); |
||
| 299 | $bIsSingleAge = !$bIsMail && !empty($aParams[SearchQueryCore::AGE]); |
||
| 300 | $bIsAge = !$bIsMail && empty($aParams[SearchQueryCore::AGE]) && !empty($aParams[SearchQueryCore::MIN_AGE]) && !empty($aParams[SearchQueryCore::MAX_AGE]); |
||
| 301 | $bIsHeight = !$bIsMail && !empty($aParams[SearchQueryCore::HEIGHT]); |
||
| 302 | $bIsWeight = !$bIsMail && !empty($aParams[SearchQueryCore::WEIGHT]); |
||
| 303 | $bIsCountry = !$bIsMail && !empty($aParams[SearchQueryCore::COUNTRY]) && Str::noSpaces($aParams[SearchQueryCore::COUNTRY]); |
||
| 304 | $bIsCity = !$bIsMail && !empty($aParams[SearchQueryCore::CITY]) && Str::noSpaces($aParams[SearchQueryCore::CITY]); |
||
| 305 | $bIsState = !$bIsMail && !empty($aParams[SearchQueryCore::STATE]) && Str::noSpaces($aParams[SearchQueryCore::STATE]); |
||
| 306 | $bIsZipCode = !$bIsMail && !empty($aParams[SearchQueryCore::ZIP_CODE]) && Str::noSpaces($aParams[SearchQueryCore::ZIP_CODE]); |
||
| 307 | $bIsSex = !$bIsMail && !empty($aParams[SearchQueryCore::SEX]) && is_array($aParams[SearchQueryCore::SEX]); |
||
| 308 | $bIsMatchSex = !$bIsMail && !empty($aParams[SearchQueryCore::MATCH_SEX]); |
||
| 309 | $bIsOnline = !$bIsMail && !empty($aParams[SearchQueryCore::ONLINE]); |
||
| 310 | $bIsAvatar = !$bIsMail && !empty($aParams[SearchQueryCore::AVATAR]); |
||
| 311 | $bHideUserLogged = !$bIsMail && !empty($this->iProfileId); |
||
| 312 | |||
| 313 | $sSqlLimit = !$bCount ? 'LIMIT :offset, :limit' : ''; |
||
| 314 | $sSqlSelect = !$bCount ? '*' : 'COUNT(m.profileId) AS totalUsers'; |
||
| 315 | $sSqlFirstName = $bIsFirstName ? ' AND firstName = :firstName' : ''; |
||
| 316 | $sSqlMiddleName = $bIsMiddleName ? ' AND middleName = :middleName' : ''; |
||
| 317 | $sSqlLastName = $bIsLastName ? ' AND lastName = :lastName' : ''; |
||
| 318 | $sSqlSingleAge = $bIsSingleAge ? ' AND birthDate LIKE :birthDate ' : ''; |
||
| 319 | $sSqlAge = $bIsAge ? ' AND birthDate BETWEEN DATE_SUB(\'' . $this->sCurrentDate . '\', INTERVAL :age2 YEAR) AND DATE_SUB(\'' . $this->sCurrentDate . '\', INTERVAL :age1 YEAR) ' : ''; |
||
| 320 | $sSqlHeight = $bIsHeight ? ' AND height = :height ' : ''; |
||
| 321 | $sSqlWeight = $bIsWeight ? ' AND weight = :weight ' : ''; |
||
| 322 | $sSqlCountry = $bIsCountry ? ' AND country = :country ' : ''; |
||
| 323 | $sSqlCity = $bIsCity ? ' AND city LIKE :city ' : ''; |
||
| 324 | $sSqlState = $bIsState ? ' AND state LIKE :state ' : ''; |
||
| 325 | $sSqlZipCode = $bIsZipCode ? ' AND zipCode LIKE :zipCode ' : ''; |
||
| 326 | $sSqlEmail = $bIsMail ? ' AND email LIKE :email ' : ''; |
||
| 327 | $sSqlOnline = $bIsOnline ? ' AND userStatus = :userStatus AND lastActivity > DATE_SUB(\'' . $this->sCurrentDate . '\', INTERVAL ' . DbConfig::getSetting('userTimeout') . ' MINUTE) ' : ''; |
||
| 328 | $sSqlAvatar = $bIsAvatar ? $this->getUserWithAvatarOnlySql() : ''; |
||
| 329 | $sSqlHideLoggedProfile = $bHideUserLogged ? ' AND (m.profileId <> :profileId)' : ''; |
||
| 330 | |||
| 331 | if (empty($aParams[SearchQueryCore::ORDER])) { |
||
| 332 | $aParams[SearchQueryCore::ORDER] = SearchCoreModel::LATEST; // Default is "ORDER BY joinDate" |
||
| 333 | } |
||
| 334 | |||
| 335 | if (empty($aParams[SearchQueryCore::SORT])) { |
||
| 336 | $aParams[SearchQueryCore::SORT] = SearchCoreModel::ASC; // Default is "ascending" |
||
| 337 | } |
||
| 338 | |||
| 339 | $sSqlOrder = SearchCoreModel::order($aParams[SearchQueryCore::ORDER], $aParams[SearchQueryCore::SORT]); |
||
| 340 | |||
| 341 | $sSqlMatchSex = $bIsMatchSex ? ' AND matchSex LIKE :matchSex ' : ''; |
||
| 342 | |||
| 343 | if ($bIsSex) { |
||
| 344 | $sGender = ''; |
||
| 345 | $aSex = $aParams[SearchQueryCore::SEX]; |
||
| 346 | foreach ($aSex as $sSex) { |
||
| 347 | if ($sSex === 'male') { |
||
| 348 | $sGender .= '\'male\','; |
||
| 349 | } |
||
| 350 | |||
| 351 | if ($sSex === 'female') { |
||
| 352 | $sGender .= '\'female\','; |
||
| 353 | } |
||
| 354 | |||
| 355 | if ($sSex === 'couple') { |
||
| 356 | $sGender .= '\'couple\','; |
||
| 357 | } |
||
| 358 | } |
||
| 359 | |||
| 360 | $sSqlSex = ' AND sex IN (' . rtrim($sGender, ',') . ') '; |
||
| 361 | } else { |
||
| 362 | $sSqlSex = ''; |
||
| 363 | } |
||
| 364 | |||
| 365 | $rStmt = Db::getInstance()->prepare( |
||
| 366 | 'SELECT ' . $sSqlSelect . ' FROM' . Db::prefix(DbTableName::MEMBER) . 'AS m LEFT JOIN' . Db::prefix(DbTableName::MEMBER_PRIVACY) . 'AS p USING(profileId) |
||
| 367 | LEFT JOIN' . Db::prefix(DbTableName::MEMBER_INFO) . 'AS i USING(profileId) WHERE username <> \'' . PH7_GHOST_USERNAME . '\' AND searchProfile = \'yes\' |
||
| 368 | AND (groupId <> 1) AND (groupId <> 9) AND (ban = 0)' . $sSqlHideLoggedProfile . $sSqlFirstName . $sSqlMiddleName . $sSqlLastName . $sSqlMatchSex . $sSqlSex . $sSqlSingleAge . $sSqlAge . $sSqlCountry . $sSqlCity . $sSqlState . |
||
| 369 | $sSqlZipCode . $sSqlHeight . $sSqlWeight . $sSqlEmail . $sSqlOnline . $sSqlAvatar . $sSqlOrder . $sSqlLimit |
||
| 370 | ); |
||
| 371 | |||
| 372 | if ($bIsMatchSex) { |
||
| 373 | $rStmt->bindValue(':matchSex', '%' . $aParams[SearchQueryCore::MATCH_SEX] . '%', \PDO::PARAM_STR); |
||
| 374 | } |
||
| 375 | if ($bIsFirstName) { |
||
| 376 | $rStmt->bindValue(':firstName', $aParams[SearchQueryCore::FIRST_NAME], \PDO::PARAM_STR); |
||
| 377 | } |
||
| 378 | if ($bIsMiddleName) { |
||
| 379 | $rStmt->bindValue(':middleName', $aParams[SearchQueryCore::MIDDLE_NAME], \PDO::PARAM_STR); |
||
| 380 | } |
||
| 381 | if ($bIsLastName) { |
||
| 382 | $rStmt->bindValue(':lastName', $aParams[SearchQueryCore::LAST_NAME], \PDO::PARAM_STR); |
||
| 383 | } |
||
| 384 | if ($bIsSingleAge) { |
||
| 385 | $rStmt->bindValue(':birthDate', '%' . $aParams[SearchQueryCore::AGE] . '%', \PDO::PARAM_STR); |
||
| 386 | } |
||
| 387 | if ($bIsAge) { |
||
| 388 | $rStmt->bindValue(':age1', $aParams[SearchQueryCore::MIN_AGE], \PDO::PARAM_INT); |
||
| 389 | } |
||
| 390 | if ($bIsAge) { |
||
| 391 | $rStmt->bindValue(':age2', $aParams[SearchQueryCore::MAX_AGE], \PDO::PARAM_INT); |
||
| 392 | } |
||
| 393 | if ($bIsHeight) { |
||
| 394 | $rStmt->bindValue(':height', $aParams[SearchQueryCore::HEIGHT], \PDO::PARAM_INT); |
||
| 395 | } |
||
| 396 | if ($bIsWeight) { |
||
| 397 | $rStmt->bindValue(':weight', $aParams[SearchQueryCore::WEIGHT], \PDO::PARAM_INT); |
||
| 398 | } |
||
| 399 | if ($bIsCountry) { |
||
| 400 | $rStmt->bindParam(':country', $aParams[SearchQueryCore::COUNTRY], \PDO::PARAM_STR, 2); |
||
| 401 | } |
||
| 402 | if ($bIsCity) { |
||
| 403 | $rStmt->bindValue(':city', '%' . str_replace('-', ' ', $aParams[SearchQueryCore::CITY]) . '%', \PDO::PARAM_STR); |
||
| 404 | } |
||
| 405 | if ($bIsState) { |
||
| 406 | $rStmt->bindValue(':state', '%' . str_replace('-', ' ', $aParams[SearchQueryCore::STATE]) . '%', \PDO::PARAM_STR); |
||
| 407 | } |
||
| 408 | if ($bIsZipCode) { |
||
| 409 | $rStmt->bindValue(':zipCode', '%' . $aParams[SearchQueryCore::ZIP_CODE] . '%', \PDO::PARAM_STR); |
||
| 410 | } |
||
| 411 | if ($bIsMail) { |
||
| 412 | $rStmt->bindValue(':email', '%' . $aParams[SearchQueryCore::EMAIL] . '%', \PDO::PARAM_STR); |
||
| 413 | } |
||
| 414 | if ($bIsOnline) { |
||
| 415 | $rStmt->bindValue(':userStatus', self::ONLINE_STATUS, \PDO::PARAM_INT); |
||
| 416 | } |
||
| 417 | if ($bHideUserLogged) { |
||
| 418 | $rStmt->bindValue(':profileId', $this->iProfileId, \PDO::PARAM_INT); |
||
| 419 | } |
||
| 420 | if (!$bCount) { |
||
| 421 | $rStmt->bindParam(':offset', $iOffset, \PDO::PARAM_INT); |
||
| 422 | $rStmt->bindParam(':limit', $iLimit, \PDO::PARAM_INT); |
||
| 423 | } |
||
| 424 | |||
| 425 | $rStmt->execute(); |
||
| 426 | |||
| 427 | if (!$bCount) { |
||
| 428 | $aRow = $rStmt->fetchAll(\PDO::FETCH_OBJ); |
||
| 429 | Db::free($rStmt); |
||
| 430 | |||
| 431 | return $aRow; |
||
| 432 | } |
||
| 433 | |||
| 434 | $oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
||
| 435 | Db::free($rStmt); |
||
| 436 | |||
| 437 | return (int)$oRow->totalUsers; |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Check online status. |
||
| 442 | * |
||
| 443 | * @param int $iProfileId |
||
| 444 | * @param int $iTime Number of minutes that a member becomes inactive (offline). Default 1 minute |
||
| 445 | * |
||
| 446 | * @return bool |
||
| 447 | */ |
||
| 448 | public function isOnline($iProfileId, $iTime = 1) |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Set the user status. |
||
| 466 | * |
||
| 467 | * @param int iProfileId |
||
| 468 | * @param int $iStatus Values: 0 = Offline, 1 = Online, 2 = Busy, 3 = Away |
||
| 469 | * |
||
| 470 | * @return void |
||
| 471 | */ |
||
| 472 | public function setUserStatus($iProfileId, $iStatus) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Get the user status. |
||
| 479 | * |
||
| 480 | * @param int $iProfileId |
||
| 481 | * |
||
| 482 | * @return int The user status. 0 = Offline, 1 = Online, 2 = Busy, 3 = Away |
||
| 483 | */ |
||
| 484 | public function getUserStatus($iProfileId) |
||
| 500 | |||
| 501 | /** |
||
| 502 | * Update the notifications. |
||
| 503 | * |
||
| 504 | * @param string $sSection |
||
| 505 | * @param string $sValue |
||
| 506 | * @param int $iProfileId Profile ID |
||
| 507 | * |
||
| 508 | * @return void |
||
| 509 | */ |
||
| 510 | public function setNotification($sSection, $sValue, $iProfileId) |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Get the user notifications. |
||
| 517 | * |
||
| 518 | * @param int $iProfileId |
||
| 519 | * |
||
| 520 | * @return stdClass |
||
| 521 | */ |
||
| 522 | public function getNotification($iProfileId) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Check notifications. |
||
| 540 | * |
||
| 541 | * @param int $iProfileId |
||
| 542 | * @param string $sNotifName Notification name. |
||
| 543 | * |
||
| 544 | * @return bool Returns TRUE if the notification is wanted, FALSE otherwise. |
||
| 545 | */ |
||
| 546 | public function isNotification($iProfileId, $sNotifName) |
||
| 564 | |||
| 565 | /** |
||
| 566 | * Set the last activity of a user. |
||
| 567 | * |
||
| 568 | * @param int $iProfileId |
||
| 569 | * @param string $sTable Default DbTableName::MEMBER |
||
| 570 | * |
||
| 571 | * @return void |
||
| 572 | */ |
||
| 573 | public function setLastActivity($iProfileId, $sTable = DbTableName::MEMBER) |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Set the last edit account of a user. |
||
| 582 | * |
||
| 583 | * @param int $iProfileId |
||
| 584 | * @param string $sTable Default DbTableName::MEMBER |
||
| 585 | * |
||
| 586 | * @return void |
||
| 587 | */ |
||
| 588 | public function setLastEdit($iProfileId, $sTable = DbTableName::MEMBER) |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Approve a profile. |
||
| 597 | * |
||
| 598 | * @param int $iProfileId |
||
| 599 | * @param int $iStatus 1 = apprved | 0 = not approved |
||
| 600 | * @param string $sTable Default DbTableName::MEMBER |
||
| 601 | * |
||
| 602 | * @return void |
||
| 603 | */ |
||
| 604 | public function approve($iProfileId, $iStatus, $sTable = DbTableName::MEMBER) |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Get member data. The hash of course but also some useful data for sending the activation email. (hash, email, username, firstName). |
||
| 613 | * |
||
| 614 | * @param string $sEmail User's email address. |
||
| 615 | * @param string $sTable Default DbTableName::MEMBER |
||
| 616 | * |
||
| 617 | * @return stdClass|bool Returns the data member (email, username, firstName, hashValidation) on success, otherwise returns false if there is an error. |
||
| 618 | */ |
||
| 619 | public function getHashValidation($sEmail, $sTable = DbTableName::MEMBER) |
||
| 631 | |||
| 632 | /** |
||
| 633 | * Valid on behalf of a user with the hash. |
||
| 634 | * |
||
| 635 | * @param string $sEmail |
||
| 636 | * @param string $sHash |
||
| 637 | * @param string $sTable Default DbTableName::MEMBER |
||
| 638 | * |
||
| 639 | * @return bool |
||
| 640 | */ |
||
| 641 | public function validateAccount($sEmail, $sHash, $sTable = DbTableName::MEMBER) |
||
| 651 | |||
| 652 | /** |
||
| 653 | * Adding a User. |
||
| 654 | * |
||
| 655 | * @param array $aData |
||
| 656 | * |
||
| 657 | * @return int The ID of the User. |
||
| 658 | */ |
||
| 659 | public function add(array $aData) |
||
| 694 | |||
| 695 | /** |
||
| 696 | * @param array $aData |
||
| 697 | * |
||
| 698 | * @return bool |
||
| 699 | */ |
||
| 700 | public function setInfoFields(array $aData) |
||
| 716 | |||
| 717 | /** |
||
| 718 | * Set the default privacy settings. |
||
| 719 | * |
||
| 720 | * @return bool Returns TRUE on success or FALSE on failure. |
||
| 721 | */ |
||
| 722 | public function setDefaultPrivacySetting() |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Set the default notifications. |
||
| 733 | * |
||
| 734 | * @return bool Returns TRUE on success or FALSE on failure. |
||
| 735 | */ |
||
| 736 | public function setDefaultNotification() |
||
| 744 | |||
| 745 | /** |
||
| 746 | * To avoid flooding! |
||
| 747 | * Waiting time before a new registration with the same IP address. |
||
| 748 | * |
||
| 749 | * @param string $sIp |
||
| 750 | * @param int $iWaitTime In minutes! |
||
| 751 | * @param string $sCurrentTime In date format: 0000-00-00 00:00:00 |
||
| 752 | * @param string $sTable Default DbTableName::MEMBER |
||
| 753 | * |
||
| 754 | * @return bool Return TRUE if the weather was fine, FALSE otherwise. |
||
| 755 | */ |
||
| 756 | public function checkWaitJoin($sIp, $iWaitTime, $sCurrentTime, $sTable = DbTableName::MEMBER) |
||
| 769 | |||
| 770 | |||
| 771 | /********** AVATAR **********/ |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Update or add a new avatar. |
||
| 775 | * |
||
| 776 | * @param int $iProfileId |
||
| 777 | * @param string $sAvatar |
||
| 778 | * @param int $iApproved |
||
| 779 | * |
||
| 780 | * @return bool |
||
| 781 | */ |
||
| 782 | public function setAvatar($iProfileId, $sAvatar, $iApproved) |
||
| 791 | |||
| 792 | /** |
||
| 793 | * Get avatar. |
||
| 794 | * |
||
| 795 | * @param int $iProfileId |
||
| 796 | * @param string|null $iApproved (1 = approved | 0 = pending | NULL = approved and pending) |
||
| 797 | * |
||
| 798 | * @return stdClass The Avatar (SQL alias is pic), profileId and approvedAvatar |
||
| 799 | */ |
||
| 800 | public function getAvatar($iProfileId, $iApproved = null) |
||
| 821 | |||
| 822 | /** |
||
| 823 | * Delete an avatar in the database. |
||
| 824 | * |
||
| 825 | * @param int $iProfileId |
||
| 826 | * |
||
| 827 | * @return bool |
||
| 828 | */ |
||
| 829 | public function deleteAvatar($iProfileId) |
||
| 833 | |||
| 834 | |||
| 835 | /********** BACKGROUND **********/ |
||
| 836 | |||
| 837 | /** |
||
| 838 | * Get file of a user background. |
||
| 839 | * |
||
| 840 | * @param int $iProfileId |
||
| 841 | * @param int|null $iApproved (1 = approved | 0 = pending | NULL = approved and pending) Default NULL |
||
| 842 | * |
||
| 843 | * @return string |
||
| 844 | */ |
||
| 845 | public function getBackground($iProfileId, $iApproved = null) |
||
| 867 | |||
| 868 | /** |
||
| 869 | * Add profile background. |
||
| 870 | * |
||
| 871 | * @param int $iProfileId |
||
| 872 | * @param string $sFile |
||
| 873 | * @param int $iApproved |
||
| 874 | * |
||
| 875 | * @return bool |
||
| 876 | */ |
||
| 877 | public function addBackground($iProfileId, $sFile, $iApproved = 1) |
||
| 886 | |||
| 887 | /** |
||
| 888 | * Delete profile background. |
||
| 889 | * |
||
| 890 | * @param int $iProfileId |
||
| 891 | * |
||
| 892 | * @return bool |
||
| 893 | */ |
||
| 894 | public function deleteBackground($iProfileId) |
||
| 900 | |||
| 901 | /** |
||
| 902 | * Delete User. |
||
| 903 | * |
||
| 904 | * @param int $iProfileId |
||
| 905 | * @param string $sUsername |
||
| 906 | * |
||
| 907 | * @return void |
||
| 908 | */ |
||
| 909 | public function delete($iProfileId, $sUsername) |
||
| 1004 | |||
| 1005 | /** |
||
| 1006 | * @param string $sUsernameSearch |
||
| 1007 | * @param string $sTable Default DbTableName::MEMBER |
||
| 1008 | * |
||
| 1009 | * @return array data of users (profileId, username, sex) |
||
| 1010 | */ |
||
| 1011 | public function getUsernameList($sUsernameSearch, $sTable = DbTableName::MEMBER) |
||
| 1023 | |||
| 1024 | /** |
||
| 1025 | * Get (all) profile data. |
||
| 1026 | * |
||
| 1027 | * @param string $sOrder |
||
| 1028 | * @param int $iOffset |
||
| 1029 | * @param int $iLimit |
||
| 1030 | * |
||
| 1031 | * @return array Data of users |
||
| 1032 | */ |
||
| 1033 | public function getProfiles($sOrder = SearchCoreModel::LAST_ACTIVITY, $iOffset = null, $iLimit = null) |
||
| 1071 | |||
| 1072 | /** |
||
| 1073 | * Get users from the location data. |
||
| 1074 | * |
||
| 1075 | * @param string $sCountryCode The country code. e.g. US, CA, FR, ES, BE, NL |
||
| 1076 | * @param string $sCity |
||
| 1077 | * @param bool $bCount |
||
| 1078 | * @param string $sOrder |
||
| 1079 | * @param int $iOffset |
||
| 1080 | * @param int $iLimit |
||
| 1081 | * |
||
| 1082 | * @return array|stdClass|int Object with the users list returned or integer for the total number users returned. |
||
| 1083 | */ |
||
| 1084 | public function getGeoProfiles($sCountryCode, $sCity, $bCount, $sOrder, $iOffset = null, $iLimit = null) |
||
| 1130 | |||
| 1131 | /** |
||
| 1132 | * Updating the privacy settings. |
||
| 1133 | * |
||
| 1134 | * @param int $iProfileId |
||
| 1135 | * |
||
| 1136 | * @return stdClass |
||
| 1137 | */ |
||
| 1138 | public function getPrivacySetting($iProfileId) |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Get the Profile ID of a user. |
||
| 1158 | * |
||
| 1159 | * @param string $sEmail Default NULL |
||
| 1160 | * @param string $sUsername Default NULL |
||
| 1161 | * @param string $sTable Default DbTableName::MEMBER |
||
| 1162 | * |
||
| 1163 | * @return int|bool The Member ID if it is found or FALSE if not found. |
||
| 1164 | */ |
||
| 1165 | public function getId($sEmail = null, $sUsername = null, $sTable = DbTableName::MEMBER) |
||
| 1193 | |||
| 1194 | /** |
||
| 1195 | * @param int $iProfileId |
||
| 1196 | * @param string $sTable Default DbTableName::MEMBER |
||
| 1197 | * |
||
| 1198 | * @return string The email address of a member |
||
| 1199 | */ |
||
| 1200 | public function getEmail($iProfileId, $sTable = DbTableName::MEMBER) |
||
| 1218 | |||
| 1219 | /** |
||
| 1220 | * Retrieves the username from the user ID. |
||
| 1221 | * |
||
| 1222 | * @param int $iProfileId |
||
| 1223 | * @param string $sTable Default DbTableName::MEMBER |
||
| 1224 | * |
||
| 1225 | * @return string The Username of member |
||
| 1226 | */ |
||
| 1227 | public function getUsername($iProfileId, $sTable = DbTableName::MEMBER) |
||
| 1249 | |||
| 1250 | /** |
||
| 1251 | * Retrieves the first name from the user ID. |
||
| 1252 | * |
||
| 1253 | * @param int $iProfileId |
||
| 1254 | * @param string $sTable Default DbTableName::MEMBER |
||
| 1255 | * |
||
| 1256 | * @return string The first name of member |
||
| 1257 | */ |
||
| 1258 | public function getFirstName($iProfileId, $sTable = DbTableName::MEMBER) |
||
| 1276 | |||
| 1277 | /** |
||
| 1278 | * Get Gender (sex) of a user. |
||
| 1279 | * |
||
| 1280 | * @param int $iProfileId Default NULL |
||
| 1281 | * @param string $sUsername Default NULL |
||
| 1282 | * @param string $sTable Default DbTableName::MEMBER |
||
| 1283 | * |
||
| 1284 | * @return string The sex of a member |
||
| 1285 | */ |
||
| 1286 | public function getSex($iProfileId = null, $sUsername = null, $sTable = DbTableName::MEMBER) |
||
| 1310 | |||
| 1311 | /** |
||
| 1312 | * Get Match sex for a member (so only from the Members table, because Affiliates and Admins don't have match sex). |
||
| 1313 | * |
||
| 1314 | * @param int $iProfileId |
||
| 1315 | * |
||
| 1316 | * @return string The User's birthdate. |
||
| 1317 | */ |
||
| 1318 | public function getMatchSex($iProfileId) |
||
| 1334 | |||
| 1335 | /** |
||
| 1336 | * Get Birth Date of a user. |
||
| 1337 | * |
||
| 1338 | * @param int $iProfileId |
||
| 1339 | * @param string $sTable Default DbTableName::MEMBER |
||
| 1340 | * |
||
| 1341 | * @return string The User's birthdate. |
||
| 1342 | */ |
||
| 1343 | public function getBirthDate($iProfileId, $sTable = DbTableName::MEMBER) |
||
| 1361 | |||
| 1362 | /** |
||
| 1363 | * Get user's group. |
||
| 1364 | * |
||
| 1365 | * @param int $iProfileId |
||
| 1366 | * @param string sTable Default DbTableName::MEMBER |
||
| 1367 | * |
||
| 1368 | * @return int The Group ID of a member |
||
| 1369 | */ |
||
| 1370 | public function getGroupId($iProfileId, $sTable = DbTableName::MEMBER) |
||
| 1388 | |||
| 1389 | /** |
||
| 1390 | * Get the membership(s) data. |
||
| 1391 | * |
||
| 1392 | * @param int $iGroupId Group ID. Select only the specific membership from a group ID. |
||
| 1393 | * |
||
| 1394 | * @return stdClass|array The membership(s) data. |
||
| 1395 | */ |
||
| 1396 | public function getMemberships($iGroupId = null) |
||
| 1414 | |||
| 1415 | /** |
||
| 1416 | * Get the membership details of a user. |
||
| 1417 | * |
||
| 1418 | * @param int $iProfileId |
||
| 1419 | * |
||
| 1420 | * @return stdClass The membership detais. |
||
| 1421 | */ |
||
| 1422 | public function getMembershipDetails($iProfileId) |
||
| 1440 | |||
| 1441 | /** |
||
| 1442 | * Check if membership is expired. |
||
| 1443 | * |
||
| 1444 | * @param int $iProfileId |
||
| 1445 | * @param string $sCurrentTime In date format: 0000-00-00 00:00:00 |
||
| 1446 | * |
||
| 1447 | * @return bool |
||
| 1448 | */ |
||
| 1449 | public function checkMembershipExpiration($iProfileId, $sCurrentTime) |
||
| 1464 | |||
| 1465 | /** |
||
| 1466 | * Update the membership group of a user. |
||
| 1467 | * |
||
| 1468 | * @param int $iNewGroupId The new ID of membership group. |
||
| 1469 | * @param int $iProfileId The user ID. |
||
| 1470 | * @param string $sDateTime In date format: 0000-00-00 00:00:00 |
||
| 1471 | * |
||
| 1472 | * @return bool Returns TRUE on success or FALSE on failure. |
||
| 1473 | */ |
||
| 1474 | public function updateMembership($iNewGroupId, $iProfileId, $sDateTime = null) |
||
| 1492 | |||
| 1493 | /** |
||
| 1494 | * Get Info Fields from profile ID. |
||
| 1495 | * |
||
| 1496 | * @param int $iProfileId |
||
| 1497 | * @param string $sTable Default DbTableName::MEMBER_INFO |
||
| 1498 | * |
||
| 1499 | * @return stdClass |
||
| 1500 | */ |
||
| 1501 | public function getInfoFields($iProfileId, $sTable = DbTableName::MEMBER_INFO) |
||
| 1525 | |||
| 1526 | /** |
||
| 1527 | * @return string |
||
| 1528 | */ |
||
| 1529 | public function getUserWithAvatarOnlySql() |
||
| 1533 | |||
| 1534 | /** |
||
| 1535 | * Clone is set to private to stop cloning. |
||
| 1536 | */ |
||
| 1537 | private function __clone() |
||
| 1540 | } |
||
| 1541 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: