function processCaseTags() { $caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Integer'); $tags = CRM_Utils_Type::escape($_POST['tag'], 'String'); if (empty($caseId)) { echo 'false'; CRM_Utils_System::civiExit(); } $tagIds = array(); if ($tags) { $tagIds = explode(',', $tags); } $params = array('entity_id' => $caseId, 'entity_table' => 'civicrm_case'); CRM_Core_BAO_EntityTag::del($params); foreach ($tagIds as $tagid) { if (is_numeric($tagid)) { $params['tag_id'] = $tagid; CRM_Core_BAO_EntityTag::add($params); } } $session = CRM_Core_Session::singleton(); $activityParams = array(); $activityParams['source_contact_id'] = $session->get('userID'); $activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue('activity_type', 'Change Case Tags', 'name'); $activityParams['activity_date_time'] = date('YmdHis'); $activityParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'); $activityParams['case_id'] = $caseId; $activityParams['is_auto'] = 0; $activityParams['subject'] = 'Change Case Tags'; $activity = CRM_Activity_BAO_Activity::create($activityParams); $caseParams = array('activity_id' => $activity->id, 'case_id' => $caseId); CRM_Case_BAO_Case::processCaseActivity($caseParams); echo 'true'; CRM_Utils_System::civiExit(); }
/** * delete all the files and associated object associated with this * combination */ static function deleteEntityFile($entityTable, $entityID, $fileTypeID = NULL, $fileID = NULL) { if (empty($entityTable) || empty($entityID)) { return; } $config = CRM_Core_Config::singleton(); list($sql, $params) = self::sql($entityTable, $entityID, $fileTypeID, $fileID); $dao = CRM_Core_DAO::executeQuery($sql, $params); $cfIDs = array(); $cefIDs = array(); while ($dao->fetch()) { $cfIDs[$dao->cfID] = $dao->uri; $cefIDs[] = $dao->cefID; } if (!empty($cefIDs)) { $cefIDs = implode(',', $cefIDs); $sql = "DELETE FROM civicrm_entity_file where id IN ( {$cefIDs} )"; CRM_Core_DAO::executeQuery($sql); } if (!empty($cfIDs)) { // Delete file only if there no any entity using this file. $deleteFiles = array(); foreach ($cfIDs as $fId => $fUri) { //delete tags from entity tag table $tagParams = array('entity_table' => 'civicrm_file', 'entity_id' => $fId); CRM_Core_BAO_EntityTag::del($tagParams); if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $fId, 'id', 'file_id')) { unlink($config->customFileUploadDir . DIRECTORY_SEPARATOR . $fUri); $deleteFiles[$fId] = $fId; } } if (!empty($deleteFiles)) { $deleteFiles = implode(',', $deleteFiles); $sql = "DELETE FROM civicrm_file where id IN ( {$deleteFiles} )"; CRM_Core_DAO::executeQuery($sql); } } }
/** * Process the form submission. * * * @param array $params * @return array|null */ public function postProcess($params = NULL) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash); // delete tags for the entity $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted successfully."), ts('Record Deleted'), 'success'); return NULL; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } // Set activity type id. if (empty($params['activity_type_id'])) { $params['activity_type_id'] = $this->_activityTypeId; } if (!empty($params['hidden_custom']) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // format params as arrays foreach (array('target', 'assignee', 'followup_assignee') as $name) { if (!empty($params["{$name}_contact_id"])) { $params["{$name}_contact_id"] = explode(',', $params["{$name}_contact_id"]); } else { $params["{$name}_contact_id"] = array(); } } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); $activity = array(); if (!empty($params['is_multi_activity']) && !CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id'])) { $targetContacts = $params['target_contact_id']; foreach ($targetContacts as $targetContactId) { $params['target_contact_id'] = array($targetContactId); // save activity $activity[] = $this->processActivity($params); } } else { // save activity $activity = $this->processActivity($params); } $activityIds = empty($this->_activityIds) ? array($this->_activityId) : $this->_activityIds; foreach ($activityIds as $activityId) { // set params for repeat configuration in create mode $params['entity_id'] = $activityId; $params['entity_table'] = 'civicrm_activity'; if (!empty($params['entity_id']) && !empty($params['entity_table'])) { $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($params['entity_id'], $params['entity_table']); if ($checkParentExistsForThisId) { $params['parent_entity_id'] = $checkParentExistsForThisId; $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $params['entity_table']); } else { $params['parent_entity_id'] = $params['entity_id']; $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($params['entity_id'], $params['entity_table']); } if (property_exists($scheduleReminderDetails, 'id')) { $params['schedule_reminder_id'] = $scheduleReminderDetails->id; } } $params['dateColumns'] = array('activity_date_time'); // Set default repetition start if it was not provided. if (empty($params['repetition_start_date'])) { $params['repetition_start_date'] = $params['activity_date_time']; } // unset activity id unset($params['id']); $linkedEntities = array(array('table' => 'civicrm_activity_contact', 'findCriteria' => array('activity_id' => $activityId), 'linkedColumns' => array('activity_id'), 'isRecurringEntityRecord' => FALSE)); CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_activity', $linkedEntities); } return array('activity' => $activity); }
/** * Process the form submission. * * * @param array $params * * @return void */ public function postProcess($params = NULL) { $transaction = new CRM_Core_Transaction(); if ($this->_action & CRM_Core_Action::DELETE) { $statusMsg = NULL; //block deleting activities which affects //case attributes.CRM-4543 $activityCondition = " AND v.name IN ('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date')"; $caseAttributeActivities = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $activityCondition); if (!array_key_exists($this->_activityTypeId, $caseAttributeActivities)) { $params = array('id' => $this->_activityId); $activityDelete = CRM_Activity_BAO_Activity::deleteActivity($params, TRUE); if ($activityDelete) { $statusMsg = ts('The selected activity has been moved to the Trash. You can view and / or restore deleted activities by checking "Deleted Activities" from the Case Activities search filter (under Manage Case).<br />'); } } else { $statusMsg = ts("Selected Activity cannot be deleted."); } $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus('', $statusMsg, 'info'); return; } if ($this->_action & CRM_Core_Action::RENEW) { $statusMsg = NULL; $params = array('id' => $this->_activityId); $activityRestore = CRM_Activity_BAO_Activity::restoreActivity($params); if ($activityRestore) { $statusMsg = ts('The selected activity has been restored.<br />'); } CRM_Core_Session::setStatus('', $statusMsg, 'info'); return; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); //set parent id if its edit mode if ($parentId = CRM_Utils_Array::value('parent_id', $this->_defaults)) { $params['parent_id'] = $parentId; } // store the dates with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); $params['activity_type_id'] = $this->_activityTypeId; // format with contact (target contact) values if (isset($params['target_contact_id'])) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } // format activity custom data if (!empty($params['hidden_custom'])) { if ($this->_activityId) { // unset custom fields-id from params since we want custom // fields to be saved for new activity. foreach ($params as $key => $value) { $match = array(); if (preg_match('/^(custom_\\d+_)(\\d+)$/', $key, $match)) { $params[$match[1] . '-1'] = $params[$key]; // for autocomplete transfer hidden value instead of label if ($params[$key] && isset($params[$key . '_id'])) { $params[$match[1] . '-1_id'] = $params[$key . '_id']; unset($params[$key . '_id']); } unset($params[$key]); } } } // build custom data getFields array $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_activityId, 'Activity'); } // assigning formatted value if (!empty($params['assignee_contact_id'])) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } if (isset($this->_activityId)) { // activity which hasn't been modified by a user yet if ($this->_defaults['is_auto'] == 1) { $params['is_auto'] = 0; } // always create a revision of an case activity. CRM-4533 $newActParams = $params; // add target contact values in update mode if (empty($params['target_contact_id']) && !empty($this->_defaults['target_contact'])) { $newActParams['target_contact_id'] = $this->_defaults['target_contact']; } } if (!isset($newActParams)) { // add more attachments if needed for old activity CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($params); foreach ($this->_caseId as $key => $val) { $params['case_id'] = $val; // activity create/update $activity = CRM_Activity_BAO_Activity::create($params); $vvalue[] = array('case_id' => $val, 'actId' => $activity->id); // call end post process, after the activity has been created/updated. $this->endPostProcess($params, $activity); } } else { // since the params we need to set are very few, and we don't want rest of the // work done by bao create method , lets use dao object to make the changes $params = array('id' => $this->_activityId); $params['is_current_revision'] = 0; $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->save(); } // create a new version of activity if activity was found to // have been modified/created by user if (isset($newActParams)) { // set proper original_id if (!empty($this->_defaults['original_id'])) { $newActParams['original_id'] = $this->_defaults['original_id']; } else { $newActParams['original_id'] = $activity->id; } //is_current_revision will be set to 1 by default. // add attachments if any CRM_Core_BAO_File::formatAttachment($newActParams, $newActParams, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($newActParams); foreach ($this->_caseId as $key => $val) { $newActParams['case_id'] = $val; $activity = CRM_Activity_BAO_Activity::create($newActParams); $vvalue[] = array('case_id' => $val, 'actId' => $activity->id); // call end post process, after the activity has been created/updated. $this->endPostProcess($newActParams, $activity); } // copy files attached to old activity if any, to new one, // as long as users have not selected the 'delete attachment' option. if (empty($newActParams['is_delete_attachment'])) { CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id); } // copy back params to original var $params = $newActParams; } foreach ($vvalue as $vkey => $vval) { if ($vval['actId']) { // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $vval['actId']); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { CRM_Core_Form_Tag::postProcess($params['taglist'], $vval['actId'], 'civicrm_activity', $this); } } // update existing case record if needed $caseParams = $params; $caseParams['id'] = $vval['case_id']; if (!empty($caseParams['case_status_id'])) { $caseParams['status_id'] = $caseParams['case_status_id']; } // unset params intended for activities only unset($caseParams['subject'], $caseParams['details'], $caseParams['status_id'], $caseParams['custom']); $case = CRM_Case_BAO_Case::create($caseParams); // create case activity record $caseParams = array('activity_id' => $vval['actId'], 'case_id' => $vval['case_id']); CRM_Case_BAO_Case::processCaseActivity($caseParams); } // Insert civicrm_log record for the activity (e.g. store the // created / edited by contact id and date for the activity) // Note - civicrm_log is already created by CRM_Activity_BAO_Activity::create() // send copy to selected contacts. $mailStatus = ''; $mailToContacts = array(); //CRM-5695 //check for notification settings for assignee contacts $selectedContacts = array('contact_check'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $selectedContacts[] = 'assignee_contact_id'; } foreach ($vvalue as $vkey => $vval) { foreach ($selectedContacts as $dnt => $val) { if (array_key_exists($val, $params) && !CRM_Utils_array::crmIsEmptyArray($params[$val])) { if ($val == 'contact_check') { $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s)."); } else { $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($vval['actId']), TRUE, FALSE); $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s)."); } //build an associative array with unique email addresses. foreach ($params[$val] as $key => $value) { if ($val == 'contact_check') { $id = $key; } else { $id = $value; } if (isset($id) && array_key_exists($id, $this->_relatedContacts) && isset($this->_relatedContacts[$id]['email'])) { //if email already exists in array then append with ', ' another role only otherwise add it to array. if ($contactDetails = CRM_Utils_Array::value($this->_relatedContacts[$id]['email'], $mailToContacts)) { $caseRole = CRM_Utils_Array::value('role', $this->_relatedContacts[$id]); $mailToContacts[$this->_relatedContacts[$id]['email']]['role'] = $contactDetails['role'] . ', ' . $caseRole; } else { $mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id]; } } } } } $extraParams = array('case_id' => $vval['case_id'], 'client_id' => $this->_currentlyViewedContactId); $result = CRM_Activity_BAO_Activity::sendToAssignee($activity, $mailToContacts, $extraParams); if (empty($result)) { $mailStatus = ''; } // create follow up activity if needed $followupStatus = ''; if (!empty($params['followup_activity_type_id'])) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($vval['actId'], $params); if ($followupActivity) { $caseParams = array('activity_id' => $followupActivity->id, 'case_id' => $vval['case_id']); CRM_Case_BAO_Case::processCaseActivity($caseParams); $followupStatus = ts("A followup activity has been scheduled.") . '<br /><br />'; } } $title = ts("%1 Saved", array(1 => $this->_activityTypeName)); CRM_Core_Session::setStatus($followupStatus . $mailStatus, $title, 'success'); } }
static function processTags() { $skipTagCreate = $skipEntityAction = $entityId = NULL; $action = CRM_Utils_Type::escape($_POST['action'], 'String'); $parentId = CRM_Utils_Type::escape($_POST['parentId'], 'Integer'); if ($_POST['entityId']) { $entityId = CRM_Utils_Type::escape($_POST['entityId'], 'Integer'); } $entityTable = CRM_Utils_Type::escape($_POST['entityTable'], 'String'); if ($_POST['skipTagCreate']) { $skipTagCreate = CRM_Utils_Type::escape($_POST['skipTagCreate'], 'Integer'); } if ($_POST['skipEntityAction']) { $skipEntityAction = CRM_Utils_Type::escape($_POST['skipEntityAction'], 'Integer'); } // check if user has selected existing tag or is creating new tag // this is done to allow numeric tags etc. $tagValue = explode(':::', $_POST['tagID']); $createNewTag = FALSE; $tagID = $tagValue[0]; if (isset($tagValue[1]) && $tagValue[1] == 'value') { $createNewTag = TRUE; } $tagInfo = array(); // if action is select if ($action == 'select') { // check the value of tagID // if numeric that means existing tag // else create new tag if (!$skipTagCreate && $createNewTag) { $params = array('name' => $tagID, 'parent_id' => $parentId); $tagObject = CRM_Core_BAO_Tag::add($params, CRM_Core_DAO::$_nullArray); $tagInfo = array('name' => $tagID, 'id' => $tagObject->id, 'action' => $action); $tagID = $tagObject->id; } if (!$skipEntityAction && $entityId) { // save this tag to contact $params = array('entity_table' => $entityTable, 'entity_id' => $entityId, 'tag_id' => $tagID); CRM_Core_BAO_EntityTag::add($params); } // if action is delete } elseif ($action == 'delete') { if (!is_numeric($tagID)) { $tagID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $tagID, 'id', 'name'); } if (!$skipEntityAction && $entityId) { // delete this tag entry for the entity $params = array('entity_table' => $entityTable, 'entity_id' => $entityId, 'tag_id' => $tagID); CRM_Core_BAO_EntityTag::del($params); } $tagInfo = array('id' => $tagID, 'action' => $action); } CRM_Utils_JSON::output($tagInfo); }
/** * Takes an associative array and creates tag entity record for all tag entities. * * @param array $params * (reference) an assoc array of name/value pairs. * @param $entityTable * @param int $entityID * * @return void */ public static function create(&$params, $entityTable, $entityID) { // get categories for the entity id $entityTag = CRM_Core_BAO_EntityTag::getTag($entityID, $entityTable); // get the list of all the categories $allTag = CRM_Core_BAO_Tag::getTags($entityTable); // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input if (!is_array($params)) { $params = array(); } // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input if (!is_array($entityTag)) { $entityTag = array(); } // check which values has to be inserted/deleted for contact foreach ($allTag as $key => $varValue) { $tagParams['entity_table'] = $entityTable; $tagParams['entity_id'] = $entityID; $tagParams['tag_id'] = $key; if (array_key_exists($key, $params) && !array_key_exists($key, $entityTag)) { // insert a new record CRM_Core_BAO_EntityTag::add($tagParams); } elseif (!array_key_exists($key, $params) && array_key_exists($key, $entityTag)) { // delete a record for existing contact CRM_Core_BAO_EntityTag::del($tagParams); } } }
/** * Deletes an existing entity tag assignment. * * @param $entity_tag object Valid entity_tag object. * @access public */ function crm_delete_entity_tag(&$entity_tag) { require_once 'CRM/Core/BAO/EntityTag.php'; if (!isset($entity_tag->id)) { return _crm_error('Required parameters missing'); } $params = array('id' => $entity_tag->id); return CRM_Core_BAO_EntityTag::del($params); }
/** * Function to process the form * * @access public * * @return void */ public function postProcess($params = NULL) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash); // delete tags for the entity $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted successfully."), ts('Record Deleted'), 'success'); return; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } //set activity type id if (empty($params['activity_type_id'])) { $params['activity_type_id'] = $this->_activityTypeId; } if (!empty($params['hidden_custom']) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // format with contact (target contact) values if (isset($params['contact'][1])) { $params['target_contact_id'] = explode(',', $params['contact'][1]); } else { $params['target_contact_id'] = array(); } // assigning formated value to related variable if (!empty($params['assignee_contact_id'])) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } // civicrm-10043 - 14/12/13 if (!empty($params['followup_assignee_contact_id'])) { $params['followup_assignee_contact_id'] = explode(',', $params['followup_assignee_contact_id']); } else { $params['followup_assignee_contact_id'] = array(); } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); // format target params if (!$this->_single) { $params['target_contact_id'] = $this->_contactIds; } $activity = array(); if (!empty($params['is_multi_activity']) && !CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id'])) { $targetContacts = $params['target_contact_id']; foreach ($targetContacts as $targetContactId) { $params['target_contact_id'] = array($targetContactId); // save activity $activity[] = $this->processActivity($params); } } else { // save activity $activity = $this->processActivity($params); } return array('activity' => $activity); }
/** * Function to process the form * * @access public * @return None */ public function postProcess($params = null) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); require_once 'CRM/Case/BAO/Case.php'; $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash); // delete tags for the entity require_once 'CRM/Core/BAO/EntityTag.php'; $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted sucessfully.")); return; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } //set activity type id if (!CRM_Utils_Array::value('activity_type_id', $params)) { $params['activity_type_id'] = $this->_activityTypeId; } if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', false, false, null, null, true)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // assigning formated value to related variable if (CRM_Utils_Array::value('target_contact_id', $params)) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } else { $params['source_contact_id'] = $this->_submitValues['source_contact_qid']; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); // format target params if (!$this->_single) { $params['target_contact_id'] = $this->_contactIds; } $activityAssigned = array(); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { require_once 'CRM/Core/Form/Tag.php'; CRM_Core_Form_Tag::postProcess($params['taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = "A followup activity has been scheduled."; } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; $config =& CRM_Core_Config::singleton(); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && $config->activityAssigneeNotification) { $mailToContacts = array(); $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, true, false); //build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sendig a copy of activity. $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); require_once "CRM/Case/BAO/Case.php"; $result = CRM_Case_BAO_Case::sendActivityCopy(null, $activity->id, $mailToContacts, $attachments, null); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // set status message if (CRM_Utils_Array::value('subject', $params)) { $params['subject'] = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2. %3', array(1 => $params['subject'], 2 => $followupStatus, 3 => $mailStatus))); return array('activity' => $activity); }
static function processTags() { $skipTagCreate = $skipEntityAction = $entityId = null; $action = CRM_Utils_Type::escape($_POST['action'], 'String'); $parentId = CRM_Utils_Type::escape($_POST['parentId'], 'Integer'); if ($_POST['entityId']) { $entityId = CRM_Utils_Type::escape($_POST['entityId'], 'Integer'); } $entityTable = CRM_Utils_Type::escape($_POST['entityTable'], 'String'); if ($_POST['skipTagCreate']) { $skipTagCreate = CRM_Utils_Type::escape($_POST['skipTagCreate'], 'Integer'); } if ($_POST['skipEntityAction']) { $skipEntityAction = CRM_Utils_Type::escape($_POST['skipEntityAction'], 'Integer'); } $tagID = $_POST['tagID']; require_once 'CRM/Core/BAO/EntityTag.php'; $tagInfo = array(); // if action is select if ($action == 'select') { // check the value of tagID // if numeric that means existing tag // else create new tag if (!$skipTagCreate && !is_numeric($tagID)) { $params = array('name' => $tagID, 'parent_id' => $parentId); require_once 'CRM/Core/BAO/Tag.php'; $tagObject = CRM_Core_BAO_Tag::add($params, CRM_Core_DAO::$_nullArray); $tagInfo = array('name' => $tagID, 'id' => $tagObject->id, 'action' => $action); $tagID = $tagObject->id; } if (!$skipEntityAction && $entityId) { // save this tag to contact $params = array('entity_table' => $entityTable, 'entity_id' => $entityId, 'tag_id' => $tagID); CRM_Core_BAO_EntityTag::add($params); } } elseif ($action == 'delete') { // if action is delete if (!is_numeric($tagID)) { $tagID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $tagID, 'id', 'name'); } if ($entityId) { // delete this tag entry for the entity $params = array('entity_table' => $entityTable, 'entity_id' => $entityId, 'tag_id' => $tagID); CRM_Core_BAO_EntityTag::del($params); } $tagInfo = array('id' => $tagID, 'action' => $action); } echo json_encode($tagInfo); CRM_Utils_System::civiExit(); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $statusMsg = null; //block deleting activities which affects //case attributes.CRM-4543 $activityCondition = " AND v.name IN ('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date')"; $caseAttributeActivities = CRM_Core_OptionGroup::values('activity_type', false, false, false, $activityCondition); if (!array_key_exists($this->_activityTypeId, $caseAttributeActivities)) { $params = array('id' => $this->_activityId); $activityDelete = CRM_Activity_BAO_Activity::deleteActivity($params, true); if ($activityDelete) { $statusMsg = ts('The selected activity has been moved to the Trash. You can view and / or restore deleted activities by checking "Deleted Activities" from the Case Activities search filter (under Manage Case).<br />'); } } else { $statusMsg = ts("Selected Activity cannot be deleted."); } require_once 'CRM/Core/BAO/EntityTag.php'; $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus($statusMsg); return; } if ($this->_action & CRM_Core_Action::RENEW) { $statusMsg = null; $params = array('id' => $this->_activityId); $activityRestore = CRM_Activity_BAO_Activity::restoreActivity($params); if ($activityRestore) { $statusMsg = ts('The selected activity has been restored.<br />'); } CRM_Core_Session::setStatus($statusMsg); return; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); if ($params['source_contact_id']) { $params['source_contact_id'] = $params['source_contact_qid']; } //set parent id if its edit mode if ($parentId = CRM_Utils_Array::value('parent_id', $this->_defaults)) { $params['parent_id'] = $parentId; } // required for status msg $recordStatus = 'created'; // store the dates with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); $params['activity_type_id'] = $this->_activityTypeId; require_once 'CRM/Case/XMLProcessor/Process.php'; $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->assign('multiClient', $isMultiClient); $targetContacts = array($this->_currentlyViewedContactId); if (CRM_Utils_Array::value('hidden_target_contact', $params) && CRM_Utils_Array::value('target_contact_id', $params)) { $targetContacts = array_unique(explode(',', $params['target_contact_id'])); } $params['target_contact_id'] = $targetContacts; // format activity custom data if (CRM_Utils_Array::value('hidden_custom', $params)) { if ($this->_activityId) { // unset custom fields-id from params since we want custom // fields to be saved for new activity. foreach ($params as $key => $value) { $match = array(); if (preg_match('/^(custom_\\d+_)(\\d+)$/', $key, $match)) { $params[$match[1] . '-1'] = $params[$key]; // for autocomplete transfer hidden value instead of label if ($params[$key] && isset($params[$key . '_id'])) { $params[$match[1] . '-1_id'] = $params[$key . '_id']; unset($params[$key . '_id']); } unset($params[$key]); } } } // build custom data getFields array $customFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', false, false, null, null, true)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $assineeContacts = explode(',', $params['assignee_contact_id']); $assineeContacts = array_unique($assineeContacts); unset($params['assignee_contact_id']); } else { $params['assignee_contact_id'] = $assineeContacts = array(); } if (isset($this->_activityId)) { // activity which hasn't been modified by a user yet if ($this->_defaults['is_auto'] == 1) { $params['is_auto'] = 0; } // always create a revision of an case activity. CRM-4533 $newActParams = $params; // add target contact values in update mode if (empty($params['target_contact_id']) && !empty($this->_defaults['target_contact'])) { $newActParams['target_contact_id'] = $this->_defaults['target_contact']; } // record status for status msg $recordStatus = 'updated'; } if (!isset($newActParams)) { // add more attachments if needed for old activity CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($params); $params['case_id'] = $this->_caseId; // activity create/update $activity = CRM_Activity_BAO_Activity::create($params); // call end post process, after the activity has been created/updated. $this->endPostProcess($params, $activity); } else { // since the params we need to set are very few, and we don't want rest of the // work done by bao create method , lets use dao object to make the changes $params = array('id' => $this->_activityId); $params['is_current_revision'] = 0; $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->save(); } // create a new version of activity if activity was found to // have been modified/created by user if (isset($newActParams)) { // set proper original_id if (CRM_Utils_Array::value('original_id', $this->_defaults)) { $newActParams['original_id'] = $this->_defaults['original_id']; } else { $newActParams['original_id'] = $activity->id; } //is_current_revision will be set to 1 by default. // add attachments if any CRM_Core_BAO_File::formatAttachment($newActParams, $newActParams, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($newActParams); $newActParams['case_id'] = $this->_caseId; $activity = CRM_Activity_BAO_Activity::create($newActParams); // call end post process, after the activity has been created/updated. $this->endPostProcess($newActParams, $activity); // copy files attached to old activity if any, to new one, // as long as users have not selected the 'delete attachment' option. if (!CRM_Utils_Array::value('is_delete_attachment', $newActParams)) { CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id); } // copy back params to original var $params = $newActParams; } if ($activity->id) { // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { require_once 'CRM/Core/Form/Tag.php'; CRM_Core_Form_Tag::postProcess($params['taglist'], $activity->id, 'civicrm_activity', $this); } } $params['assignee_contact_id'] = $assineeContacts; // update existing case record if needed $caseParams = $params; $caseParams['id'] = $this->_caseId; if (CRM_Utils_Array::value('case_type_id', $caseParams)) { $caseParams['case_type_id'] = CRM_Case_BAO_Case::VALUE_SEPERATOR . $caseParams['case_type_id'] . CRM_Case_BAO_Case::VALUE_SEPERATOR; } if (CRM_Utils_Array::value('case_status_id', $caseParams)) { $caseParams['status_id'] = $caseParams['case_status_id']; } // unset params intended for activities only unset($caseParams['subject'], $caseParams['details'], $caseParams['status_id'], $caseParams['custom']); $case = CRM_Case_BAO_Case::create($caseParams); // create case activity record $caseParams = array('activity_id' => $activity->id, 'case_id' => $this->_caseId); CRM_Case_BAO_Case::processCaseActivity($caseParams); // create activity assignee records $assigneeParams = array('activity_id' => $activity->id); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); $activityId = isset($this->_activityId) ? $this->_activityId : $activity->id; $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); foreach ($params['assignee_contact_id'] as $key => $id) { $assigneeParams['assignee_contact_id'] = $id; CRM_Activity_BAO_Activity::createActivityAssignment($assigneeParams); } //modify assigne_contact as per newly assigned contact before sending copy. CRM-4509. $params['assignee_contact_id'] = $activityAssigned; } // Insert civicrm_log record for the activity (e.g. store the // created / edited by contact id and date for the activity) // Note - civicrm_log is already created by CRM_Activity_BAO_Activity::create() // send copy to selected contacts. $mailStatus = ''; $mailToContacts = array(); //CRM-5695 //check for notification settings for assignee contacts $selectedContacts = array('contact_check'); $config =& CRM_Core_Config::singleton(); if ($config->activityAssigneeNotification) { $selectedContacts[] = 'assignee_contact_id'; } foreach ($selectedContacts as $dnt => $val) { if (array_key_exists($val, $params) && !CRM_Utils_array::crmIsEmptyArray($params[$val])) { if ($val == 'contact_check') { $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s)."); } else { $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, true, false); $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s)."); } //build an associative array with unique email addresses. foreach ($params[$val] as $id => $dnc) { if (isset($id) && array_key_exists($id, $this->_relatedContacts)) { //if email already exists in array then append with ', ' another role only otherwise add it to array. if ($contactDetails = CRM_Utils_Array::value($this->_relatedContacts[$id]['email'], $mailToContacts)) { $caseRole = CRM_Utils_Array::value('role', $this->_relatedContacts[$id]); $mailToContacts[$this->_relatedContacts[$id]['email']]['role'] = $contactDetails['role'] . ', ' . $caseRole; } else { $mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id]; } } } } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sendig a copy of activity. $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); $result = CRM_Case_BAO_Case::sendActivityCopy($this->_currentlyViewedContactId, $activity->id, $mailToContacts, $attachments, $this->_caseId); if (empty($result)) { $mailStatus = ''; } } else { $mailStatus = ''; } // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); if ($followupActivity) { $caseParams = array('activity_id' => $followupActivity->id, 'case_id' => $this->_caseId); CRM_Case_BAO_Case::processCaseActivity($caseParams); $followupStatus = ts("A followup activity has been scheduled."); } } CRM_Core_Session::setStatus(ts("'%1' activity has been %2. %3 %4", array(1 => $this->_activityTypeName, 2 => $recordStatus, 3 => $followupStatus, 4 => $mailStatus))); }