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


PHP info::convert_legacy_fields方法代码示例

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


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

示例1: process_module

 protected function process_module($data)
 {
     global $CFG, $DB;
     $data = (object) $data;
     $oldid = $data->id;
     $this->task->set_old_moduleversion($data->version);
     $data->course = $this->task->get_courseid();
     $data->module = $DB->get_field('modules', 'id', array('name' => $data->modulename));
     // Map section (first try by course_section mapping match. Useful in course and section restores)
     $data->section = $this->get_mappingid('course_section', $data->sectionid);
     if (!$data->section) {
         // mapping failed, try to get section by sectionnumber matching
         $params = array('course' => $this->get_courseid(), 'section' => $data->sectionnumber);
         $data->section = $DB->get_field('course_sections', 'id', $params);
     }
     if (!$data->section) {
         // sectionnumber failed, try to get first section in course
         $params = array('course' => $this->get_courseid());
         $data->section = $DB->get_field('course_sections', 'MIN(id)', $params);
     }
     if (!$data->section) {
         // no sections in course, create section 0 and 1 and assign module to 1
         $sectionrec = array('course' => $this->get_courseid(), 'section' => 0);
         $DB->insert_record('course_sections', $sectionrec);
         // section 0
         $sectionrec = array('course' => $this->get_courseid(), 'section' => 1);
         $data->section = $DB->insert_record('course_sections', $sectionrec);
         // section 1
     }
     $data->groupingid = $this->get_mappingid('grouping', $data->groupingid);
     // grouping
     if (!grade_verify_idnumber($data->idnumber, $this->get_courseid())) {
         // idnumber uniqueness
         $data->idnumber = '';
     }
     if (empty($CFG->enablecompletion)) {
         // completion
         $data->completion = 0;
         $data->completiongradeitemnumber = null;
         $data->completionview = 0;
         $data->completionexpected = 0;
     } else {
         $data->completionexpected = $this->apply_date_offset($data->completionexpected);
     }
     if (empty($CFG->enableavailability)) {
         $data->availability = null;
     }
     // Backups that did not include showdescription, set it to default 0
     // (this is not totally necessary as it has a db default, but just to
     // be explicit).
     if (!isset($data->showdescription)) {
         $data->showdescription = 0;
     }
     $data->instance = 0;
     // Set to 0 for now, going to create it soon (next step)
     if (empty($data->availability)) {
         // If there are legacy availablility data fields (and no new format data),
         // convert the old fields.
         $data->availability = \core_availability\info::convert_legacy_fields($data, false);
     } else {
         if (!empty($data->groupmembersonly)) {
             // There is current availability data, but it still has groupmembersonly
             // as well (2.7 backups), convert just that part.
             require_once $CFG->dirroot . '/lib/db/upgradelib.php';
             $data->availability = upgrade_group_members_only($data->groupingid, $data->availability);
         }
     }
     // course_module record ready, insert it
     $newitemid = $DB->insert_record('course_modules', $data);
     // save mapping
     $this->set_mapping('course_module', $oldid, $newitemid);
     // set the new course_module id in the task
     $this->task->set_moduleid($newitemid);
     // we can now create the context safely
     $ctxid = context_module::instance($newitemid)->id;
     // set the new context id in the task
     $this->task->set_contextid($ctxid);
     // update sequence field in course_section
     if ($sequence = $DB->get_field('course_sections', 'sequence', array('id' => $data->section))) {
         $sequence .= ',' . $newitemid;
     } else {
         $sequence = $newitemid;
     }
     $DB->set_field('course_sections', 'sequence', $sequence, array('id' => $data->section));
     // If there is the legacy showavailability data, store this for later use.
     // (This data is not present when restoring 'new' backups.)
     if (isset($data->showavailability)) {
         // Cache the showavailability flag using the backup_ids data field.
         restore_dbops::set_backup_ids_record($this->get_restoreid(), 'module_showavailability', $newitemid, 0, null, (object) array('showavailability' => $data->showavailability));
     }
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:91,代码来源:restore_stepslib.php

示例2: test_convert_legacy_fields

 /**
  * Tests the convert_legacy_fields function used in restore.
  */
 public function test_convert_legacy_fields()
 {
     // Check with no availability conditions first.
     $rec = (object) array('availablefrom' => 0, 'availableuntil' => 0, 'groupingid' => 7, 'showavailability' => 1);
     $this->assertNull(info::convert_legacy_fields($rec, false));
     // Check same list for a section.
     $this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"grouping","id":7}]}', info::convert_legacy_fields($rec, true));
     // Check groupmembersonly with grouping.
     $rec->groupmembersonly = 1;
     $this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"grouping","id":7}]}', info::convert_legacy_fields($rec, false));
     // Check groupmembersonly without grouping.
     $rec->groupingid = 0;
     $this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"group"}]}', info::convert_legacy_fields($rec, false));
     // Check start date.
     $rec->groupmembersonly = 0;
     $rec->availablefrom = 123;
     $this->assertEquals('{"op":"&","showc":[true],"c":[{"type":"date","d":">=","t":123}]}', info::convert_legacy_fields($rec, false));
     // Start date with show = false.
     $rec->showavailability = 0;
     $this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"date","d":">=","t":123}]}', info::convert_legacy_fields($rec, false));
     // End date.
     $rec->showavailability = 1;
     $rec->availablefrom = 0;
     $rec->availableuntil = 456;
     $this->assertEquals('{"op":"&","showc":[false],"c":[{"type":"date","d":"<","t":456}]}', info::convert_legacy_fields($rec, false));
     // All together now.
     $rec->groupingid = 7;
     $rec->groupmembersonly = 1;
     $rec->availablefrom = 123;
     $this->assertEquals('{"op":"&","showc":[false,true,false],"c":[' . '{"type":"grouping","id":7},' . '{"type":"date","d":">=","t":123},' . '{"type":"date","d":"<","t":456}' . ']}', info::convert_legacy_fields($rec, false));
     $this->assertEquals('{"op":"&","showc":[false,true,false],"c":[' . '{"type":"grouping","id":7},' . '{"type":"date","d":">=","t":123},' . '{"type":"date","d":"<","t":456}' . ']}', info::convert_legacy_fields($rec, false, true));
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:35,代码来源:info_test.php

示例3: process_module

 protected function process_module($data)
 {
     global $CFG, $DB;
     $data = (object) $data;
     $oldid = $data->id;
     $this->task->set_old_moduleversion($data->version);
     // Get the current course module data.
     $newitemid = $this->task->get_moduleid();
     $params = array('id' => $newitemid);
     $cmdata = $DB->get_record('course_modules', $params, '*', MUST_EXIST);
     // Group mode and Grouping.
     $cmdata->groupmode = $data->groupmode;
     $cmdata->groupingid = $this->get_mappingid('grouping', $data->groupingid);
     // Idnumber uniqueness.
     if (!grade_verify_idnumber($data->idnumber, $this->get_courseid())) {
         $data->idnumber = '';
     }
     $cmdata->idnumber = $data->idnumber;
     // Completion.
     if (!empty($CFG->enablecompletion)) {
         $cmdata->completion = $data->completion;
         $cmdata->completiongradeitemnumber = $data->completiongradeitemnumber;
         $cmdata->completionview = $data->completionview;
         $cmdata->completionexpected = $this->apply_date_offset($data->completionexpected);
     }
     // Availability.
     if (empty($CFG->enableavailability)) {
         $data->availability = null;
     }
     if (empty($data->availability)) {
         // If there are legacy availablility data fields (and no new format data),
         // convert the old fields.
         $data->availability = \core_availability\info::convert_legacy_fields($data, false);
     } else {
         if (!empty($data->groupmembersonly)) {
             // There is current availability data, but it still has groupmembersonly
             // as well (2.7 backups), convert just that part.
             require_once $CFG->dirroot . '/lib/db/upgradelib.php';
             $data->availability = upgrade_group_members_only($data->groupingid, $data->availability);
         }
     }
     $cmdata->availability = $data->availability;
     // Backups that did not include showdescription, set it to default 0
     // (this is not totally necessary as it has a db default, but just to
     // be explicit).
     if (!isset($data->showdescription)) {
         $data->showdescription = 0;
     }
     $cmdata->showdescription = $data->showdescription;
     // Course_module record ready, update it.
     $DB->update_record('course_modules', $cmdata);
     // Save mapping.
     $this->set_mapping('course_module', $oldid, $newitemid);
     // Set the new course_module id in the task.
     $this->task->set_moduleid($newitemid);
     // We can now create the context safely.
     $ctxid = context_module::instance($newitemid)->id;
     // Set the new context id in the task.
     $this->task->set_contextid($ctxid);
     // If there is the legacy showavailability data, store this for later use.
     // (This data is not present when restoring 'new' backups.)
     if (isset($cmdata->showavailability)) {
         // Cache the showavailability flag using the backup_ids data field.
         restore_dbops::set_backup_ids_record($this->get_restoreid(), 'module_showavailability', $newitemid, 0, null, (object) array('showavailability' => $cmdata->showavailability));
     }
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:66,代码来源:restore_dataform_activity_task.class.php


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