Merge pull request #4997 from monishdeb/CRM-15536
[civicrm-core.git] / CRM / Core / BAO / Location.php
index 7317b025598524908b6e6d9736991dcd21aaaa16..5fa6dade98c288c796a119b24d0a98bd5a27b7d0 100644 (file)
@@ -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,14 +46,15 @@ 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
-   * @static
+   * @return array
    */
   public static function create(&$params, $fixAddress = TRUE, $entity = NULL) {
     $location = array();
@@ -64,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);
@@ -95,7 +96,6 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
 
   /**
    * Creates the entry in the civicrm_loc_block
-   *
    */
   public static function createLocBlock(&$location, &$entityElements) {
     $locId = self::findExisting($entityElements);
@@ -106,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;
     }
@@ -130,12 +134,11 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
 
   /**
    * Takes an entity array and finds the existing location block
-   * @static
    */
   public static function findExisting($entityElements) {
-    $eid    = $entityElements['entity_id'];
+    $eid = $entityElements['entity_id'];
     $etable = $entityElements['entity_table'];
-    $query  = "
+    $query = "
 SELECT e.loc_block_id as locId
 FROM {$etable} e
 WHERE e.id = %1";
@@ -151,10 +154,11 @@ 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
-   * @static
+   * @return object
+   *   CRM_Core_BAO_locBlock object on success, null otherwise
    */
   public static function addLocBlock(&$params) {
     $locBlock = new CRM_Core_DAO_LocBlock();
@@ -167,10 +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
-   * @static
    */
   public static function deleteLocBlock($locBlockId) {
     if (!$locBlockId) {
@@ -209,10 +213,10 @@ 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
-   * @static
+   * @return bool
    */
   public static function dataExists(&$params) {
     // return if no data present
@@ -231,8 +235,8 @@ WHERE e.id = %1";
    * @param $entityBlock
    * @param bool $microformat
    *
-   * @return array   array of objects(CRM_Core_BAO_Location)
-   * @static
+   * @return array
+   *   array of objects(CRM_Core_BAO_Location)
    */
   public static function &getValues($entityBlock, $microformat = FALSE) {
     if (empty($entityBlock)) {
@@ -261,11 +265,12 @@ 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
-   * @static
    */
   public static function deleteLocationBlocks($contactId, $locationTypeId) {
     // ensure that contactId has a value
@@ -294,10 +299,13 @@ 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.
    */
   public static function copyLocBlock($locBlockId, $updateLocBlockId = NULL) {
     //get the location info.
@@ -319,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);
@@ -342,9 +350,9 @@ 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.
    *
-   * @static
    */
   public static function checkPrimaryBlocks($contactId) {
     if (!$contactId) {
@@ -356,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])
@@ -409,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(
@@ -427,4 +440,5 @@ WHERE e.id = %1";
     }
     return $elements;
   }
+
 }