本文整理汇总了PHP中xml::generate_element_attribute_map方法的典型用法代码示例。如果您正苦于以下问题:PHP xml::generate_element_attribute_map方法的具体用法?PHP xml::generate_element_attribute_map怎么用?PHP xml::generate_element_attribute_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml
的用法示例。
在下文中一共展示了xml::generate_element_attribute_map方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: download_xml
/**
* Download Reports in XML format
* @param Validation $post Validation object with the download criteria
* @param array $incidents reports to be downloaded
* @param array $categories deployment categories
* @param array $custom_forms Custom form field structure and values
*/
public static function download_xml($post, $incidents, $categories, $custom_forms)
{
// Adding XML Content
$writer = new XMLWriter();
$writer->openMemory();
$writer->startDocument('1.0', 'UTF-8');
$writer->setIndent(TRUE);
/* Category Element/Attribute maps */
// Category map
$category_map = array('attributes' => array('color' => 'category_color', 'visible' => 'category_visible', 'trusted' => 'category_trusted'), 'elements' => array('title' => 'category_title', 'description' => 'category_description'));
// Array of category elements
$category_elements = array('color', 'visible', 'trusted', 'title', 'description', 'parent');
/* Category translation Element/Attribute maps */
// Translation map
$translation_map = array('attributes' => array('locale' => 'locale'), 'elements' => array('translation_title' => 'category_title', 'translation_description' => 'category_description'));
// Array of translation elements
$translation_elements = array('locale', 'translation_title', 'translation_description');
/* Form element/attribute maps */
// Forms map
$form_map = array('attributes' => array('active' => 'form_active'), 'elements' => array('title' => 'form_title', 'description' => 'form_description'));
// Forms element
$form_elements = array('active', 'title', 'description');
/* Custom fields element/attribute maps */
// Field elements
$form_field_elements = array('type', 'required', 'visible_by', 'submit_by', 'datatype', 'hidden', 'name', 'default');
/* Reports element/attribute maps */
// Report map
$report_map = array('attributes' => array('id' => 'id', 'approved' => 'incident_active', 'verified' => 'incident_verified', 'mode' => 'incident_mode'), 'elements' => array('title' => 'incident_title', 'date' => 'incident_date', 'dateadd' => 'incident_dateadd'));
// Report elements
$report_elements = array('id', 'approved', 'verified', 'form_name', 'mode', 'title', 'date', 'dateadd');
// Location Map
$location_map = array('attributes' => array(), 'elements' => array('name' => 'location_name', 'longitude' => 'longitude', 'latitude' => 'latitude'));
// Location elements
$location_elements = array('name', 'longitude', 'latitude');
// Media Map
$media_map = array('attributes' => array('type' => 'media_type', 'active' => 'media_active', 'date' => 'media_date'), 'elements' => array());
// Media elements
$media_elements = array('type', 'active', 'date');
// Personal info map
$person_map = array('attributes' => array(), 'elements' => array('first_name' => 'person_first', 'last_name' => 'person_last', 'email' => 'person_email'));
// Personal info elements
$person_elements = array('first_name', 'last_name', 'email');
// Incident Category map
$incident_category_map = array('attributes' => array(), 'elements' => array('category' => 'category_title'));
// Incident Category elements
$incident_category_elements = array('category');
// Ensure column order is always the same
sort($post->data_include);
/* Start Import Tag*/
$writer->startElement('UshahidiReports');
foreach ($post->data_include as $item) {
switch ($item) {
case 3:
/* Start Categories element */
$writer->startElement('categories');
if (count($categories) > 0) {
foreach ($categories as $category) {
// Begin individual category tag
$writer->startElement('category');
// Generate category element map
$category_element_map = xml::generate_element_attribute_map($category, $category_map);
if ($category->parent_id > 0) {
// Category's parent
$parent = ORM::factory('category', $category->parent_id);
// If parent category exists
if ($parent->loaded) {
// Add to array of category_element_map for purposes of generating tags
$category_element_map['elements']['parent'] = $parent->category_title;
}
}
// Generate individual category tags
xml::generate_tags($writer, $category_element_map, $category_elements);
// Category Translation
$translations = ORM::factory('category_lang')->where('category_id', $category->id)->find_all();
// If translations exist
if (count($translations) > 0) {
$writer->startElement('translations');
foreach ($translations as $translation) {
// Begin individual translation element
$writer->startElement('translation');
// Generate translation element map
$translation_element_map = xml::generate_element_attribute_map($translation, $translation_map);
// Generate translation tags
xml::generate_tags($writer, $translation_element_map, $translation_elements);
// End individual category translation tag
$writer->endElement();
}
$writer->endElement();
}
$writer->endElement();
}
} else {
$writer->text('There are no categories on this deployment.');
//.........这里部分代码省略.........
示例2: testGenerateArrayMap
/**
* Tests download helper function which generates object array maps
* to be used to generate XML element tags
* @test
* @dataProvider providerTestGenerateArrayMap
* @param array $object_map associative array map skeleton
* @param array $expected_map expected output
* @param object $object_orm ORM object
* @param string $object_name
*/
public function testGenerateArrayMap($object_map, $expected_map, $object_orm, $object_name)
{
// Get array map returned by download helper function
$actual_map = xml::generate_element_attribute_map($object_orm, $object_map);
// For the random category
if ($object_name == 'Category') {
// Check if this category has a parent
if ($object_orm->parent_id > 0) {
// Fetch the parent category
$parent = ORM::Factory('category', $object_orm->parent_id);
// Add category parent to actual_map and expected_map
$expected_map['elements']['parent'] = $parent->category_title;
$actual_map['elements']['parent'] = $parent->category_title;
}
}
if ($object_name == 'Report') {
// Make sure the incident_form is loaded
if ($object_orm->form->loaded) {
// Add form_name attribute to actual map and expected map
$expected_map['attributes']['form_name'] = $object_orm->form->form_title;
$actual_map['attributes']['form_name'] = $object_orm->form->form_title;
}
}
// Test to ensure expected array map and actual array map match
$this->assertEquals($expected_map, $actual_map, 'Output does not match expected array for the ' . $object_name . ' object');
}