Merge branch 4.6 into master
[civicrm-core.git] / CRM / Utils / Migrate / Export.php
index 05be0bfc6bab006eb54c2b23c0b471a9e08821e3..ccd31a2df9056d894544653cae23bdbef6cca566 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -53,9 +53,8 @@ class CRM_Utils_Migrate_Export {
   protected $_xml;
 
   /**
-   *
    */
-  function __construct() {
+  public function __construct() {
     $this->_xml = array(
       'customGroup' => array(
         'data' => array(),
@@ -75,7 +74,7 @@ class CRM_Utils_Migrate_Export {
         'mappedFields' => array(
           array('optionGroup', 'option_group_id', 'option_group_name'),
           array('customGroup', 'custom_group_id', 'custom_group_name'),
-        )
+        ),
       ),
       'optionGroup' => array(
         'data' => array(),
@@ -127,7 +126,7 @@ class CRM_Utils_Migrate_Export {
         'required' => FALSE,
         'idNameMap' => array(),
         'mappedFields' => array(
-          array('profileGroup', 'uf_group_id', 'profile_group_name')
+          array('profileGroup', 'uf_group_id', 'profile_group_name'),
         ),
       ),
       'profileJoin' => array(
@@ -137,7 +136,7 @@ class CRM_Utils_Migrate_Export {
         'required' => FALSE,
         'idNameMap' => array(),
         'mappedFields' => array(
-          array('profileGroup', 'uf_group_id', 'profile_group_name')
+          array('profileGroup', 'uf_group_id', 'profile_group_name'),
         ),
       ),
       'mappingGroup' => array(
@@ -149,7 +148,7 @@ class CRM_Utils_Migrate_Export {
         'idNameMap' => array(),
         'mappedFields' => array(
           array('optionValue', 'mapping_type_id', 'mapping_type_name', 'mapping_type'),
-        )
+        ),
       ),
       'mappingField' => array(
         'data' => array(),
@@ -171,7 +170,7 @@ class CRM_Utils_Migrate_Export {
    *
    * @return void
    */
-  function build() {
+  public function build() {
     // fetch the option group / values for
     // activity type and event_type
 
@@ -267,10 +266,11 @@ class CRM_Utils_Migrate_Export {
   }
 
   /**
-   * @param array $customGroupIds list of custom groups to export
+   * @param array $customGroupIds
+   *   List of custom groups to export.
    * @return void
    */
-  function buildCustomGroups($customGroupIds) {
+  public function buildCustomGroups($customGroupIds) {
     $customGroupIdsSql = implode(',', array_filter($customGroupIds, 'is_numeric'));
     if (empty($customGroupIdsSql)) {
       return;
@@ -320,10 +320,11 @@ class CRM_Utils_Migrate_Export {
   }
 
   /**
-   * @param array $ufGroupIds list of custom groups to export
+   * @param array $ufGroupIds
+   *   List of custom groups to export.
    * @return void
    */
-  function buildUFGroups($ufGroupIds) {
+  public function buildUFGroups($ufGroupIds) {
     $ufGroupIdsSql = implode(',', array_filter($ufGroupIds, 'is_numeric'));
     if (empty($ufGroupIdsSql)) {
       return;
@@ -359,9 +360,10 @@ class CRM_Utils_Migrate_Export {
   /**
    * Render the in-memory representation as XML
    *
-   * @return string XML
+   * @return string
+   *   XML
    */
-  function toXML() {
+  public function toXML() {
     $buffer = '<?xml version="1.0" encoding="iso-8859-1" ?>';
     $buffer .= "\n\n<CustomData>\n";
     foreach (array_keys($this->_xml) as $key) {
@@ -385,11 +387,11 @@ class CRM_Utils_Migrate_Export {
    *
    * @return array
    */
-  function toArray() {
+  public function toArray() {
     $result = array();
     foreach (array_keys($this->_xml) as $key) {
       if (!empty($this->_xml[$key]['data'])) {
-        $result[ $this->_xml[$key]['name'] ] = array_values($this->_xml[$key]['data']);
+        $result[$this->_xml[$key]['name']] = array_values($this->_xml[$key]['data']);
       }
     }
     return $result;
@@ -400,7 +402,7 @@ class CRM_Utils_Migrate_Export {
    * @param string $daoName
    * @param null $sql
    */
-  function fetch($groupName, $daoName, $sql = NULL) {
+  public function fetch($groupName, $daoName, $sql = NULL) {
     $idNameFields = isset($this->_xml[$groupName]['idNameFields']) ? $this->_xml[$groupName]['idNameFields'] : NULL;
     $mappedFields = isset($this->_xml[$groupName]['mappedFields']) ? $this->_xml[$groupName]['mappedFields'] : NULL;
 
@@ -429,9 +431,12 @@ class CRM_Utils_Migrate_Export {
   /**
    * Compute any fields of the entity defined by the $mappedFields specification
    *
-   * @param array $mappedFields each item is an array(0 => MappedEntityname, 1 => InputFieldName (id-field), 2 => OutputFieldName (name-field), 3 => OptionalPrefix)
-   * @param CRM_Core_DAO $dao the entity for which we want to prepare mapped fields
-   * @return array new fields
+   * @param array $mappedFields
+   *   Each item is an array(0 => MappedEntityname, 1 => InputFieldName (id-field), 2 => OutputFieldName (name-field), 3 => OptionalPrefix).
+   * @param CRM_Core_DAO $dao
+   *   The entity for which we want to prepare mapped fields.
+   * @return array
+   *   new fields
    */
   public function computeMappedFields($mappedFields, $dao) {
     $keyValues = array();
@@ -452,14 +457,15 @@ class CRM_Utils_Migrate_Export {
   }
 
   /**
-   * @param string $objectName business-entity/xml-tag name
+   * @param string $objectName
+   *   Business-entity/xml-tag name.
    * @param CRM_Core_DAO $object
    * @param $mappedFields
    *
    * @return array
    */
-  function exportDAO($objectName, $object, $mappedFields) {
-    $dbFields = & $object->fields();
+  public function exportDAO($objectName, $object, $mappedFields) {
+    $dbFields = &$object->fields();
 
     // Filter the list of keys and values so that we only export interesting stuff
     $keyValues = array();
@@ -471,7 +477,15 @@ class CRM_Utils_Migrate_Export {
       if (isset($object->$name) && $object->$name !== NULL) {
         // hack for extends_entity_column_value
         if ($name == 'extends_entity_column_value') {
-          if (in_array($object->extends, array('Event', 'Activity', 'Relationship', 'Individual', 'Organization', 'Household', 'Case'))) {
+          if (in_array($object->extends, array(
+              'Event',
+              'Activity',
+              'Relationship',
+              'Individual',
+              'Organization',
+              'Household',
+              'Case',
+            ))) {
             if ($object->extends == 'Event') {
               $key = 'event_type';
             }
@@ -481,7 +495,7 @@ class CRM_Utils_Migrate_Export {
             elseif ($object->extends == 'Relationship') {
               $key = 'relationship_type';
             }
-            elseif($object->extends == 'Case') {
+            elseif ($object->extends == 'Case') {
               $key = 'case_type';
             }
             $types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($object->$name, 1, -1));
@@ -536,7 +550,8 @@ class CRM_Utils_Migrate_Export {
    * @param string $tagName
    * @param array $keyValues
    * @throws Exception
-   * @return string XML
+   * @return string
+   *   XML
    */
   public function renderKeyValueXML($tagName, $keyValues) {
     $xml = "    <$tagName>";
@@ -548,18 +563,21 @@ class CRM_Utils_Migrate_Export {
   }
 
   /**
-   * @param string $name tag name
-   * @param string $value text
+   * @param string $name
+   *   Tag name.
+   * @param string $value
+   *   Text.
    * @param string $prefix
    *
    * @throws Exception
-   * @return string XML
+   * @return string
+   *   XML
    */
-  function renderTextTag($name, $value, $prefix = '') {
+  public function renderTextTag($name, $value, $prefix = '') {
     if (!preg_match('/^[a-zA-Z0-9\_]+$/', $name)) {
       throw new Exception("Malformed tag name: $name");
     }
     return $prefix . "<$name>" . htmlentities($value) . "</$name>";
   }
-}
 
+}