/** * This function returns a list of the current ilps units. * * @param limit how many units to display per page * @param offset current page to display * @return array (grandtotalpoints: number, count: integer, data: array) * */ public static function get_units($ilp, $offset = 0, $limit = 20) { ($results = get_records_sql_array("\n SELECT a.id, at.artefact AS unit, at.status, at.points, " . db_format_tsfield('targetcompletion') . ", " . db_format_tsfield('datecompleted') . ",\n a.title, a.description, a.parent\n FROM {artefact} a\n JOIN {artefact_ilps_unit} at ON at.artefact = a.id\n WHERE a.artefacttype = 'unit' AND a.parent = ?\n ORDER BY at.targetcompletion DESC", array($ilp), $offset, $limit)) || ($results = array()); // format the date and calculate grand total of points $grandtotalpoints = 0; $aquiredpoints = 0; $remainingpoints = ArtefactTypeilp::get_points($ilp); foreach ($results as $result) { $grandtotalpoints = $grandtotalpoints + $result->points; if (!empty($result->targetcompletion)) { $result->targetcompletion = strftime(get_string('strftimedate'), $result->targetcompletion); } if (!empty($result->datecompleted)) { $result->datecompleted = strftime(get_string('strftimedate'), $result->datecompleted); $aquiredpoints = $aquiredpoints + $result->points; $remainingpoints = $remainingpoints - $result->points; } } $result = array('grandtotalpoints' => $grandtotalpoints, 'aquiredpoints' => $aquiredpoints, 'remainingpoints' => $remainingpoints, 'count' => count_records('artefact', 'artefacttype', 'unit', 'parent', $ilp), 'data' => $results, 'offset' => $offset, 'limit' => $limit, 'id' => $ilp); return $result; }