Example #1
0
 /**
  * Creates and saves a clone of badge with all its properties.
  * Clone is not active by default and has 'Copy of' attached to its name.
  *
  * @return int ID of new badge.
  */
 public function make_clone()
 {
     global $DB, $USER;
     $fordb = new stdClass();
     foreach (get_object_vars($this) as $k => $v) {
         $fordb->{$k} = $v;
     }
     $fordb->name = get_string('copyof', 'badges', $this->name);
     $fordb->status = BADGE_STATUS_INACTIVE;
     $fordb->usercreated = $USER->id;
     $fordb->usermodified = $USER->id;
     $fordb->timecreated = time();
     $fordb->timemodified = time();
     unset($fordb->id);
     if ($fordb->notification > 1) {
         $fordb->nextcron = badges_calculate_message_schedule($fordb->notification);
     }
     $criteria = $fordb->criteria;
     unset($fordb->criteria);
     if ($new = $DB->insert_record('badge', $fordb, true)) {
         $newbadge = new badge($new);
         // Copy badge image.
         $fs = get_file_storage();
         if ($file = $fs->get_file($this->get_context()->id, 'badges', 'badgeimage', $this->id, '/', 'f1.png')) {
             if ($imagefile = $file->copy_content_to_temp()) {
                 badges_process_badge_image($newbadge, $imagefile);
             }
         }
         // Copy badge criteria.
         foreach ($this->criteria as $crit) {
             $crit->make_clone($new);
         }
         return $new;
     } else {
         throw new moodle_exception('error:clone', 'badges');
         return false;
     }
 }
Example #2
0
        $fordb->description = $data->description;
        $fordb->timecreated = $now;
        $fordb->timemodified = $now;
        $fordb->usercreated = $USER->id;
        $fordb->usermodified = $USER->id;
        $fordb->issuername = $data->issuername;
        $fordb->issuerurl = $data->issuerurl;
        $fordb->issuercontact = $data->issuercontact;
        $fordb->expiredate = $data->expiry == 1 ? $data->expiredate : null;
        $fordb->expireperiod = $data->expiry == 2 ? $data->expireperiod : null;
        $fordb->type = $type;
        $fordb->courseid = $type == BADGE_TYPE_COURSE ? $courseid : null;
        $fordb->messagesubject = get_string('messagesubject', 'badges');
        $fordb->message = get_string('messagebody', 'badges', html_writer::link($CFG->wwwroot . '/badges/mybadges.php', get_string('managebadges', 'badges')));
        $fordb->attachment = 1;
        $fordb->notification = BADGE_MESSAGE_NEVER;
        $fordb->status = BADGE_STATUS_INACTIVE;
        $newid = $DB->insert_record('badge', $fordb, true);
        $newbadge = new badge($newid);
        badges_process_badge_image($newbadge, $form->save_temp_file('image'));
        // If a user can configure badge criteria, they will be redirected to the criteria page.
        if (has_capability('moodle/badges:configurecriteria', $PAGE->context)) {
            redirect(new moodle_url('/badges/criteria.php', array('id' => $newid)));
        }
        redirect(new moodle_url('/badges/overview.php', array('id' => $newid)));
    }
}
echo $OUTPUT->header();
echo $OUTPUT->box('', 'notifyproblem hide', 'check_connection');
$form->display();
echo $OUTPUT->footer();