function getMembers($groupName, $dbi, $START_DELIM = false, $DELIM = ",") { if (!$START_DELIM) { $START_DELIM = _("Members:"); } return getPageTextData($groupName, $dbi, $START_DELIM, $DELIM); }
function getBuddies($fromUser, $dbi, $thePage = "") { $START_DELIM = $thePage . _("Buddies:"); $DELIM = ","; $buddies_array = getPageTextData($fromUser, $dbi, $START_DELIM, $DELIM); if (count($buddies_array) == 0 and $thePage !== "") { $buddies_array = getPageTextData($fromUser, $dbi, _("Buddies:"), $DELIM); } if (empty($buddies_array)) { // 1. calculate buddies automatically from the 10 top raters with the most numratings (min. 5 ratings). // of all pages (only SQL) // or 2. from 10 random raters of this page (non-SQL) // or 3. from all members of your group (department) if <= 20 $rdbi = RatingsDb::getTheRatingsDb(); $dimension = ''; if (RATING_STORAGE == 'SQL') { //$result = $this->_sql_get_rating_result($dimension, null, null, 'numrating', "rater"); $dbh =& $rdbi->_sqlbackend; extract($dbh->_table_names); $query = "SELECT raterpage, COUNT(rateepage) as numrating" . " FROM {$rating_tbl} r, {$page_tbl} p " . " WHERE ratingvalue > 0" . " GROUP BY raterpage" . " ORDER BY numrating" . " LIMIT 10"; $result = $dbh->_dbh->query($query); } else { // from 10 random raters of this page (non-SQL) } } $result = array(); if (is_array($buddies_array)) { foreach ($buddies_array as $userid) { $result[] = new RatingsUser($userid); } } return $result; }
function getBuddies($fromUser, $dbi, $thePage = "") { $START_DELIM = $thePage . _("Buddies:"); $DELIM = ","; $buddies_array = getPageTextData($fromUser, $dbi, $START_DELIM, $DELIM); if (count($buddies_array) == 0 and $thePage !== "") { $buddies_array = getPageTextData($fromUser, $dbi, _("Buddies:"), $DELIM); } return $buddies_array; }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); if ($pageTextLabel == null && $category != null && $group == null) { $group = $category; } if ($category == null || $pageTextLabel == null) { return HTML::div(array('class' => "error"), "PreferencesApp Error: You must declare at least parameters category and pageTextLabel."); } $dbi = $request->getDbh(); $rdbi = RatingsDb::getTheRatingsDb(); $CATEGORY = $category; $PAGE_TEXT_LABEL = $pageTextLabel; $NEUTRAL_RATING = (int) $neutralRating; $active_user = $request->getUser(); $active_userid = $active_user->_userid; $html = HTML(); $html->pushContent(""); //Load participating Users $users_array = array(); if ($group != null) { $users_array = getMembers($group, $rdbi); } else { $people_iter = $rdbi->sql_get_users_rated(); while ($people_array = $people_iter->next()) { $users_array[] = $people_array['pagename']; } } $people = array(); foreach ($users_array as $person_indv) { if ($declareBudget == "true") { $get_array = getPageTextData($person_indv, $dbi, $PAGE_TEXT_LABEL, "cans"); if (count($get_array) == 1) { $cans_text = $get_array[0]; if (is_numeric($cans_text) && $cans_text >= 0) { $canBudget[$person_indv] = $cans_text; //Load the persons budget } else { $canBudget[$person_indv] = 0; } $people[] = $person_indv; } } else { $canBudget[$person_indv] = $lockedBudget; $people[] = $person_indv; } } if (count($people) < 1) { return fmt("Nobody has used %s on their homepage", $PAGE_TEXT_LABEL); } //Get all pages from Category $pageids = array(); $category_page = $dbi->getPage($CATEGORY); $iter = $category_page->getLinks(); while ($item = $iter->next()) { array_push($pageids, $item->getName()); } $ratingTotals = array(); foreach ($people as $person) { $ratings_iter = $rdbi->sql_get_rating(0, $person, $pageids); $ratingTotals[$person] = 0; while ($ratings_array = $ratings_iter->next()) { $can_rating = $ratings_array['ratingvalue']; if ($can_rating >= $NEUTRAL_RATING) { $ratingTotals[$person] += $can_rating; } } } //Generate numbers $canTotals = array(); $peopleTotals = array(); foreach ($pageids as $soda) { $canTotals[$soda] = 0; } foreach ($people as $person) { foreach ($pageids as $soda) { $peopleTotals[$person][$soda] = 0; } } foreach ($people as $person) { foreach ($pageids as $page) { $can_rating_iter = $rdbi->sql_get_rating(0, $person, $page); $can_rating_array = $can_rating_iter->next(); $can_rating = $can_rating_array['ratingvalue']; if ($can_rating >= $NEUTRAL_RATING) { $calc = $can_rating / $ratingTotals[$person] * $canBudget[$person]; if ($roundCalc == "true") { $adjustedCans = round($calc); } else { $adjustedCans = round($calc, 2); } $peopleTotals[$person][$page] = $adjustedCans; $canTotals[$page] = $canTotals[$page] + $adjustedCans; } } } $outputArray = array(); foreach ($people as $person) { foreach ($pageids as $page) { $outputArray[$person][$page] = 0; } } $table = HTML::table(array('cellpadding' => '5', 'cellspacing' => '1', 'border' => '0')); $tr = HTML::tr(); $td = HTML::td(array('bgcolor' => '#FFFFFF')); $td->pushContent(" "); $tr->pushContent($td); foreach ($people as $person) { $td = HTML::td(array('bgcolor' => '#FFFFFF')); $td->pushContent(HTML::a(array('href' => WikiURL($person), 'class' => 'wiki'), SplitPagename($person))); //$td->pushContent(WikiLink(" $person ")); $tr->pushContent($td); } $td = HTML::td(array('bgcolor' => '#FFFFFF')); $td->pushContent(_("Total Units")); $tr->pushContent($td); $td = HTML::td(array('bgcolor' => '#FFFFFF')); $td->pushContent(_("Total Voters")); $tr->pushContent($td); $table->pushContent($tr); for ($i = 0; $i < count($pageids); $i++) { $total_cans = 0; for ($j = 0; $j < count($people); $j++) { $td = HTML::td(array('align' => 'right')); $cans_per_soda = $peopleTotals[$people[$j]][$pageids[$i]]; $total_cans = $total_cans + $cans_per_soda; $outputArray[$people[$j]][$pageids[$i]] = $cans_per_soda; } } foreach ($people as $person) { $min_soda = ""; $min_cans = 9999999; //9 million, serving as "infinity" $total_cans = 0; foreach ($pageids as $page) { $cur_soda_cans = $outputArray[$person][$page]; if ($cur_soda_cans < $min_cans && $cur_soda_cans > 0) { $min_cans = $cur_soda_cans; $min_soda = $page; } $total_cans = $total_cans + $cur_soda_cans; } if ($total_cans != $canBudget[$person] && $total_cans > 0) { $diff = $canBudget[$person] - $total_cans; $outputArray[$person][$min_soda] = $outputArray[$person][$min_soda] + $diff; } } for ($i = 0; $i < count($pageids); $i++) { $tr = HTML::tr(); $td = HTML::td(array('align' => 'left', 'bgcolor' => '#f7f7f7')); $td->pushContent(HTML::a(array('href' => WikiURL($pageids[$i]), 'class' => 'wiki'), SplitPagename($pageids[$i]))); $tr->pushContent($td); $total_cans = 0; $total_voters = 0; for ($j = 0; $j < count($people); $j++) { $td = HTML::td(array('align' => 'right', 'bgcolor' => '#f7f7f7')); $output = $outputArray[$people[$j]][$pageids[$i]]; $total_cans = $total_cans + $output; if ($output == "") { $output = "-"; } else { $total_voters++; } $td->pushContent($output); $tr->pushContent($td); } if ($total_cans == "") { $total_cans = "-"; } if ($total_voters == "") { $total_voters = "-"; } $td = HTML::td(array('align' => 'right')); $td->pushContent($total_cans); $tr->pushContent($td); $td = HTML::td(array('align' => 'right')); $td->pushContent($total_voters); $tr->pushContent($td); $table->pushContent($tr); } $tr = HTML::tr(); $td = HTML::td(array('align' => 'left')); $td->pushContent(HTML::strong(_("Total Budget"))); $tr->pushContent($td); $cans_total = 0; $total_voters = 0; for ($i = 0; $i < count($people); $i++) { $td = HTML::td(array('align' => 'right')); $cans_for_soda = 0; foreach ($pageids as $page) { $cans_for_soda = $cans_for_soda + $outputArray[$people[$i]][$page]; } $cans = $cans_for_soda; $cans_total = $cans_total + $cans; if ($cans == "") { $cans = "-"; } else { $total_voters++; } $td->pushContent(HTML::strong($cans)); $tr->pushContent($td); } $td = HTML::td(array('align' => 'right')); $td->pushContent(HTML::strong($cans_total)); $tr->pushContent($td); $td = HTML::td(array('align' => 'right')); $td->pushContent(HTML::strong($total_voters)); $tr->pushContent($td); $table->pushContent($tr); $table2 = HTML::table(array('bgcolor' => '#dedfdf')); $table2->pushContent(HTML::tr(HTML::td($table))); $html->pushContent($table2); return $html; }