public static function get_message($condition, array $parameters) { $row = self::$db_querier->select_single_row_query('SELECT member.*, shoutbox.* FROM ' . ShoutboxSetup::$shoutbox_table . ' shoutbox LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = shoutbox.user_id ' . $condition, $parameters); $message = new ShoutboxMessage(); $message->set_properties($row); return $message; }
private function build_view() { $this->lang = LangLoader::get('common', 'shoutbox'); $this->view = new FileTemplate('shoutbox/ShoutboxAjaxMessagesBoxController.tpl'); $this->view->add_lang($this->lang); $config = ShoutboxConfig::load(); $this->view->put('C_DISPLAY_DATE', $config->is_date_displayed()); $result = PersistenceContext::get_querier()->select('SELECT * FROM ' . ShoutboxSetup::$shoutbox_table . ' s LEFT JOIN ' . DB_TABLE_MEMBER . ' m ON m.user_id = s.user_id ORDER BY s.timestamp DESC ' . ($config->is_shout_max_messages_number_enabled() ? 'LIMIT ' . $config->get_shout_max_messages_number() : '')); while ($row = $result->fetch()) { $shoutbox_message = new ShoutboxMessage(); $shoutbox_message->set_properties($row); $this->view->assign_block_vars('messages', array_merge($shoutbox_message->get_array_tpl_vars())); } $result->dispose(); }
private function build_view() { $user_accounts_config = UserAccountsConfig::load(); $messages_number = ShoutboxService::count(); $page = AppContext::get_request()->get_getint('page', 1); $pagination = $this->get_pagination($messages_number, $page); $is_guest = !AppContext::get_current_user()->check_level(User::MEMBER_LEVEL); $result = PersistenceContext::get_querier()->select('SELECT member.*, shoutbox.*, ext_field.user_avatar FROM ' . ShoutboxSetup::$shoutbox_table . ' shoutbox LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = shoutbox.user_id LEFT JOIN ' . DB_TABLE_MEMBER_EXTENDED_FIELDS . ' ext_field ON ext_field.user_id = member.user_id ORDER BY shoutbox.timestamp DESC LIMIT :number_items_per_page OFFSET :display_from', array('number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from())); while ($row = $result->fetch()) { $message = new ShoutboxMessage(); $message->set_properties($row); //Avatar $user_avatar = !empty($row['user_avatar']) ? Url::to_rel($row['user_avatar']) : ($user_accounts_config->is_default_avatar_enabled() ? Url::to_rel('/templates/' . AppContext::get_current_user()->get_theme() . '/images/' . $user_accounts_config->get_default_avatar_name()) : ''); $this->view->assign_block_vars('messages', array_merge($message->get_array_tpl_vars($page), array('C_AVATAR' => $row['user_avatar'] || $user_accounts_config->is_default_avatar_enabled(), 'C_USER_GROUPS' => !empty($row['groups']), 'U_AVATAR' => $user_avatar))); //user's groups if ($message->get_author_user()->get_groups()) { $groups_cache = GroupsCache::load(); $user_groups = $message->get_author_user()->get_groups(); foreach ($user_groups as $user_group_id) { if ($groups_cache->group_exists($user_group_id)) { $group = $groups_cache->get_group($user_group_id); $this->view->assign_block_vars('messages.user_groups', array('C_GROUP_PICTURE' => !empty($group['img']), 'GROUP_PICTURE' => $group['img'], 'GROUP_NAME' => $group['name'])); } } } } $result->dispose(); $this->view->put_all(array('C_NO_MESSAGE' => $result->get_rows_count() == 0, 'C_PAGINATION' => $messages_number > ShoutboxConfig::load()->get_items_number_per_page(), 'PAGINATION' => $pagination->display())); if (ShoutboxAuthorizationsService::check_authorizations()->write() && !AppContext::get_current_user()->is_readonly()) { $this->view->put('FORM', ShoutboxFormController::get_view()); } else { $this->view->put('MSG', MessageHelper::display($this->lang['error.post.unauthorized'], MessageHelper::WARNING)); } return $this->view; }