/** * Remove formats that are less specific * * @param string[] $allFormats * * @return string[] */ function filterFormats($allFormats) { if (in_array('Video', $allFormats) && in_array('DVD', $allFormats)) { $allFormats = array_remove_by_value($allFormats, 'Video'); } elseif (in_array('Musical Score', $allFormats) && in_array('Book', $allFormats)) { $allFormats = array_remove_by_value($allFormats, 'Book'); } elseif (in_array('Audio CD', $allFormats) && in_array('Sound Recording', $allFormats)) { $allFormats = array_remove_by_value($allFormats, 'Sound Recording'); } elseif (in_array('Book Club Kit', $allFormats) && in_array('Book', $allFormats)) { $allFormats = array_remove_by_value($allFormats, 'Book'); } elseif (in_array('Book', $allFormats) && in_array('Manuscript', $allFormats)) { $allFormats = array_remove_by_value($allFormats, 'Manuscript'); } return $allFormats; }
/** * Copies the outcomes (and associates to course if necessary) from * a source emarking activity to a destination one * * @param unknown $emarkingsrc * @param unknown $emarkingdst * @return boolean */ function emarking_copy_course_outcomes($emarkingsrc, $emarkingdst) { global $DB, $CFG; require_once $CFG->libdir . "/gradelib.php"; require_once $CFG->libdir . "/grade/grade_outcome.php"; if (!($coursesrc = $DB->get_record('course', array('id' => $emarkingsrc->course)))) { return false; } if (!($coursedst = $DB->get_record('course', array('id' => $emarkingdst->course)))) { return false; } $params = array($coursesrc->id, $emarkingsrc->id); $sql = "SELECT outcomeid, itemnumber\n FROM {grade_items}\n WHERE courseid=? AND outcomeid IS NOT NULL\n AND itemmodule = 'emarking' AND iteminstance = ?\n AND itemtype = 'mod'"; $tocopy = $DB->get_records_sql($sql, $params); $outcomesready = array(); foreach ($tocopy as $outcomeused) { $outcomesready[] = $outcomeused->outcomeid; } $params = array($coursedst->id, $emarkingdst->id); $sql = "SELECT outcomeid, itemnumber\n FROM {grade_items}\n WHERE courseid=? AND outcomeid IS NOT NULL\n AND itemmodule = 'emarking' AND iteminstance = ?\n AND itemtype = 'mod'"; $realused = $DB->get_records_sql($sql, $params); $maxitemnumber = 999; foreach ($realused as $outcomeused) { if (array_search($outcomeused->outcomeid, $outcomesready)) { array_remove_by_value($outcomesready, $outcomeused->outcomeid); } if ($outcomeused->itemnumber > $maxitemnumber) { $maxitemnumber = $outcomeused->itemnumber; } } $outcomesdst = grade_outcome::fetch_all_available($emarkingdst->course); $outcomesavailable = array(); foreach ($outcomesdst as $outcomedst) { $outcomesavailable[] = $outcomedst->id; } if ($maxitemnumber < 1000) { $maxitemnumber = 1000; } foreach ($outcomesready as $outcometocopy) { $outcome = grade_outcome::fetch(array('id' => $outcometocopy)); if (!array_search($outcometocopy, $outcomesavailable)) { $outcome->use_in($emarkingdst->course); } $outcomeitem = new grade_item(); $outcomeitem->courseid = $emarkingdst->course; $outcomeitem->itemtype = 'mod'; $outcomeitem->itemmodule = 'emarking'; $outcomeitem->iteminstance = $emarkingdst->id; $outcomeitem->itemnumber = $maxitemnumber; $outcomeitem->itemname = $outcome->fullname; $outcomeitem->outcomeid = $outcome->id; $outcomeitem->gradetype = GRADE_TYPE_SCALE; $outcomeitem->scaleid = $outcome->scaleid; $outcomeitem->insert(); $maxitemnumber++; } return true; }