当前位置: 首页>>代码示例>>PHP>>正文


PHP get_filesdir_from_context函数代码示例

本文整理汇总了PHP中get_filesdir_from_context函数的典型用法代码示例。如果您正苦于以下问题:PHP get_filesdir_from_context函数的具体用法?PHP get_filesdir_from_context怎么用?PHP get_filesdir_from_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_filesdir_from_context函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: question_edit_form

 function question_edit_form($submiturl, $question, $category, $contexts, $formeditable = true)
 {
     $this->question = $question;
     $this->contexts = $contexts;
     $this->category = $category;
     $this->categorycontext = get_context_instance_by_id($category->contextid);
     //course id or site id depending on question cat context
     $this->coursefilesid = get_filesdir_from_context(get_context_instance_by_id($category->contextid));
     parent::moodleform($submiturl, null, 'post', '', null, $formeditable);
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:10,代码来源:edit_question_form.php

示例2: list

 /// If we are moving a question, check we have permission to move it from
 /// whence it came. (Where we are moving to is validated by the form.)
 list($newcatid) = explode(',', $fromform->category);
 if (!empty($question->id) && $newcatid != $question->category) {
     question_require_capability_on($question, 'move');
 }
 /// Ensure we redirect back to the category the question is being saved into.
 $returnurl = new moodle_url($returnurl);
 $returnurl->param('category', $fromform->category);
 $returnurl = $returnurl->out();
 /// Call the appropriate method.
 if ($movecontext) {
     list($tocatid, $tocontextid) = explode(',', $fromform->categorymoveto);
     $tocontext = get_context_instance_by_id($tocontextid);
     require_capability('moodle/question:add', $tocontext);
     if (get_filesdir_from_context($categorycontext) != get_filesdir_from_context($tocontext)) {
         $movecontexturl = new moodle_url($CFG->wwwroot . '/question/contextmoveq.php', array('returnurl' => $returnurl, 'ids' => $question->id, 'tocatid' => $tocatid));
         if ($cmid) {
             $movecontexturl->param('cmid', $cmid);
         } else {
             $movecontexturl->param('courseid', $COURSE->id);
         }
         redirect($movecontexturl->out());
     }
 }
 $question = $QTYPES[$question->qtype]->save_question($question, $fromform, $COURSE, $wizardnow);
 if ($QTYPES[$question->qtype]->finished_edit_wizard($fromform) || $movecontext) {
     if ($inpopup) {
         notify(get_string('changessaved'), '');
         close_window(3);
     } else {
开发者ID:kai707,项目名称:ITSA-backup,代码行数:31,代码来源:question.php

示例3: question_showbank_actions

function question_showbank_actions($pageurl, $cm)
{
    global $CFG, $COURSE;
    /// Now, check for commands on this page and modify variables as necessary
    if (optional_param('move', false, PARAM_BOOL) and confirm_sesskey()) {
        /// Move selected questions to new category
        $category = required_param('category', PARAM_SEQUENCE);
        list($tocategoryid, $contextid) = explode(',', $category);
        if (!($tocategory = get_record('question_categories', 'id', $tocategoryid, 'contextid', $contextid))) {
            error('Could not find category record');
        }
        $tocontext = get_context_instance_by_id($contextid);
        require_capability('moodle/question:add', $tocontext);
        $rawdata = (array) data_submitted();
        $questionids = array();
        foreach ($rawdata as $key => $value) {
            // Parse input for question ids
            if (preg_match('!^q([0-9]+)$!', $key, $matches)) {
                $key = $matches[1];
                $questionids[] = $key;
            }
        }
        if ($questionids) {
            $questionidlist = join($questionids, ',');
            $sql = "SELECT q.*, c.contextid FROM {$CFG->prefix}question q, {$CFG->prefix}question_categories c WHERE q.id IN ({$questionidlist}) AND c.id = q.category";
            if (!($questions = get_records_sql($sql))) {
                print_error('questiondoesnotexist', 'question', $pageurl->out());
            }
            $checkforfiles = false;
            foreach ($questions as $question) {
                //check capabilities
                question_require_capability_on($question, 'move');
                $fromcontext = get_context_instance_by_id($question->contextid);
                if (get_filesdir_from_context($fromcontext) != get_filesdir_from_context($tocontext)) {
                    $checkforfiles = true;
                }
            }
            $returnurl = $pageurl->out(false, array('category' => "{$tocategoryid},{$contextid}"));
            if (!$checkforfiles) {
                if (!question_move_questions_to_category(implode(',', $questionids), $tocategory->id)) {
                    print_error('errormovingquestions', 'question', $returnurl, $questionids);
                }
                redirect($returnurl);
            } else {
                $movecontexturl = new moodle_url($CFG->wwwroot . '/question/contextmoveq.php', array('returnurl' => $returnurl, 'ids' => $questionidlist, 'tocatid' => $tocategoryid));
                if ($cm) {
                    $movecontexturl->param('cmid', $cm->id);
                } else {
                    $movecontexturl->param('courseid', $COURSE->id);
                }
                redirect($movecontexturl->out());
            }
        }
    }
    if (optional_param('deleteselected', false, PARAM_BOOL)) {
        // delete selected questions from the category
        if ($confirm = optional_param('confirm', '', PARAM_ALPHANUM) and confirm_sesskey()) {
            // teacher has already confirmed the action
            $deleteselected = required_param('deleteselected');
            if ($confirm == md5($deleteselected)) {
                if ($questionlist = explode(',', $deleteselected)) {
                    // for each question either hide it if it is in use or delete it
                    foreach ($questionlist as $questionid) {
                        question_require_capability_on($questionid, 'edit');
                        if (record_exists('quiz_question_instances', 'question', $questionid)) {
                            if (!set_field('question', 'hidden', 1, 'id', $questionid)) {
                                question_require_capability_on($questionid, 'edit');
                                error('Was not able to hide question');
                            }
                        } else {
                            delete_question($questionid);
                        }
                    }
                }
                redirect($pageurl->out());
            } else {
                error("Confirmation string was incorrect");
            }
        }
    }
    // Unhide a question
    if ($unhide = optional_param('unhide', '', PARAM_INT) and confirm_sesskey()) {
        question_require_capability_on($unhide, 'edit');
        if (!set_field('question', 'hidden', 0, 'id', $unhide)) {
            error("Failed to unhide the question.");
        }
        redirect($pageurl->out());
    }
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:89,代码来源:editlib.php

示例4: get_question_image

/**
* Returns a html link to the question image if there is one
*
* @return string The html image tag or the empy string if there is no image.
* @param object $question The question object
*/
function get_question_image($question)
{
    global $CFG;
    $img = '';
    if (!($category = get_record('question_categories', 'id', $question->category))) {
        error('invalid category id ' . $question->category);
    }
    $coursefilesdir = get_filesdir_from_context(get_context_instance_by_id($category->contextid));
    if ($question->image) {
        if (substr(strtolower($question->image), 0, 7) == 'http://') {
            $img .= $question->image;
        } else {
            require_once $CFG->libdir . '/filelib.php';
            $img = get_file_url("{$coursefilesdir}/{$question->image}");
        }
    }
    return $img;
}
开发者ID:e-rasvet,项目名称:reader,代码行数:24,代码来源:questionlib.php

示例5: get_context_instance_by_id

}
$tocat->context = get_context_instance_by_id($tocat->contextid);
require_capability('moodle/question:add', $tocat->context);
$tocoursefilesid = get_filesdir_from_context($tocat->context);
$urls = array();
if ($tocoursefilesid == SITEID) {
    $toareaname = get_string('filesareasite', 'question');
} else {
    $toareaname = get_string('filesareacourse', 'question');
}
$fromcoursefilesid = 0;
foreach (array_keys($questions) as $id) {
    question_require_capability_on($questions[$id], 'move');
    get_question_options($questions[$id]);
    $questions[$id]->context = get_context_instance_by_id($questions[$id]->contextid);
    $thisfilesid = get_filesdir_from_context($questions[$id]->context);
    if ($fromcoursefilesid && $thisfilesid != $fromcoursefilesid) {
        error('You can\'t use this script to move questions that have files associated with them from different areas.');
    } else {
        $fromcoursefilesid = $thisfilesid;
    }
    if ($tocoursefilesid != $fromcoursefilesid) {
        $urls = array_merge_recursive($urls, $QTYPES[$questions[$id]->qtype]->find_file_links($questions[$id], $fromcoursefilesid));
    }
}
$brokenurls = array();
foreach (array_keys($urls) as $url) {
    if (!file_exists($CFG->dataroot . "/{$fromcoursefilesid}/" . $url)) {
        $brokenurls[] = $url;
    }
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:31,代码来源:contextmoveq.php

示例6: print_error

if (!($cattomove = $DB->get_record('question_categories', array('id' => $cattomove)))) {
    print_error('invalidcategoryidtomove', 'question', $onerrorurl);
}
if ($cattomove->contextid == $contextto) {
    print_error('contexterror', '', $onerrorurl);
}
$cattomove->categorylist = question_categorylist($cattomove->id);
$thispageurl->params(array('cattomove' => $cattomove->id, 'toparent' => "{$toparent->id},{$toparent->contextid}", 'totop' => $totop));
$contextfrom = get_context_instance_by_id($cattomove->contextid);
$contextto = get_context_instance_by_id($contextto);
$contexttostring = print_context_name($contextto);
require_capability('moodle/question:managecategory', $contextfrom);
require_capability('moodle/question:managecategory', $contextto);
$fromcoursefilesid = get_filesdir_from_context($contextfrom);
//siteid or courseid
$tocoursefilesid = get_filesdir_from_context($contextto);
//siteid or courseid
if ($fromcoursefilesid != $tocoursefilesid) {
    list($usql, $params) = $DB->get_in_or_equal(explode(',', $cattomove->categorylist));
    $questions = $DB->get_records_select('question', "category {$usql}", $params);
    $urls = array();
    if ($questions) {
        foreach ($questions as $id => $question) {
            $QTYPES[$questions[$id]->qtype]->get_question_options($questions[$id]);
            $urls = array_merge_recursive($urls, $QTYPES[$questions[$id]->qtype]->find_file_links($questions[$id], $fromcoursefilesid));
        }
    }
    ksort($urls);
} else {
    $urls = array();
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:contextmove.php


注:本文中的get_filesdir_from_context函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。