X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FWebsite.php;h=e20e43de390de7a82025fccfbffaa107cd3a4f02;hb=777d4b653e4a553d8a5f7ca5c46bf08a6c4a6902;hp=ff08619fd1167c1996e17673ffdb7afd79b01d6d;hpb=6a0b768e17b6b5271ee014b4ac30066376de1f52;p=civicrm-core.git diff --git a/CRM/Core/BAO/Website.php b/CRM/Core/BAO/Website.php index ff08619fd1..e20e43de39 100644 --- a/CRM/Core/BAO/Website.php +++ b/CRM/Core/BAO/Website.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 4.6 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2014 | + | Copyright CiviCRM LLC (c) 2004-2015 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -23,12 +23,12 @@ | 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$ * */ @@ -39,13 +39,13 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { /** - * Takes an associative array and adds im + * Takes an associative array and adds im. * * @param array $params * (reference ) an assoc array of name/value pairs. * - * @return object CRM_Core_BAO_Website object on success, null otherwise - * @static + * @return object + * CRM_Core_BAO_Website object on success, null otherwise */ public static function add(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; @@ -60,65 +60,76 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { } /** - * Process website + * Process website. * * @param array $params - * Associated array. * @param int $contactID * Contact id. * - * @param $skipDelete - * * @return void - * @static */ - public static function create(&$params, $contactID, $skipDelete) { - if (empty($params)) { + public static function create(&$params, $contactID) { + + if (empty($params['website'])) { return FALSE; } - $ids = self::allWebsites($contactID); - foreach ($params as $key => $values) { - $websiteId = CRM_Utils_Array::value('id', $values); + // CRM-10551 + // Use updateBlankLocInfo to overwrite blanked values of matching type + $updateBlankLocInfo = CRM_Utils_Array::value('updateBlankLocInfo', $params, FALSE); + + // Get websites submitted in the form, and already on the Contact + $submittedWebsites = $params['website']; + $existingWebsites = self::allWebsites($contactID); + + // For each website submitted on the form + foreach ($submittedWebsites as $key => $submittedValue) { + + // Check for matching IDs on submitted / existing data + $websiteId = CRM_Utils_Array::value('id', $submittedValue); if ($websiteId) { - if (array_key_exists($websiteId, $ids)) { - unset($ids[$websiteId]); + if (array_key_exists($websiteId, $existingWebsites)) { + unset($existingWebsites[$websiteId]); } else { - unset($values['id']); + unset($submittedValue['id']); } } - if (empty($values['id']) && - is_array($ids) && !empty($ids) - ) { - foreach ($ids as $id => $value) { - if (($value['website_type_id'] == $values['website_type_id']) && !empty($values['url'])) { - $values['id'] = $id; - unset($ids[$id]); + // Match up submitted values to existing ones, based on type + if (empty($submittedValue['id']) && !empty($existingWebsites)) { + foreach ($existingWebsites as $id => $existingValue) { + if ($existingValue['website_type_id'] == $submittedValue['website_type_id']) { + $submittedValue['id'] = $id; + unset($existingWebsites[$id]); break; } } } - $values['contact_id'] = $contactID; - if (!empty($values['url'])) { - self::add($values); + + $submittedValue['contact_id'] = $contactID; + + // CRM-10551 + // If there is a matching ID, the URL is empty and we are deleting blanked values + // Then remove it from the contact + if (!empty($submittedValue['id']) && empty($submittedValue['url']) && $updateBlankLocInfo) { + self::del(array($submittedValue['id'])); } - } - if ($skipDelete && !empty($ids)) { - self::del(array_keys($ids)); + // Otherwise, add the website if the URL isn't empty + elseif (!empty($submittedValue['url'])) { + self::add($submittedValue); + } } } /** - * Delete website + * Delete website. * * @param array $ids * Website ids. * * @return void - * @static */ public static function del($ids) { $query = 'DELETE FROM civicrm_website WHERE id IN ( ' . implode(',', $ids) . ')'; @@ -134,12 +145,11 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { * @param array $params * @param $values * - * @return boolean - * @static + * @return bool */ public static function &getValues(&$params, &$values) { - $websites = array(); - $website = new CRM_Core_DAO_Website(); + $websites = array(); + $website = new CRM_Core_DAO_Website(); $website->contact_id = $params['contact_id']; $website->find(); @@ -156,15 +166,15 @@ class CRM_Core_BAO_Website extends CRM_Core_DAO_Website { } /** - * Get all the websites for a specified contact_id + * Get all the websites for a specified contact_id. * * @param int $id * The contact id. * * @param bool $updateBlankLocInfo * - * @return array the array of website details - * @static + * @return array + * the array of website details */ public static function allWebsites($id, $updateBlankLocInfo = FALSE) { if (!$id) { @@ -178,8 +188,8 @@ SELECT id, website_type_id $params = array(1 => array($id, 'Integer')); $websites = $values = array(); - $dao = CRM_Core_DAO::executeQuery($query, $params); - $count = 1; + $dao = CRM_Core_DAO::executeQuery($query, $params); + $count = 1; while ($dao->fetch()) { $values = array( 'id' => $dao->id, @@ -195,4 +205,5 @@ SELECT id, website_type_id } return $websites; } + }