3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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 * (reference ) an assoc array of name/value pairs.
46 * CRM_Core_BAO_Website object on success, null otherwise
48 public static function add(&$params) {
49 $hook = empty($params['id']) ?
'create' : 'edit';
50 CRM_Utils_Hook
::pre($hook, 'Website', CRM_Utils_Array
::value('id', $params), $params);
52 $website = new CRM_Core_DAO_Website();
53 $website->copyValues($params);
56 CRM_Utils_Hook
::post($hook, 'Website', $website->id
, $website);
63 * @param array $params
64 * @param int $contactID
67 * @param bool $skipDelete
71 public static function create(&$params, $contactID, $skipDelete) {
76 $ids = self
::allWebsites($contactID);
77 foreach ($params as $key => $values) {
78 if (empty($values['id']) && is_array($ids) && !empty($ids)) {
79 foreach ($ids as $id => $value) {
80 if (($value['website_type_id'] == $values['website_type_id'])) {
85 if (!empty($values['url'])) {
86 $values['contact_id'] = $contactID;
89 elseif ($skipDelete && !empty($values['id'])) {
90 self
::del(array($values['id']));
103 public static function del($ids) {
104 $query = 'DELETE FROM civicrm_website WHERE id IN ( ' . implode(',', $ids) . ')';
105 CRM_Core_DAO
::executeQuery($query);
106 // FIXME: we should return false if the del was unsuccessful
111 * Given the list of params in the params array, fetch the object
112 * and store the values in the values array
114 * @param array $params
119 public static function &getValues(&$params, &$values) {
121 $website = new CRM_Core_DAO_Website();
122 $website->contact_id
= $params['contact_id'];
126 while ($website->fetch()) {
127 $values['website'][$count] = array();
128 CRM_Core_DAO
::storeValues($website, $values['website'][$count]);
130 $websites[$count] = $values['website'][$count];
138 * Get all the websites for a specified contact_id.
143 * @param bool $updateBlankLocInfo
146 * the array of website details
148 public static function allWebsites($id, $updateBlankLocInfo = FALSE) {
154 SELECT id, website_type_id
156 WHERE civicrm_website.contact_id = %1';
157 $params = array(1 => array($id, 'Integer'));
159 $websites = $values = array();
160 $dao = CRM_Core_DAO
::executeQuery($query, $params);
162 while ($dao->fetch()) {
165 'website_type_id' => $dao->website_type_id
,
168 if ($updateBlankLocInfo) {
169 $websites[$count++
] = $values;
172 $websites[$dao->id
] = $values;