3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class contain function for Website handling.
21 class CRM_Core_BAO_Website
extends CRM_Core_DAO_Website
{
22 use CRM_Contact_AccessTrait
;
25 * Create or update Website record.
27 * @param array $params
29 * @return CRM_Core_DAO_Website
30 * @throws \CRM_Core_Exception
32 public static function create($params) {
33 return self
::writeRecord($params);
39 * If called in a legacy manner this, temporarily, fails back to calling the legacy function.
41 * @param array $params
43 * @return bool|CRM_Core_BAO_Website
44 * @throws \CRM_Core_Exception
46 public static function add($params) {
47 CRM_Core_Error
::deprecatedFunctionWarning('use apiv4');
48 return self
::create($params);
54 * @param array $params
55 * @param int $contactID
58 * @param bool $skipDelete
61 * @throws \CRM_Core_Exception
63 public static function process($params, $contactID, $skipDelete) {
68 $ids = self
::allWebsites($contactID);
69 foreach ($params as $key => $values) {
70 $id = $values['id'] ??
NULL;
71 if (array_key_exists($id, $ids)) {
74 if (empty($values['id']) && is_array($ids) && !empty($ids)) {
75 foreach ($ids as $id => $value) {
76 if (($value['website_type_id'] == $values['website_type_id'])) {
82 if (!empty($values['url'])) {
83 $values['contact_id'] = $contactID;
84 self
::create($values);
86 elseif ($skipDelete && !empty($values['id'])) {
87 self
::del($values['id']);
99 public static function del($id) {
105 CRM_Utils_Hook
::pre('delete', 'Website', $id, $params);
111 CRM_Utils_Hook
::post('delete', 'Website', $id, $obj);
116 * Given the list of params in the params array, fetch the object
117 * and store the values in the values array
119 * @param array $params
124 public static function &getValues(&$params = [], &$values = []) {
126 $website = new CRM_Core_DAO_Website();
127 $website->contact_id
= $params['contact_id'];
131 while ($website->fetch()) {
132 $values['website'][$count] = [];
133 CRM_Core_DAO
::storeValues($website, $values['website'][$count]);
135 $websites[$count] = $values['website'][$count];
143 * Get all the websites for a specified contact_id.
148 * @param bool $updateBlankLocInfo
151 * the array of website details
153 public static function allWebsites($id, $updateBlankLocInfo = FALSE) {
159 SELECT id, website_type_id
161 WHERE civicrm_website.contact_id = %1';
162 $params = [1 => [$id, 'Integer']];
164 $websites = $values = [];
165 $dao = CRM_Core_DAO
::executeQuery($query, $params);
167 while ($dao->fetch()) {
170 'website_type_id' => $dao->website_type_id
,
173 if ($updateBlankLocInfo) {
174 $websites[$count++
] = $values;
177 $websites[$dao->id
] = $values;