phpbb /
ideas
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * |
||
| 4 | * Ideas extension for the phpBB Forum Software package. |
||
| 5 | * |
||
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
||
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
||
| 8 | * |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace phpbb\ideas; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * This ext class is optional and can be omitted if left empty. |
||
| 15 | * However, you can add special (un)installation commands in the |
||
| 16 | * methods enable_step(), disable_step() and purge_step(). As it is, |
||
| 17 | * these methods are defined in \phpbb\extension\base, which this |
||
| 18 | * class extends, but you can overwrite them to give special |
||
| 19 | * instructions for those cases. |
||
| 20 | */ |
||
| 21 | class ext extends \phpbb\extension\base |
||
| 22 | { |
||
| 23 | public const SORT_AUTHOR = 'author'; |
||
| 24 | public const SORT_DATE = 'date'; |
||
| 25 | public const SORT_NEW = 'new'; |
||
| 26 | public const SORT_SCORE = 'score'; |
||
| 27 | public const SORT_TITLE = 'title'; |
||
| 28 | public const SORT_TOP = 'top'; |
||
| 29 | public const SORT_VOTES = 'votes'; |
||
| 30 | public const SORT_MYIDEAS = 'egosearch'; |
||
| 31 | public const SUBJECT_LENGTH = 120; |
||
| 32 | public const NUM_IDEAS = 5; |
||
| 33 | private const NOTIFICATION_TYPE = 'phpbb.ideas.notification.type.status'; |
||
| 34 | |||
| 35 | /** @var array Idea status names and IDs */ |
||
| 36 | public static $statuses = [ |
||
| 37 | 'NEW' => 1, |
||
| 38 | 'IN_PROGRESS' => 2, |
||
| 39 | 'IMPLEMENTED' => 3, |
||
| 40 | 'DUPLICATE' => 4, |
||
| 41 | 'INVALID' => 5, |
||
| 42 | ]; |
||
| 43 | |||
| 44 | /** @var array Cached flipped statuses array */ |
||
| 45 | private static $status_names; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Return the status name from the status ID. |
||
| 49 | * |
||
| 50 | * @param int $id ID of the status. |
||
| 51 | * @return string The status name. |
||
| 52 | */ |
||
| 53 | public static function status_name($id) |
||
| 54 | { |
||
| 55 | if (self::$status_names === null) |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 56 | { |
||
| 57 | self::$status_names = array_flip(self::$statuses); |
||
| 58 | } |
||
| 59 | |||
| 60 | return self::$status_names[$id]; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Check whether the extension can be enabled. |
||
| 65 | * |
||
| 66 | * Requires phpBB >= 3.3.0 due to use of PHP 7 features |
||
| 67 | * Requires PHP >= 7.2.0 |
||
| 68 | * |
||
| 69 | * @return bool |
||
| 70 | */ |
||
| 71 | public function is_enableable() |
||
| 72 | { |
||
| 73 | return PHP_VERSION_ID >= 70200 |
||
| 74 | && phpbb_version_compare(PHPBB_VERSION, '3.3.0', '>=') |
||
| 75 | && phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '<'); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Handle notification management for extension lifecycle |
||
| 80 | * |
||
| 81 | * @param string $method The notification manager method to call |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | private function handle_notifications($method) |
||
| 85 | { |
||
| 86 | $this->container->get('notification_manager')->$method(self::NOTIFICATION_TYPE); |
||
| 87 | return 'notification'; |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Enable notifications for the extension |
||
| 92 | * |
||
| 93 | * @param mixed $old_state |
||
| 94 | * @return bool|string |
||
| 95 | */ |
||
| 96 | public function enable_step($old_state) |
||
| 97 | { |
||
| 98 | return $old_state === false ? $this->handle_notifications('enable_notifications') : parent::enable_step($old_state); |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Disable notifications for the extension |
||
| 103 | * |
||
| 104 | * @param mixed $old_state |
||
| 105 | * @return bool|string |
||
| 106 | */ |
||
| 107 | public function disable_step($old_state) |
||
| 108 | { |
||
| 109 | return $old_state === false ? $this->handle_notifications('disable_notifications') : parent::disable_step($old_state); |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Purge notifications for the extension |
||
| 114 | * |
||
| 115 | * @param mixed $old_state |
||
| 116 | * @return bool|string |
||
| 117 | */ |
||
| 118 | public function purge_step($old_state) |
||
| 119 | { |
||
| 120 | return $old_state === false ? $this->handle_notifications('purge_notifications') : parent::purge_step($old_state); |
||
| 121 | } |
||
| 122 | } |
||
| 123 |