3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * This class contain function for Website handling.
37 class CRM_Core_BAO_Website
extends CRM_Core_DAO_Website
{
40 * Takes an associative array and adds im.
42 * @param array $params
43 * an assoc array of name/value pairs.
45 * @return CRM_Core_BAO_Website
47 public static function add($params) {
48 $hook = empty($params['id']) ?
'create' : 'edit';
49 CRM_Utils_Hook
::pre($hook, 'Website', CRM_Utils_Array
::value('id', $params), $params);
51 $website = new CRM_Core_DAO_Website();
52 $website->copyValues($params);
55 CRM_Utils_Hook
::post($hook, 'Website', $website->id
, $website);
62 * If called in a legacy manner this, temporarily, fails back to calling the legacy function.
64 * @param array $params
65 * @param int $contactID
66 * @param bool $skipDelete
68 * @return bool|CRM_Core_BAO_Website
70 public static function create($params, $contactID = NULL, $skipDelete = NULL) {
71 if ($skipDelete !== NULL ||
($contactID && !is_array($contactID))) {
72 \Civi
::log()->warning(ts('Calling website:create with vars other than $params is deprecated. Use process'), ['civi.tag' => 'deprecated']);
73 return self
::process($params, $contactID, $skipDelete);
75 foreach ($params as $key => $value) {
76 if (is_numeric($key)) {
77 \Civi
::log()->warning(ts('Calling website:create for multiple websites $params is deprecated. Use process'), ['civi.tag' => 'deprecated']);
78 return self
::process($params, $contactID, $skipDelete);
81 return self
::add($params);
87 * @param array $params
88 * @param int $contactID
91 * @param bool $skipDelete
95 public static function process($params, $contactID, $skipDelete) {
100 $ids = self
::allWebsites($contactID);
101 foreach ($params as $key => $values) {
102 if (empty($values['id']) && is_array($ids) && !empty($ids)) {
103 foreach ($ids as $id => $value) {
104 if (($value['website_type_id'] == $values['website_type_id'])) {
109 if (!empty($values['url'])) {
110 $values['contact_id'] = $contactID;
113 elseif ($skipDelete && !empty($values['id'])) {
114 self
::del($values['id']);
126 public static function del($id) {
132 CRM_Utils_Hook
::pre('delete', 'Website', $id, $params);
138 CRM_Utils_Hook
::post('delete', 'Website', $id, $obj);
144 * Given the list of params in the params array, fetch the object
145 * and store the values in the values array
147 * @param array $params
152 public static function &getValues(&$params, &$values) {
154 $website = new CRM_Core_DAO_Website();
155 $website->contact_id
= $params['contact_id'];
159 while ($website->fetch()) {
160 $values['website'][$count] = array();
161 CRM_Core_DAO
::storeValues($website, $values['website'][$count]);
163 $websites[$count] = $values['website'][$count];
171 * Get all the websites for a specified contact_id.
176 * @param bool $updateBlankLocInfo
179 * the array of website details
181 public static function allWebsites($id, $updateBlankLocInfo = FALSE) {
187 SELECT id, website_type_id
189 WHERE civicrm_website.contact_id = %1';
190 $params = array(1 => array($id, 'Integer'));
192 $websites = $values = array();
193 $dao = CRM_Core_DAO
::executeQuery($query, $params);
195 while ($dao->fetch()) {
198 'website_type_id' => $dao->website_type_id
,
201 if ($updateBlankLocInfo) {
202 $websites[$count++
] = $values;
205 $websites[$dao->id
] = $values;