api.extmobiles.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Light version for userstats
  4. */
  5. class UserstatsMobilesExt {
  6. /**
  7. * Contains all additiona mobile numbers as id=>data
  8. *
  9. * @var array
  10. */
  11. protected $allMobiles = array();
  12. /**
  13. * Contains current instance user login
  14. *
  15. * @var string
  16. */
  17. protected $login = '';
  18. /**
  19. * Creates new UserstatsMobilesExt instance
  20. *
  21. *
  22. * @return void
  23. */
  24. public function __construct($login) {
  25. $this->setLogin($login);
  26. $this->loadAllUserMobiles();
  27. }
  28. /**
  29. * Sets current instance user login
  30. *
  31. * @return void
  32. */
  33. protected function setLogin($login) {
  34. $this->login = $login;
  35. }
  36. /**
  37. * Loads all additional mobiles data from database for some user
  38. *
  39. * @return void
  40. */
  41. protected function loadAllUserMobiles() {
  42. $userLoginClean = mysql_real_escape_string($this->login);
  43. if (!empty($userLoginClean)) {
  44. $query = "SELECT * from `mobileext` WHERE `login`='" . $userLoginClean . "';";
  45. $all = simple_queryall($query);
  46. if (!empty($all)) {
  47. foreach ($all as $io => $each) {
  48. $this->allMobiles[$each['id']] = $each;
  49. }
  50. }
  51. }
  52. }
  53. /**
  54. * Returns filtered array for some user phones as id=>data
  55. *
  56. * @param string $login
  57. *
  58. * @return array
  59. */
  60. public function getUserMobiles() {
  61. $result = array();
  62. if (!empty($this->allMobiles)) {
  63. foreach ($this->allMobiles as $io => $each) {
  64. $result[$each['id']] = $each;
  65. }
  66. }
  67. return ($result);
  68. }
  69. /**
  70. * Renders additional user mobile numbers
  71. *
  72. * @return string
  73. */
  74. public function renderUserMobiles() {
  75. $result = '';
  76. $allExtRaw = $this->getUserMobiles();
  77. $allExt = array();
  78. if (!empty($allExtRaw)) {
  79. foreach ($allExtRaw as $io => $each) {
  80. $allExt[] = $each['mobile'];
  81. }
  82. }
  83. /**
  84. * Emptiness is power, loneliness is pain
  85. * Serenity is might
  86. * Yet we shall be honoured
  87. * In the starforsaken night
  88. * Astral strain
  89. * All around my silent moon
  90. * Life suffers defeat
  91. */
  92. if (!empty($allExt)) {
  93. $additionalNumbers = implode(', ', $allExt);
  94. } else {
  95. $additionalNumbers = '';
  96. }
  97. $result.= $additionalNumbers;
  98. return ($result);
  99. }
  100. }