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


PHP assign::delete_instance方法代码示例

本文整理汇总了PHP中assign::delete_instance方法的典型用法代码示例。如果您正苦于以下问题:PHP assign::delete_instance方法的具体用法?PHP assign::delete_instance怎么用?PHP assign::delete_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在assign的用法示例。


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

示例1: assign_delete_instance

/**
 * delete an assignment instance
 * @param int $id
 * @return bool
 */
function assign_delete_instance($id)
{
    global $CFG;
    require_once $CFG->dirroot . '/mod/assign/locallib.php';
    $cm = get_coursemodule_from_instance('assign', $id, 0, false, MUST_EXIST);
    $context = context_module::instance($cm->id);
    $assignment = new assign($context, null, null);
    return $assignment->delete_instance();
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:14,代码来源:lib.php

示例2: upgrade_assignment


//.........这里部分代码省略.........
                 // Submission has been graded - create a grade record.
                 $grade = new stdClass();
                 $grade->assignment = $newassignment->get_instance()->id;
                 $grade->userid = $oldsubmission->userid;
                 $grade->grader = $oldsubmission->teacher;
                 $grade->timemodified = $oldsubmission->timemarked;
                 $grade->timecreated = $oldsubmission->timecreated;
                 $grade->grade = $oldsubmission->grade;
                 if ($oldsubmission->mailed) {
                     // The mailed flag goes in the flags table.
                     $flags = new stdClass();
                     $flags->userid = $oldsubmission->userid;
                     $flags->assignment = $newassignment->get_instance()->id;
                     $flags->mailed = 1;
                     $DB->insert_record('assign_user_flags', $flags);
                 }
                 $grade->id = $DB->insert_record('assign_grades', $grade);
                 if (!$grade->id) {
                     $log .= get_string('couldnotinsertgrade', 'mod_assign', $grade->userid);
                     $rollback = true;
                 }
                 // Copy any grading instances.
                 if ($gradingarea) {
                     $gradeidmap[$grade->id] = $oldsubmission->id;
                     foreach ($gradingdefinitions as $definition) {
                         $params = array('definitionid' => $definition->id, 'itemid' => $oldsubmission->id);
                         $DB->set_field('grading_instances', 'itemid', $grade->id, $params);
                     }
                 }
                 foreach ($newassignment->get_feedback_plugins() as $plugin) {
                     if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
                         if (!$plugin->upgrade($oldcontext, $oldassignment, $oldsubmission, $grade, $log)) {
                             $rollback = true;
                         }
                     }
                 }
             }
         }
         $newassignment->update_calendar($newcoursemodule->id);
         // Reassociate grade_items from the old assignment instance to the new assign instance.
         // This includes outcome linked grade_items.
         $params = array('assign', $newassignment->get_instance()->id, 'assignment', $oldassignment->id);
         $sql = 'UPDATE {grade_items} SET itemmodule = ?, iteminstance = ? WHERE itemmodule = ? AND iteminstance = ?';
         $DB->execute($sql, $params);
         // Create a mapping record to map urls from the old to the new assignment.
         $mapping = new stdClass();
         $mapping->oldcmid = $oldcoursemodule->id;
         $mapping->oldinstance = $oldassignment->id;
         $mapping->newcmid = $newcoursemodule->id;
         $mapping->newinstance = $newassignment->get_instance()->id;
         $mapping->timecreated = time();
         $DB->insert_record('assignment_upgrade', $mapping);
         $gradesdone = true;
     } catch (Exception $exception) {
         $rollback = true;
         $log .= get_string('conversionexception', 'mod_assign', $exception->getMessage());
     }
     if ($rollback) {
         // Roll back the grades changes.
         if ($gradesdone) {
             // Reassociate grade_items from the new assign instance to the old assignment instance.
             $params = array('assignment', $oldassignment->id, 'assign', $newassignment->get_instance()->id);
             $sql = 'UPDATE {grade_items} SET itemmodule = ?, iteminstance = ? WHERE itemmodule = ? AND iteminstance = ?';
             $DB->execute($sql, $params);
         }
         // Roll back the completion changes.
         if ($completiondone) {
             $DB->set_field('course_modules_completion', 'coursemoduleid', $oldcoursemodule->id, array('coursemoduleid' => $newcoursemodule->id));
             $allcriteria = $DB->get_records('course_completion_criteria', array('moduleinstance' => $newcoursemodule->id));
             foreach ($allcriteria as $criteria) {
                 $criteria->module = 'assignment';
                 $criteria->moduleinstance = $oldcoursemodule->id;
                 $DB->update_record('course_completion_criteria', $criteria);
             }
         }
         // Roll back the log changes.
         $logparams = array('cmid' => $newcoursemodule->id, 'course' => $newcoursemodule->course);
         $DB->set_field('log', 'module', 'assignment', $logparams);
         $DB->set_field('log', 'cmid', $oldcoursemodule->id, $logparams);
         // Roll back the advanced grading update.
         if ($gradingarea) {
             foreach ($gradeidmap as $newgradeid => $oldsubmissionid) {
                 foreach ($gradingdefinitions as $definition) {
                     $DB->set_field('grading_instances', 'itemid', $oldsubmissionid, array('definitionid' => $definition->id, 'itemid' => $newgradeid));
                 }
             }
             $params = array('id' => $gradingarea->id, 'contextid' => $oldcontext->id, 'component' => 'mod_assignment', 'areaname' => 'submission');
             $DB->update_record('grading_areas', $params);
         }
         $newassignment->delete_instance();
         return false;
     }
     // Delete the old assignment (use object delete).
     $cm = get_coursemodule_from_id('', $oldcoursemodule->id, $oldcoursemodule->course);
     if ($cm) {
         course_delete_module($cm->id);
     }
     rebuild_course_cache($oldcoursemodule->course);
     return true;
 }
开发者ID:gwsd2015,项目名称:LogiClass,代码行数:101,代码来源:upgradelib.php

示例3: upgrade_assignment


//.........这里部分代码省略.........
             $submission->timemodified = $oldsubmission->timemodified;
             $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
             $submission->id = $DB->insert_record('assign_submission', $submission);
             if (!$submission->id) {
                 $log .= get_string('couldnotinsertsubmission', 'mod_assign', $submission->userid);
                 $rollback = true;
             }
             foreach ($newassignment->get_submission_plugins() as $plugin) {
                 if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
                     if (!$plugin->upgrade($oldcontext, $oldassignment, $oldsubmission, $submission, $log)) {
                         $rollback = true;
                     }
                 }
             }
             if ($oldsubmission->timemarked) {
                 // submission has been graded - create a grade record
                 $grade = new stdClass();
                 $grade->assignment = $newassignment->get_instance()->id;
                 $grade->userid = $oldsubmission->userid;
                 $grade->grader = $oldsubmission->teacher;
                 $grade->timemodified = $oldsubmission->timemarked;
                 $grade->timecreated = $oldsubmission->timecreated;
                 // $grade->locked = $oldsubmission->locked;
                 $grade->grade = $oldsubmission->grade;
                 $grade->mailed = $oldsubmission->mailed;
                 $grade->id = $DB->insert_record('assign_grades', $grade);
                 if (!$grade->id) {
                     $log .= get_string('couldnotinsertgrade', 'mod_assign', $grade->userid);
                     $rollback = true;
                 }
                 // copy any grading instances
                 if ($gradingarea) {
                     $gradeidmap[$grade->id] = $oldsubmission->id;
                     foreach ($gradingdefinitions as $definition) {
                         $DB->set_field('grading_instances', 'itemid', $grade->id, array('definitionid' => $definition->id, 'itemid' => $oldsubmission->id));
                     }
                 }
                 foreach ($newassignment->get_feedback_plugins() as $plugin) {
                     if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
                         if (!$plugin->upgrade($oldcontext, $oldassignment, $oldsubmission, $grade, $log)) {
                             $rollback = true;
                         }
                     }
                 }
             }
         }
         $newassignment->update_calendar($newcoursemodule->id);
         // Reassociate grade_items from the old assignment instance to the new assign instance.
         // This includes outcome linked grade_items.
         $params = array('assign', $newassignment->get_instance()->id, 'assignment', $oldassignment->id);
         $sql = 'UPDATE {grade_items} SET itemmodule = ?, iteminstance = ? WHERE itemmodule = ? AND iteminstance = ?';
         $DB->execute($sql, $params);
         $gradesdone = true;
     } catch (Exception $exception) {
         $rollback = true;
         $log .= get_string('conversionexception', 'mod_assign', $exception->error);
     }
     if ($rollback) {
         // roll back the grades changes
         if ($gradesdone) {
             // Reassociate grade_items from the new assign instance to the old assignment instance.
             $params = array('assignment', $oldassignment->id, 'assign', $newassignment->get_instance()->id);
             $sql = 'UPDATE {grade_items} SET itemmodule = ?, iteminstance = ? WHERE itemmodule = ? AND iteminstance = ?';
             $DB->execute($sql, $params);
         }
         // roll back the completion changes
         if ($completiondone) {
             $DB->set_field('course_modules_completion', 'coursemoduleid', $oldcoursemodule->id, array('coursemoduleid' => $newcoursemodule->id));
             $allcriteria = $DB->get_records('course_completion_criteria', array('moduleinstance' => $newcoursemodule->id));
             foreach ($allcriteria as $criteria) {
                 $criteria->module = 'assignment';
                 $criteria->moduleinstance = $oldcoursemodule->id;
                 $DB->update_record('course_completion_criteria', $criteria);
             }
         }
         // Roll back the log changes
         $logparams = array('cmid' => $newcoursemodule->id, 'course' => $newcoursemodule->course);
         $DB->set_field('log', 'module', 'assignment', $logparams);
         $DB->set_field('log', 'cmid', $oldcoursemodule->id, $logparams);
         // roll back the advanced grading update
         if ($gradingarea) {
             foreach ($gradeidmap as $newgradeid => $oldsubmissionid) {
                 foreach ($gradingdefinitions as $definition) {
                     $DB->set_field('grading_instances', 'itemid', $oldsubmissionid, array('definitionid' => $definition->id, 'itemid' => $newgradeid));
                 }
             }
             $DB->update_record('grading_areas', array('id' => $gradingarea->id, 'contextid' => $oldcontext->id, 'component' => 'mod_assignment', 'areaname' => 'submission'));
         }
         $newassignment->delete_instance();
         return false;
     }
     // all is well,
     // delete the old assignment (use object delete)
     $cm = get_coursemodule_from_id('', $oldcoursemodule->id, $oldcoursemodule->course);
     if ($cm) {
         $this->delete_course_module($cm);
     }
     rebuild_course_cache($oldcoursemodule->course);
     return true;
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:101,代码来源:upgradelib.php


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