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


PHP info::add_legacy_availability_field_condition方法代码示例

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


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

示例1: test_add_legacy_availability_field_condition

 /**
  * Tests the add_legacy_availability_field_condition function used in restore.
  */
 public function test_add_legacy_availability_field_condition()
 {
     // User field, normal operator.
     $rec = (object) array('userfield' => 'email', 'shortname' => null, 'operator' => 'contains', 'value' => '@');
     $this->assertEquals('{"op":"&","showc":[true],"c":[' . '{"type":"profile","op":"contains","sf":"email","v":"@"}]}', info::add_legacy_availability_field_condition(null, $rec, true));
     // User field, non-value operator.
     $rec = (object) array('userfield' => 'email', 'shortname' => null, 'operator' => 'isempty', 'value' => '');
     $this->assertEquals('{"op":"&","showc":[true],"c":[' . '{"type":"profile","op":"isempty","sf":"email"}]}', info::add_legacy_availability_field_condition(null, $rec, true));
     // Custom field.
     $rec = (object) array('userfield' => null, 'shortname' => 'frogtype', 'operator' => 'isempty', 'value' => '');
     $this->assertEquals('{"op":"&","showc":[true],"c":[' . '{"type":"profile","op":"isempty","cf":"frogtype"}]}', info::add_legacy_availability_field_condition(null, $rec, true));
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:15,代码来源:info_test.php

示例2: process_availability_field

 /**
  * Process the legacy availability fields table record. This table does not
  * exist in Moodle 2.7+ but we still support restore.
  *
  * @param stdClass $data Record data
  */
 protected function process_availability_field($data)
 {
     global $DB;
     $data = (object) $data;
     // Mark it is as passed by default
     $passed = true;
     $customfieldid = null;
     // If a customfield has been used in order to pass we must be able to match an existing
     // customfield by name (data->customfield) and type (data->customfieldtype)
     if (!empty($data->customfield) xor !empty($data->customfieldtype)) {
         // xor is sort of uncommon. If either customfield is null or customfieldtype is null BUT not both.
         // If one is null but the other isn't something clearly went wrong and we'll skip this condition.
         $passed = false;
     } else {
         if (!empty($data->customfield)) {
             $params = array('shortname' => $data->customfield, 'datatype' => $data->customfieldtype);
             $customfieldid = $DB->get_field('user_info_field', 'id', $params);
             $passed = $customfieldid !== false;
         }
     }
     if ($passed) {
         // Create the object to insert into the database
         $availfield = new stdClass();
         $availfield->coursemoduleid = $this->task->get_moduleid();
         // Lets add the availability cmid
         $availfield->userfield = $data->userfield;
         $availfield->customfieldid = $customfieldid;
         $availfield->operator = $data->operator;
         $availfield->value = $data->value;
         // Get showavailability option.
         $showrec = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'module_showavailability', $availfield->coursemoduleid);
         if (!$showrec) {
             // Should not happen.
             throw new coding_exception('No matching showavailability record');
         }
         $show = $showrec->info->showavailability;
         // The $availfieldobject is now in the format used in the old
         // system. Interpret this and convert to new system.
         $currentvalue = $DB->get_field('course_modules', 'availability', array('id' => $availfield->coursemoduleid), MUST_EXIST);
         $newvalue = \core_availability\info::add_legacy_availability_field_condition($currentvalue, $availfield, $show);
         $DB->set_field('course_modules', 'availability', $newvalue, array('id' => $availfield->coursemoduleid));
     }
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:49,代码来源:restore_stepslib.php


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