* @access public
*/
function preProcess() {
- $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this);
+ $caseIds = CRM_Utils_Request::retrieve('caseid', 'String', $this);
+ $this->_caseId = explode(',', $caseIds);
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
if (!$this->_context) {
$this->_context = 'caseActivity';
}
if ($this->_caseId) {
$this->assign('caseId', $this->_caseId);
+ $this->assign('countId', count($this->_caseId));
}
if (!$this->_caseId ||
}
}
- $this->_caseType = CRM_Case_BAO_Case::getCaseType($this->_caseId, 'name');
+ foreach ($this->_caseId as $key => $val) {
+ $this->_caseType[] = CRM_Case_BAO_Case::getCaseType($val, 'name');
+ }
$this->assign('caseType', $this->_caseType);
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
$this->assign('multiClient', $isMultiClient);
- $clients = CRM_Case_BAO_Case::getContactNames($this->_caseId);
+ foreach ($this->_caseId as $key => $val) {
+ $clients[] = CRM_Case_BAO_Case::getContactNames($val);
+ }
$this->assign('client_names', $clients);
+ $caseIds = implode(',', $this->_caseId);
// set context for pushUserContext and for statusBounce
if ($this->_context == 'fulltext') {
if ($this->_action == CRM_Core_Action::UPDATE || $this->_action == CRM_Core_Action::DELETE) {
$url = CRM_Utils_System::url('civicrm/contact/view/case',
- "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$this->_caseId}&show=1&context={$this->_context}"
+ "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1&context={$this->_context}"
);
}
else {
}
else {
$url = CRM_Utils_System::url('civicrm/contact/view/case',
- "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$this->_caseId}&show=1"
+ "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"
);
}
if (!$this->_activityId) {
if (empty($caseTypes) && ($this->_activityTypeName == 'Change Case Type') && !$this->_caseId) {
$url = CRM_Utils_System::url('civicrm/contact/view/case',
- "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$this->_caseId}&show=1"
+ "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
// check if activity count is within the limit
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
- $activityInst = $xmlProcessor->getMaxInstance($this->_caseType);
+ foreach ($this->_caseType as $key => $val) {
+ $activityInst = $xmlProcessor->getMaxInstance($val);
// If not bounce back and also provide activity edit link
- if (isset($activityInst[$this->_activityTypeName])) {
- $activityCount = CRM_Case_BAO_Case::getCaseActivityCount($this->_caseId, $this->_activityTypeId);
- if ($activityCount >= $activityInst[$this->_activityTypeName]) {
- if ($activityInst[$this->_activityTypeName] == 1) {
- $atArray = array('activity_type_id' => $this->_activityTypeId);
- $activities = CRM_Case_BAO_Case::getCaseActivity($this->_caseId,
+ if (isset($activityInst[$this->_activityTypeName])) {
+ $activityCount = CRM_Case_BAO_Case::getCaseActivityCount($val, $this->_activityTypeId);
+ if ($activityCount >= $activityInst[$this->_activityTypeName]) {
+ if ($activityInst[$this->_activityTypeName] == 1) {
+ $atArray = array('activity_type_id' => $this->_activityTypeId);
+ $activities = CRM_Case_BAO_Case::getCaseActivity($val,
$atArray,
$this->_currentUserId
- );
- $activities = array_keys($activities);
- $activities = $activities[0];
- $editUrl = CRM_Utils_System::url('civicrm/case/activity',
- "reset=1&cid={$this->_currentlyViewedContactId}&caseid={$this->_caseId}&action=update&id={$activities}"
+ );
+ $activities = array_keys($activities);
+ $activities = $activities[0];
+ $editUrl = CRM_Utils_System::url('civicrm/case/activity',
+ "reset=1&cid={$this->_currentlyViewedContactId}&caseid={$val}&action=update&id={$activities}"
+ );
+ }
+ CRM_Core_Error::statusBounce(ts("You can not add another '%1' activity to this case. %2",
+ array(
+ 1 => $this->_activityTypeName,
+ 2 => "Do you want to <a href='$editUrl'>edit the existing activity</a> ?"
+ )
+ ),
+ $url
);
}
- CRM_Core_Error::statusBounce(ts("You can not add another '%1' activity to this case. %2",
- array(
- 1 => $this->_activityTypeName,
- 2 => "Do you want to <a href='$editUrl'>edit the existing activity</a> ?"
- )
- ),
- $url
- );
}
}
}
function setDefaultValues() {
$this->_defaults = parent::setDefaultValues();
$targetContactValues = array();
-
- //get all clients.
- $clients = CRM_Case_BAO_Case::getContactNames($this->_caseId);
- if (isset($this->_activityId) && empty($_POST)) {
- if (!CRM_Utils_Array::crmIsEmptyArray($this->_defaults['target_contact'])) {
- $targetContactValues = array_combine(array_unique($this->_defaults['target_contact']),
- explode(';', trim($this->_defaults['target_contact_value']))
- );
-
- //exclude all clients.
- foreach ($clients as $clientId => $vals) {
- if (array_key_exists($clientId, $targetContactValues)) {
- unset($targetContactValues[$clientId]);
+ foreach ($this->_caseId as $key => $val) {
+ //get all clients.
+ $clients = CRM_Case_BAO_Case::getContactNames($val);
+ if (isset($this->_activityId) && empty($_POST)) {
+ if (!CRM_Utils_Array::crmIsEmptyArray($this->_defaults['target_contact'])) {
+ $targetContactValues = array_combine(array_unique($this->_defaults['target_contact']),
+ explode(';', trim($this->_defaults['target_contact_value']))
+ );
+ //exclude all clients.
+ foreach ($clients as $clientId => $vals) {
+ if (array_key_exists($clientId, $targetContactValues)) {
+ unset($targetContactValues[$clientId]);
+ }
}
}
}
- }
- $this->assign('targetContactValues', empty($targetContactValues) ? FALSE : $targetContactValues);
+ $this->assign('targetContactValues', empty($targetContactValues) ? FALSE : $targetContactValues);
- //return form for ajax
- if ($this->_cdType) {
- return $this->_defaults;
- }
+ //return form for ajax
+ if ($this->_cdType) {
+ return $this->_defaults;
+ }
- if (isset($this->_encounterMedium)) {
- $this->_defaults['medium_id'] = $this->_encounterMedium;
- }
- elseif (empty($this->_defaults['medium_id'])) {
- // set default encounter medium CRM-4816
- $medium = CRM_Core_OptionGroup::values('encounter_medium', FALSE, FALSE, FALSE, 'AND is_default = 1');
- if (count($medium) == 1) {
- $this->_defaults['medium_id'] = key($medium);
+ if (isset($this->_encounterMedium)) {
+ $this->_defaults['medium_id'] = $this->_encounterMedium;
+ }
+ elseif (empty($this->_defaults['medium_id'])) {
+ // set default encounter medium CRM-4816
+ $medium = CRM_Core_OptionGroup::values('encounter_medium', FALSE, FALSE, FALSE, 'AND is_default = 1');
+ if (count($medium) == 1) {
+ $this->_defaults['medium_id'] = key($medium);
+ }
}
- }
- return $this->_defaults;
+ return $this->_defaults;
+ }
}
public function buildQuickForm() {
if ($this->_caseType) {
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
- $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE);
+ $aTypes = array();
+ foreach ($this->_caseType as $key => $val) {
+ $activityTypes = $xmlProcessor->get($val, 'ActivityTypes', TRUE);
+ $aTypes = $aTypes + $activityTypes;
+ }
// remove Open Case activity type since we're inside an existing case
$openCaseID = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name');
}
$this->add('select', 'medium_id', ts('Medium'), $encounterMediums, TRUE);
+ $i = 0;
+ foreach ($this->_caseId as $key => $val) {
+ $this->_relatedContacts[] = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($val);
+ $contName = CRM_Case_BAO_Case::getContactNames($val);
+ foreach ($contName as $nkey => $nval) {
+ array_push($this->_relatedContacts[$i][0] , $this->_relatedContacts[$i][0]['managerOf']= $nval['display_name']);
+ }
+ $i++;
+ }
- $this->_relatedContacts = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($this->_caseId);
//add case client in send a copy selector.CRM-4438.
- $relatedContacts = CRM_Case_BAO_Case::getContactNames($this->_caseId);
+ foreach ($this->_caseId as $key => $val) {
+ $relatedContacts[] = CRM_Case_BAO_Case::getContactNames($val);
+ }
+
if (!empty($relatedContacts)) {
foreach ($relatedContacts as $relatedContact) {
$this->_relatedContacts[] = $relatedContact;
$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) {
// 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);
+ 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
// 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);
-
+ 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'])) {
$params = $newActParams;
}
- if ($activity->id) {
- // add tags if exists
- $tagParams = array();
- if (!empty($params['tag'])) {
- foreach ($params['tag'] as $tag) {
- $tagParams[$tag] = 1;
+ 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', $activity->id);
+ //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'], $activity->id, 'civicrm_activity', $this);
+ //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'] = $this->_caseId;
+ // update existing case record if needed
+ $caseParams = $params;
+ $caseParams['id'] = $vval['case_id'];
+ if (!empty($caseParams['case_type_id'])) {
+ $caseParams['case_type_id'] = CRM_Core_DAO::VALUE_SEPARATOR . $caseParams['case_type_id'] . CRM_Core_DAO::VALUE_SEPARATOR;
+ }
+ if (!empty($caseParams['case_status_id'])) {
+ $caseParams['status_id'] = $caseParams['case_status_id'];
+ }
- if (!empty($caseParams['case_type_id'])) {
- $caseParams['case_type_id'] = CRM_Core_DAO::VALUE_SEPARATOR . $caseParams['case_type_id'] . CRM_Core_DAO::VALUE_SEPARATOR;
- }
- 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);
}
- // 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);
-
// 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()
$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(array($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 $key => $value) {
+ 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') {
- $id = $key;
+ $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s).");
}
else {
- $id = $value;
+ $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).");
}
-
- 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;
+ //build an associative array with unique email addresses.
+ foreach ($params[$val] as $key => $value) {
+ if ($val == 'contact_check') {
+ $id = $key;
}
else {
- $mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id];
+ $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];
+ }
}
}
}
}
- }
-
- if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) {
- //include attachments while sending a copy of activity.
- $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity',
- $activity->id
- );
- $ics = new CRM_Activity_BAO_ICalendar($activity);
- $ics->addAttachment($attachments, $mailToContacts);
-
- $result = CRM_Case_BAO_Case::sendActivityCopy($this->_currentlyViewedContactId,
- $activity->id, $mailToContacts, $attachments, $this->_caseId
- );
-
- $ics->cleanup();
+ if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) {
+ //include attachments while sending a copy of activity.
+ $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity',
+ $vval['actId']
+ );
- if (empty($result)) {
+ $ics = new CRM_Activity_BAO_ICalendar($activity);
+ $ics->addAttachment($attachments, $mailToContacts);
+ $result = CRM_Case_BAO_Case::sendActivityCopy($this->_currentlyViewedContactId,
+ $vval['actId'], $mailToContacts, $attachments, $vval['case_id']
+ );
+ $ics->cleanup();
+ if (empty($result)) {
+ $mailStatus = '';
+ }
+ }
+ else {
$mailStatus = '';
}
- }
- else {
- $mailStatus = '';
- }
- // create follow up activity if needed
- $followupStatus = '';
- if (!empty($params['followup_activity_type_id'])) {
- $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
+ // 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' => $this->_caseId,
- );
- CRM_Case_BAO_Case::processCaseActivity($caseParams);
- $followupStatus = ts("A followup activity has been scheduled.");
+ 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.");
+ }
}
- }
- CRM_Core_Session::setStatus('', ts("'%1' activity has been %2. %3 %4",
- array(
- 1 => $this->_activityTypeName,
- 2 => $recordStatus,
- 3 => $followupStatus,
- 4 => $mailStatus
- )
- ), 'info');
+ CRM_Core_Session::setStatus('', ts("'%1' activity has been %2. %3 %4",
+ array(
+ 1 => $this->_activityTypeName,
+ 2 => $recordStatus,
+ 3 => $followupStatus,
+ 4 => $mailStatus
+ )
+ ), 'info');
+ }
}
}