本文整理汇总了PHP中xml::get_node_text方法的典型用法代码示例。如果您正苦于以下问题:PHP xml::get_node_text方法的具体用法?PHP xml::get_node_text怎么用?PHP xml::get_node_text使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml
的用法示例。
在下文中一共展示了xml::get_node_text方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCheckReportsXML
/**
* Tests whether XML Report element matches ORM objects provided for download
* @test
* @depends testReadDownloadXML
* @param array $domnodes DOMNodeList Objects
*/
public function testCheckReportsXML(array $domnodes)
{
$d_reports = $domnodes[2];
// Ensure that the DOMNodeList Object is not empty
$this->assertGreaterThan(0, $d_reports->length, 'Reports Element MUST exist.');
// Contents of <Reports> element
$reports_element = $d_reports->item(0);
/* Report Check */
// If we have no reports on this deployment
if (count($this->incident) == 0) {
// Ensure the customforms element has the following message
$this->assertEquals('There are no reports on this deployment.', $d_reports->item(0)->nodeValue);
} else {
// Grab individual Report
$incident = $this->incident[0];
// Grab contents of <report> element
$report_element = $reports_element->getElementsByTagName('report');
// Test to see if the <report> element exists
$this->assertGreaterThan(0, $report_element->length, 'Report element does not exist for deployment with reports');
/* Report Check */
// Test report id
$id = $report_element->item(0)->getAttribute('id');
$this->assertEquals($incident->id, $id, 'Report id does not match/attribute does not exist');
// Test Report approval status
$approved = $report_element->item(0)->getAttribute('approved');
$this->assertEquals($incident->incident_active, $approved, 'Report active status does not match/attribute does not exist');
// Test Report verified status
$verified = $report_element->item(0)->getAttribute('verified');
$this->assertEquals($incident->incident_verified, $verified, 'Report verified status does not match/attribute does not exist');
// Test Report mode status
$mode = $report_element->item(0)->getAttribute('mode');
$this->assertEquals($incident->incident_mode, $mode, 'Report mode does not match/attribute does not exist');
// Test Report form_name
// Grab Default form object
$default_form = ORM::factory('form', 1);
$expected_form = $incident->form->loaded ? $incident->form->form_title : $default_form->form_title;
$form_name = xml::get_node_text($report_element->item(0), 'form_name', FALSE);
$this->assertEquals($expected_form, $form_name, 'Report form_name does not match/attribute does not exist');
// Test Report Title
$title = xml::get_node_text($report_element->item(0), 'title');
$this->assertEquals($incident->incident_title, $title, 'Report title does not match/element does not exist');
// Test Report Date
$date = xml::get_node_text($report_element->item(0), 'date');
$this->assertEquals($incident->incident_date, $date, 'Report date does not match/element does not exist');
// Test Report Dateadd
$date_add = xml::get_node_text($report_element->item(0), 'dateadd');
$this->assertEquals($incident->incident_dateadd, $date_add, 'Report dateadd does not match/element does not exist');
// Test report description
$description = xml::get_node_text($report_element->item(0), 'description');
// If download report description option is selected by user
if (in_array(2, $this->post['data_include'])) {
$this->assertEquals($incident->incident_description, $description, 'Report description does not match/element does not exist');
} else {
$this->assertEquals(FALSE, $description, 'Report description element should not exist');
}
/* Location Check */
$locations_element = $report_element->item(0)->getElementsByTagName('location');
$location = $incident->location;
// Include location option has been selected
if (in_array(1, $this->post['data_include'])) {
// Make sure the <location> element exists
$this->assertGreaterThan(0, $locations_element->length, 'Report location element SHOULD exist');
// Test location name
$location_name = xml::get_node_text($locations_element->item(0), 'name');
$this->assertEquals($location->location_name, $location_name, 'Location name does not match/element does not exist');
// Test Latitude
$latitude = xml::get_node_text($locations_element->item(0), 'latitude');
$this->assertEquals($location->latitude, $latitude, 'Latitude does not match/element does not exist');
// Test longitude
$longitude = xml::get_node_text($locations_element->item(0), 'longitude');
$this->assertEquals($location->longitude, $longitude, 'Longitude does not match/element does not exist');
} else {
$this->assertEquals(0, $locations_element->length, "Report location element should not exist");
}
/* Media Check */
$incident_media = ORM::Factory('media')->where('media_type = 2 OR media_type = 4')->where('incident_id', $incident->id)->find_all();
$media_element = $report_element->item(0)->getElementsByTagName('media');
if (count($incident_media) > 0) {
$media_count = count($incident_media);
$media_index = rand(0, $media_count - 1);
// Make sure the media element exists
$this->assertGreaterThan(0, $media_element->length, 'The media element SHOULD exist');
// Grab contents of media <item> element
$media_item = $media_element->item(0)->getElementsByTagName('item');
// Grab random individual media item
$this_media = $incident_media[$media_index];
if ($this_media->media_type == 2 or $this_media->media_type == 4) {
// Make sure the <item> element exists
$this->assertEquals('item', $media_item->item($media_index)->tagName, 'The media item element SHOULD exist');
// Test Media Type
$media_type = $media_item->item($media_index)->getAttribute('type');
$this->assertEquals($this_media->media_type, $media_type, 'Media type does not match/ attribute does not exist');
// Test media active
$media_active = $media_item->item($media_index)->getAttribute('active');
//.........这里部分代码省略.........
示例2: import_reports
/**
* Import Reports via XML
* @param DOMNodeList Object $report
* @return bool
*/
public function import_reports($reports)
{
/* Import individual reports */
foreach ($reports->getElementsByTagName('report') as $report) {
$this->totalreports++;
// Get Report id
$report_id = $report->getAttribute('id');
// Check if this incident already exists in the db
if (isset($report_id) and isset($this->incident_ids[$report_id])) {
$this->notices[] = Kohana::lang('import.incident_exists') . $report_id;
} else {
/* Step 1: Location information */
$locations = $report->getElementsByTagName('location');
// If location information has been provided
if ($locations->length > 0) {
$report_location = $locations->item(0);
// Location Name
$location_name = xml::get_node_text($report_location, 'name');
// Longitude
$longitude = xml::get_node_text($report_location, 'longitude');
// Latitude
$latitude = xml::get_node_text($report_location, 'latitude');
if ($location_name) {
// For geocoding purposes
$location_geocoded = map::geocode($location_name);
// Save the location
$new_location = new Location_Model();
$new_location->location_name = $location_name ? $location_name : NULL;
$new_location->location_date = $this->time;
// If longitude/latitude values are present
if ($latitude and $longitude) {
$new_location->latitude = $latitude ? $latitude : 0;
$new_location->longitude = $longitude ? $longitude : 0;
} else {
// Get geocoded lat/lon values
$new_location->latitude = $location_geocoded ? $location_geocoded['latitude'] : $latitude;
$new_location->longitude = $location_geocoded ? $location_geocoded['longitude'] : $longitude;
}
$new_location->country_id = $location_geocoded ? $location_geocoded['country_id'] : 0;
$new_location->save();
// Add this location to array of imported locations
$this->locations_added[] = $new_location->id;
}
}
/* Step 2: Save Report */
// Report Title
$report_title = xml::get_node_text($report, 'title');
// Report Date
$report_date = xml::get_node_text($report, 'date');
// Missing report title or report date?
if (!$report_title or !$report_date) {
$this->errors[] = Kohana::lang('import.xml.incident_title_date') . $this->totalreports;
}
// If report date is not in the required format
if (!strtotime($report_date)) {
$this->errors[] = Kohana::lang('import.incident_date') . $this->totalreports . ': ' . html::escape($report_date);
} else {
// Approval status?
$approved = $report->getAttribute('approved');
$report_approved = (isset($approved) and in_array($approved, $this->allowable)) ? $approved : 0;
// Verified Status?
$verified = $report->getAttribute('verified');
$report_verified = (isset($verified) and in_array($verified, $this->allowable)) ? $verified : 0;
// Report mode?
$allowed_modes = array(1, 2, 3, 4);
$mode = $report->getAttribute('mode');
$report_mode = (isset($mode) and in_array($mode, $allowed_modes)) ? $mode : 1;
// Report Form
$report_form = xml::get_node_text($report, 'form_name', FALSE);
if ($report_form) {
if (!isset($this->existing_forms[utf8::strtoupper($report_form)])) {
$this->notices[] = Kohana::lang('import.xml.no_form_exists') . $this->totalreports . ': "' . $report_form . '"';
}
$form_id = isset($this->existing_forms[utf8::strtoupper($report_form)]) ? $this->existing_forms[utf8::strtoupper($report_form)] : 1;
}
// Report Date added
$dateadd = xml::get_node_text($report, 'dateadd');
// Report Description
$report_description = xml::get_node_text($report, 'description');
$new_report = new Incident_Model();
$new_report->location_id = isset($new_location) ? $new_location->id : 0;
$new_report->user_id = 0;
$new_report->incident_title = $report_title;
$new_report->incident_description = $report_description ? $report_description : '';
$new_report->incident_date = date("Y-m-d H:i:s", strtotime($report_date));
$new_report->incident_dateadd = ($dateadd and strtotime($dateadd)) ? $dateadd : $this->time;
$new_report->incident_active = $report_approved;
$new_report->incident_verified = $report_verified;
$new_report->incident_mode = $report_mode;
$new_report->form_id = isset($form_id) ? $form_id : 1;
$new_report->save();
// Increment imported rows counter
$this->importedreports++;
// Add this report to array of reports added during import
$this->incidents_added[] = $new_report->id;
//.........这里部分代码省略.........