BlockedUser.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ hkZjoGLOWZ0cqGeM/U8ASu1lgLmkR9qJZSNvnWbjuSI=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2016 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.8
  11. */
  12. /**
  13. * blocked user table row object model
  14. */
  15. namespace Ppb\Db\Table\Row;
  16. class BlockedUser extends AbstractRow
  17. {
  18. /**
  19. * types of variables/values accepted for blocking
  20. */
  21. const TYPE_IP = 'ip';
  22. const TYPE_EMAIL = 'email';
  23. const TYPE_USERNAME = 'username';
  24. /**
  25. * types of actions that can be blocked
  26. */
  27. const ACTION_REGISTER = 'register';
  28. const ACTION_PURCHASE = 'purchase';
  29. const ACTION_MESSAGING = 'messaging';
  30. /**
  31. *
  32. * block types
  33. *
  34. * @var array
  35. */
  36. public static $blockTypes = array(
  37. self::TYPE_IP => 'IP Address',
  38. self::TYPE_EMAIL => 'Email Address',
  39. self::TYPE_USERNAME => 'Username',
  40. );
  41. /**
  42. *
  43. * blocked actions
  44. *
  45. * @var array
  46. */
  47. public static $blockedActions = array(
  48. self::ACTION_REGISTER => 'Registering / Logging In',
  49. self::ACTION_PURCHASE => 'Purchasing',
  50. self::ACTION_MESSAGING => 'Messaging',
  51. );
  52. /**
  53. *
  54. * get blocked actions as an array
  55. * or for display purposes
  56. *
  57. * @param bool|string $separator
  58. *
  59. * @return array
  60. */
  61. public function getBlockedActions($separator = false)
  62. {
  63. $blockedActions = array_filter(\Ppb\Utility::unserialize($this->getData('blocked_actions'), array()));
  64. if ($separator !== false) {
  65. $output = array();
  66. $translate = $this->getTranslate();
  67. foreach ($blockedActions as $blockedAction) {
  68. $output[] = $translate->_(self::$blockedActions[$blockedAction]);
  69. }
  70. return implode($separator, $output);
  71. }
  72. return $blockedActions;
  73. }
  74. /**
  75. *
  76. * return the block message that the blocked user sees
  77. *
  78. * @return string
  79. */
  80. public function blockMessage()
  81. {
  82. $translate = $this->getTranslate();
  83. $blocker = $this->findParentRow('\Ppb\Db\Table\Users');
  84. $type = $this->getData('type');
  85. $value = $this->getData('value');
  86. $blockReason = $this->getData('block_reason');
  87. $showReason = $this->getData('show_reason');
  88. $message = sprintf(
  89. $translate->_('Your %s (%s) has been blocked from %s by %s.'),
  90. self::$blockTypes[$type],
  91. $value,
  92. $this->getBlockedActions(', '),
  93. ($blocker) ? $blocker['username'] : $translate->_('the administrator'));
  94. if ($showReason && !empty($blockReason)) {
  95. $message .= '<br>' . sprintf($translate->_('Block Reason: %s'), $blockReason);
  96. }
  97. return $message;
  98. }
  99. }