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


PHP student::to_array方法代码示例

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


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

示例1: class_enrolment_create

 /**
  * Performs class_enrolment creation
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error creating the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function class_enrolment_create(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     static $completestatuses = array('not completed' => STUSTATUS_NOTCOMPLETE, 'not_completed' => STUSTATUS_NOTCOMPLETE, 'notcompleted' => STUSTATUS_NOTCOMPLETE, 'failed' => 'STUSTATUS_FAILED', 'passed' => STUSTATUS_PASSED);
     // Parameter validation.
     $params = self::validate_parameters(self::class_enrolment_create_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     // Parse class
     if (empty($data->class_idnumber) || !($classid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $data->class_idnumber)))) {
         throw new data_object_exception('ws_class_enrolment_create_fail_invalid_class', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:class_enrol', \local_elisprogram\context\pmclass::instance($classid));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $userparams = array();
     $userid = $importplugin->get_userid_from_record($data, '', $userparams);
     if ($userid == false) {
         $a = new stdClass();
         if (empty($userparams)) {
             $a->userparams = '{empty}';
         } else {
             $a->userparams = '';
             foreach ($userparams as $userfield => $uservalue) {
                 $subfield = strpos($userfield, '_');
                 $userfield = substr($userfield, $subfield === false ? 0 : $subfield + 1);
                 if (!empty($a->userparams)) {
                     $a->userparams .= ', ';
                 }
                 $a->userparams .= "{$userfield}: '{$uservalue}'";
             }
         }
         throw new data_object_exception('ws_class_enrolment_create_fail_invalid_user', 'local_datahub', '', $a);
     }
     $record = new stdClass();
     $record->userid = $userid;
     $record->classid = $classid;
     $record->completestatusid = STUSTATUS_NOTCOMPLETE;
     if (isset($data->completestatus)) {
         $completestatus = strtolower($data->completestatus);
         if (isset($completestatuses[$completestatus])) {
             $record->completestatusid = $completestatuses[$completestatus];
         } else {
             throw new data_object_exception('ws_class_enrolment_create_fail_invalid_completestatus', 'local_datahub', '', $data);
         }
     }
     $record->grade = isset($data->grade) && is_numeric($data->grade) ? $data->grade : 0;
     $record->credits = isset($data->credits) && is_numeric($data->credits) ? $data->credits : 0;
     $record->locked = !empty($data->locked) ? 1 : 0;
     if (isset($data->enrolmenttime)) {
         $enrolmenttime = $importplugin->parse_date($data->enrolmenttime);
         if (empty($enrolmenttime)) {
             throw new data_object_exception('ws_class_enrolment_create_fail_invalid_enrolmenttime', 'local_datahub', '', $data);
         } else {
             $record->enrolmenttime = $enrolmenttime;
         }
     } else {
         $record->enrolmenttime = rlip_timestamp();
     }
     $record->completetime = 0;
     if (isset($data->completetime)) {
         $completetime = $importplugin->parse_date($data->completetime);
         if (empty($completetime)) {
             throw new data_object_exception('ws_class_enrolment_create_fail_invalid_completetime', 'local_datahub', '', $data);
         } else {
             $record->completetime = $completetime;
         }
     } else {
         if (!empty($record->completestatusid)) {
             $record->completetime = rlip_timestamp();
         }
     }
     $stu = new student($record);
     $stu->save();
     // Respond.
     if (!empty($stu->id)) {
         return array('messagecode' => get_string('ws_class_enrolment_create_success_code', 'local_datahub'), 'message' => get_string('ws_class_enrolment_create_success_msg', 'local_datahub'), 'record' => $stu->to_array());
     } else {
         throw new data_object_exception('ws_class_enrolment_create_fail', 'local_datahub');
     }
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:94,代码来源:class_enrolment_create.class.php


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