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 * Takes an associative array and adds im.
26 * @param array $params
27 * an assoc array of name/value pairs.
29 * @return CRM_Core_BAO_Website
31 public static function add($params) {
32 $hook = empty($params['id']) ?
'create' : 'edit';
33 CRM_Utils_Hook
::pre($hook, 'Website', CRM_Utils_Array
::value('id', $params), $params);
35 $website = new CRM_Core_DAO_Website();
36 $website->copyValues($params);
39 CRM_Utils_Hook
::post($hook, 'Website', $website->id
, $website);
46 * If called in a legacy manner this, temporarily, fails back to calling the legacy function.
48 * @param array $params
49 * @param int $contactID
50 * @param bool $skipDelete
52 * @return bool|CRM_Core_BAO_Website
54 public static function create($params, $contactID = NULL, $skipDelete = NULL) {
55 if ($skipDelete !== NULL ||
($contactID && !is_array($contactID))) {
56 \Civi
::log()->warning(ts('Calling website:create with vars other than $params is deprecated. Use process'), ['civi.tag' => 'deprecated']);
57 return self
::process($params, $contactID, $skipDelete);
59 foreach ($params as $key => $value) {
60 if (is_numeric($key)) {
61 \Civi
::log()->warning(ts('Calling website:create for multiple websites $params is deprecated. Use process'), ['civi.tag' => 'deprecated']);
62 return self
::process($params, $contactID, $skipDelete);
65 return self
::add($params);
71 * @param array $params
72 * @param int $contactID
75 * @param bool $skipDelete
79 public static function process($params, $contactID, $skipDelete) {
84 $ids = self
::allWebsites($contactID);
85 foreach ($params as $key => $values) {
86 $id = $values['id'] ??
NULL;
87 if (array_key_exists($id, $ids)) {
90 if (empty($values['id']) && is_array($ids) && !empty($ids)) {
91 foreach ($ids as $id => $value) {
92 if (($value['website_type_id'] == $values['website_type_id'])) {
98 if (!empty($values['url'])) {
99 $values['contact_id'] = $contactID;
102 elseif ($skipDelete && !empty($values['id'])) {
103 self
::del($values['id']);
115 public static function del($id) {
121 CRM_Utils_Hook
::pre('delete', 'Website', $id, $params);
127 CRM_Utils_Hook
::post('delete', 'Website', $id, $obj);
132 * Given the list of params in the params array, fetch the object
133 * and store the values in the values array
135 * @param array $params
140 public static function &getValues(&$params = [], &$values = []) {
142 $website = new CRM_Core_DAO_Website();
143 $website->contact_id
= $params['contact_id'];
147 while ($website->fetch()) {
148 $values['website'][$count] = [];
149 CRM_Core_DAO
::storeValues($website, $values['website'][$count]);
151 $websites[$count] = $values['website'][$count];
159 * Get all the websites for a specified contact_id.
164 * @param bool $updateBlankLocInfo
167 * the array of website details
169 public static function allWebsites($id, $updateBlankLocInfo = FALSE) {
175 SELECT id, website_type_id
177 WHERE civicrm_website.contact_id = %1';
178 $params = [1 => [$id, 'Integer']];
180 $websites = $values = [];
181 $dao = CRM_Core_DAO
::executeQuery($query, $params);
183 while ($dao->fetch()) {
186 'website_type_id' => $dao->website_type_id
,
189 if ($updateBlankLocInfo) {
190 $websites[$count++
] = $values;
193 $websites[$dao->id
] = $values;