$xmlFile .= "</CaseRoles>\n";
}
+ if (array_key_exists('restrictActivityAsgmtToCmsUser', $definition)) {
+ $xmlFile .= "<RestrictActivityAsgmtToCmsUser>" . $definition['restrictActivityAsgmtToCmsUser'] . "</RestrictActivityAsgmtToCmsUser>\n";
+ }
+
+ if (!empty($definition['activityAsgmtGrps'])) {
+ $xmlFile .= "<ActivityAsgmtGrps>\n";
+ foreach ($definition['activityAsgmtGrps'] as $value) {
+ $xmlFile .= "<Group>$value</Group>\n";
+ }
+ $xmlFile .= "</ActivityAsgmtGrps>\n";
+ }
+
$xmlFile .= '</CaseType>';
+
return $xmlFile;
}
$definition['forkable'] = (int) $xml->forkable;
}
+ if (isset($xml->RestrictActivityAsgmtToCmsUser)) {
+ $definition['restrictActivityAsgmtToCmsUser'] = (int) $xml->RestrictActivityAsgmtToCmsUser;
+ }
+
+ if (isset($xml->ActivityAsgmtGrps)) {
+ $definition['activityAsgmtGrps'] = (array) $xml->ActivityAsgmtGrps->Group;
+ }
+
// set activity types
if (isset($xml->ActivityTypes)) {
$definition['activityTypes'] = array();
class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
/**
- * The default variable defined.
+ * Cases this activity belongs to.
*
- * @var int
+ * @var []int
*/
public $_caseId;
/**
* The default case type variable defined.
*
- * @var int
+ * @var []int
*/
public $_caseType;
*/
public $_relatedContacts;
+ /**
+ * The case type definition column info
+ * for the caseId;
+ *
+ * @var array
+ */
+ public $_caseTypeDefinition;
+
/**
* Build the form object.
*/
public function preProcess() {
- $caseIds = CRM_Utils_Request::retrieve('caseid', 'String', $this);
- $this->_caseId = explode(',', $caseIds);
+ $caseIds = CRM_Utils_Request::retrieve('caseid', 'CommaSeparatedIntegers', $this);
+ $this->_caseId = $caseIds ? explode(',', $caseIds) : [];
$this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
if (!$this->_context) {
$this->_context = 'caseActivity';
$this->assign('scheduleStatusId', $scheduleStatusId);
if (!$this->_caseId && $this->_activityId) {
- $this->_caseId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $this->_activityId,
+ $this->_caseId = (array) CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $this->_activityId,
'case_id', 'activity_id'
);
}
}
$this->assign('caseType', $this->_caseType);
+ $this->_caseTypeDefinition = $this->getCaseTypeDefinition();
+
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
$this->assign('multiClient', $isMultiClient);
$this->_fields['source_contact_id']['label'] = ts('Reported By');
unset($this->_fields['status_id']['attributes']['required']);
+ if ($this->restrictAssignmentByUserAccount()) {
+ $assigneeParameters['uf_user'] = 1;
+ }
+
+ $activityAssignmentGroups = $this->getActivityAssignmentGroups();
+ if (!empty($activityAssignmentGroups)) {
+ $assigneeParameters['group'] = ['IN' => $activityAssignmentGroups];
+ }
+
+ if (!empty($assigneeParameters)) {
+ $this->_fields['assignee_contact_id']['attributes']['api']['params']
+ = array_merge($this->_fields['assignee_contact_id']['attributes']['api']['params'], $assigneeParameters);
+
+ $this->_fields['followup_assignee_contact_id']['attributes']['api']['params']
+ = array_merge($this->_fields['followup_assignee_contact_id']['attributes']['api']['params'], $assigneeParameters);
+
+ //Disallow creating a contact from the assignee field UI.
+ $this->_fields['assignee_contact_id']['attributes']['create'] = FALSE;
+ $this->_fields['followup_assignee_contact_id']['attributes']['create'] = FALSE;
+ }
+
if ($this->_caseType) {
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$aTypes = array();
- foreach ($this->_caseType as $key => $val) {
+ foreach (array_unique($this->_caseType) as $val) {
$activityTypes = $xmlProcessor->get($val, 'ActivityTypes', TRUE);
$aTypes = $aTypes + $activityTypes;
}
}
}
+ /**
+ * Returns the groups that contacts must belong to in order to be assigned
+ * an activity for this case. It returns an empty array if no groups are found for
+ * the case type linked to the caseId.
+ *
+ * @return array
+ */
+ private function getActivityAssignmentGroups() {
+ if (!$this->_caseTypeDefinition) {
+ return [];
+ }
+
+ $assignmentGroups = [];
+ foreach ($this->_caseTypeDefinition as $caseId => $definition) {
+ if (!empty($definition['activityAsgmtGrps'])) {
+ $assignmentGroups = array_merge($assignmentGroups, $definition['activityAsgmtGrps']);
+ }
+ }
+
+ return $assignmentGroups;
+ }
+
+ /**
+ * Returns whether contacts must have a user account in order to be
+ * assigned an activity for this case.
+ *
+ * @return bool
+ */
+ private function restrictAssignmentByUserAccount() {
+ if (!$this->_caseTypeDefinition) {
+ return FALSE;
+ }
+
+ foreach ($this->_caseTypeDefinition as $caseId => $definition) {
+ if (!empty($definition['restrictActivityAsgmtToCmsUser'])) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+ }
+
+ /**
+ * Returns the case type definition column value for the case type linked to the caseId.
+ *
+ * @return array
+ */
+ private function getCaseTypeDefinition() {
+ if (!$this->_caseId) {
+ return [];
+ }
+
+ $definitions = civicrm_api3('CaseType', 'get', [
+ 'return' => ['name', 'definition'],
+ 'name' => ['IN' => array_unique($this->_caseType)],
+ ]);
+
+ return array_column($definitions['values'], 'definition', 'name');
+ }
+
}
$scope.caseType.definition.caseRoles = $scope.caseType.definition.caseRoles || [];
$scope.caseType.definition.statuses = $scope.caseType.definition.statuses || [];
$scope.caseType.definition.timelineActivityTypes = $scope.caseType.definition.timelineActivityTypes || [];
+ $scope.caseType.definition.restrictActivityAsgmtToCmsUser = $scope.caseType.definition.restrictActivityAsgmtToCmsUser || 0;
+ $scope.caseType.definition.activityAsgmtGrps = $scope.caseType.definition.activityAsgmtGrps || [];
_.each($scope.caseType.definition.activitySets, function (set) {
_.each(set.activityTypes, function (type, name) {
});
// Ignore if ALL or NONE selected
$scope.caseType.definition.statuses = selectedStatuses.length == _.size($scope.selectedStatuses) ? [] : selectedStatuses;
+
+ if ($scope.caseType.definition.activityAsgmtGrps) {
+ $scope.caseType.definition.activityAsgmtGrps = $scope.caseType.definition.activityAsgmtGrps.toString().split(",");
+ }
+
var result = crmApi('CaseType', 'create', $scope.caseType, true);
result.then(function(data) {
if (data.is_error === 0 || data.is_error == '0') {