dbprefix}digimina_review WHERE user_guid=$user_guid AND status = 'pending'"; return get_data_row($query); } function digimina_get_user_accepted_review() { global $CONFIG; $user_guid = elgg_get_logged_in_user_guid(); $query = "SELECT * FROM {$CONFIG->dbprefix}digimina_review WHERE user_guid=$user_guid AND status = 'accepted'"; return get_data_row($query); } function digimina_get_user_completed_reviews() { global $CONFIG; $user_guid = elgg_get_logged_in_user_guid(); $query = "SELECT * FROM {$CONFIG->dbprefix}digimina_review WHERE user_guid=$user_guid AND status = 'completed'"; return get_data($query); } function digimina_add_for_review($user_guid, $test_guid, $competency_guid) { global $CONFIG; $now = time(); $query = "INSERT INTO {$CONFIG->dbprefix}digimina_review (user_guid, test_guid, competency_guid, status, time_created, time_updated) VALUES ($user_guid, $test_guid, $competency_guid, 'pending', $now, $now)"; return insert_data($query); } function digimina_is_section_in_review($test_guid, $competency_guid) { global $CONFIG; $query = "SELECT COUNT(*) AS count FROM {$CONFIG->dbprefix}digimina_review WHERE test_guid = $test_guid AND competency_guid = $competency_guid AND status IN ('pending', 'accepted')"; $count = get_data_row($query); if ((int)$count->count > 0) { return true; } return false; } function digimina_find_reviewer($owner_guid) { global $CONFIG; // XXX Using RAND() is slow on huge tables, need a better approach $query = "SELECT guid FROM {$CONFIG->dbprefix}users_entity WHERE guid NOT IN (SELECT user_guid FROM {$CONFIG->dbprefix}digimina_review WHERE status IN ('pending', 'accepted')) AND guid != $owner_guid ORDER BY RAND() LIMIT 1"; $guid = get_data_row($query); if ($guid) { return $guid->guid; } return false; } function digimina_update_active_review_status($review_id, $status) { global $CONFIG; $now = time(); $query = "UPDATE {$CONFIG->dbprefix}digimina_review SET status = '{$status}', time_updated = {$now} WHERE id = {$review_id}"; return update_data($query); }