Merge pull request #4997 from monishdeb/CRM-15536
[civicrm-core.git] / CRM / Core / BAO / Location.php
index de56bd6ce96b2f945972bf70f5265d200c4b0102..5fa6dade98c288c796a119b24d0a98bd5a27b7d0 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        |
   +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -46,17 +46,17 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
   /**
    * Create various elements of location block
    *
-   * @param array $params (reference ) an assoc array of name/value pairs
-   * @param boolean $fixAddress true if you need to fix (format) address values
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
+   * @param bool $fixAddress
+   *   True if you need to fix (format) address values.
    *                               before inserting in db
    *
    * @param null $entity
    *
-   * @return array   $location
-   * @access public
-   * @static
+   * @return array
    */
-  static function create(&$params, $fixAddress = TRUE, $entity = NULL) {
+  public static function create(&$params, $fixAddress = TRUE, $entity = NULL) {
     $location = array();
     if (!self::dataExists($params)) {
       return $location;
@@ -65,7 +65,7 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
     // create location blocks.
     foreach (self::$blocks as $block) {
       if ($block != 'address') {
-        $location[$block] = CRM_Core_BAO_Block::create( $block, $params, $entity );
+        $location[$block] = CRM_Core_BAO_Block::create($block, $params, $entity);
       }
       else {
         $location[$block] = CRM_Core_BAO_Address::create($params, $fixAddress, $entity);
@@ -96,9 +96,8 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
 
   /**
    * Creates the entry in the civicrm_loc_block
-   *
    */
-  static function createLocBlock(&$location, &$entityElements) {
+  public static function createLocBlock(&$location, &$entityElements) {
     $locId = self::findExisting($entityElements);
     $locBlock = array();
 
@@ -107,7 +106,11 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
     }
 
     foreach (array(
-      'phone', 'email', 'im', 'address') as $loc) {
+               'phone',
+               'email',
+               'im',
+               'address',
+             ) as $loc) {
       $locBlock["{$loc}_id"] = !empty($location["$loc"][0]) ? $location["$loc"][0]->id : NULL;
       $locBlock["{$loc}_2_id"] = !empty($location["$loc"][1]) ? $location["$loc"][1]->id : NULL;
     }
@@ -131,13 +134,11 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
 
   /**
    * Takes an entity array and finds the existing location block
-   * @access public
-   * @static
    */
-  static function findExisting($entityElements) {
-    $eid    = $entityElements['entity_id'];
+  public static function findExisting($entityElements) {
+    $eid = $entityElements['entity_id'];
     $etable = $entityElements['entity_table'];
-    $query  = "
+    $query = "
 SELECT e.loc_block_id as locId
 FROM {$etable} e
 WHERE e.id = %1";
@@ -153,13 +154,13 @@ WHERE e.id = %1";
   /**
    * Takes an associative array and adds location block
    *
-   * @param array  $params         (reference ) an assoc array of name/value pairs
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
    *
-   * @return object       CRM_Core_BAO_locBlock object on success, null otherwise
-   * @access public
-   * @static
+   * @return object
+   *   CRM_Core_BAO_locBlock object on success, null otherwise
    */
-  static function addLocBlock(&$params) {
+  public static function addLocBlock(&$params) {
     $locBlock = new CRM_Core_DAO_LocBlock();
 
     $locBlock->copyValues($params);
@@ -170,11 +171,10 @@ WHERE e.id = %1";
   /**
    * Delete the Location Block
    *
-   * @param  int  $locBlockId    id of the Location Block
+   * @param int $locBlockId
+   *   Id of the Location Block.
    *
    * @return void
-   * @access public
-   * @static
    */
   public static function deleteLocBlock($locBlockId) {
     if (!$locBlockId) {
@@ -213,13 +213,12 @@ WHERE e.id = %1";
   /**
    * Check if there is data to create the object
    *
-   * @param array  $params         (reference ) an assoc array of name/value pairs
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
    *
-   * @return boolean
-   * @access public
-   * @static
+   * @return bool
    */
-  static function dataExists(&$params) {
+  public static function dataExists(&$params) {
     // return if no data present
     $dataExists = FALSE;
     foreach (self::$blocks as $block) {
@@ -236,11 +235,10 @@ WHERE e.id = %1";
    * @param $entityBlock
    * @param bool $microformat
    *
-   * @return array   array of objects(CRM_Core_BAO_Location)
-   * @access public
-   * @static
+   * @return array
+   *   array of objects(CRM_Core_BAO_Location)
    */
-  static function &getValues($entityBlock, $microformat = FALSE) {
+  public static function &getValues($entityBlock, $microformat = FALSE) {
     if (empty($entityBlock)) {
       return NULL;
     }
@@ -267,14 +265,14 @@ WHERE e.id = %1";
   /**
    * Delete all the block associated with the location
    *
-   * @param  int  $contactId      contact id
-   * @param  int  $locationTypeId id of the location to delete
+   * @param int $contactId
+   *   Contact id.
+   * @param int $locationTypeId
+   *   Id of the location to delete.
    *
    * @return void
-   * @access public
-   * @static
    */
-  static function deleteLocationBlocks($contactId, $locationTypeId) {
+  public static function deleteLocationBlocks($contactId, $locationTypeId) {
     // ensure that contactId has a value
     if (empty($contactId) ||
       !CRM_Utils_Rule::positiveInteger($contactId)
@@ -301,12 +299,15 @@ WHERE e.id = %1";
   /**
    * Copy or update location block.
    *
-   * @param  int  $locBlockId  location block id.
-   * @param  int  $updateLocBlockId update location block id
+   * @param int $locBlockId
+   *   Location block id.
+   * @param int $updateLocBlockId
+   *   Update location block id.
    *
-   * @return int  newly created/updated location block id.
+   * @return int
+   *   newly created/updated location block id.
    */
-  static function copyLocBlock($locBlockId, $updateLocBlockId = NULL) {
+  public static function copyLocBlock($locBlockId, $updateLocBlockId = NULL) {
     //get the location info.
     $defaults = $updateValues = array();
     $locBlock = array('id' => $locBlockId);
@@ -326,8 +327,8 @@ WHERE e.id = %1";
     //copy all location blocks (email, phone, address, etc)
     foreach ($defaults as $key => $value) {
       if ($key != 'id') {
-        $tbl          = explode("_", $key);
-        $name         = ucfirst($tbl[0]);
+        $tbl = explode("_", $key);
+        $name = ucfirst($tbl[0]);
         $updateParams = NULL;
         if ($updateId = CRM_Utils_Array::value($key, $updateValues)) {
           $updateParams = array('id' => $updateId);
@@ -349,12 +350,11 @@ WHERE e.id = %1";
    * If contact has data for any location block, make sure
    * contact should have only one primary block, CRM-5051
    *
-   * @param  int $contactId - contact id
+   * @param int $contactId
+   *   Contact id.
    *
-   * @access public
-   * @static
    */
-  static function checkPrimaryBlocks($contactId) {
+  public static function checkPrimaryBlocks($contactId) {
     if (!$contactId) {
       return;
     }
@@ -364,7 +364,12 @@ WHERE e.id = %1";
     $nonPrimaryBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($contactId, array('is_primary' => 0));
 
     foreach (array(
-      'Email', 'IM', 'Phone', 'Address', 'OpenID') as $block) {
+               'Email',
+               'IM',
+               'Phone',
+               'Address',
+               'OpenID',
+             ) as $block) {
       $name = strtolower($block);
       if (array_key_exists($name, $primaryLocBlockIds) &&
         !CRM_Utils_System::isNull($primaryLocBlockIds[$name])
@@ -395,7 +400,7 @@ WHERE e.id = %1";
    *
    * @return array
    */
-  static function getChainSelectValues($values, $valueType, $flatten = FALSE) {
+  public static function getChainSelectValues($values, $valueType, $flatten = FALSE) {
     if (!$values) {
       return array();
     }
@@ -417,13 +422,13 @@ WHERE e.id = %1";
 
       // Format for js
       else {
-       // Option-groups for multiple categories
+        // Option-groups for multiple categories
         if ($result && count($values) > 1) {
           $elements[] = array(
             'value' => CRM_Core_PseudoConstant::$valueType($val, FALSE),
             'children' => array(),
           );
-          $list = & $elements[count($elements) - 1]['children'];
+          $list = &$elements[count($elements) - 1]['children'];
         }
         foreach ($result as $id => $name) {
           $list[] = array(
@@ -435,5 +440,5 @@ WHERE e.id = %1";
     }
     return $elements;
   }
-}
 
+}