copyValues($params); $website->save(); CRM_Utils_Hook::post($hook, 'Website', $website->id, $website); return $website; } /** * Process website * * @param array $params * Associated array. * @param int $contactID * Contact id. * * @param $skipDelete * * @return void * @static */ public static function create(&$params, $contactID, $skipDelete) { if (empty($params)) { return FALSE; } $ids = self::allWebsites($contactID); foreach ($params as $key => $values) { $websiteId = CRM_Utils_Array::value('id', $values); if ($websiteId) { if (array_key_exists($websiteId, $ids)) { unset($ids[$websiteId]); } else { unset($values['id']); } } if (empty($values['id']) && is_array($ids) && !empty($ids) ) { foreach ($ids as $id => $value) { if (($value['website_type_id'] == $values['website_type_id']) && !empty($values['url'])) { $values['id'] = $id; unset($ids[$id]); break; } } } $values['contact_id'] = $contactID; if (!empty($values['url'])) { self::add($values); } } if ($skipDelete && !empty($ids)) { self::del(array_keys($ids)); } } /** * Delete website * * @param array $ids * Website ids. * * @return void * @static */ public static function del($ids) { $query = 'DELETE FROM civicrm_website WHERE id IN ( ' . implode(',', $ids) . ')'; CRM_Core_DAO::executeQuery($query); // FIXME: we should return false if the del was unsuccessful return TRUE; } /** * Given the list of params in the params array, fetch the object * and store the values in the values array * * @param array $params * @param $values * * @return boolean * @static */ public static function &getValues(&$params, &$values) { $websites = array(); $website = new CRM_Core_DAO_Website(); $website->contact_id = $params['contact_id']; $website->find(); $count = 1; while ($website->fetch()) { $values['website'][$count] = array(); CRM_Core_DAO::storeValues($website, $values['website'][$count]); $websites[$count] = $values['website'][$count]; $count++; } return $websites; } /** * Get all the websites for a specified contact_id * * @param int $id * The contact id. * * @param bool $updateBlankLocInfo * * @return array the array of website details * @static */ public static function allWebsites($id, $updateBlankLocInfo = FALSE) { if (!$id) { return NULL; } $query = ' SELECT id, website_type_id FROM civicrm_website WHERE civicrm_website.contact_id = %1'; $params = array(1 => array($id, 'Integer')); $websites = $values = array(); $dao = CRM_Core_DAO::executeQuery($query, $params); $count = 1; while ($dao->fetch()) { $values = array( 'id' => $dao->id, 'website_type_id' => $dao->website_type_id, ); if ($updateBlankLocInfo) { $websites[$count++] = $values; } else { $websites[$dao->id] = $values; } } return $websites; } }