/** * Required parameter check * @param $params params extracted from the POST */ protected function validateParams($params) { $required = array('eventid', 'startdate', 'enddate', 'increment', 'userdefs'); foreach ($required as $arg) { if (!isset($params[$arg])) { $this->dieUsageMsg(array('missingparam', $arg)); } } // check if event id parses to an int greater than zero if ((int) $params['eventid'] < 0) { $this->dieUsage('Invalid event ID', 'badeventid'); } // check start and end date are of proper format if ($params['startdate'] != 0 && strptime(SpecialClickTracking::space_out_date($params['startdate']), "%Y %m %d") === false) { $this->dieUsage("startdate not in YYYYMMDD format: <<{$params['startdate']}>>", 'badstartdate'); } if ($params['enddate'] != 0 && strptime(SpecialClickTracking::space_out_date($params['enddate']), "%Y %m %d") === false) { $this->dieUsage("enddate not in YYYYMMDD format: <<{$params['enddate']}>>", 'badenddate'); } // check if increment is a positive int if ((int) $params['increment'] <= 0) { $this->dieUsage('Invalid increment', 'badincrement'); } if (json_decode($params['userdefs']) == null) { $this->dieUsage("Invalid JSON encoding <<{$params['userdefs']}>>", 'badjson'); } }
/** * Generates a query for a user type definition * @param $include_anon_users boolean, include anon users or not * @param $total_contribs array, nonempty if total contribs to be included * @param $contrib_1 array, nonempty AND conditions for user_contribs_1 * @param $contrib_2 array, nonempty AND conditions for user_contribs_1 * @param $contrib_3 array, nonempty AND conditions for user_contribs_1 * @return unknown_type query */ public static function buildUserDefConstraints($def) { $dbr = wfGetDB(DB_SLAVE); $include_anon_users = empty($def['anonymous']) ? array() : $def['anonymous']; $total_contribs = empty($def['total_contribs']) ? array() : $def['total_contribs']; $contrib_1 = empty($def['contrib_1']) ? array() : $def['contrib_1']; $contrib_2 = empty($def['contrib_2']) ? array() : $def['contrib_2']; $contrib_3 = empty($def['contrib_3']) ? array() : $def['contrib_3']; $or_conds = array(); $and_conds = array(); $sql = ""; if ((bool) $include_anon_users) { $or_conds[] = array("field" => "is_logged_in", "operation" => "=", "value" => "0"); } if (!empty($total_contribs)) { foreach ($total_contribs as $contribs) { $and_conds[] = array("field" => "user_total_contribs", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); } } if (!empty($contrib_1)) { foreach ($contrib_1 as $contribs) { $and_conds[] = array("field" => "user_contribs_span1", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); } } if (!empty($contrib_2)) { foreach ($contrib_2 as $contribs) { $and_conds[] = array("field" => "user_contribs_span2", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); } } if (!empty($contrib_3)) { foreach ($contrib_3 as $contribs) { $and_conds[] = array("field" => "user_contribs_span3", "operation" => SpecialClickTracking::validate_oper($contribs["operation"]), "value" => intval($contribs["value"])); } } foreach ($and_conds as $cond) { if (!empty($sql)) { $sql .= " AND "; } $sql .= $cond["field"] . " " . $cond["operation"] . " " . $dbr->addQuotes($cond["value"]); } foreach ($or_conds as $cond) { if (!empty($sql)) { $sql .= " OR "; } $sql .= $cond["field"] . " " . $cond["operation"] . " " . $dbr->addQuotes($cond["value"]); } return array($sql); }