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


PHP backup_nested_element::get_final_element方法代码示例

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


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

示例1: add_question_usages

 /**
  * Attach to $element (usually attempts) the needed backup structures
  * for question_usages and all the associated data.
  *
  * @param backup_nested_element $element the element that will contain all the question_usages data.
  * @param string $usageidname the name of the element that holds the usageid.
  *      This must be child of $element, and must be a final element.
  * @param string $nameprefix this prefix is added to all the element names we create.
  *      Element names in the XML must be unique, so if you are using usages in
  *      two different ways, you must give a prefix to at least one of them. If
  *      you only use one sort of usage, then you can just use the default empty prefix.
  *      This should include a trailing underscore. For example "myprefix_"
  */
 protected function add_question_usages($element, $usageidname, $nameprefix = '')
 {
     global $CFG;
     require_once $CFG->dirroot . '/question/engine/lib.php';
     // Check $element is one nested_backup_element
     if (!$element instanceof backup_nested_element) {
         throw new backup_step_exception('question_states_bad_parent_element', $element);
     }
     if (!$element->get_final_element($usageidname)) {
         throw new backup_step_exception('question_states_bad_question_attempt_element', $usageidname);
     }
     $quba = new backup_nested_element($nameprefix . 'question_usage', array('id'), array('component', 'preferredbehaviour'));
     $qas = new backup_nested_element($nameprefix . 'question_attempts');
     $qa = new backup_nested_element($nameprefix . 'question_attempt', array('id'), array('slot', 'behaviour', 'questionid', 'variant', 'maxmark', 'minfraction', 'maxfraction', 'flagged', 'questionsummary', 'rightanswer', 'responsesummary', 'timemodified'));
     $steps = new backup_nested_element($nameprefix . 'steps');
     $step = new backup_nested_element($nameprefix . 'step', array('id'), array('sequencenumber', 'state', 'fraction', 'timecreated', 'userid'));
     $response = new backup_nested_element($nameprefix . 'response');
     $variable = new backup_nested_element($nameprefix . 'variable', null, array('name', 'value'));
     // Build the tree
     $element->add_child($quba);
     $quba->add_child($qas);
     $qas->add_child($qa);
     $qa->add_child($steps);
     $steps->add_child($step);
     $step->add_child($response);
     $response->add_child($variable);
     // Set the sources
     $quba->set_source_table('question_usages', array('id' => '../' . $usageidname));
     $qa->set_source_table('question_attempts', array('questionusageid' => backup::VAR_PARENTID), 'slot ASC');
     $step->set_source_table('question_attempt_steps', array('questionattemptid' => backup::VAR_PARENTID), 'sequencenumber ASC');
     $variable->set_source_table('question_attempt_step_data', array('attemptstepid' => backup::VAR_PARENTID));
     // Annotate ids
     $qa->annotate_ids('question', 'questionid');
     $step->annotate_ids('user', 'userid');
     // Annotate files
     $fileareas = question_engine::get_all_response_file_areas();
     foreach ($fileareas as $filearea) {
         $step->annotate_files('question', $filearea, 'id');
     }
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:53,代码来源:backup_stepslib.php

示例2: array

 /**
  * Backup structures tests (construction, definition and execution)
  */
 function test_backup_structure_construct()
 {
     global $DB;
     $backupid = 'Testing Backup ID';
     // Official backupid for these tests
     // Create all the elements that will conform the tree
     $forum = new backup_nested_element('forum', array('id'), array('type', 'name', 'intro', 'introformat', 'assessed', 'assesstimestart', 'assesstimefinish', 'scale', 'maxbytes', 'maxattachments', 'forcesubscribe', 'trackingtype', 'rsstype', 'rssarticles', 'timemodified', 'warnafter', 'blockafter', new backup_final_element('blockperiod'), new mock_skip_final_element('completiondiscussions'), new mock_modify_final_element('completionreplies'), new mock_final_element_interceptor('completionposts')));
     $discussions = new backup_nested_element('discussions');
     $discussion = new backup_nested_element('discussion', array('id'), array('forum', 'name', 'firstpost', 'userid', 'groupid', 'assessed', 'timemodified', 'usermodified', 'timestart', 'timeend'));
     $posts = new backup_nested_element('posts');
     $post = new backup_nested_element('post', array('id'), array('discussion', 'parent', 'userid', 'created', 'modified', 'mailed', 'subject', 'message', 'messageformat', 'messagetrust', 'attachment', 'totalscore', 'mailnow'));
     $ratings = new backup_nested_element('ratings');
     $rating = new backup_nested_element('rating', array('id'), array('userid', 'itemid', 'time', 'post_rating'));
     $reads = new backup_nested_element('readposts');
     $read = new backup_nested_element('read', array('id'), array('userid', 'discussionid', 'postid', 'firstread', 'lastread'));
     $inventeds = new backup_nested_element('invented_elements', array('reason', 'version'));
     $invented = new backup_nested_element('invented', null, array('one', 'two', 'three'));
     $one = $invented->get_final_element('one');
     $one->add_attributes(array('attr1', 'attr2'));
     // Build the tree
     $forum->add_child($discussions);
     $discussions->add_child($discussion);
     $discussion->add_child($posts);
     $posts->add_child($post);
     $post->add_child($ratings);
     $ratings->add_child($rating);
     $forum->add_child($reads);
     $reads->add_child($read);
     $forum->add_child($inventeds);
     $inventeds->add_child($invented);
     // Let's add 1 optigroup with 4 elements
     $alternative1 = new backup_optigroup_element('alternative1', array('name', 'value'), '../../id', 1);
     $alternative2 = new backup_optigroup_element('alternative2', array('name', 'value'), backup::VAR_PARENTID, 2);
     $alternative3 = new backup_optigroup_element('alternative3', array('name', 'value'), '/forum/discussions/discussion/posts/post/id', 3);
     $alternative4 = new backup_optigroup_element('alternative4', array('forumtype', 'forumname'));
     // Alternative without conditions
     // Create the optigroup, adding one element
     $optigroup = new backup_optigroup('alternatives', $alternative1, false);
     // Add second opti element
     $optigroup->add_child($alternative2);
     // Add optigroup to post element
     $post->add_optigroup($optigroup);
     // Add third opti element, on purpose after the add_optigroup() line above to check param evaluation works ok
     $optigroup->add_child($alternative3);
     // Add 4th opti element (the one without conditions, so will be present always)
     $optigroup->add_child($alternative4);
     /// Create some new nested elements, both named 'dupetest1', and add them to alternative1 and alternative2
     /// (not problem as far as the optigroup in not unique)
     $dupetest1 = new backup_nested_element('dupetest1', null, array('field1', 'field2'));
     $dupetest2 = new backup_nested_element('dupetest2', null, array('field1', 'field2'));
     $dupetest3 = new backup_nested_element('dupetest3', null, array('field1', 'field2'));
     $dupetest4 = new backup_nested_element('dupetest1', null, array('field1', 'field2'));
     $dupetest1->add_child($dupetest3);
     $dupetest2->add_child($dupetest4);
     $alternative1->add_child($dupetest1);
     $alternative2->add_child($dupetest2);
     // Define sources
     $forum->set_source_table('forum', array('id' => backup::VAR_ACTIVITYID));
     $discussion->set_source_sql('SELECT *
                                    FROM {forum_discussions}
                                   WHERE forum = ?', array('/forum/id'));
     $post->set_source_table('forum_posts', array('discussion' => '/forum/discussions/discussion/id'));
     $rating->set_source_sql('SELECT *
                                FROM {rating}
                               WHERE itemid = ?', array(backup::VAR_PARENTID));
     $read->set_source_table('forum_read', array('id' => '../../id'));
     $inventeds->set_source_array(array((object) array('reason' => 'I love Moodle', 'version' => '1.0'), (object) array('reason' => 'I love Moodle', 'version' => '2.0')));
     // 2 object array
     $invented->set_source_array(array((object) array('one' => 1, 'two' => 2, 'three' => 3), (object) array('one' => 11, 'two' => 22, 'three' => 33)));
     // 2 object array
     // Set optigroup_element sources
     $alternative1->set_source_array(array((object) array('name' => 'alternative1', 'value' => 1)));
     // 1 object array
     // Skip alternative2 source definition on purpose (will be tested)
     // $alternative2->set_source_array(array((object)array('name' => 'alternative2', 'value' => 2))); // 1 object array
     $alternative3->set_source_array(array((object) array('name' => 'alternative3', 'value' => 3)));
     // 1 object array
     // Alternative 4 source is the forum type and name, so we'll get that in ALL posts (no conditions) that
     // have not another alternative (post4 in our testing data in the only not matching any other alternative)
     $alternative4->set_source_sql('SELECT type AS forumtype, name AS forumname
                                      FROM {forum}
                                     WHERE id = ?', array('/forum/id'));
     // Set children of optigroup_element source
     $dupetest1->set_source_array(array((object) array('field1' => '1', 'field2' => 1)));
     // 1 object array
     $dupetest2->set_source_array(array((object) array('field1' => '2', 'field2' => 2)));
     // 1 object array
     $dupetest3->set_source_array(array((object) array('field1' => '3', 'field2' => 3)));
     // 1 object array
     $dupetest4->set_source_array(array((object) array('field1' => '4', 'field2' => 4)));
     // 1 object array
     // Define some aliases
     $rating->set_source_alias('rating', 'post_rating');
     // Map the 'rating' value from DB to 'post_rating' final element
     // Mark to detect files of type 'forum_intro' in forum (and not item id)
     $forum->annotate_files('mod_forum', 'intro', null);
     // Mark to detect file of type 'forum_post' and 'forum_attachment' in post (with itemid being post->id)
//.........这里部分代码省略.........
开发者ID:bobpuffer,项目名称:moodleUCLA-LUTH,代码行数:101,代码来源:structure_test.php


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