aps_functions = $aps_functions; $this->auth = $auth; $this->config = $config; $this->db = $db; $this->group_helper = $group_helper; $this->operator_item = $operator_item; $this->template = $template; $this->user_loader = $user_loader; $this->categories_table = $categories_table; $this->items_table = $items_table; $this->logs_table = $logs_table; } /** * Get the Shop display blocks. * * @return array The shop display blocks */ public function get_blocks() { return [ 'charts' => [ 'purchases_category' => 'ASS_DISPLAY_PURCHASES_CATEGORY', 'purchases_group' => 'ASS_DISPLAY_PURCHASES_GROUP', ], 'items' => [ 'sale' => 'ASS_SALE_ITEMS', 'featured' => 'ASS_FEATURED_ITEMS', 'recent' => 'ASS_ITEMS_RECENT', 'purchases' => 'ASS_DISPLAY_PURCHASES_RECENT', 'available' => 'ASS_DISPLAY_LIMITED_AVAILABLE', 'limited' => 'ASS_DISPLAY_LIMITED_STOCK', ], 'users' => [ 'buyers' => 'ASS_DISPLAY_BIGGEST_BUYERS', 'gifters' => 'ASS_DISPLAY_BIGGEST_GIFTERS', 'spenders' => 'ASS_DISPLAY_BIGGEST_SPENDERS', ], ]; } /** * Display the "charts" blocks. * * @param string $block The block name * @return void */ protected function charts($block) { $s_group = $block === 'purchases_group'; if ($s_group) { $sql = 'SELECT g.group_name, COUNT(l.log_id) as purchases FROM ' . $this->logs_table . ' l, ' . $this->aps_functions->table('users') . ' u, ' . $this->aps_functions->table('groups') . ' g WHERE l.item_purchase = 1 AND l.user_id = u.user_id AND u.group_id = g.group_id AND g.group_type <> ' . GROUP_HIDDEN . ' GROUP BY g.group_name ORDER BY purchases DESC'; } else { $sql = 'SELECT c.category_title, SUM(i.item_purchases) as purchases FROM ' . $this->items_table . ' i, ' . $this->categories_table . ' c WHERE i.category_id = c.category_id' . (!$this->auth->acl_get('u_ass_can_view_inactive_items') ? ' AND c.category_active = 1' : '') . ' GROUP BY i.category_id ORDER BY c.category_order'; } $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $name = $s_group ? $this->group_helper->get_name($row['group_name']) : $row['category_title']; $this->template->assign_block_vars($block, [ 'NAME' => (string) $name, 'PURCHASES' => (int) $row['purchases'], ]); } $this->db->sql_freeresult($result); } /** * Display the "items" blocks. * * @param string $block The block name * @return void */ protected function items($block) { $items = $this->operator_item->assign_specific_items($block, 3, 0, false); foreach ($items as $item) { $this->template->assign_block_vars($block, $this->operator_item->get_variables($item)); } } /** * Display the "users" blocks. * * @param string $block The block name * @return void */ protected function users($block) { switch ($block) { case 'buyers': $select = 'COUNT(log_id)'; $where = ' WHERE item_purchase = 1 AND recipient_id = 0'; break; case 'gifters': $select = 'COUNT(log_id)'; $where = ' WHERE item_purchase = 1 AND recipient_id <> 0'; break; case 'spenders': default: $select = 'SUM(points_sum)'; $where = ''; break; } $sql = 'SELECT ' . $select . ' as count, user_id FROM ' . $this->logs_table . $where . ' GROUP BY user_id ORDER BY count DESC'; $result = $this->db->sql_query_limit($sql, 3); $rowset = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); $users = array_column($rowset, 'count', 'user_id'); $this->user_loader->load_users(array_map('intval', array_keys($users))); foreach ($users as $user_id => $count) { $avatar = $this->user_loader->get_avatar($user_id); $avatar = $avatar ? $avatar : $this->aps_functions->get_no_avatar(); $this->template->assign_block_vars($block, [ 'NAME' => $this->user_loader->get_username($user_id, 'full'), 'AVATAR' => $avatar, 'COUNT' => $count, ]); } $this->template->assign_var('USER_BLOCK', $block); } /** * Magic method to call a function within this object. * * Needed as APS only calls each function ones, * and ASS groups all blocks to certain categories. * So, the block listener calls the block name in this object, * which by this method is routed to the category's function. * * @see \phpbbstudio\ass\event\blocks_listener * * @param $method * @param $arguments * @return void */ public function __call($method, $arguments) { foreach ($this->get_blocks() as $type => $blocks) { if (in_array($method, array_keys($blocks))) { call_user_func_array([$this, $type], $arguments); } } } }