private function _getRandomMep($campaign_id) { /* * Simply put, we need to find a random MEP giving is score. * So we generate a 0<=x<=100 random x and then we pick one mep * among the ones who have a score greater or equal to x. * We will ponderate the scores with the number of call received divided * by the total number of call related to the campaign. */ if ($_REQUEST["country"]) { $country = $_REQUEST["country"]; } if (isset($country)) { $high_score = mqonefield("SELECT max(pond_scores) from lists where campaign='" . $campaign_id . "' AND country='{$country}' AND enabled='1';"); } else { $high_score = mqonefield("SELECT max(pond_scores) from lists where campaign='" . $campaign_id . "' AND enabled='1';"); } $threshold = mt_rand(1, $high_score); if ($high_score == 0) { $threshold = 0; } // lists contains the mep, they have score and pond_score as fields $query = "SELECT id FROM lists WHERE campaign='" . $campaign_id . "' AND enabled='1'"; if ($_REQUEST["country"]) { $country = $_REQUEST["country"]; } if (isset($country)) { $query .= " AND country='" . $country . "'"; } $query .= " AND pond_scores >= '" . $threshold . "'"; $query .= " ORDER BY RAND() LIMIT 1;"; $mep = mqonefield($query); return $mep; }
/** Get the list of campaigns */ function indexAction() { global $view; $view["campaign"] = mqlist("SELECT campaign.*, IF(datestart<=NOW() AND datestop>=NOW(),0,1) AS expired FROM campaign ORDER BY enabled DESC, datestart DESC"); for ($i = 0; $i < count($view["campaign"]); $i++) { $view["campaign"][$i]["count"] = mqonefield("SELECT COUNT(*) FROM lists WHERE campaign=" . $view["campaign"][$i]["id"]); $view["campaign"][$i]["calls"] = mqonefield("SELECT COUNT(*) FROM calls WHERE campaign=" . $view["campaign"][$i]["id"] . " AND (uuid!='' OR feedback!='')"); } render("adminlist"); }