/**
  * Cosntructor.
  *
  * @param \stdClass $collaborate
  * @param \stdClass $cm
  * @param \context_module $context
  * @param \mod_collaborate_renderer $renderer
  */
 public function __construct(\stdClass $collaborate, \cm_info $cm, \context_module $context, \mod_collaborate_renderer $renderer)
 {
     $this->collaborate = $collaborate;
     $this->cm = $cm;
     $this->context = $context;
     $this->renderer = $renderer;
     $this->course = $cm->get_course();
 }
 /**
  * Constructor
  *
  * @param \stdClass $collaborate
  * @param \cm_info $cm
  * @param \context_module $context;
  * @param \stdClass $user;
  * @throws \coding_exception
  * @throws \require_login_exception
  */
 public function __construct(\stdClass $collaborate, \cm_info $cm, \context_module $context, \stdClass $user)
 {
     global $DB;
     $this->collaborate = $collaborate;
     $this->course = $cm->get_course();
     $this->cm = $cm;
     $this->id = $cm->instance;
     $this->context = $context;
     $this->user = $user;
     $this->collaborate = $DB->get_record('collaborate', array('id' => $this->id), '*', MUST_EXIST);
     $this->api = api::get_api();
 }
/**
 *
 * @param cm_info $cm
 * @param stdClass $stopwatch
 * @param int $duration
 */
function mod_stopwatch_update_timer(cm_info $cm, $stopwatch, $duration)
{
    global $USER, $DB, $CFG;
    require_once $CFG->libdir . '/completionlib.php';
    $record = $DB->get_record('stopwatch_user', array('stopwatchid' => $cm->instance, 'courseid' => $cm->course, 'userid' => $USER->id));
    if ($record) {
        $data = array('id' => $record->id, 'timemodified' => time(), 'duration' => $duration);
        $DB->update_record('stopwatch_user', $data);
    } else {
        $data = array('courseid' => $cm->course, 'stopwatchid' => $cm->instance, 'userid' => $USER->id, 'timecreated' => time(), 'timemodified' => time(), 'duration' => $duration);
        $DB->insert_record('stopwatch_user', $data);
    }
    // Update completion state
    $completion = new completion_info($cm->get_course());
    if ($completion->is_enabled($cm) && $stopwatch->completiontimed) {
        $completion->update_state($cm, COMPLETION_COMPLETE);
    }
}
/**
 * @param cm_info $cm
 * @return bool
 */
function navbuttons_mod_assignment_showbuttons($cm)
{
    global $DB, $CFG, $USER;
    if (!($assignment = $DB->get_record('assignment', array('id' => $cm->instance)))) {
        return true;
        // Not quite sure what went wrong
    }
    $type = $assignment->assignmenttype;
    if ($type == 'offline') {
        return true;
        // Cannot track 'offline' assignments
    }
    require_once $CFG->dirroot . '/mod/assignment/type/' . $type . '/assignment.class.php';
    $class = 'assignment_' . $type;
    /** @var assignment_base $instance */
    $instance = new $class($cm->id, $assignment, $cm, $cm->get_course());
    if (!($submission = $instance->get_submission($USER->id))) {
        return false;
        // No submission
    }
    if ($type == 'upload' || $type == 'uploadpdf') {
        if ($instance->drafts_tracked()) {
            if ($instance->is_finalized($submission)) {
                return true;
                // Upload submission is 'finalised'
            } else {
                return false;
            }
        }
    }
    if ($submission->timemodified > 0) {
        return true;
        // Submission has a 'modified' time
    }
    return false;
}
Exemplo n.º 5
0
/**
 * Returns the move action.
 *
 * @param cm_info $mod The module to produce a move button for
 * @param int $sr The section to link back to (used for creating the links)
 * @return The markup for the move action, or an empty string if not available.
 */
function course_get_cm_move(cm_info $mod, $sr = null)
{
    global $OUTPUT;
    static $str;
    static $baseurl;
    $modcontext = context_module::instance($mod->id);
    $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
    if (!isset($str)) {
        $str = get_strings(array('move'));
    }
    if (!isset($baseurl)) {
        $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
        if ($sr !== null) {
            $baseurl->param('sr', $sr);
        }
    }
    if ($hasmanageactivities) {
        $pixicon = 'i/dragdrop';
        if (!course_ajax_enabled($mod->get_course())) {
            // Override for course frontpage until we get drag/drop working there.
            $pixicon = 't/move';
        }
        return html_writer::link(new moodle_url($baseurl, array('copy' => $mod->id)), $OUTPUT->pix_icon($pixicon, $str->move, 'moodle', array('class' => 'iconsmall', 'title' => '')), array('class' => 'editing_move', 'data-action' => 'move'));
    }
    return '';
}
Exemplo n.º 6
0
 /**
  * Renders HTML to show course module availability information (for someone who isn't allowed
  * to see the activity itself, or for staff)
  *
  * @param cm_info $mod
  * @param array $displayoptions
  * @return string
  */
 public function course_section_cm_availability(cm_info $mod, $displayoptions = array())
 {
     global $CFG;
     if (!$mod->uservisible) {
         // this is a student who is not allowed to see the module but might be allowed
         // to see availability info (i.e. "Available from ...")
         if (!empty($mod->availableinfo)) {
             $formattedinfo = \core_availability\info::format_info($mod->availableinfo, $mod->get_course());
             $output = html_writer::tag('div', $formattedinfo, array('class' => 'availabilityinfo'));
         }
         return $output;
     }
     // this is a teacher who is allowed to see module but still should see the
     // information that module is not available to all/some students
     $modcontext = context_module::instance($mod->id);
     $canviewhidden = has_capability('moodle/course:viewhiddenactivities', $modcontext);
     if ($canviewhidden && !empty($CFG->enableavailability)) {
         // Don't add availability information if user is not editing and activity is hidden.
         if ($mod->visible || $this->page->user_is_editing()) {
             $hidinfoclass = '';
             if (!$mod->visible) {
                 $hidinfoclass = 'hide';
             }
             $ci = new \core_availability\info_module($mod);
             $fullinfo = $ci->get_full_information();
             if ($fullinfo) {
                 $formattedinfo = \core_availability\info::format_info($fullinfo, $mod->get_course());
                 return html_writer::div($formattedinfo, 'availabilityinfo ' . $hidinfoclass);
             }
         }
     }
     return '';
 }
Exemplo n.º 7
0
 /**
  * Constructs with item details.
  *
  * @param \cm_info $cm Course-module object
  */
 public function __construct(\cm_info $cm)
 {
     parent::__construct($cm->get_course(), $cm->visible, $cm->availability);
     $this->cm = $cm;
 }
Exemplo n.º 8
0
/**
 * Retrieves the completion status of the LO for an specific user (100 if this is completed and 0 if not), returns NULL if completion tracking is not enabled for that LO (or the entire course) and if the LO corresponds to a section or course LO
 * @author elever
 * @param cm_info $coursemodule_info : Moodle object with information of a module in a course
 * @param int $userid : moodle identifier of the user
 * @return int $completion_status | null
 */
function block_intuitel_get_completion_status(\cm_info $coursemodule_info, $userid)
{
    $completion = new \completion_info($coursemodule_info->get_course());
    if ($completion->is_enabled($coursemodule_info) > 0) {
        //check if completion is enabled for a particular course and activity, returns 0 if it is not enabled, 1 if completion is enabled and is manual and 2 if automatic
        $completion_status = $completion->get_data($coursemodule_info, false, $userid);
        //this object has also information about viewed...is the row of the related table in the database
        $completion_status = $completion_status->completionstate;
        if ($completion_status > 0) {
            $completion_status = 100;
            // moodle completion system retrieves 0 when the activity is not completed, 1 when the activity is completed (regardless of mark), 2 when the activity is completed with a passed mark, 3 when the activity is completed but with a fail mark
        }
    } else {
        $completion_status = null;
    }
    return $completion_status;
}
Exemplo n.º 9
0
function mod_forumng_cm_info_view(cm_info $cm)
{
    global $CFG;
    require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php';
    static $forums = null;
    if ($forums === null) {
        // Read tracking is for real users only
        if (mod_forumng::enabled_read_tracking() && !isguestuser() && isloggedin()) {
            $forums = mod_forumng::get_course_forums($cm->get_course(), 0, mod_forumng::UNREAD_BINARY);
        } else {
            $forums = array();
        }
    }
    // If current forum is listed, check whether it's unread or not
    if (array_key_exists($cm->instance, $forums)) {
        if ($forums[$cm->instance]->has_unread_discussions()) {
            $cm->set_after_link('<span class="unread">' . get_string('hasunreadposts', 'forumng') . '</span>');
        }
    }
}