Exemplo n.º 1
0
/**
 * Function to display episodes by category
 * @global stdClass $CFG
 * @global stdClass $DB
 * @global stdClass $USER
 * @param object $pcast
 * @param object $cm
 * @param int $groupmode
 * @param string $hook
 */
function pcast_display_category_episodes($pcast, $cm, $groupmode = 0, $hook = PCAST_SHOW_ALL_CATEGORIES)
{
    global $CFG, $DB, $USER;
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    // Get the current group
    if ($groupmode > 0) {
        $currentgroup = groups_get_activity_group($cm);
    } else {
        $currentgroup = 0;
    }
    // Get the episodes for this pcast
    $sql = pcast_get_episode_sql();
    $sql .= " WHERE p.pcastid = ? AND (p.approved =? OR p.userid =? )";
    if ($hook == PCAST_SHOW_ALL_CATEGORIES) {
        $sql .= " ORDER BY cat.name, ncat.name, p.name ASC";
        $episodes = $DB->get_records_sql($sql, array($pcast->id, '1', $USER->id));
    } else {
        if ($hook == PCAST_SHOW_NOT_CATEGORISED) {
            $sql .= " AND\r\n                p.topcategory = ?\r\n                ORDER BY p.name ASC";
            $episodes = $DB->get_records_sql($sql, array($pcast->id, '1', $USER->id, '0'));
        } else {
            $category->category = $hook;
            $category = pcast_get_itunes_categories($category, $pcast);
            if ($category->nestedcategory == 0) {
                $sql .= " AND\r\n                    p.topcategory = ?\r\n                    ORDER BY cat.name, ncat.name, p.name ASC";
                $episodes = $DB->get_records_sql($sql, array($pcast->id, '1', $USER->id, $category->topcategory));
            } else {
                $sql .= " AND\r\n                    p.nestedcategory = ?\r\n                    ORDER BY cat.name, ncat.name, p.name ASC";
                $episodes = $DB->get_records_sql($sql, array($pcast->id, '1', $USER->id, $category->nestedcategory));
            }
        }
    }
    //Get Group members
    $members = get_enrolled_users($context, 'mod/pcast:write', $currentgroup, 'u.id', 'u.id ASC');
    foreach ($episodes as $episode) {
        if (isset($members[$episode->userid]->id) and $members[$episode->userid]->id == $episode->userid) {
            //Display this episode (User is in the group)
            pcast_display_episode_brief($episode, $cm);
        } else {
            if ($currentgroup == 0) {
                //Display this episode (NO GROUPS USED)
                pcast_display_episode_brief($episode, $cm);
            }
        }
    }
}
Exemplo n.º 2
0
} else {
    if ($episode = $mform->get_data()) {
        $timenow = time();
        //Calculated settings
        if (empty($episode->id)) {
            $episode->pcastid = $pcast->id;
            $episode->timecreated = $timenow;
            $episode->userid = $USER->id;
            $episode->course = $COURSE->id;
        }
        $episode->summary = $episode->summary['text'];
        $episode->timemodified = $timenow;
        $episode->approved = 0;
        $episode->name = clean_param($episode->name, PARAM_ALPHANUM);
        // Get the episode category information
        $episode = pcast_get_itunes_categories($episode, $pcast);
        // Episode approval
        if (!$pcast->requireapproval or has_capability('mod/pcast:approve', $context)) {
            $episode->approved = 1;
        }
        if (empty($episode->id)) {
            //new entry
            $episode->id = $DB->insert_record('pcast_episodes', $episode);
            add_to_log($course->id, "pcast", "add episode", "view.php?id={$cm->id}&mode=" . PCAST_ADDENTRY_VIEW . "&hook={$episode->id}", $episode->id, $cm->id);
        } else {
            //existing entry
            $DB->update_record('pcast_episodes', $episode);
            add_to_log($course->id, "pcast", "update episode", "view.php?id={$cm->id}&mode=" . PCAST_ADDENTRY_VIEW . "&hook={$episode->id}", $episode->id, $cm->id);
        }
        file_save_draft_area_files($episode->mediafile, $context->id, 'mod_pcast', 'episode', $episode->id, array('subdirs' => 0, 'maxbytes' => $COURSE->maxbytes, 'maxfiles' => 1, 'filetypes' => array('audio', 'video')));
        //Get the duration if an MP3 file
Exemplo n.º 3
0
/**
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will update an existing instance with new data.
 *
 * @param stdClass $pcast An object from the form in mod_form.php
 * @global stdClass $DB
 * @global stdClass $USER
 * @return boolean Success/Fail
 */
function pcast_update_instance($pcast)
{
    global $DB, $USER;
    $pcast->timemodified = time();
    // Handle ratings
    if (empty($pcast->assessed)) {
        $pcast->assessed = 0;
    }
    if (empty($pcast->ratingtime) or empty($pcast->assessed)) {
        $pcast->assesstimestart = 0;
        $pcast->assesstimefinish = 0;
    }
    $pcast->id = $pcast->instance;
    // If no owner then set it to the instance creator.
    if (isset($pcast->enablerssitunes) and $pcast->enablerssitunes == 1) {
        if (!isset($pcast->userid)) {
            $pcast->userid = $USER->id;
        }
    }
    // Get the episode category information
    $defaults->topcategory = 0;
    $defaults->nestedcategory = 0;
    $pcast = pcast_get_itunes_categories($pcast, $defaults);
    # You may have to add extra stuff in here #
    $result = $DB->update_record('pcast', $pcast);
    $cmid = $pcast->coursemodule;
    $draftitemid = $pcast->image;
    // we need to use context now, so we need to make sure all needed info is already in db
    $context = get_context_instance(CONTEXT_MODULE, $cmid);
    if ($draftitemid) {
        file_save_draft_area_files($draftitemid, $context->id, 'mod_pcast', 'logo', 0, array('subdirs' => false));
    }
    return $result;
}