function dailyCohortActiveStudents($threshold, $start_time, $end_time) { $conn = new mysqli("localhost", "root", "admin", "moodledb"); if ($conn->connect_errno) { echo "failed to connect to mysql:(" . $conn->connect_errno . ") " . $mysql->connect_error; } $code = "select id,name from mdl_cohort;"; $resp = $conn->query($code); $name_map = array(); $namelist = array(); while ($row = $resp->fetch_assoc()) { $name_map[$row['id']] = convert_name($row['name'], $namelist); } $code = "select " . "l.userid, l.timecreated, cm.cohortid " . "from " . "mdl_logstore_standard_log l,mdl_cohort_members cm, mdl_role_assignments r " . "where " . "l.userid=cm.userid and r.userid = l.userid " . "and r.roleid=5 order by l.timecreated asc;"; $resp = $conn->query($code); $days = array(); $days[$start_time] = createEmptyCohortList($name_map); $next_day = $start_time + 86400; $day_rec = array(); while ($row = $resp->fetch_assoc()) { // $key = convert_name($row['name'],$namelist); while ($row['timecreated'] > $next_day) { // aggregate $days[$start_time] = createEmptyCohortList($name_map); //create a new thingy for today's aggregation foreach ($day_rec as $insti) { if ($insti != null) { foreach ($insti as $usrCount) { if ($usrCount >= $threshold) { $days[$start_time][$name_map[$row['cohortid']]] += 1; } } } } //iterate $start_time = $next_day; $day_rec = createEmptyCohortList($name_map); //print_r($day_rec); $next_day += 86400; } // if(isset($day_rec[$row['cohortid']])) // print_r( $day_rec[$row['cohortid']]); if (!isset($day_rec[$row['cohortid']])) { echo "--------being set------\n"; // $day_rec[$row['cohortid']] = array($row['userid'] => 0); // $day_rec[$row['cohortid']] = [$row['userid'] => 0]; // $day_rec[$row['cohortid']][$row['userid']] = 0; } // echo '---'.$day_rec[$row['cohortid']][$row['userid']].'---'; $day_rec[$row['cohortid']][$row['userid']] = $day_rec[$row['cohortid']][$row['userid']] + 1; //$days[$start_time][$name_map[$row['cohortid']]] += 1; } //$return_obj['column_names'] = ['institutions','values']; //$return_obj['values'] = $days; //echo json_encode($return_obj); }
function dailyLTI($start_time, $end_time) { global $DB; $code = "select id,name from mdl_cohort;"; $name_map = array(); $namelist = array(); $result = $DB->get_records_sql($code, null); foreach ($result as $row) { // while ($row = $resp->fetch_assoc()) { $name_map[$row->id] = convert_name($row->name, $namelist); } $code = "select " . "l.timecreated, cm.cohortid " . "from " . "mdl_logstore_standard_log l,mdl_cohort_members cm, mdl_role_assignments r " . "where " . "l.userid=cm.userid and r.userid = l.userid " . "and l.component = 'mod_lti' " . "and r.roleid=5 order by l.timecreated asc;"; $result = $DB->get_records_sql($code, null); $days = array(); $days[$start_time] = createEmptyCohortList($name_map); $next_day = $start_time + 86400; foreach ($result as $row) { while ($row->timecreated > $next_day) { $start_time = $next_day; $days[$start_time] = createEmptyCohortList($name_map); $next_day += 86400; } $days[$start_time][$name_map[$row->cohortid]] += 1; } $return_obj['column_names'] = ['institutions', 'values']; $return_obj['values'] = $days; echo json_encode($return_obj); }