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 CRM_Core_DAO_Website
44 * @throws \CRM_Core_Exception
47 public static function add($params) {
48 CRM_Core_Error
::deprecatedFunctionWarning('use apiv4');
49 return self
::create($params);
55 * @param array $params
56 * @param int $contactID
59 * @param bool $skipDelete
62 * @throws \CRM_Core_Exception
64 public static function process($params, $contactID, $skipDelete) {
69 $ids = self
::allWebsites($contactID);
70 foreach ($params as $key => $values) {
71 $id = $values['id'] ??
NULL;
72 if (array_key_exists($id, $ids)) {
75 if (empty($values['id']) && is_array($ids) && !empty($ids)) {
76 foreach ($ids as $id => $value) {
77 if (($value['website_type_id'] == $values['website_type_id'])) {
83 if (!empty($values['url'])) {
84 $values['contact_id'] = $contactID;
85 self
::create($values);
87 elseif ($skipDelete && !empty($values['id'])) {
88 self
::del($values['id']);
100 public static function del($id) {
106 CRM_Utils_Hook
::pre('delete', 'Website', $id, $params);
112 CRM_Utils_Hook
::post('delete', 'Website', $id, $obj);
117 * Given the list of params in the params array, fetch the object
118 * and store the values in the values array
120 * @param array $params
125 public static function &getValues($params = [], &$values = []) {
127 $website = new CRM_Core_DAO_Website();
128 $website->contact_id
= $params['contact_id'];
132 while ($website->fetch()) {
133 $values['website'][$count] = [];
134 CRM_Core_DAO
::storeValues($website, $values['website'][$count]);
136 $websites[$count] = $values['website'][$count];
144 * Get all the websites for a specified contact_id.
149 * @param bool $updateBlankLocInfo
152 * the array of website details
154 public static function allWebsites($id, $updateBlankLocInfo = FALSE) {
160 SELECT id, website_type_id
162 WHERE civicrm_website.contact_id = %1';
163 $params = [1 => [$id, 'Integer']];
165 $websites = $values = [];
166 $dao = CRM_Core_DAO
::executeQuery($query, $params);
168 while ($dao->fetch()) {
171 'website_type_id' => $dao->website_type_id
,
174 if ($updateBlankLocInfo) {
175 $websites[$count++
] = $values;
178 $websites[$dao->id
] = $values;