private static function update_user_points($points_data, $ent_attributes = null) { $curr_points = 0; $points_obj = UserPopularity::getUserPopularity((int) $points_data['user_id']); if (is_object($points_obj)) { $curr_points = $points_obj->get_popularity(); } $new_rating = $points_data['rating']['value']; if (!empty($ent_attributes)) { $old_rating = $ent_attributes['rating']['value']; $curr_points = $curr_points - $old_rating; } $curr_points = $curr_points + $new_rating; if ($curr_points < 0) { $curr_points = 0; } $upd_points = new UserPopularity(); $upd_points->populateFromArray(array("user_id" => (int) $points_data['user_id'], "popularity" => (int) $curr_points, "time" => time())); $upd_points->save_UserPopularity(); }
function initializeModule($request_method, $request_data) { global $error_msg; if ($this->column == 'middle') { $this->page_size = 10; $this->page = !empty($request_data['page']) ? $request_data['page'] : 0; $this->title = PA::$network_info->name . ' ' . __('Leader Board'); $this->outer_template = 'outer_public_center_module.tpl'; $this->set_inner_template('module_middle.tpl.php'); } else { $this->page = 0; $this->title = __('Leader Board'); $this->page_size = 5; $this->outer_template = 'outer_public_side_module.tpl'; $this->set_inner_template('module_default.tpl.php'); $this->view_all_url = PA::$url . PA_ROUTE_LEADER_BOARD; } $pagination_links = null; $users_ranking = array(); $act = array(); $users_counter_increment = 0; $nb_items = UserPopularity::countUserPopularity(); if ($nb_items > 0) { $rankings = UserPopularity::listUserPopularity(null, 'popularity', 'DESC'); $max_rank = $rankings[0]->get_popularity(); $pagination = UserPopularity::getPagging($rankings, $this->page_size, $this->page); $page_items = $pagination->getPageItems(); foreach ($page_items as $idx => $item) { try { $user = new User(); $user->load((int) $item->get_user_id()); $user_generaldata = User::load_user_profile($item->get_user_id(), PA::$login_uid, GENERAL); $user->profile_info = sanitize_user_data($user_generaldata); $user->ranking_points = $item->get_popularity(); $user->ranking_stars = intval($user->ranking_points * 5 / $max_rank); $user->last_activity = $item->get_time(); $users_ranking[$idx] = $user; // Grab the recent activities of the user $act[$idx] = Activities::get_activities(array("limit" => 3), array("subject" => $item->get_user_id(), "status" => "new")); } catch (Exception $e) { $error_msg = "Exception in LeaderBoardModule, message: <br />" . $e->getMessage(); return 'skip'; } } $pagination_links = $pagination->getPaggingLinks(PA::$url . PA_ROUTE_LEADER_BOARD, 'page', 'pagging', 'pagging_selected'); $users_counter_increment = $this->page_size * $this->page; } $this->inner_HTML = $this->generate_inner_html(array('page_id' => $this->page_id, 'users_ranking' => $users_ranking, 'pagination_links' => $pagination_links, 'increment' => $users_counter_increment, 'activities' => $act)); }
/** * Retrieved list of objects base on a given parameters - dynamic method: list_UserPopularity() * * * Generated with the DalClassGenerator created by: * Zoran Hron <*****@*****.**> * * @param conditionalStatement = null * @param orderby = null * @param sort = null * @param limit = 0 * @param fetchmode = DB_FETCHMODE_OBJECT * @result array of objects: UserPopularity **/ public function list_UserPopularity($conditionalStatement = null, $orderby = null, $sort = null, $limit = 0, $fetchmode = DB_FETCHMODE_OBJECT) { // build MySQL query $sql = "SELECT * FROM { user_popularity } "; if ($conditionalStatement) { $sql .= "WHERE {$conditionalStatement}"; } if ($orderby) { $sql .= " ORDER BY {$orderby}"; } if ($sort) { $sql .= " {$sort}"; } if ($limit) { $sql .= " LIMIT {$limit}"; } $sql .= ";"; // execute query $res = Dal::query($sql); $objects = array(); // data found? if ($res->numRows() > 0) { // retrieve data objects while ($row = $res->fetchRow($fetchmode)) { if ($fetchmode == DB_FETCHMODE_OBJECT) { $obj = new UserPopularity(); $obj->populateFromObject($row); $objects[] = $obj; } else { $objects[] = $row; } } } return $objects; }
/** * Soft delete of user related data. * function to delete a user from the system. * this function uses the method of th respective api's to delete the user related data. */ public static function delete_user($user_id) { Logger::log("Enter: function User::delete_user"); // Delete user content on homepage: Call content delete. $uid = (int) $user_id; try { Content::delete_user_content($uid); // Deleting user groups. $Group = new Group(); $Group->delete_user_groups($uid); // Deleting user albums. Album::delete_user_albums($uid); // Deleting user relations. Relation::delete_user_relations($uid); // Deleting user comments. Comment::delete_user_comments($uid); PaForumsUsers::delete_PaForumsUsers($uid); UserPopularity::deleteUserPopularity($uid); } catch (PAException $e) { Logger::log('Exception occured while deleting user:'******' : ' . $e->message); throw new PAException(INVALID_ARGUMENTS, "User deletion failed for user_id = '{$uid}' due to '{$e->message}'"); } Logger::log("Exit: function User::delete_user"); }