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
{
24 * Create or update Website record.
26 * @param array $params
28 * @return CRM_Core_DAO_Website
29 * @throws \CRM_Core_Exception
31 public static function create($params) {
32 return self
::writeRecord($params);
38 * If called in a legacy manner this, temporarily, fails back to calling the legacy function.
40 * @param array $params
42 * @return bool|CRM_Core_BAO_Website
43 * @throws \CRM_Core_Exception
45 public static function add($params) {
46 CRM_Core_Error
::deprecatedFunctionWarning('use apiv4');
47 return self
::create($params);
53 * @param array $params
54 * @param int $contactID
57 * @param bool $skipDelete
60 * @throws \CRM_Core_Exception
62 public static function process($params, $contactID, $skipDelete) {
67 $ids = self
::allWebsites($contactID);
68 foreach ($params as $key => $values) {
69 $id = $values['id'] ??
NULL;
70 if (array_key_exists($id, $ids)) {
73 if (empty($values['id']) && is_array($ids) && !empty($ids)) {
74 foreach ($ids as $id => $value) {
75 if (($value['website_type_id'] == $values['website_type_id'])) {
81 if (!empty($values['url'])) {
82 $values['contact_id'] = $contactID;
83 self
::create($values);
85 elseif ($skipDelete && !empty($values['id'])) {
86 self
::del($values['id']);
98 public static function del($id) {
104 CRM_Utils_Hook
::pre('delete', 'Website', $id, $params);
110 CRM_Utils_Hook
::post('delete', 'Website', $id, $obj);
115 * Given the list of params in the params array, fetch the object
116 * and store the values in the values array
118 * @param array $params
123 public static function &getValues(&$params = [], &$values = []) {
125 $website = new CRM_Core_DAO_Website();
126 $website->contact_id
= $params['contact_id'];
130 while ($website->fetch()) {
131 $values['website'][$count] = [];
132 CRM_Core_DAO
::storeValues($website, $values['website'][$count]);
134 $websites[$count] = $values['website'][$count];
142 * Get all the websites for a specified contact_id.
147 * @param bool $updateBlankLocInfo
150 * the array of website details
152 public static function allWebsites($id, $updateBlankLocInfo = FALSE) {
158 SELECT id, website_type_id
160 WHERE civicrm_website.contact_id = %1';
161 $params = [1 => [$id, 'Integer']];
163 $websites = $values = [];
164 $dao = CRM_Core_DAO
::executeQuery($query, $params);
166 while ($dao->fetch()) {
169 'website_type_id' => $dao->website_type_id
,
172 if ($updateBlankLocInfo) {
173 $websites[$count++
] = $values;
176 $websites[$dao->id
] = $values;