Esempio n. 1
0
/**
 * This function looks for course descriptions that issue certificates and students who have met the criteria to receive a
 * certificate
 * @return bool This function will always return true as to not interfere with the rest of the cron process.
 */
function pm_issue_course_certificates()
{
    require_once elispm::lib('certificate.php');
    require_once elispm::lib('data/certificateissued.class.php');
    global $DB;
    $status = true;
    $certuser = null;
    $certusers = array();
    // Find all courses having certificate settings and are enabled.
    $params = array('entity_type' => CERTIFICATE_ENTITY_TYPE_COURSE, 'disable' => 0);
    $certcourses = $DB->get_recordset('local_elisprogram_certcfg', $params, '', 'id, entity_id');
    if (empty($certcourses)) {
        return $status;
    }
    foreach ($certcourses as $certcoursesetting) {
        /* Find all users who completed classes and have not already recieved
         * certificates for those classes
         */
        $subselect = "SELECT * ";
        $subfrom = "FROM {local_elisprogram_certissued} certissued ";
        $subwhere = "WHERE certissued.cert_setting_id = :certsettingid AND " . "certissued.cm_userid = clsenrol.userid AND clsenrol.completetime = certissued.timeissued ";
        $params = array('completestatus' => STUSTATUS_PASSED, 'locked' => 1, 'courseid' => $certcoursesetting->entity_id, 'certsettingid' => $certcoursesetting->id);
        $select = "SELECT clsenrol.userid, clsenrol.completetime ";
        $from = "FROM {local_elisprogram_cls} cmclass " . "INNER JOIN {local_elisprogram_cls_enrol} clsenrol ON clsenrol.classid = cmclass.id ";
        $where = "WHERE clsenrol.completestatusid = :completestatus AND clsenrol.locked = :locked AND " . "cmclass.courseid = :courseid AND " . "NOT EXISTS ({$subselect} {$subfrom} {$subwhere}) ORDER BY clsenrol.userid ";
        $certusers = $DB->get_recordset_sql($select . $from . $where, $params);
        $certissueddata = new certificateissued(0);
        $result = pm_issue_user_certificate($certcoursesetting->id, $certusers, $certissueddata);
        $certusers->close();
    }
    return $status;
}
 /**
  * This function tests issuing a user a certificate with an illegit data class
  */
 public function test_issue_user_certificate_illegit_data_class_fail()
 {
     global $DB, $CFG;
     $certsettingid = 1;
     $user = array();
     $user[0] = new stdClass();
     $user[0]->userid = 20;
     $user[0]->completetime = '1357851284';
     $certissued = new stdClass();
     $CFG->debug = DEBUG_NONE;
     $result = pm_issue_user_certificate($certsettingid, $user, $certissued);
     $record = $DB->get_record('local_elisprogram_certissued', array('timeissued' => '1357851284'));
     $this->assertEquals(false, $record);
     $this->assertEquals(false, $result);
 }