function browseExperimentsByActivity($page = 1, $limit = 10, $override = false) { global $db; $sqlCmd = "SELECT \texperiments.*, \n\t\t\t\t\t\t(experiments.rating / experiments.rating_votes ) AS rating_comp,\n\t\t\t\t\t\tusers.firstname AS owner_firstname, \n\t\t\t\t\t\tusers.lastname AS owner_lastname\n\t\t\t\t\t\tFROM experiments \n\t\t\t\t\t\tLEFT JOIN ( users ) ON ( users.user_id = experiments.owner_id ) \n\t\t\t\t\t\tWHERE experiments.hidden = 0\n\t\t\t\t\t\tAND experiments.activity = 0"; $output = $db->query($sqlCmd); if ($db->numOfRows) { for ($i = 0; $i < count($output); $i++) { $session_count = countNumberOfSessions($output[$i]['experiment_id']); $output[$i]['session_count'] = $session_count; } uasort($output, 'session_cmp'); $output = array_reverse($output); return packageBrowseExperimentResults($output, $page, $limit, $override); } return false; }
function packageBrowseActivityResults($results, $page = 1, $limit = 10, $override = false) { global $db; $output = array(); if ($page != -1) { $offset = ($page - 1) * $limit; $results = array_splice($results, $offset, $limit); if (!$override) { foreach ($results as $result) { $sessioncount = countNumberOfSessions($result['experiment_id']); $contribcount = countNumberOfContributors($result['experiment_id']); $output[$result['experiment_id']] = array("meta" => $result, "tags" => array(), "relevancy" => 0, 'session_count' => $sessioncount, 'contrib_count' => $contribcount); } } else { foreach ($results as $result) { $contribcount = isset($result['contrib_count']) ? $result['contrib_count'] : countNumberOfContributors($result['experiment_id']); $sessioncount = isset($result['session_count']) ? $result['session_count'] : countNumberOfContributors($result['experiment_id']); $output[] = array("meta" => $result, "tags" => array(), "relevancy" => 0, 'session_count' => $sessioncount, 'contrib_count' => $contribcount); } } return $output; } else { return count($results); } return $output; }