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


PHP choice_delete_responses函数代码示例

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


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

示例1: completion_info

        // Update completion state
        $completion = new completion_info($course);
        if ($completion->is_enabled($cm) && $choice->completionsubmit) {
            $completion->update_state($cm, COMPLETION_INCOMPLETE);
        }
        redirect("view.php?id={$cm->id}");
    }
}
$PAGE->set_title($choice->name);
$PAGE->set_heading($course->fullname);
/// Submit any new data if there is any
if (data_submitted() && is_enrolled($context, NULL, 'mod/choice:choose') && confirm_sesskey()) {
    $timenow = time();
    if (has_capability('mod/choice:deleteresponses', $context) && $action == 'delete') {
        //some responses need to be deleted
        choice_delete_responses($attemptids, $choice, $cm, $course);
        //delete responses.
        redirect("view.php?id={$cm->id}");
    }
    // Redirection after all POSTs breaks block editing, we need to be more specific!
    if ($choice->allowmultiple) {
        $answer = optional_param_array('answer', array(), PARAM_INT);
    } else {
        $answer = optional_param('answer', '', PARAM_INT);
    }
    if (!$choiceavailable) {
        $reason = current(array_keys($warnings));
        throw new moodle_exception($reason, 'choice', '', $warnings[$reason]);
    }
    if ($answer) {
        choice_user_submit_response($answer, $choice, $USER->id, $course, $cm);
开发者ID:pzhu2004,项目名称:moodle,代码行数:31,代码来源:view.php

示例2: test_answer_deleted

 /**
  * Test to ensure that event data is being stored correctly.
  */
 public function test_answer_deleted()
 {
     global $DB, $USER;
     // Generate user data.
     $user = $this->getDataGenerator()->create_user();
     $optionids = array_keys($DB->get_records('choice_options', array('choiceid' => $this->choice->id)));
     // Create the first answer.
     choice_user_submit_response($optionids[2], $this->choice, $user->id, $this->course, $this->cm);
     // Get the users response.
     $answer = $DB->get_record('choice_answers', array('userid' => $user->id, 'choiceid' => $this->choice->id), '*', $strictness = IGNORE_MULTIPLE);
     // Redirect event.
     $sink = $this->redirectEvents();
     // Now delete the answer.
     choice_delete_responses(array($answer->id), $this->choice, $this->cm, $this->course);
     // Get our event event.
     $events = $sink->get_events();
     $event = reset($events);
     // Data checking.
     $this->assertInstanceOf('\\mod_choice\\event\\answer_deleted', $event);
     $this->assertEquals($USER->id, $event->userid);
     $this->assertEquals($user->id, $event->relateduserid);
     $this->assertEquals(context_module::instance($this->choice->cmid), $event->get_context());
     $this->assertEquals($this->choice->id, $event->other['choiceid']);
     $this->assertEquals($answer->optionid, $event->other['optionid']);
     $this->assertEventContextNotUsed($event);
     $sink->close();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:30,代码来源:events_test.php

示例3: error

}
if (!($course = get_record("course", "id", $cm->course))) {
    error("Course module is misconfigured");
}
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/choice:readresponses', $context);
if (!($choice = choice_get_choice($cm->instance))) {
    error("Course module is incorrect");
}
$strchoice = get_string("modulename", "choice");
$strchoices = get_string("modulenameplural", "choice");
$strresponses = get_string("responses", "choice");
add_to_log($course->id, "choice", "report", "report.php?id={$cm->id}", "{$choice->id}", $cm->id);
if (data_submitted() && $action == 'delete' && has_capability('mod/choice:deleteresponses', $context) && confirm_sesskey()) {
    choice_delete_responses($attemptids, $choice->id);
    //delete responses.
    redirect("report.php?id={$cm->id}");
}
if (!$download) {
    $navigation = build_navigation($strresponses, $cm);
    print_header_simple(format_string($choice->name) . ": {$strresponses}", "", $navigation, "", '', true, update_module_button($cm->id, $course->id, $strchoice), navmenu($course, $cm));
    /// Check to see if groups are being used in this choice
    $groupmode = groups_get_activity_groupmode($cm);
    if ($groupmode) {
        groups_get_activity_group($cm, true);
        groups_print_activity_menu($cm, 'report.php?id=' . $id);
    }
} else {
    $groupmode = groups_get_activity_groupmode($cm);
}
开发者ID:henriquecrang,项目名称:e-UNI,代码行数:31,代码来源:report.php

示例4: delete_choice_responses

 /**
  * Delete the given submitted responses in a choice
  *
  * @param int $choiceid the choice instance id
  * @param array $responses the response ids,  empty for deleting all the user responses
  * @return array status information and warnings
  * @throws moodle_exception
  * @since Moodle 3.0
  */
 public static function delete_choice_responses($choiceid, $responses = array())
 {
     $status = false;
     $warnings = array();
     $params = self::validate_parameters(self::delete_choice_responses_parameters(), array('choiceid' => $choiceid, 'responses' => $responses));
     if (!($choice = choice_get_choice($params['choiceid']))) {
         throw new moodle_exception("invalidcoursemodule", "error");
     }
     list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/choice:choose', $context);
     // If we have the capability, delete all the passed responses.
     if (has_capability('mod/choice:deleteresponses', $context)) {
         if (empty($params['responses'])) {
             // Get all the responses for the choice.
             $params['responses'] = array_keys(choice_get_all_responses($choice));
         }
         $status = choice_delete_responses($params['responses'], $choice, $cm, $course);
     } else {
         if ($choice->allowupdate) {
             // Check if we can delate our own responses.
             $timenow = time();
             if ($choice->timeclose != 0) {
                 if ($timenow > $choice->timeclose) {
                     throw new moodle_exception("expired", "choice", '', userdate($choice->timeclose));
                 }
             }
             // Delete only our responses.
             $myresponses = array_keys(choice_get_my_response($choice));
             if (empty($params['responses'])) {
                 $todelete = $myresponses;
             } else {
                 $todelete = array();
                 foreach ($params['responses'] as $response) {
                     if (!in_array($response, $myresponses)) {
                         $warnings[] = array('item' => 'response', 'itemid' => $response, 'warningcode' => 'nopermissions', 'message' => 'No permission to delete this response');
                     } else {
                         $todelete[] = $response;
                     }
                 }
             }
             $status = choice_delete_responses($todelete, $choice, $cm, $course);
         } else {
             // The user requires the capability to delete responses.
             throw new required_capability_exception($context, 'mod/choice:deleteresponses', 'nopermissions', '');
         }
     }
     return array('status' => $status, 'warnings' => $warnings);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:59,代码来源:external.php


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