First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
|
@ -0,0 +1,248 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for OpenCase Activity.
|
||||
*/
|
||||
class CRM_Case_Form_Activity_ChangeCaseStartDate {
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function preProcess(&$form) {
|
||||
if (!isset($form->_caseId)) {
|
||||
CRM_Core_Error::fatal(ts('Case Id not found.'));
|
||||
}
|
||||
if (count($form->_caseId) != 1) {
|
||||
CRM_Core_Resources::fatal(ts('Expected one case-type'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* For edit/view mode the default values are retrieved from the database.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setDefaultValues(&$form) {
|
||||
$defaults = array();
|
||||
|
||||
$openCaseActivityType = CRM_Core_OptionGroup::getValue('activity_type',
|
||||
'Open Case',
|
||||
'name'
|
||||
);
|
||||
$caseId = CRM_Utils_Array::first($form->_caseId);
|
||||
$openCaseParams = array('activity_type_id' => $openCaseActivityType);
|
||||
$openCaseInfo = CRM_Case_BAO_Case::getCaseActivityDates($caseId, $openCaseParams, TRUE);
|
||||
if (empty($openCaseInfo)) {
|
||||
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults();
|
||||
}
|
||||
else {
|
||||
// We know there can only be one result
|
||||
$openCaseInfo = current($openCaseInfo);
|
||||
|
||||
// store activity id for updating it later
|
||||
$form->openCaseActivityId = $openCaseInfo['id'];
|
||||
|
||||
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($openCaseInfo['activity_date'], 'activityDateTime');
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
$form->removeElement('status_id');
|
||||
$form->removeElement('priority_id');
|
||||
$caseId = CRM_Utils_Array::first($form->_caseId);
|
||||
|
||||
$currentStartDate = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'start_date');
|
||||
$form->assign('current_start_date', $currentStartDate);
|
||||
$form->addDate('start_date', ts('New Start Date'), FALSE, array('formatType' => 'activityDateTime'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @param $files
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values, $files, $form) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
*/
|
||||
public static function beginPostProcess(&$form, &$params) {
|
||||
if ($form->_context == 'case') {
|
||||
$params['id'] = $form->_id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
* @param $activity
|
||||
*/
|
||||
public static function endPostProcess(&$form, &$params, $activity) {
|
||||
if (!empty($params['start_date'])) {
|
||||
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
|
||||
}
|
||||
|
||||
$caseType = CRM_Utils_Array::first($form->_caseType);
|
||||
$caseId = CRM_Utils_Array::first($form->_caseId);
|
||||
|
||||
if (!$caseType && $caseId) {
|
||||
$caseType = CRM_Case_BAO_Case::getCaseType($caseId, 'title');
|
||||
}
|
||||
|
||||
if (!$form->_currentlyViewedContactId ||
|
||||
!$form->_currentUserId ||
|
||||
!$caseId ||
|
||||
!$caseType
|
||||
) {
|
||||
CRM_Core_Error::fatal('Required parameter missing for ChangeCaseType - end post processing');
|
||||
}
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
$params['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
|
||||
$activity->status_id = $params['status_id'];
|
||||
$params['priority_id'] = CRM_Core_OptionGroup::getValue('priority', 'Normal', 'name');
|
||||
$activity->priority_id = $params['priority_id'];
|
||||
|
||||
// 1. save activity subject with new start date
|
||||
$currentStartDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case',
|
||||
$caseId, 'start_date'
|
||||
), $config->dateformatFull);
|
||||
$newStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Date::mysqlToIso($params['start_date']), $config->dateformatFull);
|
||||
$subject = 'Change Case Start Date from ' . $currentStartDate . ' to ' . $newStartDate;
|
||||
$activity->subject = $subject;
|
||||
$activity->save();
|
||||
// 2. initiate xml processor
|
||||
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
|
||||
$xmlProcessorParams = array(
|
||||
'clientID' => $form->_currentlyViewedContactId,
|
||||
'creatorID' => $form->_currentUserId,
|
||||
'standardTimeline' => 0,
|
||||
'activity_date_time' => $params['start_date'],
|
||||
'caseID' => $caseId,
|
||||
'caseType' => $caseType,
|
||||
'activityTypeName' => 'Change Case Start Date',
|
||||
'activitySetName' => 'standard_timeline',
|
||||
'resetTimeline' => 1,
|
||||
);
|
||||
|
||||
$xmlProcessor->run($caseType, $xmlProcessorParams);
|
||||
|
||||
// 2.5 Update open case activity date
|
||||
// Multiple steps since revisioned
|
||||
if ($form->openCaseActivityId) {
|
||||
|
||||
$abao = new CRM_Activity_BAO_Activity();
|
||||
$oldParams = array('id' => $form->openCaseActivityId);
|
||||
$oldActivityDefaults = array();
|
||||
$oldActivity = $abao->retrieve($oldParams, $oldActivityDefaults);
|
||||
|
||||
// save the old values
|
||||
require_once 'api/v3/utils.php';
|
||||
$openCaseParams = array();
|
||||
//@todo calling api functions directly is not supported
|
||||
_civicrm_api3_object_to_array($oldActivity, $openCaseParams);
|
||||
|
||||
// update existing revision
|
||||
$oldParams = array(
|
||||
'id' => $form->openCaseActivityId,
|
||||
'is_current_revision' => 0,
|
||||
);
|
||||
$oldActivity = new CRM_Activity_DAO_Activity();
|
||||
$oldActivity->copyValues($oldParams);
|
||||
$oldActivity->save();
|
||||
|
||||
// change some params for the new one
|
||||
unset($openCaseParams['id']);
|
||||
$openCaseParams['activity_date_time'] = $params['start_date'];
|
||||
$openCaseParams['target_contact_id'] = $oldActivityDefaults['target_contact'];
|
||||
$openCaseParams['assignee_contact_id'] = $oldActivityDefaults['assignee_contact'];
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$openCaseParams['source_contact_id'] = $session->get('userID');
|
||||
|
||||
// original_id always refers to the first activity, so only update if null (i.e. this is the second revision)
|
||||
$openCaseParams['original_id'] = $openCaseParams['original_id'] ? $openCaseParams['original_id'] : $form->openCaseActivityId;
|
||||
|
||||
$newActivity = CRM_Activity_BAO_Activity::create($openCaseParams);
|
||||
if (is_a($newActivity, 'CRM_Core_Error')) {
|
||||
CRM_Core_Error::fatal('Unable to update Open Case activity');
|
||||
}
|
||||
else {
|
||||
// Create linkage to case
|
||||
$caseActivityParams = array(
|
||||
'activity_id' => $newActivity->id,
|
||||
'case_id' => $caseId,
|
||||
);
|
||||
|
||||
CRM_Case_BAO_Case::processCaseActivity($caseActivityParams);
|
||||
|
||||
$caseActivityParams = array(
|
||||
'activityID' => $form->openCaseActivityId,
|
||||
'mainActivityId' => $newActivity->id,
|
||||
);
|
||||
CRM_Activity_BAO_Activity::copyExtendedActivityData($caseActivityParams);
|
||||
}
|
||||
}
|
||||
|
||||
// 3.status msg
|
||||
$params['statusMsg'] = ts('Case Start Date changed successfully.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,207 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for OpenCase Activity.
|
||||
*/
|
||||
class CRM_Case_Form_Activity_ChangeCaseStatus {
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function preProcess(&$form) {
|
||||
if (!isset($form->_caseId)) {
|
||||
CRM_Core_Error::fatal(ts('Case Id not found.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* For edit/view mode the default values are retrieved from the database.
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setDefaultValues(&$form) {
|
||||
$defaults = array();
|
||||
// Retrieve current case status
|
||||
$defaults['case_status_id'] = $form->_defaultCaseStatus;
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
$form->removeElement('status_id');
|
||||
$form->removeElement('priority_id');
|
||||
|
||||
$caseTypes = array();
|
||||
|
||||
$form->_caseStatus = CRM_Case_PseudoConstant::caseStatus();
|
||||
$statusNames = CRM_Case_PseudoConstant::caseStatus('name');
|
||||
|
||||
// Limit case statuses to allowed types for these case(s)
|
||||
$allCases = civicrm_api3('Case', 'get', array('return' => 'case_type_id', 'id' => array('IN' => (array) $form->_caseId)));
|
||||
foreach ($allCases['values'] as $case) {
|
||||
$caseTypes[$case['case_type_id']] = $case['case_type_id'];
|
||||
}
|
||||
$caseTypes = civicrm_api3('CaseType', 'get', array('id' => array('IN' => $caseTypes)));
|
||||
foreach ($caseTypes['values'] as $ct) {
|
||||
if (!empty($ct['definition']['statuses'])) {
|
||||
foreach ($form->_caseStatus as $id => $label) {
|
||||
if (!in_array($statusNames[$id], $ct['definition']['statuses'])) {
|
||||
unset($form->_caseStatus[$id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($form->_caseId as $key => $val) {
|
||||
$form->_oldCaseStatus[] = $form->_defaultCaseStatus[] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $val, 'status_id');
|
||||
}
|
||||
|
||||
foreach ($form->_defaultCaseStatus as $keydefault => $valdefault) {
|
||||
if (!array_key_exists($valdefault, $form->_caseStatus)) {
|
||||
$form->_caseStatus[$valdefault] = CRM_Core_OptionGroup::getLabel('case_status',
|
||||
$valdefault,
|
||||
FALSE
|
||||
);
|
||||
}
|
||||
}
|
||||
$element = $form->add('select', 'case_status_id', ts('Case Status'),
|
||||
$form->_caseStatus, TRUE
|
||||
);
|
||||
// check if the case status id passed in url is a valid one, set as default and freeze
|
||||
if (CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form)) {
|
||||
$caseStatusId = CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form);
|
||||
$caseStatus = CRM_Case_PseudoConstant::caseStatus();
|
||||
$form->_defaultCaseStatus = array_key_exists($caseStatusId, $caseStatus) ? $caseStatusId : NULL;
|
||||
$element->freeze();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @param $files
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values, $files, $form) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
*/
|
||||
public static function beginPostProcess(&$form, &$params) {
|
||||
$params['id'] = CRM_Utils_Array::value('case_id', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
* @param CRM_Activity_BAO_Activity $activity
|
||||
*/
|
||||
public static function endPostProcess(&$form, &$params, $activity) {
|
||||
$groupingValues = CRM_Core_OptionGroup::values('case_status', FALSE, TRUE, FALSE, NULL, 'value');
|
||||
|
||||
// Set case end_date if we're closing the case. Clear end_date if we're (re)opening it.
|
||||
if (CRM_Utils_Array::value($params['case_status_id'], $groupingValues) == 'Closed' && !empty($params['activity_date_time'])) {
|
||||
$params['end_date'] = $params['activity_date_time'];
|
||||
|
||||
// End case-specific relationships (roles)
|
||||
foreach ($params['target_contact_id'] as $cid) {
|
||||
$rels = CRM_Case_BAO_Case::getCaseRoles($cid, $params['case_id']);
|
||||
// FIXME: Is there an existing function to close a relationship?
|
||||
$query = 'UPDATE civicrm_relationship SET end_date=%2 WHERE id=%1';
|
||||
foreach ($rels as $relId => $relData) {
|
||||
$relParams = array(
|
||||
1 => array($relId, 'Integer'),
|
||||
2 => array($params['end_date'], 'Timestamp'),
|
||||
);
|
||||
CRM_Core_DAO::executeQuery($query, $relParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (CRM_Utils_Array::value($params['case_status_id'], $groupingValues) == 'Opened') {
|
||||
$params['end_date'] = "null";
|
||||
|
||||
// Reopen case-specific relationships (roles)
|
||||
foreach ($params['target_contact_id'] as $cid) {
|
||||
$rels = CRM_Case_BAO_Case::getCaseRoles($cid, $params['case_id']);
|
||||
// FIXME: Is there an existing function?
|
||||
$query = 'UPDATE civicrm_relationship SET end_date=NULL WHERE id=%1';
|
||||
foreach ($rels as $relId => $relData) {
|
||||
$relParams = array(1 => array($relId, 'Integer'));
|
||||
CRM_Core_DAO::executeQuery($query, $relParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
$params['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
|
||||
$activity->status_id = $params['status_id'];
|
||||
$params['priority_id'] = CRM_Core_OptionGroup::getValue('priority', 'Normal', 'name');
|
||||
$activity->priority_id = $params['priority_id'];
|
||||
|
||||
foreach ($form->_oldCaseStatus as $statuskey => $statusval) {
|
||||
if ($activity->subject == 'null') {
|
||||
$activity->subject = ts('Case status changed from %1 to %2', array(
|
||||
1 => CRM_Utils_Array::value($statusval, $form->_caseStatus),
|
||||
2 => CRM_Utils_Array::value($params['case_status_id'], $form->_caseStatus),
|
||||
)
|
||||
);
|
||||
$activity->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for OpenCase Activity.
|
||||
*/
|
||||
class CRM_Case_Form_Activity_ChangeCaseType {
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function preProcess(&$form) {
|
||||
if (!isset($form->_caseId)) {
|
||||
CRM_Core_Error::fatal(ts('Case Id not found.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* For edit/view mode the default values are retrieved from the database.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setDefaultValues(&$form) {
|
||||
$defaults = array();
|
||||
|
||||
$defaults['is_reset_timeline'] = 1;
|
||||
|
||||
$defaults['reset_date_time'] = array();
|
||||
list($defaults['reset_date_time'], $defaults['reset_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
|
||||
$defaults['case_type_id'] = $form->_caseTypeId;
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
$form->removeElement('status_id');
|
||||
$form->removeElement('priority_id');
|
||||
|
||||
$caseId = CRM_Utils_Array::first($form->_caseId);
|
||||
$form->_caseType = CRM_Case_BAO_Case::buildOptions('case_type_id', 'create');
|
||||
$form->_caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case',
|
||||
$caseId,
|
||||
'case_type_id'
|
||||
);
|
||||
if (!in_array($form->_caseTypeId, $form->_caseType)) {
|
||||
$form->_caseType[$form->_caseTypeId] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $form->_caseTypeId, 'title');
|
||||
}
|
||||
|
||||
$form->addField('case_type_id', array('context' => 'create', 'entity' => 'Case'));
|
||||
|
||||
// timeline
|
||||
$form->addYesNo('is_reset_timeline', ts('Reset Case Timeline?'), NULL, TRUE, array('onclick' => "return showHideByValue('is_reset_timeline','','resetTimeline','table-row','radio',false);"));
|
||||
$form->addDateTime('reset_date_time', ts('Reset Start Date'), FALSE, array('formatType' => 'activityDateTime'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @param $files
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values, $files, $form) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
*/
|
||||
public static function beginPostProcess(&$form, &$params) {
|
||||
if ($form->_context == 'case') {
|
||||
$params['id'] = $form->_id;
|
||||
}
|
||||
|
||||
if (CRM_Utils_Array::value('is_reset_timeline', $params) == 0) {
|
||||
unset($params['reset_date_time']);
|
||||
}
|
||||
else {
|
||||
// store the date with proper format
|
||||
$params['reset_date_time'] = CRM_Utils_Date::processDate($params['reset_date_time'], $params['reset_date_time_time']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
* @param $activity
|
||||
*/
|
||||
public static function endPostProcess(&$form, &$params, $activity) {
|
||||
if (!$form->_caseId) {
|
||||
// always expecting a change, so case-id is a must.
|
||||
return;
|
||||
}
|
||||
|
||||
$caseTypes = CRM_Case_PseudoConstant::caseType('name');
|
||||
$allCaseTypes = CRM_Case_PseudoConstant::caseType('title', FALSE);
|
||||
|
||||
if (!empty($caseTypes[$params['case_type_id']])) {
|
||||
$caseType = $caseTypes[$params['case_type_id']];
|
||||
}
|
||||
|
||||
if (!$form->_currentlyViewedContactId ||
|
||||
!$form->_currentUserId ||
|
||||
!$params['case_type_id'] ||
|
||||
!$caseType
|
||||
) {
|
||||
CRM_Core_Error::fatal('Required parameter missing for ChangeCaseType - end post processing');
|
||||
}
|
||||
|
||||
$params['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
|
||||
$activity->status_id = $params['status_id'];
|
||||
$params['priority_id'] = CRM_Core_OptionGroup::getValue('priority', 'Normal', 'name');
|
||||
$activity->priority_id = $params['priority_id'];
|
||||
|
||||
if ($activity->subject == 'null') {
|
||||
$activity->subject = ts('Case type changed from %1 to %2',
|
||||
array(
|
||||
1 => CRM_Utils_Array::value($form->_defaults['case_type_id'], $allCaseTypes),
|
||||
2 => CRM_Utils_Array::value($params['case_type_id'], $allCaseTypes),
|
||||
)
|
||||
);
|
||||
$activity->save();
|
||||
}
|
||||
|
||||
// 1. initiate xml processor
|
||||
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
|
||||
$caseId = CRM_Utils_Array::first($form->_caseId);
|
||||
$xmlProcessorParams = array(
|
||||
'clientID' => $form->_currentlyViewedContactId,
|
||||
'creatorID' => $form->_currentUserId,
|
||||
'standardTimeline' => 1,
|
||||
'activityTypeName' => 'Change Case Type',
|
||||
'activity_date_time' => CRM_Utils_Array::value('reset_date_time', $params),
|
||||
'caseID' => $caseId,
|
||||
'resetTimeline' => CRM_Utils_Array::value('is_reset_timeline', $params),
|
||||
);
|
||||
|
||||
$xmlProcessor->run($caseType, $xmlProcessorParams);
|
||||
// status msg
|
||||
$params['statusMsg'] = ts('Case Type changed successfully.');
|
||||
}
|
||||
|
||||
}
|
163
sites/all/modules/civicrm/CRM/Case/Form/Activity/LinkCases.php
Normal file
163
sites/all/modules/civicrm/CRM/Case/Form/Activity/LinkCases.php
Normal file
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for LinkCase Activity.
|
||||
*/
|
||||
class CRM_Case_Form_Activity_LinkCases {
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function preProcess(&$form) {
|
||||
if (empty($form->_caseId)) {
|
||||
CRM_Core_Error::fatal(ts('Case Id not found.'));
|
||||
}
|
||||
if (count($form->_caseId) != 1) {
|
||||
CRM_Core_Resources::fatal(ts('Expected one case-type'));
|
||||
}
|
||||
|
||||
$caseId = CRM_Utils_Array::first($form->_caseId);
|
||||
|
||||
$form->assign('clientID', $form->_currentlyViewedContactId);
|
||||
$form->assign('sortName', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $form->_currentlyViewedContactId, 'sort_name'));
|
||||
$form->assign('caseTypeLabel', CRM_Case_BAO_Case::getCaseType($caseId));
|
||||
|
||||
// get the related cases for given case.
|
||||
$relatedCases = $form->get('relatedCases');
|
||||
if (!isset($relatedCases)) {
|
||||
$relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId);
|
||||
$form->set('relatedCases', empty($relatedCases) ? FALSE : $relatedCases);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setDefaultValues(&$form) {
|
||||
$defaults = array();
|
||||
if (!empty($_GET['link_to_case_id']) && CRM_Utils_Rule::positiveInteger($_GET['link_to_case_id'])) {
|
||||
$defaults['link_to_case_id'] = $_GET['link_to_case_id'];
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
$excludeCaseIds = (array) $form->_caseId;
|
||||
$relatedCases = $form->get('relatedCases');
|
||||
if (is_array($relatedCases) && !empty($relatedCases)) {
|
||||
$excludeCaseIds = array_merge($excludeCaseIds, array_keys($relatedCases));
|
||||
}
|
||||
$form->addEntityRef('link_to_case_id', ts('Link To Case'), array(
|
||||
'entity' => 'Case',
|
||||
'api' => array(
|
||||
'extra' => array('case_id.case_type_id.title', 'contact_id.sort_name'),
|
||||
'params' => array(
|
||||
'case_id' => array('NOT IN' => $excludeCaseIds),
|
||||
'case_id.is_deleted' => 0,
|
||||
),
|
||||
),
|
||||
), TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @param $files
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values, $files, $form) {
|
||||
$errors = array();
|
||||
|
||||
$linkCaseId = CRM_Utils_Array::value('link_to_case_id', $values);
|
||||
assert('is_numeric($linkCaseId)');
|
||||
if ($linkCaseId == CRM_Utils_Array::first($form->_caseId)) {
|
||||
$errors['link_to_case'] = ts('Please select some other case to link.');
|
||||
}
|
||||
|
||||
// do check for existing related cases.
|
||||
$relatedCases = $form->get('relatedCases');
|
||||
if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) {
|
||||
$errors['link_to_case'] = ts('Selected case is already linked.');
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
*/
|
||||
public static function beginPostProcess(&$form, &$params) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
* @param CRM_Activity_BAO_Activity $activity
|
||||
*/
|
||||
public static function endPostProcess(&$form, &$params, &$activity) {
|
||||
$activityId = $activity->id;
|
||||
$linkCaseID = CRM_Utils_Array::value('link_to_case_id', $params);
|
||||
|
||||
//create a link between two cases.
|
||||
if ($activityId && $linkCaseID) {
|
||||
$caseParams = array(
|
||||
'case_id' => $linkCaseID,
|
||||
'activity_id' => $activityId,
|
||||
);
|
||||
CRM_Case_BAO_Case::processCaseActivity($caseParams);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
368
sites/all/modules/civicrm/CRM/Case/Form/Activity/OpenCase.php
Normal file
368
sites/all/modules/civicrm/CRM/Case/Form/Activity/OpenCase.php
Normal file
|
@ -0,0 +1,368 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for OpenCase Activity.
|
||||
*/
|
||||
class CRM_Case_Form_Activity_OpenCase {
|
||||
|
||||
/**
|
||||
* The id of the client associated with this case.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_contactID;
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function preProcess(&$form) {
|
||||
//get multi client case configuration
|
||||
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
|
||||
$form->_allowMultiClient = (bool) $xmlProcessorProcess->getAllowMultipleCaseClients();
|
||||
|
||||
if ($form->_context == 'caseActivity') {
|
||||
$contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $form);
|
||||
$atype = CRM_Core_OptionGroup::getValue('activity_type',
|
||||
'Change Case Start Date',
|
||||
'name'
|
||||
);
|
||||
$caseId = CRM_Utils_Array::first($form->_caseId);
|
||||
$form->assign('changeStartURL', CRM_Utils_System::url('civicrm/case/activity',
|
||||
"action=add&reset=1&cid=$contactID&caseid={$caseId}&atype=$atype"
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$form->_context = CRM_Utils_Request::retrieve('context', 'String', $form);
|
||||
$form->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $form);
|
||||
$form->assign('context', $form->_context);
|
||||
|
||||
// check if the case type id passed in url is a valid one
|
||||
$caseTypeId = CRM_Utils_Request::retrieve('ctype', 'Positive', $form);
|
||||
$caseTypes = CRM_Case_BAO_Case::buildOptions('case_type_id', 'create');
|
||||
$form->_caseTypeId = array_key_exists($caseTypeId, $caseTypes) ? $caseTypeId : NULL;
|
||||
|
||||
// check if the case status id passed in url is a valid one
|
||||
$caseStatusId = CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form);
|
||||
$caseStatus = CRM_Case_PseudoConstant::caseStatus();
|
||||
$form->_caseStatusId = array_key_exists($caseStatusId, $caseStatus) ? $caseStatusId : NULL;
|
||||
|
||||
// Add attachments
|
||||
CRM_Core_BAO_File::buildAttachment($form, 'civicrm_activity', $form->_activityId);
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/case', 'reset=1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. For edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function setDefaultValues(&$form) {
|
||||
$defaults = array();
|
||||
if ($form->_context == 'caseActivity') {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
|
||||
|
||||
// set default case status, case type, encounter medium, location type and phone type defaults are set in DB
|
||||
if ($form->_caseStatusId) {
|
||||
$caseStatus = $form->_caseStatusId;
|
||||
}
|
||||
else {
|
||||
$caseStatus = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, 'AND is_default = 1');
|
||||
if (count($caseStatus) == 1) {
|
||||
$caseStatus = key($caseStatus); //$defaults['status_id'] = key($caseStatus);
|
||||
}
|
||||
}
|
||||
$defaults['status_id'] = $caseStatus;
|
||||
|
||||
// set default case type passed in url
|
||||
if ($form->_caseTypeId) {
|
||||
$defaults['case_type_id'] = $form->_caseTypeId;
|
||||
}
|
||||
else {
|
||||
// TODO: Not possible yet to set a default case type in the system
|
||||
// For now just add the convenience of auto-selecting if there is only one option
|
||||
$caseTypes = CRM_Case_BAO_Case::buildOptions('case_type_id', 'create');
|
||||
if (count($caseTypes) == 1) {
|
||||
reset($caseTypes);
|
||||
$defaults['case_type_id'] = key($caseTypes);
|
||||
}
|
||||
}
|
||||
|
||||
$medium = CRM_Core_OptionGroup::values('encounter_medium', FALSE, FALSE, FALSE, 'AND is_default = 1');
|
||||
if (count($medium) == 1) {
|
||||
$defaults['medium_id'] = key($medium);
|
||||
}
|
||||
|
||||
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
if ($defaultLocationType->id) {
|
||||
$defaults['location[1][location_type_id]'] = $defaultLocationType->id;
|
||||
}
|
||||
|
||||
$phoneType = CRM_Core_OptionGroup::values('phone_type', FALSE, FALSE, FALSE, 'AND is_default = 1');
|
||||
if (count($phoneType) == 1) {
|
||||
$defaults['location[1][phone][1][phone_type_id]'] = key($phoneType);
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Case_Form_Case $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
if ($form->_context == 'caseActivity') {
|
||||
return;
|
||||
}
|
||||
if ($form->_context == 'standalone') {
|
||||
$form->addEntityRef('client_id', ts('Client'), array(
|
||||
'create' => TRUE,
|
||||
'multiple' => $form->_allowMultiClient,
|
||||
), TRUE);
|
||||
}
|
||||
|
||||
$element = $form->addField('case_type_id', array(
|
||||
'context' => 'create',
|
||||
'entity' => 'Case',
|
||||
'onchange' => "CRM.buildCustomData('Case', this.value);",
|
||||
), TRUE);
|
||||
if ($form->_caseTypeId) {
|
||||
$element->freeze();
|
||||
}
|
||||
|
||||
$csElement = $form->addField('status_id', array(
|
||||
'context' => 'create',
|
||||
'entity' => 'Case',
|
||||
), TRUE);
|
||||
if ($form->_caseStatusId) {
|
||||
$csElement->freeze();
|
||||
}
|
||||
|
||||
$form->add('text', 'duration', ts('Activity Duration'), array('size' => 4, 'maxlength' => 8));
|
||||
$form->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
|
||||
|
||||
if ($form->_currentlyViewedContactId) {
|
||||
list($displayName) = CRM_Contact_BAO_Contact::getDisplayAndImage($form->_currentlyViewedContactId);
|
||||
$form->assign('clientName', $displayName);
|
||||
}
|
||||
|
||||
$form->addDate('start_date', ts('Case Start Date'), TRUE, array('formatType' => 'activityDateTime'));
|
||||
|
||||
$form->addField('medium_id', array('entity' => 'activity', 'context' => 'create'), TRUE);
|
||||
|
||||
// calling this field activity_location to prevent conflict with contact location fields
|
||||
$form->add('text', 'activity_location', ts('Location'), CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'location'));
|
||||
|
||||
$form->add('wysiwyg', 'activity_details', ts('Details'), array('rows' => 4, 'cols' => 60), FALSE);
|
||||
|
||||
$form->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and New'),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
*/
|
||||
public static function beginPostProcess(&$form, &$params) {
|
||||
if ($form->_context == 'caseActivity') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($form->_context == 'standalone') {
|
||||
$params['client_id'] = explode(',', $params['client_id']);
|
||||
$form->_currentlyViewedContactId = $params['client_id'][0];
|
||||
}
|
||||
|
||||
// for open case start date should be set to current date
|
||||
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
|
||||
$caseStatus = CRM_Case_PseudoConstant::caseStatus('name');
|
||||
// for resolved case the end date should set to now
|
||||
if ($params['status_id'] == array_search('Closed', $caseStatus)) {
|
||||
$params['end_date'] = $params['now'];
|
||||
}
|
||||
|
||||
// rename activity_location param to the correct column name for activity DAO
|
||||
$params['location'] = CRM_Utils_Array::value('activity_location', $params);
|
||||
|
||||
// Add attachments
|
||||
CRM_Core_BAO_File::formatAttachment(
|
||||
$params,
|
||||
$params,
|
||||
'civicrm_activity',
|
||||
$form->_activityId
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param $fields
|
||||
* @param $files
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields, $files, $form) {
|
||||
if ($form->_context == 'caseActivity') {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$errors = array();
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param array $params
|
||||
*/
|
||||
public static function endPostProcess(&$form, &$params) {
|
||||
if ($form->_context == 'caseActivity') {
|
||||
return;
|
||||
}
|
||||
|
||||
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
|
||||
$isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
|
||||
|
||||
if (!$isMultiClient && !$form->_currentlyViewedContactId) {
|
||||
CRM_Core_Error::fatal('Required parameter missing for OpenCase - end post processing');
|
||||
}
|
||||
|
||||
if (!$form->_currentUserId ||
|
||||
!$params['case_id'] ||
|
||||
!$params['case_type']
|
||||
) {
|
||||
CRM_Core_Error::fatal('Required parameter missing for OpenCase - end post processing');
|
||||
}
|
||||
|
||||
// 1. create case-contact
|
||||
if ($isMultiClient && $form->_context == 'standalone') {
|
||||
foreach ($params['client_id'] as $cliId) {
|
||||
if (empty($cliId)) {
|
||||
CRM_Core_Error::fatal('client_id cannot be empty');
|
||||
}
|
||||
$contactParams = array(
|
||||
'case_id' => $params['case_id'],
|
||||
'contact_id' => $cliId,
|
||||
);
|
||||
CRM_Case_BAO_CaseContact::create($contactParams);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$contactParams = array(
|
||||
'case_id' => $params['case_id'],
|
||||
'contact_id' => $form->_currentlyViewedContactId,
|
||||
);
|
||||
CRM_Case_BAO_CaseContact::create($contactParams);
|
||||
}
|
||||
|
||||
// 2. initiate xml processor
|
||||
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
|
||||
|
||||
$xmlProcessorParams = array(
|
||||
'clientID' => $form->_currentlyViewedContactId,
|
||||
'creatorID' => $form->_currentUserId,
|
||||
'standardTimeline' => 1,
|
||||
'activityTypeName' => 'Open Case',
|
||||
'caseID' => $params['case_id'],
|
||||
'subject' => $params['activity_subject'],
|
||||
'location' => $params['location'],
|
||||
'activity_date_time' => $params['start_date'],
|
||||
'duration' => CRM_Utils_Array::value('duration', $params),
|
||||
'medium_id' => $params['medium_id'],
|
||||
'details' => $params['activity_details'],
|
||||
);
|
||||
|
||||
if (array_key_exists('custom', $params) && is_array($params['custom'])) {
|
||||
$xmlProcessorParams['custom'] = $params['custom'];
|
||||
}
|
||||
|
||||
// Add parameters for attachments
|
||||
$numAttachments = Civi::settings()->get('max_attachments');
|
||||
for ($i = 1; $i <= $numAttachments; $i++) {
|
||||
$attachName = "attachFile_$i";
|
||||
if (isset($params[$attachName]) && !empty($params[$attachName])) {
|
||||
$xmlProcessorParams[$attachName] = $params[$attachName];
|
||||
}
|
||||
}
|
||||
|
||||
$xmlProcessor->run($params['case_type'], $xmlProcessorParams);
|
||||
|
||||
// status msg
|
||||
$params['statusMsg'] = ts('Case opened successfully.');
|
||||
|
||||
$buttonName = $form->controller->getButtonName();
|
||||
$session = CRM_Core_Session::singleton();
|
||||
if ($buttonName == $form->getButtonName('upload', 'new')) {
|
||||
if ($form->_context == 'standalone') {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/case/add',
|
||||
'reset=1&action=add&context=standalone'
|
||||
));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/case',
|
||||
"reset=1&action=add&context=case&cid={$form->_contactID}"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue