Merge branch '4.5' of https://github.com/civicrm/civicrm-core into 4.6
[civicrm-core.git] / CRM / Utils / Migrate / ExportJSON.php
index f0e074cc89e29318a7964ddc793f16aaa81983de..10ca18cf00c8449b584d22ed56bed87512761cca 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -33,7 +33,7 @@
  *
  */
 class CRM_Utils_Migrate_ExportJSON {
-  CONST CHUNK_SIZE = 128;
+  const CHUNK_SIZE = 128;
 
   protected $_contactIDs;
 
@@ -52,7 +52,7 @@ class CRM_Utils_Migrate_ExportJSON {
   /**
    * @param array $params
    */
-  function __construct(&$params) {
+  public function __construct(&$params) {
     foreach ($params as $name => $value) {
       $varName = '_' . $name;
       $this->$varName = $value;
@@ -60,9 +60,9 @@ class CRM_Utils_Migrate_ExportJSON {
   }
 
   /**
-   * Split a large array of contactIDs into more manageable smaller chunks
+   * Split a large array of contactIDs into more manageable smaller chunks.
    */
-  function &splitContactIDs(&$contactIDs) {
+  public function &splitContactIDs(&$contactIDs) {
     // contactIDs could be a real large array, so we split it up into
     // smaller chunks and then general xml for each chunk
     $chunks = array();
@@ -89,9 +89,9 @@ class CRM_Utils_Migrate_ExportJSON {
   }
 
   /**
-   * Given a set of contact IDs get the values
+   * Given a set of contact IDs get the values.
    */
-  function getValues(&$contactIDs, &$additionalContactIDs) {
+  public function getValues(&$contactIDs, &$additionalContactIDs) {
 
     $this->contact($contactIDs);
     $this->address($contactIDs);
@@ -112,7 +112,7 @@ class CRM_Utils_Migrate_ExportJSON {
     $this->activity($contactIDs, $additionalContactIDs);
   }
 
-  function metaData() {
+  public function metaData() {
     $optionGroupVars = array(
       'prefix_id' => 'individual_prefix',
       'suffix_id' => 'individual_suffix',
@@ -140,9 +140,9 @@ class CRM_Utils_Migrate_ExportJSON {
   /**
    * @param $tables
    */
-  function auxTable($tables) {
+  public function auxTable($tables) {
     foreach ($tables as $tableName => $daoName) {
-      $fields = & $this->dbFields($daoName, TRUE);
+      $fields = &$this->dbFields($daoName, TRUE);
 
       $sql = "SELECT * from $tableName";
       $this->sql($sql, $tableName, $fields);
@@ -152,7 +152,7 @@ class CRM_Utils_Migrate_ExportJSON {
   /**
    * @param $optionGroupVars
    */
-  function optionGroup($optionGroupVars) {
+  public function optionGroup($optionGroupVars) {
     $names = array_values($optionGroupVars);
     $str = array();
     foreach ($names as $name) {
@@ -165,7 +165,7 @@ SELECT *
 FROM   civicrm_option_group
 WHERE  name IN ( $nameString )
 ";
-    $fields = & $this->dbFields('CRM_Core_DAO_OptionGroup', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_OptionGroup', TRUE);
     $this->sql($sql, 'civicrm_option_group', $fields);
 
     $sql = "
@@ -174,7 +174,7 @@ FROM       civicrm_option_value v
 INNER JOIN civicrm_option_group g ON v.option_group_id = g.id
 WHERE      g.name IN ( $nameString )
 ";
-    $fields = & $this->dbFields('CRM_Core_DAO_OptionValue', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_OptionValue', TRUE);
     $this->sql($sql, 'civicrm_option_value', $fields);
   }
 
@@ -185,11 +185,12 @@ WHERE      g.name IN ( $nameString )
    * @param $whereField
    * @param null $additionalWhereCond
    */
-  function table(&$ids,
-                 $tableName,
-                 &$fields,
-                 $whereField,
-                 $additionalWhereCond = NULL
+  public function table(
+    &$ids,
+    $tableName,
+    &$fields,
+    $whereField,
+    $additionalWhereCond = NULL
   ) {
     if (empty($ids)) {
       return;
@@ -215,8 +216,8 @@ SELECT *
    * @param string $tableName
    * @param $fields
    */
-  function sql($sql, $tableName, &$fields) {
-    $dao = & CRM_Core_DAO::executeQuery($sql);
+  public function sql($sql, $tableName, &$fields) {
+    $dao = &CRM_Core_DAO::executeQuery($sql);
 
     while ($dao->fetch()) {
       $value = array();
@@ -236,73 +237,73 @@ SELECT *
   /**
    * @param $contactIDs
    */
-  function contact(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Contact_DAO_Contact', TRUE);
+  public function contact(&$contactIDs) {
+    $fields = &$this->dbFields('CRM_Contact_DAO_Contact', TRUE);
     $this->table($contactIDs, 'civicrm_contact', $fields, 'id', NULL);
   }
 
   /**
    * @param $contactIDs
    */
-  function note(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_Note', TRUE);
+  public function note(&$contactIDs) {
+    $fields = &$this->dbFields('CRM_Core_DAO_Note', TRUE);
     $this->table($contactIDs, 'civicrm_note', $fields, 'entity_id', "entity_table = 'civicrm_contact'");
   }
 
   /**
    * @param $contactIDs
    */
-  function phone(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_Phone', TRUE);
+  public function phone(&$contactIDs) {
+    $fields = &$this->dbFields('CRM_Core_DAO_Phone', TRUE);
     $this->table($contactIDs, 'civicrm_phone', $fields, 'contact_id', NULL);
   }
 
   /**
    * @param $contactIDs
    */
-  function email(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_Email', TRUE);
+  public function email(&$contactIDs) {
+    $fields = &$this->dbFields('CRM_Core_DAO_Email', TRUE);
     $this->table($contactIDs, 'civicrm_email', $fields, 'contact_id', NULL);
   }
 
   /**
    * @param $contactIDs
    */
-  function im(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_IM', TRUE);
+  public function im(&$contactIDs) {
+    $fields = &$this->dbFields('CRM_Core_DAO_IM', TRUE);
     $this->table($contactIDs, 'civicrm_im', $fields, 'contact_id', NULL);
   }
 
   /**
    * @param $contactIDs
    */
-  function website(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_Website', TRUE);
+  public function website(&$contactIDs) {
+    $fields = &$this->dbFields('CRM_Core_DAO_Website', TRUE);
     $this->table($contactIDs, 'civicrm_website', $fields, 'contact_id', NULL);
   }
 
   /**
    * @param $contactIDs
    */
-  function address(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_Email', TRUE);
+  public function address(&$contactIDs) {
+    $fields = &$this->dbFields('CRM_Core_DAO_Email', TRUE);
     $this->table($contactIDs, 'civicrm_address', $fields, 'contact_id', NULL);
   }
 
   /**
    * @param $contactIDs
    */
-  function groupContact(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Contact_DAO_GroupContact', TRUE);
+  public function groupContact(&$contactIDs) {
+    $fields = &$this->dbFields('CRM_Contact_DAO_GroupContact', TRUE);
     $this->table($contactIDs, 'civicrm_group_contact', $fields, 'contact_id', NULL);
   }
 
-  // TODO - support group inheritance
-  // Parent child group ids are encoded in a text string
   /**
+   * TODO - support group inheritance
+   * Parent child group ids are encoded in a text string
    * @param $contactIDs
    */
-  function group(&$contactIDs) {
+  public function group(&$contactIDs) {
     // handle groups only once
     static $_groupsHandled = array();
 
@@ -322,17 +323,17 @@ WHERE  contact_id IN ( $ids )
       }
     }
 
-    $fields = & $this->dbFields('CRM_Contact_DAO_Group', TRUE);
+    $fields = &$this->dbFields('CRM_Contact_DAO_Group', TRUE);
     $this->table($groupIDs, 'civicrm_group', $fields, 'id');
 
     $this->savedSearch($groupIDs);
   }
 
-  // TODO - support search builder and custom saved searches
   /**
+   * TODO - support search builder and custom saved searches
    * @param $groupIDs
    */
-  function savedSearch(&$groupIDs) {
+  public function savedSearch(&$groupIDs) {
     if (empty($groupIDs)) {
       return;
     }
@@ -345,22 +346,22 @@ INNER JOIN civicrm_group g on g.saved_search_id = s.id
 WHERE      g.id IN ( $idString )
 ";
 
-    $fields = & $this->dbFields('CRM_Contact_DAO_SavedSearch', TRUE);
+    $fields = &$this->dbFields('CRM_Contact_DAO_SavedSearch', TRUE);
     $this->sql($sql, 'civicrm_saved_search', $fields);
   }
 
   /**
    * @param $contactIDs
    */
-  function entityTag(&$contactIDs) {
-    $fields = & $this->dbFields('CRM_Core_DAO_EntityTag', TRUE);
+  public function entityTag(&$contactIDs) {
+    $fields = &$this->dbFields('CRM_Core_DAO_EntityTag', TRUE);
     $this->table($contactIDs, 'civicrm_entity_tag', $fields, 'entity_id', "entity_table = 'civicrm_contact'");
   }
 
   /**
    * @param $contactIDs
    */
-  function tag(&$contactIDs) {
+  public function tag(&$contactIDs) {
     // handle tags only once
     static $_tagsHandled = array();
 
@@ -381,7 +382,7 @@ AND    entity_table = 'civicrm_contact'
       }
     }
 
-    $fields = & $this->dbFields('CRM_Core_DAO_Tag', TRUE);
+    $fields = &$this->dbFields('CRM_Core_DAO_Tag', TRUE);
     $this->table($tagIDs, 'civicrm_tag', $fields, 'id');
   }
 
@@ -389,7 +390,7 @@ AND    entity_table = 'civicrm_contact'
    * @param $contactIDs
    * @param $additionalContacts
    */
-  function relationship(&$contactIDs, &$additionalContacts) {
+  public function relationship(&$contactIDs, &$additionalContacts) {
     // handle relationships only once
     static $_relationshipsHandled = array();
 
@@ -407,7 +408,7 @@ AND    entity_table = 'civicrm_contact'
 ";
 
     $fields = $this->dbFields('CRM_Contact_DAO_Relationship', TRUE);
-    $dao = & CRM_Core_DAO::executeQuery($sql);
+    $dao = &CRM_Core_DAO::executeQuery($sql);
     while ($dao->fetch()) {
       if (isset($_relationshipsHandled[$dao->id])) {
         continue;
@@ -439,7 +440,7 @@ AND    entity_table = 'civicrm_contact'
    * @param $contactIDs
    * @param $additionalContacts
    */
-  function activity(&$contactIDs, &$additionalContacts) {
+  public function activity(&$contactIDs, &$additionalContacts) {
     static $_activitiesHandled = array();
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
@@ -455,9 +456,9 @@ WHERE ac.contact_id IN ( $ids )
   AND (a.activity_type_id != 3 AND a.activity_type_id != 20)
 ";
 
-    $fields = & $this->dbFields('CRM_Activity_DAO_Activity', TRUE);
+    $fields = &$this->dbFields('CRM_Activity_DAO_Activity', TRUE);
 
-    $dao = & CRM_Core_DAO::executeQuery($sql);
+    $dao = &CRM_Core_DAO::executeQuery($sql);
     while ($dao->fetch()) {
       // adding source, target and assignee contacts in additional contacts array
       $this->addAdditionalContacts(array($dao->contact_id),
@@ -469,7 +470,7 @@ WHERE ac.contact_id IN ( $ids )
         'id' => $dao->acID,
         'contact_id' => $dao->contact_id,
         'activity_id' => $dao->activity_id,
-        'record_type_id' => $dao->record_type_id
+        'record_type_id' => $dao->record_type_id,
       );
       $this->appendValue($dao->acID, 'civicrm_activity_contact', $activityContacts);
 
@@ -499,7 +500,7 @@ WHERE ac.contact_id IN ( $ids )
    * @param string $name
    * @param $value
    */
-  function appendValue($id, $name, $value) {
+  public function appendValue($id, $name, $value) {
     if (empty($value)) {
       return;
     }
@@ -517,18 +518,18 @@ WHERE ac.contact_id IN ( $ids )
    *
    * @return array
    */
-  function dbFields($daoName, $onlyKeys = FALSE) {
+  public function dbFields($daoName, $onlyKeys = FALSE) {
     static $_fieldsRetrieved = array();
 
     if (!isset($_fieldsRetrieved[$daoName])) {
       $_fieldsRetrieved[$daoName] = array();
       $daoFile = str_replace('_',
-        DIRECTORY_SEPARATOR,
-        $daoName
-      ) . '.php';
-      include_once ($daoFile);
+          DIRECTORY_SEPARATOR,
+          $daoName
+        ) . '.php';
+      include_once $daoFile;
 
-      $daoFields = & $daoName::fields();
+      $daoFields = &$daoName::fields();
 
       foreach ($daoFields as $key => & $value) {
         $_fieldsRetrieved[$daoName][$value['name']] = array(
@@ -551,7 +552,7 @@ WHERE ac.contact_id IN ( $ids )
    * @param $contactIDs
    * @param $additionalContacts
    */
-  function addAdditionalContacts($contactIDs, &$additionalContacts) {
+  public function addAdditionalContacts($contactIDs, &$additionalContacts) {
     if (!$this->_discoverContacts) {
       return;
     }
@@ -569,8 +570,8 @@ WHERE ac.contact_id IN ( $ids )
   /**
    * @param $contactIDs
    */
-  function export(&$contactIDs) {
-    $chunks = & $this->splitContactIDs($contactIDs);
+  public function export(&$contactIDs) {
+    $chunks = &$this->splitContactIDs($contactIDs);
 
     $additionalContactIDs = array();
 
@@ -589,9 +590,10 @@ WHERE ac.contact_id IN ( $ids )
    * @param null $lastExportTime
    * @param bool $discoverContacts
    */
-  function run($fileName,
-               $lastExportTime = NULL,
-               $discoverContacts = FALSE
+  public function run(
+    $fileName,
+    $lastExportTime = NULL,
+    $discoverContacts = FALSE
   ) {
     $this->_discoverContacts = $discoverContacts;
 
@@ -615,8 +617,7 @@ WHERE  date >= $lastExportTime
 ";
     }
 
-
-    $dao = & CRM_Core_DAO::executeQuery($sql);
+    $dao = &CRM_Core_DAO::executeQuery($sql);
 
     $contactIDs = array();
     while ($dao->fetch()) {
@@ -637,5 +638,5 @@ WHERE  date >= $lastExportTime
 
     // print_r( json_decode( $json ) );
   }
-}
 
+}