Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 50 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| birthday_helper | |
0.00% |
0 / 50 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| display_birthdays | |
0.00% |
0 / 43 |
|
0.00% |
0 / 1 |
90 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of 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 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | namespace phpbb\forum; |
| 15 | |
| 16 | use phpbb\auth\auth; |
| 17 | use phpbb\config\config; |
| 18 | use phpbb\db\driver\driver_interface; |
| 19 | use phpbb\event\dispatcher; |
| 20 | use phpbb\language\language; |
| 21 | use phpbb\template\template; |
| 22 | use phpbb\user; |
| 23 | |
| 24 | class birthday_helper |
| 25 | { |
| 26 | /** @var auth */ |
| 27 | protected $auth; |
| 28 | |
| 29 | /** @var config */ |
| 30 | protected $config; |
| 31 | |
| 32 | /** @var driver_interface */ |
| 33 | protected $db; |
| 34 | |
| 35 | /** @var dispatcher */ |
| 36 | protected $dispatcher; |
| 37 | |
| 38 | /** @var language */ |
| 39 | protected $language; |
| 40 | |
| 41 | /** @var template */ |
| 42 | protected $template; |
| 43 | |
| 44 | /** @var user */ |
| 45 | protected $user; |
| 46 | |
| 47 | /** |
| 48 | * Constructor |
| 49 | * |
| 50 | * @param auth $auth |
| 51 | * @param config $config |
| 52 | * @param driver_interface $db |
| 53 | * @param dispatcher $dispatcher |
| 54 | * @param language $language |
| 55 | * @param template $template |
| 56 | * @param user $user |
| 57 | */ |
| 58 | public function __construct(auth $auth, config $config, driver_interface $db, dispatcher $dispatcher, language $language, template $template, user $user) |
| 59 | { |
| 60 | $this->auth = $auth; |
| 61 | $this->config = $config; |
| 62 | $this->db = $db; |
| 63 | $this->dispatcher = $dispatcher; |
| 64 | $this->language = $language; |
| 65 | $this->template = $template; |
| 66 | $this->user = $user; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Display birthdays in index page |
| 71 | * |
| 72 | * @return void |
| 73 | * |
| 74 | * @psalm-suppress InvalidArgument |
| 75 | */ |
| 76 | public function display_birthdays(): void |
| 77 | { |
| 78 | $show_birthdays = ($this->config['load_birthdays'] && $this->config['allow_birthdays'] && $this->auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel')); |
| 79 | |
| 80 | $birthdays = array(); |
| 81 | if ($show_birthdays) |
| 82 | { |
| 83 | $time = $this->user->create_datetime(); |
| 84 | $now = phpbb_gmgetdate($time->getTimestamp() + $time->getOffset()); |
| 85 | |
| 86 | // Display birthdays of 29th february on 28th february in non-leap-years |
| 87 | $leap_year_birthdays = ''; |
| 88 | if ($now['mday'] == 28 && $now['mon'] == 2 && !$time->format('L')) |
| 89 | { |
| 90 | $leap_year_birthdays = " OR u.user_birthday LIKE '" . $this->db->sql_escape(sprintf('%2d-%2d-', 29, 2)) . "%'"; |
| 91 | } |
| 92 | |
| 93 | $sql_ary = array( |
| 94 | 'SELECT' => 'u.user_id, u.username, u.user_colour, u.user_birthday', |
| 95 | 'FROM' => array( |
| 96 | USERS_TABLE => 'u', |
| 97 | ), |
| 98 | 'LEFT_JOIN' => array( |
| 99 | array( |
| 100 | 'FROM' => array(BANS_TABLE => 'b'), |
| 101 | 'ON' => 'u.user_id = b.ban_userid', |
| 102 | ), |
| 103 | ), |
| 104 | 'WHERE' => 'b.ban_id IS NULL |
| 105 | AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ") |
| 106 | AND (u.user_birthday LIKE '" . $this->db->sql_escape(sprintf('%2d-%2d-', $now['mday'], $now['mon'])) . "%' $leap_year_birthdays)", |
| 107 | ); |
| 108 | |
| 109 | /** |
| 110 | * Event to modify the SQL query to get birthdays data |
| 111 | * |
| 112 | * @event core.index_modify_birthdays_sql |
| 113 | * @var array now The assoc array with the 'now' local timestamp data |
| 114 | * @var array sql_ary The SQL array to get the birthdays data |
| 115 | * @var object time The user related Datetime object |
| 116 | * @since 3.1.7-RC1 |
| 117 | */ |
| 118 | $vars = array('now', 'sql_ary', 'time'); |
| 119 | extract($this->dispatcher->trigger_event('core.index_modify_birthdays_sql', compact($vars))); |
| 120 | |
| 121 | $sql = $this->db->sql_build_query('SELECT', $sql_ary); |
| 122 | $result = $this->db->sql_query($sql); |
| 123 | $rows = $this->db->sql_fetchrowset($result); |
| 124 | $this->db->sql_freeresult($result); |
| 125 | |
| 126 | foreach ($rows as $row) |
| 127 | { |
| 128 | $birthday_username = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']); |
| 129 | $birthday_year = (int) substr($row['user_birthday'], -4); |
| 130 | $birthday_age = ($birthday_year) ? max(0, $now['year'] - $birthday_year) : ''; |
| 131 | |
| 132 | $birthdays[] = array( |
| 133 | 'USERNAME' => $birthday_username, |
| 134 | 'AGE' => $birthday_age, |
| 135 | ); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Event to modify the birthdays list |
| 140 | * |
| 141 | * @event core.index_modify_birthdays_list |
| 142 | * @var array birthdays Array with the users birthdays data |
| 143 | * @var array rows Array with the birthdays SQL query result |
| 144 | * @since 3.1.7-RC1 |
| 145 | */ |
| 146 | $vars = array('birthdays', 'rows'); |
| 147 | extract($this->dispatcher->trigger_event('core.index_modify_birthdays_list', compact($vars))); |
| 148 | |
| 149 | $this->template->assign_block_vars_array('birthdays', $birthdays); |
| 150 | } |
| 151 | |
| 152 | $this->template->assign_vars([ |
| 153 | 'S_DISPLAY_BIRTHDAY_LIST' => $show_birthdays, |
| 154 | ]); |
| 155 | } |
| 156 | } |