Beispiel #1
0
 /**
  * Return an collection of records as XML. 
  * 
  * @see getRecordAsXml for options to set in the record class to control this.
  *
  * @param Doctrine_Collection $collection
  * @param SimpleXMLElement $xml
  * @return string Xml as string 
  */
 public static function getCollectionAsXml(Doctrine_Collection $collection, SimpleXMLElement $incomming_xml = null)
 {
     $collectionName = Doctrine_Lib::plurelize($collection->getTable()->tableName);
     if ($collection->count != 0) {
         $record = $collection[0];
         $xml_options = $record->option("xml");
         if (isset($xml_options["collection_name"])) {
             $collectionName = $xml_options["collection_name"];
         }
     }
     if (!isset($incomming_xml)) {
         $new_xml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><" . $collectionName . "></" . $collectionName . ">";
         $xml = new SimpleXMLElement($new_xml_string);
     } else {
         $xml = $incomming_xml->addChild($collectionName);
     }
     foreach ($collection as $key => $record) {
         Doctrine_Lib::getRecordAsXml($record, $xml);
     }
     return $xml->asXML();
 }