3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class contain function for Website handling.
37 class CRM_Core_BAO_Website
extends CRM_Core_DAO_Website
{
40 * Takes an associative array and adds im.
42 * @param array $params
43 * an assoc array of name/value pairs.
45 * @return CRM_Core_BAO_Website
47 public static function add($params) {
48 $hook = empty($params['id']) ?
'create' : 'edit';
49 CRM_Utils_Hook
::pre($hook, 'Website', CRM_Utils_Array
::value('id', $params), $params);
51 $website = new CRM_Core_DAO_Website();
52 $website->copyValues($params);
55 CRM_Utils_Hook
::post($hook, 'Website', $website->id
, $website);
62 * If called in a legacy manner this, temporarily, fails back to calling the legacy function.
64 * @param array $params
65 * @param int $contactID
66 * @param bool $skipDelete
68 * @return bool|CRM_Core_BAO_Website
70 public static function create($params, $contactID = NULL, $skipDelete = NULL) {
71 if ($skipDelete !== NULL ||
($contactID && !is_array($contactID))) {
72 \Civi
::log()->warning(ts('Calling website:create with vars other than $params is deprecated. Use process'), ['civi.tag' => 'deprecated']);
73 return self
::process($params, $contactID, $skipDelete);
75 foreach ($params as $key => $value) {
76 if (is_numeric($key)) {
77 \Civi
::log()->warning(ts('Calling website:create for multiple websites $params is deprecated. Use process'), ['civi.tag' => 'deprecated']);
78 return self
::process($params, $contactID, $skipDelete);
81 return self
::add($params);
87 * @param array $params
88 * @param int $contactID
91 * @param bool $skipDelete
95 public static function process($params, $contactID, $skipDelete) {
100 $ids = self
::allWebsites($contactID);
101 foreach ($params as $key => $values) {
102 $id = CRM_Utils_Array
::value('id', $values);
103 if (array_key_exists($id, $ids)) {
106 if (empty($values['id']) && is_array($ids) && !empty($ids)) {
107 foreach ($ids as $id => $value) {
108 if (($value['website_type_id'] == $values['website_type_id'])) {
114 if (!empty($values['url'])) {
115 $values['contact_id'] = $contactID;
118 elseif ($skipDelete && !empty($values['id'])) {
119 self
::del($values['id']);
131 public static function del($id) {
137 CRM_Utils_Hook
::pre('delete', 'Website', $id, $params);
143 CRM_Utils_Hook
::post('delete', 'Website', $id, $obj);
148 * Given the list of params in the params array, fetch the object
149 * and store the values in the values array
151 * @param array $params
156 public static function &getValues(&$params = [], &$values = []) {
158 $website = new CRM_Core_DAO_Website();
159 $website->contact_id
= $params['contact_id'];
163 while ($website->fetch()) {
164 $values['website'][$count] = [];
165 CRM_Core_DAO
::storeValues($website, $values['website'][$count]);
167 $websites[$count] = $values['website'][$count];
175 * Get all the websites for a specified contact_id.
180 * @param bool $updateBlankLocInfo
183 * the array of website details
185 public static function allWebsites($id, $updateBlankLocInfo = FALSE) {
191 SELECT id, website_type_id
193 WHERE civicrm_website.contact_id = %1';
194 $params = [1 => [$id, 'Integer']];
196 $websites = $values = [];
197 $dao = CRM_Core_DAO
::executeQuery($query, $params);
199 while ($dao->fetch()) {
202 'website_type_id' => $dao->website_type_id
,
205 if ($updateBlankLocInfo) {
206 $websites[$count++
] = $values;
209 $websites[$dao->id
] = $values;