/** * Takes an associative array and creates a note object. * * the function extract all the params it needs to initialize the create a * note object. the params array could contain additional unused name/value * pairs * * @param array $params * (reference) an assoc array of name/value pairs. * @param array $ids * (deprecated) associated array with note id - preferably set $params['id']. * * @return object * $note CRM_Core_BAO_Note object */ public static function add(&$params, $ids = array()) { $dataExists = self::dataExists($params); if (!$dataExists) { return CRM_Core_DAO::$_nullObject; } $note = new CRM_Core_BAO_Note(); if (!isset($params['modified_date'])) { $params['modified_date'] = date("Ymd"); } if (!isset($params['privacy'])) { $params['privacy'] = 0; } $note->copyValues($params); if (empty($params['contact_id'])) { if ($params['entity_table'] == 'civicrm_contact') { $note->contact_id = $params['entity_id']; } } $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); if ($id) { $note->id = $id; } $note->save(); // check and attach and files as needed CRM_Core_BAO_File::processAttachment($params, 'civicrm_note', $note->id); if ($note->entity_table == 'civicrm_contact') { CRM_Core_BAO_Log::register($note->entity_id, 'civicrm_note', $note->id); $displayName = CRM_Contact_BAO_Contact::displayName($note->entity_id); $noteActions = FALSE; $session = CRM_Core_Session::singleton(); if ($session->get('userID')) { if ($session->get('userID') == $note->entity_id) { $noteActions = TRUE; } elseif (CRM_Contact_BAO_Contact_Permission::allow($note->entity_id, CRM_Core_Permission::EDIT)) { $noteActions = TRUE; } } $recentOther = array(); if ($noteActions) { $recentOther = array('editUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=update&cid={$note->entity_id}&id={$note->id}&context=home"), 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=delete&cid={$note->entity_id}&id={$note->id}&context=home")); } // add the recently created Note CRM_Utils_Recent::add($displayName . ' - ' . $note->subject, CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=view&cid={$note->entity_id}&id={$note->id}&context=home"), $note->id, 'Note', $note->entity_id, $displayName, $recentOther); } return $note; }
/** * takes an associative array and creates a note object * * the function extract all the params it needs to initialize the create a * note object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Core_BAO_Note object * @access public * @static */ static function &add(&$params, $ids) { $dataExists = self::dataExists($params); if (!$dataExists) { return CRM_Core_DAO::$_nullObject; } $note = new CRM_Core_BAO_Note(); if (!isset($params['modified_date'])) { $params['modified_date'] = date("Ymd"); } if (!isset($params['privacy'])) { $params['privacy'] = 0; } $note->copyValues($params); if (!$params['contact_id']) { if ($params['entity_table'] == 'civicrm_contact') { $note->contact_id = $params['entity_id']; } else { CRM_Core_Error::statusBounce(ts('We could not find your logged in user ID')); } } if (CRM_Utils_Array::value('id', $ids)) { $note->id = CRM_Utils_Array::value('id', $ids); } $note->save(); if ($note->entity_table == 'civicrm_contact') { require_once 'CRM/Core/BAO/Log.php'; CRM_Core_BAO_Log::register($note->entity_id, 'civicrm_note', $note->id); require_once 'CRM/Contact/BAO/Contact.php'; $displayName = CRM_Contact_BAO_Contact::displayName($note->entity_id); $noteActions = false; $session = CRM_Core_Session::singleton(); if ($session->get('userID')) { require_once 'CRM/Contact/BAO/Contact/Permission.php'; if ($session->get('userID') == $note->entity_id) { $noteActions = true; } else { if (CRM_Contact_BAO_Contact_Permission::allow($note->entity_id, CRM_Core_Permission::EDIT)) { $noteActions = true; } } } $recentOther = array(); if ($noteActions) { $recentOther = array('editUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=update&cid={$note->entity_id}&id={$note->id}&context=home"), 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=delete&cid={$note->entity_id}&id={$note->id}&context=home")); } // add the recently created Note require_once 'CRM/Utils/Recent.php'; CRM_Utils_Recent::add($displayName . ' - ' . $note->subject, CRM_Utils_System::url('civicrm/contact/view/note', "reset=1&action=view&cid={$note->entity_id}&id={$note->id}&context=home"), $note->id, 'Note', $note->entity_id, $displayName, $recentOther); } return $note; }