/** * process the form after the input has been submitted and validated * * @access public * * @return void */ public function postProcess() { $deletedActivities = 0; foreach ($this->_activityHolderIds as $activityId['id']) { $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($activityId['id']); if (CRM_Activity_BAO_Activity::deleteActivity($activityId, $moveToTrash)) { $deletedActivities++; } } CRM_Core_Session::setStatus($deletedActivities, ts('Deleted Activities'), "success"); CRM_Core_Session::setStatus("", ts('Total Selected Activities: %1', array(1 => count($this->_activityHolderIds))), "info"); }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ public function postProcess() { $deletedActivities = 0; foreach ($this->_activityHolderIds as $activityId['id']) { require_once 'CRM/Case/BAO/Case.php'; $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($activityId['id']); if (CRM_Activity_BAO_Activity::deleteActivity($activityId, $moveToTrash)) { $deletedActivities++; } } $status = array(ts('Deleted Activities: %1', array(1 => $deletedActivities)), ts('Total Selected Activities: %1', array(1 => count($this->_activityHolderIds)))); CRM_Core_Session::setStatus($status); }
/** * Process the form after the input has been submitted and validated. * * * @return void */ public function postProcess() { $deleted = $failed = 0; foreach ($this->_activityHolderIds as $activityId['id']) { $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($activityId['id']); if (CRM_Activity_BAO_Activity::deleteActivity($activityId, $moveToTrash)) { $deleted++; } else { $failed++; } } if ($deleted) { $msg = ts('%count activity deleted.', array('plural' => '%count activities deleted.', 'count' => $deleted)); CRM_Core_Session::setStatus($msg, ts('Removed'), 'success'); } if ($failed) { CRM_Core_Session::setStatus(ts('1 could not be deleted.', array('plural' => '%count could not be deleted.', 'count' => $failed)), ts('Error'), 'error'); } }
/** * Delete a specified Activity. * * @param array $params * Array holding 'id' of activity to be deleted. * * @throws API_Exception * * @return array * API result array */ function civicrm_api3_activity_delete($params) { if (CRM_Activity_BAO_Activity::deleteActivity($params)) { return civicrm_api3_create_success(1, $params, 'Activity', 'delete'); } else { throw new API_Exception('Could not delete Activity'); } }
/** * Delete the record that are associated with this participation * * @param int $id id of the participation to delete * * @return void * @access public * @static */ static function deleteParticipant($id) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); //delete activity record require_once "CRM/Activity/BAO/Activity.php"; $params = array('source_record_id' => $id, 'activity_type_id' => 5); // activity type id for event registration CRM_Activity_BAO_Activity::deleteActivity($params); // delete the participant payment record // we need to do this since the cascaded constraints // dont work with join tables require_once 'CRM/Event/BAO/ParticipantPayment.php'; $p = array('participant_id' => $id); CRM_Event_BAO_ParticipantPayment::deleteParticipantPayment($p); // cleanup line items. require_once 'CRM/Price/BAO/LineItem.php'; $participantsId = array(); $participantsId = self::getAdditionalParticipantIds($id); $participantsId[] = $id; CRM_Price_BAO_LineItem::deleteLineItems($participantsId, 'civicrm_participant'); $participant = new CRM_Event_DAO_Participant(); $participant->id = $id; $participant->delete(); $transaction->commit(); // delete the recently created Participant require_once 'CRM/Utils/Recent.php'; $participantRecent = array('id' => $id, 'type' => 'Participant'); CRM_Utils_Recent::del($participantRecent); return $participant; }
/** * Delete the record that are associated with this case * record are deleted from case * @param int $caseId id of the case to delete * * @return void * @access public * @static */ static function deleteCase($caseId, $moveToTrash = false) { //delete activities $activities = self::getCaseActivityDates($caseId); if ($activities) { require_once "CRM/Activity/BAO/Activity.php"; foreach ($activities as $value) { CRM_Activity_BAO_Activity::deleteActivity($value, $moveToTrash); } } if (!$moveToTrash) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); } require_once 'CRM/Case/DAO/Case.php'; $case =& new CRM_Case_DAO_Case(); $case->id = $caseId; if (!$moveToTrash) { $result = $case->delete(); $transaction->commit(); } else { $result = $case->is_deleted = 1; $case->save(); } if ($result) { // remove case from recent items. $caseRecent = array('id' => $caseId, 'type' => 'Case'); require_once 'CRM/Utils/Recent.php'; CRM_Utils_Recent::del($caseRecent); return true; } return false; }
/** * Delete a specified Activity. * @param CRM_Activity $activity Activity object to be deleted * * @return void|CRM_Core_Error An error if 'activityName or ID' is invalid, * permissions are insufficient, etc. * * @access public * */ function civicrm_activity_delete(&$params) { _civicrm_initialize(); $errors = array(); //check for various error and required conditions $errors = _civicrm_activity_check_params($params); if (!empty($errors)) { return $errors; } if (CRM_Activity_BAO_Activity::deleteActivity($params)) { return civicrm_create_success(); } else { return civicrm_create_error(ts('Could not delete activity')); } }
/** * Function to delete membership. * * @param int $membershipId membership id that needs to be deleted * * @static * * @return $results no of deleted Membership on success, false otherwise * @access public */ static function deleteMembership($membershipId) { CRM_Utils_Hook::pre('delete', 'Membership', $membershipId, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); $results = NULL; //delete activity record $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'); $params = array(); $deleteActivity = false; $membershipActivities = array('Membership Signup', 'Membership Renewal', 'Change Membership Status', 'Change Membership Type', 'Membership Renewal Reminder'); foreach ($membershipActivities as $membershipActivity) { $activityId = array_search($membershipActivity, $activityTypes); if ($activityId) { $params['activity_type_id'][] = $activityId; $deleteActivity = true; } } if ($deleteActivity) { $params['source_record_id'] = $membershipId; CRM_Activity_BAO_Activity::deleteActivity($params); } self::deleteMembershipPayment($membershipId); $membership = new CRM_Member_DAO_Membership(); $membership->id = $membershipId; $results = $membership->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Membership', $membership->id, $membership); // delete the recently created Membership $membershipRecent = array('id' => $membershipId, 'type' => 'Membership'); CRM_Utils_Recent::del($membershipRecent); return $results; }
/** * Delete the record that are associated with this case * record are deleted from case * * @param int $caseId id of the case to delete * * @param bool $moveToTrash * * @return bool is successful * @access public * @static */ static function deleteCase($caseId, $moveToTrash = FALSE) { CRM_Utils_Hook::pre('delete', 'Case', $caseId, CRM_Core_DAO::$_nullArray); //delete activities $activities = self::getCaseActivityDates($caseId); if ($activities) { foreach ($activities as $value) { CRM_Activity_BAO_Activity::deleteActivity($value, $moveToTrash); } } if (!$moveToTrash) { $transaction = new CRM_Core_Transaction(); } $case = new CRM_Case_DAO_Case(); $case->id = $caseId; if (!$moveToTrash) { $result = $case->delete(); $transaction->commit(); } else { $result = $case->is_deleted = 1; $case->save(); } if ($result) { // CRM-7364, disable relationships self::enableDisableCaseRelationships($caseId, FALSE); CRM_Utils_Hook::post('delete', 'Case', $caseId, $case); // remove case from recent items. $caseRecent = array('id' => $caseId, 'type' => 'Case'); CRM_Utils_Recent::del($caseRecent); return TRUE; } return FALSE; }
/** * Delete the indirect records associated with this contribution first * * @return $results no of deleted Contribution on success, false otherwise * @access public * @static */ static function deleteContribution($id) { require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $results = null; //delete activity record require_once "CRM/Activity/BAO/Activity.php"; $params = array('source_record_id' => $id, 'activity_type_id' => 6); // activity type id for contribution CRM_Activity_BAO_Activity::deleteActivity($params); //delete billing address if exists for this contribution. self::deleteAddress($id); //update pledge and pledge payment, CRM-3961 require_once 'CRM/Pledge/BAO/Payment.php'; CRM_Pledge_BAO_Payment::resetPledgePayment($id); // remove entry from civicrm_price_set_entity, CRM-5095 require_once 'CRM/Price/BAO/Set.php'; if (CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) { CRM_Price_BAO_Set::removeFrom('civicrm_contribution', $id); } // cleanup line items. require_once 'CRM/Price/BAO/Field.php'; require_once 'CRM/Event/BAO/ParticipantPayment.php'; $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id'); // delete any related entity_financial_trxn and financial_trxn records. require_once 'CRM/Core/BAO/FinancialTrxn.php'; CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id, 'civicrm_contribution'); if ($participantId) { require_once 'CRM/Price/BAO/LineItem.php'; CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant'); } else { require_once 'CRM/Price/BAO/LineItem.php'; CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution'); } $dao = new CRM_Contribute_DAO_Contribution(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao); // delete the recently created Contribution require_once 'CRM/Utils/Recent.php'; $contributionRecent = array('id' => $id, 'type' => 'Contribution'); CRM_Utils_Recent::del($contributionRecent); return $results; }
/** * Delete the indirect records associated with this contribution first. * * @param int $id * * @return mixed|null * $results no of deleted Contribution on success, false otherwise */ public static function deleteContribution($id) { CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); $results = NULL; //delete activity record $params = array('source_record_id' => $id, 'activity_type_id' => 6); CRM_Activity_BAO_Activity::deleteActivity($params); //delete billing address if exists for this contribution. self::deleteAddress($id); //update pledge and pledge payment, CRM-3961 CRM_Pledge_BAO_PledgePayment::resetPledgePayment($id); // remove entry from civicrm_price_set_entity, CRM-5095 if (CRM_Price_BAO_PriceSet::getFor('civicrm_contribution', $id)) { CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution', $id); } // cleanup line items. $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id'); // delete any related entity_financial_trxn, financial_trxn and financial_item records. CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id); if ($participantId) { CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant'); } else { CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution'); } //delete note. $note = CRM_Core_BAO_Note::getNote($id, 'civicrm_contribution'); $noteId = key($note); if ($noteId) { CRM_Core_BAO_Note::del($noteId, FALSE); } $dao = new CRM_Contribute_DAO_Contribution(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao); // delete the recently created Contribution $contributionRecent = array('id' => $id, 'type' => 'Contribution'); CRM_Utils_Recent::del($contributionRecent); return $results; }
/** * 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'); } }
/** * 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); CRM_Activity_BAO_Activity::deleteActivity($deleteParams); 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); // 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); }
/** * Delete a specified Activity. * * @param array $params array holding 'id' of activity to be deleted * {@getfields activity_delete} * * @return void|CRM_Core_Error An error if 'activityName or ID' is invalid, * permissions are insufficient, etc. or CiviCRM success array * * * * @example ActivityDelete.php Standard Delete Example * * */ function civicrm_api3_activity_delete($params) { if (CRM_Activity_BAO_Activity::deleteActivity($params)) { return civicrm_api3_create_success(1, $params, 'activity', 'delete'); } else { return civicrm_api3_create_error('Could not delete activity'); } }
/** * 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 void */ public function postProcess() { $session = CRM_Core_Session::singleton(); if ($this->_action & CRM_Core_Action::DELETE) { $params['id'] = $this->_id; CRM_Activity_BAO_Activity::deleteActivity($params); CRM_Core_Session::setStatus(ts('Selected Public Holiday has been deleted.'), 'Success', 'success'); } else { $params = $ids = array(); // store the submitted values in an array $params = $this->exportValues(); $activity_type_id = civicrm_api3('OptionValue', 'getvalue', array('name' => 'Public Holiday', 'return' => 'value')); $params['activity_type_id'] = $activity_type_id; $params['source_contact_id'] = $session->get('userID'); $status = CRM_Core_PseudoConstant::activityStatus(); $params['status_id'] = !empty($params['status_id']) ? array_search('Scheduled', $status) : array_search('Cancelled', $status); $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } $publicHoliday = CRM_Activity_BAO_Activity::create($params); if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Core_Session::setStatus(ts('The Public holiday \'%1\' has been updated.', array(1 => $publicHoliday->subject)), 'Success', 'success'); } else { CRM_Core_Session::setStatus(ts('The Public Holiday \'%1\' has been added.', array(1 => $publicHoliday->subject)), 'Success', 'success'); } $url = CRM_Utils_System::url('civicrm/absence/holidays', 'reset=1&action=browse'); $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); } }
/** * 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); $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.")); 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 CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_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); // CRM-9590 $this->_activityId = $activity->id; // 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 = ts('A followup activity has been scheduled.'); } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $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); // CRM-8400 add param with _currentlyViewedContactId for URL link in mail $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); }
/** * Function to delete membership. * * @param int $membershipId membership id that needs to be deleted * * @static * @return $results no of deleted Membership on success, false otherwise * @access public */ static function deleteMembership($membershipId) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $results = null; //delete activity record $activityTypes = CRM_Core_Pseudoconstant::activityType(true, false, false, 'name'); require_once "CRM/Activity/BAO/Activity.php"; $params = array('source_record_id' => $membershipId, 'activity_type_id' => array(array_search('Membership Signup', $activityTypes), array_search('Membership Renewal', $activityTypes))); CRM_Activity_BAO_Activity::deleteActivity($params); self::deleteMembershipPayment($membershipId); require_once 'CRM/Member/DAO/Membership.php'; $membership = new CRM_Member_DAO_Membership(); $membership->id = $membershipId; $results = $membership->delete(); $transaction->commit(); // delete the recently created Membership require_once 'CRM/Utils/Recent.php'; $membershipRecent = array('id' => $membershipId, 'type' => 'Membership'); CRM_Utils_Recent::del($membershipRecent); return $results; }
/** * Send an SMS Message via the Clickatell API Server * * @param array the message with a to/from/text * * @return mixed true on sucess or PEAR_Error object * @access public */ function send($recipients, $header, $message, $jobID = NULL) { if ($this->_apiType = 'http') { $postDataArray = array(); $url = $this->formURLPostData("/http/sendmsg", $postDataArray); if (array_key_exists('from', $this->_providerInfo['api_params'])) { $postDataArray['from'] = $this->_providerInfo['api_params']['from']; } $postDataArray['to'] = $header['To']; $postDataArray['text'] = substr($message, 0, 160); // max of 160 characters, is probably not multi-lingual if (array_key_exists('mo', $this->_providerInfo['api_params'])) { $postDataArray['mo'] = $this->_providerInfo['api_params']['mo']; } // sendmsg with callback request: $postDataArray['callback'] = 3; $isTest = 0; if (array_key_exists('is_test', $this->_providerInfo['api_params']) && $this->_providerInfo['api_params']['is_test'] == 1) { $isTest = 1; } /** * Check if we are using a queue when sending as each account * with Clickatell is assigned three queues namely 1, 2 and 3. */ if (isset($header['queue']) && is_numeric($header['queue'])) { if (in_array($header['queue'], range(1, 3))) { $postDataArray['queue'] = $header['queue']; } } /** * Must we escalate message delivery if message is stuck in * the queue at Clickatell? */ if (isset($header['escalate']) && !empty($header['escalate'])) { if (is_numeric($header['escalate'])) { if (in_array($header['escalate'], range(1, 2))) { $postDataArray['escalate'] = $header['escalate']; } } } if ($isTest == 1) { $response = array('data' => 'ID:' . rand()); } else { $postData = CRM_Utils_Array::urlEncode($postDataArray); $response = $this->curl($url, $postData); } if (PEAR::isError($response)) { return $response; } $send = explode(":", $response['data']); if ($send[0] == "ID") { //trim whitespace around the id $apiMsgID = trim($send[1], " \t\r\n"); $this->createActivity($apiMsgID, $message, $header, $jobID); return $apiMsgID; } else { // delete any parent activity & throw error if (CRM_Utils_Array::value('parent_activity_id', $header)) { $params = array('id' => $header['parent_activity_id']); CRM_Activity_BAO_Activity::deleteActivity($params); } return PEAR::raiseError($response['data']); } } }
/** * 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); }
/** * Test case for deleteActivity() method. * * deleteActivity($params) method deletes activity for given params. */ public function testDeleteActivity() { $contactId = Contact::createIndividual(); $params = array('first_name' => 'liz', 'last_name' => 'hurleey'); $targetContactId = Contact::createIndividual($params); $params = array('source_contact_id' => $contactId, 'source_record_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2, 'target_contact_id' => array($targetContactId), 'activity_date_time' => date('Ymd')); CRM_Activity_BAO_Activity::create($params); $activityId = $this->assertDBNotNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id', 'subject', 'Database check for created activity.'); $activityTargetId = $this->assertDBNotNull('CRM_Activity_DAO_ActivityContact', $targetContactId, 'id', 'contact_id', 'Database check for created activity target.'); $params = array('source_contact_id' => $contactId, 'source_record_id' => $contactId, 'subject' => 'Scheduling Meeting', 'activity_type_id' => 2); $result = CRM_Activity_BAO_Activity::deleteActivity($params); $activityId = $this->assertDBNull('CRM_Activity_DAO_Activity', 'Scheduling Meeting', 'id', 'subject', 'Database check for deleted activity.'); Contact::delete($contactId); Contact::delete($targetContactId); }
/** * Delete the records that are associated with this participation. * * @param int $id * Id of the participation to delete. * * @return \CRM_Event_DAO_Participant */ public static function deleteParticipant($id) { CRM_Utils_Hook::pre('delete', 'Participant', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); //delete activity record $params = array('source_record_id' => $id, 'activity_type_id' => 5); CRM_Activity_BAO_Activity::deleteActivity($params); // delete the participant payment record // we need to do this since the cascaded constraints // dont work with join tables $p = array('participant_id' => $id); CRM_Event_BAO_ParticipantPayment::deleteParticipantPayment($p); // cleanup line items. $participantsId = array(); $participantsId = self::getAdditionalParticipantIds($id); $participantsId[] = $id; CRM_Price_BAO_LineItem::deleteLineItems($participantsId, 'civicrm_participant'); //delete note when participant deleted. $note = CRM_Core_BAO_Note::getNote($id, 'civicrm_participant'); $noteId = key($note); if ($noteId) { CRM_Core_BAO_Note::del($noteId, FALSE); } $participant = new CRM_Event_DAO_Participant(); $participant->id = $id; $participant->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Participant', $participant->id, $participant); // delete the recently created Participant $participantRecent = array('id' => $id, 'type' => 'Participant'); CRM_Utils_Recent::del($participantRecent); return $participant; }
/** * Function to delete membership. * * @param int $membershipId membership id that needs to be deleted * * @static * @return $results no of deleted Membership on success, false otherwise * @access public */ static function deleteMembership($membershipId) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $results = null; //delete activity record require_once "CRM/Activity/BAO/Activity.php"; $params = array('source_record_id' => $membershipId, 'activity_type_id' => 7); // activity type id for membership CRM_Activity_BAO_Activity::deleteActivity($params); self::deleteMembershipPayment($membershipId); require_once 'CRM/Member/DAO/Membership.php'; $membership =& new CRM_Member_DAO_Membership(); $membership->id = $membershipId; $results = $membership->delete(); $transaction->commit(); // delete the recently created Activity require_once 'CRM/Utils/Recent.php'; CRM_Utils_Recent::del($membershipId); return $results; }
/** * Delete membership. * * @param int $membershipId * Membership id that needs to be deleted. * * @return int * Id of deleted Membership on success, false otherwise. */ public static function deleteMembership($membershipId) { // CRM-12147, retrieve membership data before we delete it for hooks $params = array('id' => $membershipId); $memValues = array(); $memberships = self::getValues($params, $memValues); $membership = $memberships[$membershipId]; CRM_Utils_Hook::pre('delete', 'Membership', $membershipId, $memValues); $transaction = new CRM_Core_Transaction(); $results = NULL; //delete activity record $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'); $params = array(); $deleteActivity = FALSE; $membershipActivities = array('Membership Signup', 'Membership Renewal', 'Change Membership Status', 'Change Membership Type', 'Membership Renewal Reminder'); foreach ($membershipActivities as $membershipActivity) { $activityId = array_search($membershipActivity, $activityTypes); if ($activityId) { $params['activity_type_id'][] = $activityId; $deleteActivity = TRUE; } } if ($deleteActivity) { $params['source_record_id'] = $membershipId; CRM_Activity_BAO_Activity::deleteActivity($params); } self::deleteMembershipPayment($membershipId); $results = $membership->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Membership', $membership->id, $membership); // delete the recently created Membership $membershipRecent = array('id' => $membershipId, 'type' => 'Membership'); CRM_Utils_Recent::del($membershipRecent); return $results; }
/** * 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))); }