本文整理汇总了PHP中XmlWriter::writeElement方法的典型用法代码示例。如果您正苦于以下问题:PHP XmlWriter::writeElement方法的具体用法?PHP XmlWriter::writeElement怎么用?PHP XmlWriter::writeElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlWriter
的用法示例。
在下文中一共展示了XmlWriter::writeElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeElement
public function writeElement($name, $value, $prefix = null, $url = null)
{
if ($prefix !== null) {
$this->cursor->writeElementNs($prefix, $name, $url, $value);
} else {
$this->cursor->writeElement($name, $value);
}
}
示例2: writeElement
public function writeElement($name, $value, $prefix = null, $url = null)
{
if ($prefix !== null) {
$this->cursor->writeElementNs($prefix, $name, $url, $value);
} elseif ($this->needsCdataWrapping($value)) {
$this->startElement($name, $prefix, $url);
$this->cursor->writeCdata($value);
$this->endElement();
} else {
$this->cursor->writeElement($name, $value);
}
}
示例3: executeXml
public function executeXml(AgaviRequestDataHolder $request_data)
{
$report = $this->prepareReport($request_data);
$xml = new XmlWriter();
$xml->openMemory();
$xml->setIndent(true);
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('application');
$xml->writeAttribute('name', $report['application']);
$xml->startElement('status');
$xml->text($report['status']);
$xml->endElement();
$connections = $report['connections'];
$xml->startElement('connections');
foreach ($connections['stats'] as $name => $value) {
$xml->writeAttribute($name, $value);
}
$xml->writeElement('status', $connections['status']);
$xml->startElement('stats');
foreach ($connections['stats'] as $name => $value) {
$xml->writeElement($name, $value);
}
$xml->endElement();
// connections/stats
foreach ($connections['details'] as $name => $value) {
$xml->startElement('connection');
$xml->writeAttribute('name', $name);
if (is_array($value)) {
$this->array2xml($value, $xml);
} else {
$xml->writeCData((string) $value);
}
$xml->endElement();
}
$xml->endElement();
// connections
$xml->endElement();
// application
$xml->endDocument();
return $xml->outputMemory();
}
示例4: outputSitemap
public function outputSitemap(Kwf_Component_Data $page)
{
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('urlset');
$xml->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
foreach (array_unique($this->_getSitemap($page)) as $url) {
$xml->startElement('url');
$xml->writeElement('loc', $url);
$xml->endElement();
}
$xml->endElement();
$xml->endDocument();
header('Content-Type: text/xml; charset=utf-8');
echo $xml->outputMemory(true);
exit;
}
示例5: addEntityInfo
/**
* @param \Product\Entity\Product|Post $entity
*/
public function addEntityInfo($entity)
{
$this->writer->startElement('url');
$this->writer->writeElement('lastmod', date(\Datetime::ATOM, time()));
$this->writer->startElement('image:image');
if ($entity instanceof Post) {
$this->writer->writeElement('image:loc', "http://www.infolightingco.com/images/posts/" . $entity->getThumbnail());
$this->writer->writeElement('loc', "http://www.infolightingco.com/news/" . $entity->getUrl());
} else {
$this->writer->writeElement('image:loc', "http://www.infolightingco.com/images/posts/" . $entity->getThumbnail());
$this->writer->writeElement('loc', "http://www.infolightingco.com/products/view/" . $entity->getProductNumber());
}
$this->writer->endElement();
$this->writer->endElement();
}
示例6: writeImage
private function writeImage(\XmlWriter $writer, Image $image)
{
$writer->startElement('image');
$writer->writeElement('url', $image->getUrl());
$writer->writeElement('link', $image->getLink());
$writer->startElement('title');
$writer->writeCdata($image->getTitle());
$writer->endElement();
$writer->endElement();
}
示例7: objectSerialize
/**
* Serialize an object with specified root element name.
*
* @param object $targetObject The target object.
* @param string $rootName The name of the root element.
*
* @return string
*/
public static function objectSerialize($targetObject, $rootName)
{
Validate::notNull($targetObject, 'targetObject');
Validate::isString($rootName, 'rootName');
$xmlWriter = new \XmlWriter();
$xmlWriter->openMemory();
$xmlWriter->setIndent(true);
$reflectionClass = new \ReflectionClass($targetObject);
$methodArray = $reflectionClass->getMethods();
$attributes = self::_getInstanceAttributes($targetObject, $methodArray);
$xmlWriter->startElement($rootName);
if (!is_null($attributes)) {
foreach (array_keys($attributes) as $attributeKey) {
$xmlWriter->writeAttribute($attributeKey, $attributes[$attributeKey]);
}
}
foreach ($methodArray as $method) {
if (strpos($method->name, 'get') === 0 && $method->isPublic() && $method->name != 'getAttributes') {
$variableName = substr($method->name, 3);
$variableValue = $method->invoke($targetObject);
if (!empty($variableValue)) {
if (gettype($variableValue) === 'object') {
$xmlWriter->writeRaw(XmlSerializer::objectSerialize($variableValue, $variableName));
} else {
$xmlWriter->writeElement($variableName, $variableValue);
}
}
}
}
$xmlWriter->endElement();
return $xmlWriter->outputMemory(true);
}
示例8: array
/**
* do the search via the API
* @param q - the search string.
*
* @param limit - the value to limit by.
*
* @return the search result.
*/
function _doSearch($q, $limit)
{
/**
* This is mostly borrowed from the search functionality
* see application/controller/search.php
*/
$search_query = "";
$keyword_string = "";
$where_string = "";
$plus = "";
$or = "";
$search_info = "";
$html = "";
$json_searches = array();
// Stop words that we won't search for
// Add words as needed!!
$stop_words = array('the', 'and', 'a', 'to', 'of', 'in', 'i', 'is', 'that', 'it', 'on', 'you', 'this', 'for', 'but', 'with', 'are', 'have', 'be', 'at', 'or', 'as', 'was', 'so', 'if', 'out', 'not');
$retJsonOrXml = '';
//will hold the json/xml string to return
$replar = array();
//assists in proper xml generation
// Doing this manaully. It was wasting my time trying to modularize it.
// Will have to visit this again after a good rest. I mean a good rest.
//XML elements
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('response');
$xml->startElement('payload');
$xml->startElement('searches');
$keywords = explode(' ', $q);
if (is_array($keywords) && !empty($keywords)) {
array_change_key_case($keywords, CASE_LOWER);
$i = 0;
foreach ($keywords as $value) {
if (!in_array($value, $stop_words) && !empty($value)) {
$chunk = mysql_real_escape_string($value);
if ($i > 0) {
$plus = ' + ';
$or = ' OR ';
}
// Give relevancy weighting
// Title weight = 2
// Description weight = 1
$keyword_string = $keyword_string . $plus . "(CASE WHEN incident_title LIKE '%{$chunk}%' THEN 2 ELSE 0 END) + (CASE WHEN incident_description LIKE '%{$chunk}%' THEN 1 ELSE 0 END)";
$where_string = $where_string . $or . "incident_title LIKE '%{$chunk}%' OR incident_description LIKE '%{$chunk}%'";
$i++;
}
}
if (!empty($keyword_string) && !empty($where_string)) {
$search_query = "SELECT *, (" . $keyword_string . ") AS relevance FROM incident WHERE (" . $where_string . ") ORDER BY relevance DESC ";
}
}
if (!empty($search_query)) {
if (!empty($limit) && is_numeric($limit)) {
$l = "LIMIT 0 ," . $limit;
} else {
$l = " LIMIT ," . $this->list_limit;
}
$total_items = ORM::factory('incident')->where($where_string)->count_all();
$s = $search_query . $l;
$query = $this->db->query($s);
$this->total_records = $total_items;
// Results Bar
if ($total_items != 0) {
if ($this->responseType == 'json') {
$json_searches[] = array("total" => $total_items);
} else {
$xml->writeElement('total', $total_items);
}
} else {
$xml->writeElement('total', $total_items);
//create the json array
$data = array("payload" => array("searches" => $json_searches), "error" => $this->_getErrorMsg(0));
if ($this->responseType == 'json') {
$retJsonOrXml = $this->_arrayAsJSON($data);
return $retJsonOrXml;
} else {
$xml->endElement();
//end searches
$xml->endElement();
// end payload
$xml->startElement('error');
$xml->writeElement('code', 0);
$xml->writeElement('message', 'No Error');
$xml->endElement();
//end error
$xml->endElement();
// end response
return $xml->outputMemory(true);
}
}
//.........这里部分代码省略.........
示例9: _get_incidents
/**
* Generic function to get reports by given set of parameters
*
* @param string $where SQL where clause
* @param int $limit No. of records to return - set to 20 by default
* @return string XML or JSON string
*/
public function _get_incidents($where = array())
{
// STEP 1.
// Get the incidents
$items = Incident_Model::get_incidents($where, $this->list_limit, $this->order_field, $this->sort);
//No record found.
if ($items->count() == 0) {
return $this->response(4, $this->error_messages);
}
// Records found - proceed
// Set the no. of records returned
$this->record_count = $items->count();
// Will hold the XML/JSON string to return
$ret_json_or_xml = '';
$json_reports = array();
$json_report_media = array();
$json_report_categories = array();
$json_incident_media = array();
$upload_path = str_replace("media/uploads/", "", Kohana::config('upload.relative_directory') . "/");
//XML elements
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('response');
$xml->startElement('payload');
$xml->writeElement('domain', $this->domain);
$xml->startElement('incidents');
// Records found, proceed
// Store the incident ids
$incidents_ids = array();
foreach ($items as $item) {
$incident_ids[] = $item->incident_id;
}
//
// STEP 2.
// Fetch the incident categories
//
$this->query = "SELECT c.category_title AS categorytitle, ic.incident_id, " . "c.id AS cid, c.category_image_thumb AS categorythumb, " . "d.decayimage_thumb AS decayimagethumb " . "FROM " . $this->table_prefix . "category AS c " . "INNER JOIN " . $this->table_prefix . "incident_category AS ic ON ic.category_id = c.id " . "LEFT JOIN " . $this->table_prefix . "decayimage as d ON c.id = d.category_id " . "WHERE ic.incident_id IN (" . implode(',', $incident_ids) . ")";
// Execute the query
$incident_categories = $this->db->query($this->query);
// To hold the incident category items
$category_items = array();
// Temporary counter
$i = 1;
// Fetch items into array
foreach ($incident_categories as $incident_category) {
$category_items[$incident_category->incident_id][$i]['cid'] = $incident_category->cid;
$category_items[$incident_category->incident_id][$i]['categorytitle'] = $incident_category->categorytitle;
$category_items[$incident_category->incident_id][$i]['categorythumb'] = $incident_category->categorythumb;
$category_items[$incident_category->incident_id][$i]['decayimagethumb'] = $incident_category->decayimagethumb;
$i++;
}
// Free temporary variables from memory
unset($incident_categories);
//
// STEP 3.
// Fetch the media associated with all the incidents
//
$this->query = "SELECT i.id AS incident_id, m.id AS mediaid, m.media_title AS mediatitle, " . "m.media_type AS mediatype, m.media_link AS medialink, m.media_thumb AS mediathumb " . "FROM " . $this->table_prefix . "media AS m " . "INNER JOIN " . $this->table_prefix . "incident AS i ON i.id = m.incident_id " . "WHERE i.id IN (" . implode(",", $incident_ids) . ")";
$media_items_result = $this->db->query($this->query);
// To store the fetched media items
$media_items = array();
// Reset the temporary counter
$i = 1;
// Fetch items into array
foreach ($media_items_result as $media_item) {
$media_items[$media_item->incident_id][$i]['mediaid'] = $media_item->mediaid;
$media_items[$media_item->incident_id][$i]['mediatitle'] = $media_item->mediatitle;
$media_items[$media_item->incident_id][$i]['mediatype'] = $media_item->mediatype;
$media_items[$media_item->incident_id][$i]['medialink'] = $media_item->medialink;
$media_items[$media_item->incident_id][$i]['mediathumb'] = $media_item->mediathumb;
$i++;
}
// Free temporary variables
unset($media_items_result, $i);
//
// STEP 4.
// Fetch the comments associated with the incidents
//
if ($this->comments) {
$this->query = "SELECT id, incident_id, comment_author, comment_email, " . "comment_description, comment_rating, comment_date " . "FROM " . $this->table_prefix . "comment AS c " . "WHERE c.incident_id IN (" . implode(',', $incident_ids) . ")";
// Execute the query
$incident_comments = $this->db->query($this->query);
// To hold the incident category items
$comment_items = array();
// Temporary counter
$i = 1;
// Fetch items into array
foreach ($incident_comments as $incident_comment) {
$comment_items[$incident_comment->incident_id][$i]['id'] = $incident_comment->id;
$comment_items[$incident_comment->incident_id][$i]['incident_id'] = $incident_comment->incident_id;
$comment_items[$incident_comment->incident_id][$i]['comment_author'] = $incident_comment->comment_author;
$comment_items[$incident_comment->incident_id][$i]['comment_email'] = $incident_comment->comment_email;
//.........这里部分代码省略.........
示例10: array
/**
* Function for returning deleted incident id's only
*/
function _getDeletedIncidents($where = '', $limit = '')
{
$items = array();
//will hold the items from the query
$data = array();
//items to parse to json
$json_incidents = array();
//incidents to parse to json
$media_items = array();
//incident media
$json_incident_media = array();
//incident media
$retJsonOrXml = '';
//will hold the json/xml string to return
$replar = array();
//assists in proper xml generation
// Doing this manually. It was wasting my time trying to modularize it.
// Will have to visit this again after a good rest. I mean a good rest.
//XML elements
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('response');
$xml->startElement('payload');
$xml->writeElement('domain', $this->domain);
$xml->startElement('incidents');
//find incidents
$query = "SELECT id, " . "incident_dateadd" . " FROM " . $this->table_prefix . "incident" . "{$where} {$limit}";
$items = $this->db->query($query);
$i = 0;
foreach ($items as $item) {
if ($this->responseType == 'json') {
$json_incident_media = array();
}
//build xml file
$xml->startElement('incident');
$xml->writeElement('id', $item->id);
$xml->writeElement('date', $item->incident_dateadd);
$xml->endElement();
}
$xml->endElement();
//end incidents
$xml->endElement();
// end payload
$xml->startElement('error');
$xml->writeElement('code', 0);
$xml->writeElement('message', 'No Error');
$xml->endElement();
//end error
$xml->endElement();
// end response
return $xml->outputMemory(true);
}
示例11: _get_incidents
/**
* Generic function to get reports by given set of parameters
*/
public function _get_incidents($where = '', $limit = '')
{
$ret_json_or_xml = '';
// Will hold the XML/JSON string to return
$json_reports = array();
$json_report_media = array();
$json_report_categories = array();
$json_incident_media = array();
$upload_path = str_replace("media/uploads/", "", Kohana::config('upload.relative_directory') . "/");
//XML elements
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('response');
$xml->startElement('payload');
$xml->writeElement('domain', $this->domain);
$xml->startElement('incidents');
// Find incidents
$this->query = "SELECT i.id AS incidentid,\n i.incident_title AS incidenttitle," . "i.incident_description AS incidentdescription, " . "i.incident_date AS incidentdate, " . "i.incident_mode AS incidentmode, " . "i.incident_active AS incidentactive, " . "i.incident_verified AS incidentverified, " . "l.id AS locationid, " . "l.location_name AS locationname, " . "l.latitude AS locationlatitude, " . "l.longitude AS locationlongitude " . "FROM " . $this->table_prefix . "incident AS i " . "INNER JOIN " . $this->table_prefix . "location as l on l.id = i.location_id " . "{$where} {$limit}";
$items = $this->db->query($this->query);
// Set the no. of records returned
$this->record_count = $items->count();
$incidentids = array();
foreach ($items as $item) {
$incidentids[] = $item->incidentid;
}
// Fetch categories
$this->query = " SELECT c.category_title AS categorytitle, \n c.id as cid ,ic.incident_id as incidentid " . "FROM " . $this->table_prefix . "category AS c INNER JOIN " . $this->table_prefix . "incident_category AS ic ON " . "ic.category_id = c.id WHERE ic.incident_id IN(" . implode(',', $incidentids) . ")";
$category_items_temp = $this->db->query($this->query);
$category_items = array();
$temp_index = 1;
foreach ($category_items_temp as $category_item) {
$category_items[$category_item->incidentid][$temp_index]['categorytitle'] = $category_item->categorytitle;
$category_items[$category_item->incidentid][$temp_index]['cid'] = $category_item->cid;
$temp_index++;
}
unset($category_items_temp);
//fetch media associated with an incident
$this->query = "SELECT i.id as incidentid , m.id as mediaid, m.media_title AS \n mediatitle, " . "m.media_type AS mediatype, m.media_link AS medialink, " . "m.media_thumb AS mediathumb FROM " . $this->table_prefix . "media AS m " . "INNER JOIN " . $this->table_prefix . "incident AS i ON i.id = m.incident_id " . "WHERE i.id IN(" . implode(',', $incidentids) . ")";
$media_items = $this->db->query($this->query);
$media_items_temp = $this->db->query($this->query);
$media_items = array();
$temp_index = 1;
foreach ($media_items_temp as $media_item) {
$media_items[$media_item->incidentid][$temp_index]['mediaid'] = $media_item->mediaid;
$media_items[$media_item->incidentid][$temp_index]['mediatitle'] = $media_item->mediatitle;
$media_items[$media_item->incidentid][$temp_index]['mediatype'] = $media_item->mediatype;
$media_items[$media_item->incidentid][$temp_index]['medialink'] = $media_item->medialink;
$media_items[$media_item->incidentid][$temp_index]['mediathumb'] = $media_item->mediathumb;
$temp_index++;
}
unset($media_items_temp);
unset($temp_index);
$i = 0;
//No record found.
if ($items->count() == 0) {
return $this->response(4, $this->error_messages);
}
foreach ($items as $item) {
// Build xml file
$xml->startElement('incident');
$xml->writeElement('id', $item->incidentid);
$xml->writeElement('title', $item->incidenttitle);
$xml->writeElement('description', $item->incidentdescription);
$xml->writeElement('date', $item->incidentdate);
$xml->writeElement('mode', $item->incidentmode);
$xml->writeElement('active', $item->incidentactive);
$xml->writeElement('verified', $item->incidentverified);
$xml->startElement('location');
$xml->writeElement('id', $item->locationid);
$xml->writeElement('name', $item->locationname);
$xml->writeElement('latitude', $item->locationlatitude);
$xml->writeElement('longitude', $item->locationlongitude);
$xml->endElement();
$xml->startElement('categories');
$json_report_categories[$item->incidentid] = array();
foreach ($category_items[$item->incidentid] as $category_item) {
if ($this->response_type == 'json') {
$json_report_categories[$item->incidentid][] = array("category" => array("id" => $category_item['cid'], "title" => $category_item['categorytitle']));
} else {
$xml->startElement('category');
$xml->writeElement('id', $category_item['cid']);
$xml->writeElement('title', $category_item['categorytitle']);
$xml->endElement();
}
}
$xml->endElement();
//end categories
$json_report_media[$item->incidentid] = array();
if (isset($media_items[$item->incidentid]) && count($media_items[$item->incidentid]) > 0) {
$xml->startElement('mediaItems');
foreach ($media_items[$item->incidentid] as $media_item) {
if ($media_item['mediatype'] != 1) {
$upload_path = "";
}
if ($this->response_type == 'json') {
$json_report_media[$item->incidentid] = array("id" => $media_item['mediaid'], "type" => $media_item['mediatype'], "link" => $upload_path . $media_item['medialink'], "thumb" => $upload_path . $media_item['mediathumb']);
//.........这里部分代码省略.........
示例12: generate
/**
* Generates the XML output and saves it to a file or returns it as a string
*
* @return null|int Returns the number of bytes written to a local file or false on failure
*/
protected function generate()
{
$w = new \XmlWriter();
$w->openMemory();
$w->setIndent(true);
$w->setIndentString(" ");
$w->startDocument('1.0', 'utf-8');
$w->startElement($this->rootname);
while ($object = $this->getRow()) {
// Start a new row for each object
$w->startElement($this->rowname);
foreach ($object as $key => $value) {
if ($this->suppress && in_array($key, $this->suppress)) {
continue;
}
$this->isValidName($key);
// Check if the key contains another object
if (is_object($value)) {
// Start parent element containing rows of each object
$w->startElement($key . "s");
// $value is an array of objects
foreach ($value as $obj) {
$w->startElement($key);
foreach ($obj as $field => $val) {
$this->isValidName($key);
$w->writeElement($field, $val);
}
$w->endElement();
}
$w->endElement();
} else {
// Write each object's property->value as <key>value</key>
if ($this->hasChildren && in_array($key, $this->hasChildren)) {
$stripped = $this->stripHtml($value);
$w->startElement($key);
foreach ($stripped as $para) {
$w->writeElement('p', $para);
}
$w->endElement();
} else {
$w->writeElement($key, $value);
}
}
}
$w->endElement();
}
$w->endElement();
$w->endDocument();
$this->xml = $w->outputMemory();
// write to file
if (isset($this->filename) && $this->local) {
$success = file_put_contents($this->filename, $this->xml);
return $success;
} elseif (isset($this->filename) && $this->download) {
$this->outputHeaders();
file_put_contents('php://output', $this->xml);
exit;
}
}
示例13: _get_incidents
/**
* Generic function to get reports by given set of parameters
*
* @param string $where SQL where clause
* @return string XML or JSON string
*/
public function _get_incidents($where = array())
{
// STEP 1.
// Get the incidents
$items = Incident_Model::get_incidents($where, $this->list_limit, $this->order_field, $this->sort);
//No record found.
if ($items->count() == 0) {
return $this->response(4, $this->error_messages);
}
// Records found - proceed
// Set the no. of records returned
$this->record_count = $items->count();
// Will hold the XML/JSON string to return
$ret_json_or_xml = '';
$json_reports = array();
$json_report_media = array();
$json_report_categories = array();
$json_incident_media = array();
$upload_path = str_replace("media/uploads/", "", Kohana::config('upload.relative_directory') . "/");
//XML elements
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('response');
$xml->startElement('payload');
$xml->writeElement('domain', $this->domain);
$xml->startElement('incidents');
// Records found, proceed
// Store the incident ids
$incidents_ids = array();
$custom_field_items = array();
foreach ($items as $item) {
$incident_ids[] = $item->incident_id;
$thiscustomfields = customforms::get_custom_form_fields($item->incident_id, null, false, "view");
if (!empty($thiscustomfields)) {
$custom_field_items[$item->incident_id] = $thiscustomfields;
}
}
//
// STEP 2.
// Fetch the incident categories
//
// Execute the query
$incident_categories = ORM::factory('category')->select('category.*, incident_category.incident_id')->join('incident_category', 'category.id', 'incident_category.category_id')->in('incident_category.incident_id', $incident_ids)->find_all();
// To hold the incident category items
$category_items = array();
// Fetch items into array
foreach ($incident_categories as $incident_category) {
$category_items[$incident_category->incident_id][] = $incident_category->as_array();
}
// Free temporary variables from memory
unset($incident_categories);
//
// STEP 3.
// Fetch the media associated with all the incidents
//
$media_items_result = ORM::factory('media')->in('incident_id', $incident_ids)->find_all();
// To store the fetched media items
$media_items = array();
// Fetch items into array
foreach ($media_items_result as $media_item) {
$media_item_array = $media_item->as_array();
if ($media_item->media_type == 1 and !empty($media_item->media_thumb)) {
$media_item_array["media_thumb_url"] = url::convert_uploaded_to_abs($media_item->media_thumb);
$media_item_array["media_link_url"] = url::convert_uploaded_to_abs($media_item->media_link);
}
$media_items[$media_item->incident_id][] = $media_item_array;
}
// Free temporary variables
unset($media_items_result, $media_item_array);
//
// STEP 4.
// Fetch the comments associated with the incidents
//
if ($this->comments) {
// Execute the query
$incident_comments = ORM::factory('comment')->in('incident_id', $incident_ids)->where('comment_spam', 0)->find_all();
// To hold the incident category items
$comment_items = array();
// Fetch items into array
foreach ($incident_comments as $incident_comment) {
$comment_items[$incident_comment->incident_id][] = $incident_comment->as_array();
}
// Free temporary variables from memory
unset($incident_comments);
}
//
// STEP 5.
// Return XML
//
foreach ($items as $item) {
// Build xml file
$xml->startElement('incident');
$xml->writeElement('id', $item->incident_id);
//.........这里部分代码省略.........
示例14: buildOpenPayUDocument
/**
* Function builds OpenPayU Xml Document
* @access public
* @param string $data
* @param string $startElement
* @param integer $request
* @param string $xml_version
* @param string $xml_encoding
* @return string $xml
*/
public static function buildOpenPayUDocument($data, $startElement, $request = 1, $xml_version = '1.0', $xml_encoding = 'UTF-8')
{
if (!is_array($data)) {
return false;
}
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument($xml_version, $xml_encoding);
if (OpenPayU_Configuration::getApiVersion() < 2) {
$xml->startElementNS(null, 'OpenPayU', 'http://www.openpayu.com/openpayu.xsd');
$header = $request == 1 ? 'HeaderRequest' : 'HeaderResponse';
$xml->startElement($header);
$xml->writeElement('Algorithm', OpenPayU_Configuration::getHashAlgorithm());
$xml->writeElement('SenderName', 'exampleSenderName');
$xml->writeElement('Version', $xml_version);
$xml->endElement();
} else {
$xml->startElementNS(null, 'OpenPayU', 'http://www.openpayu.com/20/openpayu.xsd');
}
// domain level - open
if (OpenPayU_Configuration::getApiVersion() < 2) {
$xml->startElement(OpenPayUDomain::getDomain4Message($startElement));
}
// message level - open
$xml->startElement($startElement);
OpenPayU_Util::convertArrayToXml($xml, $data);
// message level - close
$xml->endElement();
// domain level - close
$xml->endElement();
// document level - close
if (OpenPayU_Configuration::getApiVersion() < 2) {
$xml->endElement();
}
return $xml->outputMemory(true);
}
示例15: array
/**
* generic function to get incidents by given set of parameters
*/
function _getIncidents($where = '', $limit = '')
{
$items = array();
//will hold the items from the query
$data = array();
//items to parse to json
$json_incidents = array();
//incidents to parse to json
$media_items = array();
//incident media
$json_incident_media = array();
//incident media
$retJsonOrXml = '';
//will hold the json/xml string to return
$replar = array();
//assists in proper xml generation
// Doing this manaully. It was wasting my time trying modularize it.
// Will have to visit this again after a good rest. I mean a good rest.
//XML elements
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('response');
$xml->startElement('payload');
$xml->startElement('incidents');
//find incidents
$query = "SELECT i.id AS incidentid,i.incident_title AS incidenttitle," . "i.incident_description AS incidentdescription, i.incident_date AS " . "incidentdate, i.incident_mode AS incidentmode,i.incident_active AS " . "incidentactive, i.incident_verified AS incidentverified, l.id AS " . "locationid,l.location_name AS locationname,l.latitude AS " . "locationlatitude,l.longitude AS locationlongitude FROM incident AS i " . "INNER JOIN location as l on l.id = i.location_id " . "{$where} {$limit}";
$items = $this->db->query($query);
$i = 0;
foreach ($items as $item) {
if ($this->responseType == 'json') {
$json_incident_media = array();
}
//build xml file
$xml->startElement('incident');
$xml->writeElement('id', $item->incidentid);
$xml->writeElement('title', $item->incidenttitle);
$xml->writeElement('description', $item->incidentdescription);
$xml->writeElement('date', $item->incidentdate);
$xml->writeElement('mode', $item->incidentmode);
$xml->writeElement('active', $item->incidentactive);
$xml->writeElement('verified', $item->incidentverified);
$xml->startElement('location');
$xml->writeElement('id', $item->locationid);
$xml->writeElement('name', $item->locationname);
$xml->writeElement('latitude', $item->locationlatitude);
$xml->writeElement('longitude', $item->locationlongitude);
$xml->endElement();
$xml->startElement('categories');
//fetch categories
$query = " SELECT c.category_title AS categorytitle, c.id AS cid " . "FROM category AS c INNER JOIN incident_category AS ic ON " . "ic.category_id = c.id WHERE ic.incident_id =" . $item->incidentid . " LIMIT 0 , 20";
$category_items = $this->db->query($query);
foreach ($category_items as $category_item) {
$xml->startElement('category');
$xml->writeElement('id', $category_item->cid);
$xml->writeElement('title', $category_item->categorytitle);
$xml->endElement();
}
$xml->endElement();
//end categories
//fetch media associated with an incident
$query = "SELECT m.id as mediaid, m.media_title AS mediatitle, " . "m.media_type AS mediatype, m.media_link AS medialink, " . "m.media_thumb AS mediathumb FROM media AS m " . "INNER JOIN incident AS i ON i.id = m.incident_id " . "WHERE i.id =" . $item->incidentid . " LIMIT 0 , 20";
$media_items = $this->db->query($query);
if (count($media_items) > 0) {
$xml->startElement('mediaItems');
foreach ($media_items as $media_item) {
if ($this->responseType == 'json') {
$json_incident_media[] = $media_item;
} else {
$xml->startElement('media');
$xml->writeElement('id', $media_item->mediaid);
$xml->writeElement('title', $media_item->mediatitle);
$xml->writeElement('type', $media_item->mediatype);
$xml->writeElement('link', $media_item->medialink);
$xml->writeElement('thumb', $media_item->mediathumb);
$xml->endElement();
}
}
$xml->endElement();
// media
}
$xml->endElement();
// end incident
//needs different treatment depending on the output
if ($this->responseType == 'json') {
$json_incidents[] = array("incident" => $item, "media" => $json_incident_media);
}
}
//create the json array
$data = array("payload" => array("incidents" => $json_incidents), "error" => $this->_getErrorMsg(0));
if ($this->responseType == 'json') {
$retJsonOrXml = $this->_arrayAsJSON($data);
return $retJsonOrXml;
} else {
$xml->endElement();
//end incidents
$xml->endElement();
//.........这里部分代码省略.........