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
27 * @return CRM_Core_DAO_Website
29 public static function add($params) {
30 return self
::writeRecord($params);
36 * If called in a legacy manner this, temporarily, fails back to calling the legacy function.
38 * @param array $params
39 * @param int $contactID
40 * @param bool $skipDelete
42 * @return bool|CRM_Core_BAO_Website
44 public static function create($params, $contactID = NULL, $skipDelete = NULL) {
45 if ($skipDelete !== NULL ||
($contactID && !is_array($contactID))) {
46 \Civi
::log()->warning(ts('Calling website:create with vars other than $params is deprecated. Use process'), ['civi.tag' => 'deprecated']);
47 return self
::process($params, $contactID, $skipDelete);
49 foreach ($params as $key => $value) {
50 if (is_numeric($key)) {
51 \Civi
::log()->warning(ts('Calling website:create for multiple websites $params is deprecated. Use process'), ['civi.tag' => 'deprecated']);
52 return self
::process($params, $contactID, $skipDelete);
55 return self
::add($params);
61 * @param array $params
62 * @param int $contactID
65 * @param bool $skipDelete
69 public static function process($params, $contactID, $skipDelete) {
74 $ids = self
::allWebsites($contactID);
75 foreach ($params as $key => $values) {
76 $id = $values['id'] ??
NULL;
77 if (array_key_exists($id, $ids)) {
80 if (empty($values['id']) && is_array($ids) && !empty($ids)) {
81 foreach ($ids as $id => $value) {
82 if (($value['website_type_id'] == $values['website_type_id'])) {
88 if (!empty($values['url'])) {
89 $values['contact_id'] = $contactID;
92 elseif ($skipDelete && !empty($values['id'])) {
93 self
::del($values['id']);
105 public static function del($id) {
111 CRM_Utils_Hook
::pre('delete', 'Website', $id, $params);
117 CRM_Utils_Hook
::post('delete', 'Website', $id, $obj);
122 * Given the list of params in the params array, fetch the object
123 * and store the values in the values array
125 * @param array $params
130 public static function &getValues(&$params = [], &$values = []) {
132 $website = new CRM_Core_DAO_Website();
133 $website->contact_id
= $params['contact_id'];
137 while ($website->fetch()) {
138 $values['website'][$count] = [];
139 CRM_Core_DAO
::storeValues($website, $values['website'][$count]);
141 $websites[$count] = $values['website'][$count];
149 * Get all the websites for a specified contact_id.
154 * @param bool $updateBlankLocInfo
157 * the array of website details
159 public static function allWebsites($id, $updateBlankLocInfo = FALSE) {
165 SELECT id, website_type_id
167 WHERE civicrm_website.contact_id = %1';
168 $params = [1 => [$id, 'Integer']];
170 $websites = $values = [];
171 $dao = CRM_Core_DAO
::executeQuery($query, $params);
173 while ($dao->fetch()) {
176 'website_type_id' => $dao->website_type_id
,
179 if ($updateBlankLocInfo) {
180 $websites[$count++
] = $values;
183 $websites[$dao->id
] = $values;