First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,246 @@
<?php
/**
* Class CRM_Case_Audit_Audit
*/
class CRM_Case_Audit_Audit {
private $auditConfig;
private $xmlString;
/**
* @param $xmlString
* @param string $confFilename
*/
public function __construct($xmlString, $confFilename) {
$this->xmlString = $xmlString;
$this->auditConfig = new CRM_Case_Audit_AuditConfig($confFilename);
}
/**
* @param bool $printReport
*
* @return array
*/
public function getActivities($printReport = FALSE) {
$retval = array();
/*
* Loop through the activities in the file and add them to the appropriate region array.
*/
$doc = new DOMDocument();
if ($doc->loadXML($this->xmlString)) {
$regionList = $this->auditConfig->getRegions();
$ifBlanks = $this->auditConfig->getIfBlanks();
$includeAll = $doc->getElementsByTagName("IncludeActivities")->item(0)->nodeValue;
$includeAll = ($includeAll == 'All');
$activityindex = 0;
$activityList = $doc->getElementsByTagName("Activity");
$caseActivities = array();
$activityStatusType = array();
foreach ($activityList as $activity) {
$retval[$activityindex] = array();
$ifBlankReplacements = array();
$completed = FALSE;
$sortValues = array('1970-01-01');
$category = '';
$fieldindex = 1;
$fields = $activity->getElementsByTagName("Field");
foreach ($fields as $field) {
$datatype_elements = $field->getElementsByTagName("Type");
$datatype = $datatype_elements->item(0)->nodeValue;
$label_elements = $field->getElementsByTagName("Label");
$label = $label_elements->item(0)->nodeValue;
$value_elements = $field->getElementsByTagName("Value");
$value = $value_elements->item(0)->nodeValue;
$category_elements = $field->getElementsByTagName("Category");
if (!empty($category_elements->length)) {
$category = $category_elements->item(0)->nodeValue;
}
// Based on the config file, does this field's label and value indicate a completed activity?
if ($label == $this->auditConfig->getCompletionLabel() && $value == $this->auditConfig->getCompletionValue()) {
$completed = TRUE;
}
// Based on the config file, does this field's label match the one to use for sorting activities?
if (in_array($label, $this->auditConfig->getSortByLabels())) {
$sortValues[$label] = $value;
}
foreach ($regionList as $region) {
// Based on the config file, is this field a potential replacement for another?
if (!empty($ifBlanks[$region])) {
if (in_array($label, $ifBlanks[$region])) {
$ifBlankReplacements[$label] = $value;
}
}
if ($this->auditConfig->includeInRegion($label, $region)) {
$retval[$activityindex][$region][$fieldindex] = array();
$retval[$activityindex][$region][$fieldindex]['label'] = $label;
$retval[$activityindex][$region][$fieldindex]['datatype'] = $datatype;
$retval[$activityindex][$region][$fieldindex]['value'] = $value;
if ($datatype == 'Date') {
$retval[$activityindex][$region][$fieldindex]['includeTime'] = $this->auditConfig->includeTime($label, $region);
}
//CRM-4570
if ($printReport) {
if (!in_array($label, array(
'Activity Type',
'Status',
))
) {
$caseActivities[$activityindex][$fieldindex] = array();
$caseActivities[$activityindex][$fieldindex]['label'] = $label;
$caseActivities[$activityindex][$fieldindex]['datatype'] = $datatype;
$caseActivities[$activityindex][$fieldindex]['value'] = $value;
}
else {
$activityStatusType[$activityindex][$fieldindex] = array();
$activityStatusType[$activityindex][$fieldindex]['label'] = $label;
$activityStatusType[$activityindex][$fieldindex]['datatype'] = $datatype;
$activityStatusType[$activityindex][$fieldindex]['value'] = $value;
}
}
}
}
$fieldindex++;
}
if ($printReport) {
$caseActivities[$activityindex] = CRM_Utils_Array::crmArrayMerge($activityStatusType[$activityindex], $caseActivities[$activityindex]);
$caseActivities[$activityindex]['sortValues'] = $sortValues;
}
if ($includeAll || !$completed) {
$retval[$activityindex]['completed'] = $completed;
$retval[$activityindex]['category'] = $category;
$retval[$activityindex]['sortValues'] = $sortValues;
// Now sort the fields based on the order in the config file.
foreach ($regionList as $region) {
$this->auditConfig->sort($retval[$activityindex][$region], $region);
}
$retval[$activityindex]['editurl'] = $activity->getElementsByTagName("EditURL")->item(0)->nodeValue;
// If there are any fields with ifBlank specified, replace their values.
// We need to do this as a second pass because if we do it while looping through fields we might not have come across the field we need yet.
foreach ($regionList as $region) {
foreach ($retval[$activityindex][$region] as & $v) {
$vlabel = $v['label'];
if (trim($v['value']) == '' && !empty($ifBlanks[$region][$vlabel])) {
if (!empty($ifBlankReplacements[$ifBlanks[$region][$vlabel]])) {
$v['value'] = $ifBlankReplacements[$ifBlanks[$region][$vlabel]];
}
}
}
unset($v);
}
$activityindex++;
}
else {
/* This is a little bit inefficient, but the alternative is to do two passes
because we don't know until we've examined all the field values whether the activity
is completed, since the field that determines it and its value is configurable,
so either way isn't ideal. */
unset($retval[$activityindex]);
unset($caseActivities[$activityindex]);
}
}
if ($printReport) {
@uasort($caseActivities, array($this, "compareActivities"));
}
else {
@uasort($retval, array($this, "compareActivities"));
}
}
if ($printReport) {
return $caseActivities;
}
else {
return $retval;
}
}
/* compareActivities
*
* This is intended to be called as a sort callback function, returning whether an activity's date is earlier or later than another's.
* The type of date to use is specified in the config.
*/
/**
* @param $a
* @param $b
*
* @return int
*/
public function compareActivities($a, $b) {
// This should work
foreach ($this->auditConfig->getSortByLabels() as $label) {
$aval .= empty($a['sortValues']) ? "" : (empty($a['sortValues'][$label]) ? "" : $a['sortValues'][$label]);
$bval .= empty($b['sortValues']) ? "" : (empty($b['sortValues'][$label]) ? "" : $b['sortValues'][$label]);
}
if ($aval < $bval) {
return -1;
}
elseif ($aval > $bval) {
return 1;
}
else {
return 0;
}
}
/**
* @param string $xmlString
* @param int $clientID
* @param int $caseID
* @param bool $printReport
*
* @return mixed
*/
public static function run($xmlString, $clientID, $caseID, $printReport = FALSE) {
/*
$fh = fopen('C:/temp/audit2.xml', 'w');
fwrite($fh, $xmlString);
fclose($fh);
*/
$audit = new CRM_Case_Audit_Audit($xmlString, 'audit.conf.xml');
$activities = $audit->getActivities($printReport);
$template = CRM_Core_Smarty::singleton();
$template->assign_by_ref('activities', $activities);
if ($printReport) {
$reportDate = CRM_Utils_Date::customFormat(date('Y-m-d H:i'));
$template->assign('reportDate', $reportDate);
$contents = $template->fetch('CRM/Case/Audit/Report.tpl');
}
else {
$contents = $template->fetch('CRM/Case/Audit/Audit.tpl');
}
return $contents;
}
}

View file

@ -0,0 +1,259 @@
<?php
/**
* Class CRM_Case_Audit_AuditConfig
*/
class CRM_Case_Audit_AuditConfig {
private $filename;
private $completionLabel;
private $completionValue;
private $sortByLabels;
private $regionFieldList;
private $includeRules;
private $sortRegion;
private $ifBlanks;
/**
* @param string $filename
*/
public function __construct($filename) {
$this->filename = $filename;
// set some defaults
$this->completionLabel = "Status";
$this->completionValue = "Completed";
$this->sortByLabels = array("Actual Date", "Due Date");
$this->ifBlanks = array();
$this->loadConfig();
}
/**
* @return string
*/
public function getCompletionValue() {
return $this->completionValue;
}
/**
* @return string
*/
public function getCompletionLabel() {
return $this->completionLabel;
}
/**
* @return array
*/
public function getSortByLabels() {
return $this->sortByLabels;
}
/**
* @return array
*/
public function getIfBlanks() {
return $this->ifBlanks;
}
public function loadConfig() {
$this->regionFieldList = array();
$this->includeRules = array();
$doc = new DOMDocument();
$xmlString = file_get_contents(dirname(__FILE__) . '/' . $this->filename);
$load = $doc->loadXML($xmlString);
if ($load) {
$regions = $doc->getElementsByTagName("region");
foreach ($regions as $region) {
$regionName = $region->getAttribute("name");
$this->regionFieldList[$regionName] = array();
// Inclusion/exclusion settings
$includeRule = $region->getAttribute("includeRule");
if (empty($includeRule)) {
$includeRule = 'include';
}
$this->includeRules[$regionName] = array('rule' => $includeRule);
if ($includeRule == 'exclude') {
$altRegion = $region->getAttribute("exclusionCorrespondingRegion");
$this->includeRules[$regionName]['altRegion'] = $altRegion;
}
// Time component display settings
$includeTime = $region->getAttribute("includeTime");
if (empty($includeTime)) {
$includeTime = 'false';
}
$this->includeRules[$regionName]['includeTime'] = $includeTime;
$fieldCount = 0;
$fields = $region->getElementsByTagName("field");
foreach ($fields as $field) {
/* Storing them this way, which is backwards to how you might normally
have arrays with a numeric key and a text value, ends up making things better
in the other functions, in particular the sorting and also inRegion should end
up being more efficient (searching for a key instead of a value). */
$this->regionFieldList[$regionName][$field->nodeValue] = $fieldCount;
// Field-level overrides of time component display settings
$includeTime = $field->getAttribute("includeTime");
if (!empty($includeTime)) {
$this->regionFieldList[$regionName][$field->nodeValue]['includeTime'] = $includeTime;
}
// ifBlank attribute
$ifBlank = $field->getAttribute("ifBlank");
if (!empty($ifBlank)) {
$this->ifBlanks[$regionName][$field->nodeValue] = $ifBlank;
}
$fieldCount++;
}
}
$completionStatus = $doc->getElementsByTagName("completionStatus");
if (!empty($completionStatus)) {
$label_elements = $completionStatus->item(0)->getElementsByTagName("label");
$this->completionLabel = $label_elements->item(0)->nodeValue;
$value_elements = $completionStatus->item(0)->getElementsByTagName("value");
$this->completionValue = $value_elements->item(0)->nodeValue;
}
$sortElement = $doc->getElementsByTagName("sortByLabels");
if (!empty($sortElement)) {
$this->sortByLabels = array();
$label_elements = $sortElement->item(0)->getElementsByTagName("label");
foreach ($label_elements as $ele) {
$this->sortByLabels[] = $ele->nodeValue;
}
}
}
}
/**
* Check if label $n is explicitly listed in region $r in the config.
*
* @param $n
* @param $r
*
* @return bool
*/
public function inRegion($n, $r) {
if (empty($this->regionFieldList[$r])) {
return FALSE;
}
else {
return array_key_exists($n, $this->regionFieldList[$r]);
}
}
/**
* Should field $n be included in region $r, taking into account exclusion rules.
*
* @param $n
* @param $r
*
* @return bool
*/
public function includeInRegion($n, $r) {
$add_it = FALSE;
$rules = $this->includeRules[$r];
if ($rules['rule'] == 'exclude') {
if (!$this->inRegion($n, $r) && !$this->inRegion($n, $rules['altRegion'])) {
$add_it = TRUE;
}
}
elseif ($this->inRegion($n, $r)) {
$add_it = TRUE;
}
return $add_it;
}
/**
* Should the time component of field $n in region $r be displayed?
*
* @param $n
* @param $r
*
* @return bool
*/
public function includeTime($n, $r) {
$retval = FALSE;
if (empty($this->regionFieldList[$r][$n]['includeTime'])) {
// No field-level override, so look at the region's settings
if (!empty($this->includeRules[$r]['includeTime'])) {
$retval = $this->includeRules[$r]['includeTime'];
}
}
else {
$retval = $this->regionFieldList[$r][$n]['includeTime'];
}
// There's a mix of strings and boolean, so convert any strings.
if ($retval == 'false') {
$retval = FALSE;
}
elseif ($retval == 'true') {
$retval = TRUE;
}
return $retval;
}
/**
* Return a list of all the regions in the config file.
*
* @return array
*/
public function getRegions() {
return array_keys($this->regionFieldList);
}
/**
* Sort a group of fields for a given region according to the order in the config.
* The array to be sorted should have elements that have a member with a key of 'label', and the value should be the field label.
*
* @param $f
* @param $r
*/
public function sort(&$f, $r) {
// For exclusion-type regions, there's nothing to do, because we won't have been given any ordering.
if ($this->includeRules[$r]['rule'] == 'exclude') {
return;
}
$this->sortRegion = $r;
uasort($f, array(&$this, "compareFields"));
}
/**
* This is intended to be called as a sort callback function, returning whether a field in a region comes before or after another one.
* See also PHP's usort().
*
* @param $a
* @param $b
*
* @return int
*/
public function compareFields($a, $b) {
if (empty($this->regionFieldList[$this->sortRegion][$a['label']])) {
$x = 0;
}
else {
$x = $this->regionFieldList[$this->sortRegion][$a['label']];
}
if (empty($this->regionFieldList[$this->sortRegion][$b['label']])) {
$y = 0;
}
else {
$y = $this->regionFieldList[$this->sortRegion][$b['label']];
}
return $x - $y;
}
}

View file

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
includeRule can be "include" or "exclude".
include means include the fields listed in the region.
exclude means include all fields not listed in the region AND not listed in the exclusionCorrespondingRegion.
includeTime is true or false and says whether to include the time component of date fields.
It can be overridden at the Field level.
ifBlank specifies an alternate field to display if the field is blank.
-->
<regions>
<region name="leftpane" includeRule="include" includeTime="false">
<fields>
<field ifBlank="Due Date">Actual Date</field>
<field ifBlank="Activity Type">Subject</field>
</fields>
</region>
<region name="rightpaneheader" includeRule="include" includeTime="true">
<fields>
<field>Activity Type</field>
<field>Subject</field>
<field>Actual Date</field>
<field>Created By</field>
<field>Revision</field>
</fields>
</region>
<!-- The rightpane body then gets "everything that isn't in the header", EXCEPT
the fields you specify here. This seems a good compromise
over explicitly having to define which fields we want for each activity type,
given that they are custom.
One future tweak is to improve the way the fields get ordered here. Right now
they'll just come out the same order as in the export, which will likely be semi-random.
-->
<region name="rightpanebody" includeRule="exclude" exclusionCorrespondingRegion="rightpaneheader" includeTime="true">
<fields>
<field>Some field nobody likes</field>
</fields>
</region>
<!-- Haven't decided if this one belongs in here. Probably belongs in yet another config file.
This tells us which field has the semantic meaning of "status", and which value indicates "completed".
-->
<completionStatus>
<label>Status</label>
<value>Completed</value>
</completionStatus>
<!-- Similarly this probably doesn't belong in here. This tells what field(s) to sort by.
-->
<sortByLabels>
<label>Actual Date</label> <!-- Sort by this first -->
<label>Due Date</label> <!-- Then if equal sort by this -->
<label>Date and Time</label>
</sortByLabels>
</regions>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,93 @@
<?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 contains the functions for Case Contact management.
*/
class CRM_Case_BAO_CaseContact extends CRM_Case_DAO_CaseContact {
/**
* Create case contact record.
*
* @param array $params
* case_id, contact_id
*
* @return CRM_Case_BAO_CaseContact
*/
public static function create($params) {
$caseContact = new self();
$caseContact->copyValues($params);
$caseContact->save();
// add to recently viewed
$caseType = CRM_Case_BAO_Case::getCaseType($caseContact->case_id);
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"action=view&reset=1&id={$caseContact->case_id}&cid={$caseContact->contact_id}&context=home"
);
$title = CRM_Contact_BAO_Contact::displayName($caseContact->contact_id) . ' - ' . $caseType;
$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case',
"action=delete&reset=1&id={$caseContact->case_id}&cid={$caseContact->contact_id}&context=home"
);
}
// add the recently created case
CRM_Utils_Recent::add($title,
$url,
$caseContact->case_id,
'Case',
$caseContact->contact_id,
NULL,
$recentOther
);
return $caseContact;
}
/**
* @inheritDoc
*/
public function addSelectWhereClause() {
return array(
// Reuse case acls
'case_id' => CRM_Utils_SQL::mergeSubquery('Case'),
// Case acls already check for contact access so we can just mark contact_id as handled
'contact_id' => array(),
);
// Don't call hook selectWhereClause, the case query already did
}
}

View file

@ -0,0 +1,422 @@
<?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 contains the functions for Case Type management.
*/
class CRM_Case_BAO_CaseType extends CRM_Case_DAO_CaseType {
/**
* Static field for all the case information that we can potentially export.
*
* @var array
*/
static $_exportableFields = NULL;
/**
* Takes an associative array and creates a Case Type object.
*
* the function extract all the params it needs to initialize the create a
* case type object. the params array could contain additional unused name/value
* pairs
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @throws CRM_Core_Exception
*
* @return CRM_Case_BAO_CaseType
*/
public static function add(&$params) {
$caseTypeDAO = new CRM_Case_DAO_CaseType();
// form the name only if missing: CRM-627
$nameParam = CRM_Utils_Array::value('name', $params, NULL);
if (!$nameParam && empty($params['id'])) {
$params['name'] = CRM_Utils_String::titleToVar($params['title']);
}
// Old case-types (pre-4.5) may keep their ucky names, but new case-types must satisfy isValidName()
if (empty($params['id']) && !empty($params['name']) && !CRM_Case_BAO_CaseType::isValidName($params['name'])) {
throw new CRM_Core_Exception("Cannot create new case-type with malformed name [{$params['name']}]");
}
$caseTypeName = (isset($params['name'])) ? $params['name'] : CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $params['id'], 'name', 'id', TRUE);
// function to format definition column
if (isset($params['definition']) && is_array($params['definition'])) {
$params['definition'] = self::convertDefinitionToXML($caseTypeName, $params['definition']);
CRM_Core_ManagedEntities::scheduleReconciliation();
}
$caseTypeDAO->copyValues($params);
$result = $caseTypeDAO->save();
CRM_Case_XMLRepository::singleton()->flush();
return $result;
}
/**
* Generate and assign an arbitrary value to a field of a test object.
*
* @param string $fieldName
* @param array $fieldDef
* @param int $counter
* The globally-unique ID of the test object.
*/
protected function assignTestValue($fieldName, &$fieldDef, $counter) {
if ($fieldName == 'definition') {
$this->{$fieldName} = "<CaseType><name>TestCaseType{$counter}</name></CaseType>";
}
else {
parent::assignTestValue($fieldName, $fieldDef, $counter);
}
}
/**
* Format / convert submitted array to xml for case type definition
*
* @param string $name
* @param array $definition
* The case-type definition expressed as an array-tree.
* @return string
* XML
*/
public static function convertDefinitionToXML($name, $definition) {
$xmlFile = '<?xml version="1.0" encoding="utf-8" ?>' . "\n\n<CaseType>\n";
$xmlFile .= "<name>" . self::encodeXmlString($name) . "</name>\n";
if (array_key_exists('forkable', $definition)) {
$xmlFile .= "<forkable>" . ((int) $definition['forkable']) . "</forkable>\n";
}
if (isset($definition['activityTypes'])) {
$xmlFile .= "<ActivityTypes>\n";
foreach ($definition['activityTypes'] as $values) {
$xmlFile .= "<ActivityType>\n";
foreach ($values as $key => $value) {
$xmlFile .= "<{$key}>" . self::encodeXmlString($value) . "</{$key}>\n";
}
$xmlFile .= "</ActivityType>\n";
}
$xmlFile .= "</ActivityTypes>\n";
}
if (!empty($definition['statuses'])) {
$xmlFile .= "<Statuses>\n";
foreach ($definition['statuses'] as $value) {
$xmlFile .= "<Status>$value</Status>\n";
}
$xmlFile .= "</Statuses>\n";
}
if (isset($definition['activitySets'])) {
$xmlFile .= "<ActivitySets>\n";
foreach ($definition['activitySets'] as $k => $val) {
$xmlFile .= "<ActivitySet>\n";
foreach ($val as $index => $setVal) {
switch ($index) {
case 'activityTypes':
if (!empty($setVal)) {
$xmlFile .= "<ActivityTypes>\n";
foreach ($setVal as $values) {
$xmlFile .= "<ActivityType>\n";
foreach ($values as $key => $value) {
$xmlFile .= "<{$key}>" . self::encodeXmlString($value) . "</{$key}>\n";
}
$xmlFile .= "</ActivityType>\n";
}
$xmlFile .= "</ActivityTypes>\n";
}
break;
case 'sequence': // passthrough
case 'timeline':
if ($setVal) {
$xmlFile .= "<{$index}>true</{$index}>\n";
}
break;
default:
$xmlFile .= "<{$index}>" . self::encodeXmlString($setVal) . "</{$index}>\n";
}
}
$xmlFile .= "</ActivitySet>\n";
}
$xmlFile .= "</ActivitySets>\n";
}
if (isset($definition['caseRoles'])) {
$xmlFile .= "<CaseRoles>\n";
foreach ($definition['caseRoles'] as $values) {
$xmlFile .= "<RelationshipType>\n";
foreach ($values as $key => $value) {
$xmlFile .= "<{$key}>" . self::encodeXmlString($value) . "</{$key}>\n";
}
$xmlFile .= "</RelationshipType>\n";
}
$xmlFile .= "</CaseRoles>\n";
}
$xmlFile .= '</CaseType>';
return $xmlFile;
}
/**
* Ugh. This shouldn't exist. Use a real XML-encoder.
*
* Escape a string for use in XML.
*
* @param string $str
* A string which should outputted to XML.
* @return string
* @deprecated
*/
protected static function encodeXmlString($str) {
// PHP 5.4: return htmlspecialchars($str, ENT_XML1, 'UTF-8')
return htmlspecialchars($str);
}
/**
* Get the case definition either from db or read from xml file.
*
* @param SimpleXmlElement $xml
* A single case-type record.
*
* @return array
* the definition of the case-type, expressed as PHP array-tree
*/
public static function convertXmlToDefinition($xml) {
// build PHP array based on definition
$definition = array();
if (isset($xml->forkable)) {
$definition['forkable'] = (int) $xml->forkable;
}
// set activity types
if (isset($xml->ActivityTypes)) {
$definition['activityTypes'] = array();
foreach ($xml->ActivityTypes->ActivityType as $activityTypeXML) {
$definition['activityTypes'][] = json_decode(json_encode($activityTypeXML), TRUE);
}
}
// set statuses
if (isset($xml->Statuses)) {
$definition['statuses'] = (array) $xml->Statuses->Status;
}
// set activity sets
if (isset($xml->ActivitySets)) {
$definition['activitySets'] = array();
foreach ($xml->ActivitySets->ActivitySet as $activitySetXML) {
// parse basic properties
$activitySet = array();
$activitySet['name'] = (string) $activitySetXML->name;
$activitySet['label'] = (string) $activitySetXML->label;
if ('true' == (string) $activitySetXML->timeline) {
$activitySet['timeline'] = 1;
}
if ('true' == (string) $activitySetXML->sequence) {
$activitySet['sequence'] = 1;
}
if (isset($activitySetXML->ActivityTypes)) {
$activitySet['activityTypes'] = array();
foreach ($activitySetXML->ActivityTypes->ActivityType as $activityTypeXML) {
$activitySet['activityTypes'][] = json_decode(json_encode($activityTypeXML), TRUE);
}
}
$definition['activitySets'][] = $activitySet;
}
}
// set case roles
if (isset($xml->CaseRoles)) {
$definition['caseRoles'] = array();
foreach ($xml->CaseRoles->RelationshipType as $caseRoleXml) {
$definition['caseRoles'][] = json_decode(json_encode($caseRoleXml), TRUE);
}
}
return $definition;
}
/**
* Given the list of params in the params array, fetch the object
* and store the values in the values array
*
* @param array $params
* Input parameters to find object.
* @param array $values
* Output values of the object.
*
* @return CRM_Case_BAO_CaseType|null the found object or null
*/
public static function &getValues(&$params, &$values) {
$caseType = new CRM_Case_BAO_CaseType();
$caseType->copyValues($params);
if ($caseType->find(TRUE)) {
CRM_Core_DAO::storeValues($caseType, $values);
return $caseType;
}
return NULL;
}
/**
* Takes an associative array and creates a case type object.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @return CRM_Case_BAO_CaseType
*/
public static function &create(&$params) {
$transaction = new CRM_Core_Transaction();
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'CaseType', $params['id'], $params);
}
else {
CRM_Utils_Hook::pre('create', 'CaseType', NULL, $params);
}
$caseType = self::add($params);
if (is_a($caseType, 'CRM_Core_Error')) {
$transaction->rollback();
return $caseType;
}
if (!empty($params['id'])) {
CRM_Utils_Hook::post('edit', 'CaseType', $caseType->id, $case);
}
else {
CRM_Utils_Hook::post('create', 'CaseType', $caseType->id, $case);
}
$transaction->commit();
CRM_Case_XMLRepository::singleton(TRUE);
CRM_Core_OptionGroup::flushAll();
return $caseType;
}
/**
* Retrieve DB object based on input parameters.
*
* It also stores all the retrieved values in the default array.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $defaults
* (reference ) an assoc array to hold the name / value pairs.
* in a hierarchical manner
*
* @return CRM_Case_BAO_CaseType
*/
public static function retrieve(&$params, &$defaults) {
$caseType = CRM_Case_BAO_CaseType::getValues($params, $defaults);
return $caseType;
}
/**
* @param int $caseTypeId
*
* @throws CRM_Core_Exception
* @return mixed
*/
public static function del($caseTypeId) {
$caseType = new CRM_Case_DAO_CaseType();
$caseType->id = $caseTypeId;
$refCounts = $caseType->getReferenceCounts();
$total = array_sum(CRM_Utils_Array::collect('count', $refCounts));
if ($total) {
throw new CRM_Core_Exception(ts("You can not delete this case type -- it is assigned to %1 existing case record(s). If you do not want this case type to be used going forward, consider disabling it instead.", array(1 => $total)));
}
$result = $caseType->delete();
CRM_Case_XMLRepository::singleton(TRUE);
return $result;
}
/**
* Determine if a case-type name is well-formed
*
* @param string $caseType
* @return bool
*/
public static function isValidName($caseType) {
return preg_match('/^[a-zA-Z0-9_]+$/', $caseType);
}
/**
* Determine if the case-type has *both* DB and file-based definitions.
*
* @param int $caseTypeId
* @return bool|null
* TRUE if there are *both* DB and file-based definitions
*/
public static function isForked($caseTypeId) {
$caseTypeName = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $caseTypeId, 'name', 'id', TRUE);
if ($caseTypeName) {
$dbDefinition = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $caseTypeId, 'definition', 'id', TRUE);
$fileDefinition = CRM_Case_XMLRepository::singleton()->retrieveFile($caseTypeName);
return $fileDefinition && $dbDefinition;
}
return NULL;
}
/**
* Determine if modifications are allowed on the case-type
*
* @param int $caseTypeId
* @return bool
* TRUE if the definition can be modified
*/
public static function isForkable($caseTypeId) {
$caseTypeName = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $caseTypeId, 'name', 'id', TRUE);
if ($caseTypeName) {
// if file-based definition explicitly disables "forkable" option, then don't allow changes to definition
$fileDefinition = CRM_Case_XMLRepository::singleton()->retrieveFile($caseTypeName);
if ($fileDefinition && isset($fileDefinition->forkable)) {
return CRM_Utils_String::strtobool((string) $fileDefinition->forkable);
}
}
return TRUE;
}
}

View file

@ -0,0 +1,754 @@
<?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
*/
class CRM_Case_BAO_Query extends CRM_Core_BAO_Query {
/**
* Get fields.
*
* @param bool $excludeActivityFields
*
* @return array
*/
public static function &getFields($excludeActivityFields = FALSE) {
$fields = CRM_Case_BAO_Case::exportableFields();
// add activity related fields
if (!$excludeActivityFields) {
$fields = array_merge($fields, CRM_Activity_BAO_Activity::exportableFields('Case'));
}
return $fields;
}
/**
* Build select for Case.
*
* @param CRM_Contact_BAO_Query $query
*/
public static function select(&$query) {
if (($query->_mode & CRM_Contact_BAO_Query::MODE_CASE) || !empty($query->_returnProperties['case_id'])) {
$query->_select['case_id'] = "civicrm_case.id as case_id";
$query->_element['case_id'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
}
if (!empty($query->_returnProperties['case_type_id'])) {
$query->_select['case_type_id'] = "civicrm_case_type.id as case_type_id";
$query->_element['case_type_id'] = 1;
$query->_tables['case_type'] = $query->_whereTables['case_type'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_type'])) {
$query->_select['case_type'] = "civicrm_case_type.title as case_type";
$query->_element['case_type'] = 1;
$query->_tables['case_type'] = $query->_whereTables['case_type'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_start_date'])) {
$query->_select['case_start_date'] = "civicrm_case.start_date as case_start_date";
$query->_element['case_start_date'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_end_date'])) {
$query->_select['case_end_date'] = "civicrm_case.end_date as case_end_date";
$query->_element['case_end_date'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_status_id'])) {
$query->_select['case_status_id'] = "case_status.id as case_status_id";
$query->_element['case_status_id'] = 1;
$query->_tables['case_status_id'] = $query->_whereTables['case_status_id'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_status'])) {
$query->_select['case_status'] = "case_status.label as case_status";
$query->_element['case_status'] = 1;
$query->_tables['case_status_id'] = $query->_whereTables['case_status_id'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_deleted'])) {
$query->_select['case_deleted'] = "civicrm_case.is_deleted as case_deleted";
$query->_element['case_deleted'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_role'])) {
$query->_select['case_role'] = "case_relation_type.label_b_a as case_role";
$query->_element['case_role'] = 1;
$query->_tables['case_relationship'] = $query->_whereTables['case_relationship'] = 1;
$query->_tables['case_relation_type'] = $query->_whereTables['case_relation_type'] = 1;
}
if (!empty($query->_returnProperties['case_recent_activity_date'])) {
$query->_select['case_recent_activity_date'] = "case_activity.activity_date_time as case_recent_activity_date";
$query->_element['case_recent_activity_date'] = 1;
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
}
if (!empty($query->_returnProperties['case_activity_subject'])) {
$query->_select['case_activity_subject'] = "case_activity.subject as case_activity_subject";
$query->_element['case_activity_subject'] = 1;
$query->_tables['case_activity'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_subject'])) {
$query->_select['case_subject'] = "civicrm_case.subject as case_subject";
$query->_element['case_subject'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_source_contact_id'])) {
$query->_select['case_source_contact_id'] = "civicrm_case_reporter.sort_name as case_source_contact_id";
$query->_element['case_source_contact_id'] = 1;
$query->_tables['civicrm_case_reporter'] = 1;
$query->_tables['case_activity'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_activity_status_id'])) {
$query->_select['case_activity_status_id'] = "rec_activity_status.id as case_activity_status_id";
$query->_element['case_activity_status_id'] = 1;
$query->_tables['case_activity'] = 1;
$query->_tables['recent_activity_status'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_activity_status'])) {
$query->_select['case_activity_status'] = "rec_activity_status.label as case_activity_status";
$query->_element['case_activity_status'] = 1;
$query->_tables['case_activity'] = 1;
$query->_tables['recent_activity_status'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_activity_duration'])) {
$query->_select['case_activity_duration'] = "case_activity.duration as case_activity_duration";
$query->_element['case_activity_duration'] = 1;
$query->_tables['case_activity'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_activity_medium_id'])) {
$query->_select['case_activity_medium_id'] = "recent_activity_medium.label as case_activity_medium_id";
$query->_element['case_activity_medium_id'] = 1;
$query->_tables['case_activity'] = 1;
$query->_tables['case_activity_medium'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_activity_details'])) {
$query->_select['case_activity_details'] = "case_activity.details as case_activity_details";
$query->_element['case_activity_details'] = 1;
$query->_tables['case_activity'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_activity_is_auto'])) {
$query->_select['case_activity_is_auto'] = "case_activity.is_auto as case_activity_is_auto";
$query->_element['case_activity_is_auto'] = 1;
$query->_tables['case_activity'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_scheduled_activity_date'])) {
$query->_select['case_scheduled_activity_date'] = "case_activity.activity_date_time as case_scheduled_activity_date";
$query->_element['case_scheduled_activity_date'] = 1;
$query->_tables['case_activity'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
if (!empty($query->_returnProperties['case_recent_activity_type'])) {
$query->_select['case_recent_activity_type'] = "rec_activity_type.label as case_recent_activity_type";
$query->_element['case_recent_activity_type'] = 1;
$query->_tables['case_activity'] = 1;
$query->_tables['case_activity_type'] = 1;
$query->_tables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case'] = 1;
}
}
/**
* Given a list of conditions in query generate the required where clause.
*
* @param CRM_Contact_BAO_Query $query
*/
public static function where(&$query) {
foreach ($query->_params as $id => $values) {
if (!is_array($values) || count($values) != 5) {
continue;
}
if (substr($query->_params[$id][0], 0, 5) == 'case_') {
if ($query->_mode == CRM_Contact_BAO_Query::MODE_CONTACTS) {
$query->_useDistinct = TRUE;
}
self::whereClauseSingle($query->_params[$id], $query);
}
}
// Add acl clause
// This is new and so far only for cases - it would be good to find a more abstract
// way to auto-apply this for all search components rather than copy-pasting this code to others
if (isset($query->_tables['civicrm_case'])) {
$aclClauses = array_filter(CRM_Case_BAO_Case::getSelectWhereClause());
foreach ($aclClauses as $clause) {
$query->_where[0][] = $clause;
}
}
}
/**
* Where clause for a single field.
*
* CRM-17120 adds a test that checks the Qill on some of these parameters.
* However, I couldn't find a way, other than via test, to access the
* case_activity options in the code below and invalid sql was returned.
* Perhaps the options are just legacy?
*
* Also, CRM-17120 locks in the Qill - but it probably is not quite right as I
* see 'Activity Type = Scheduled' (rather than activity status).
*
* See CRM_Case_BAO_QueryTest for more.
*
* @param array $values
* @param CRM_Contact_BAO_Query $query
*/
public static function whereClauseSingle(&$values, &$query) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$val = $names = array();
switch ($name) {
case 'case_type_id':
case 'case_type':
case 'case_status':
case 'case_status_id':
case 'case_id':
if (strpos($name, 'type')) {
$name = 'case_type_id';
$label = 'Case Type(s)';
}
elseif (strpos($name, 'status')) {
$name = 'status_id';
$label = 'Case Status(s)';
}
else {
$name = 'id';
$label = 'Case ID';
}
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.{$name}", $op, $value, "Integer");
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Case_DAO_Case', $name, $value, $op);
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $label, 2 => $op, 3 => $value));
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
return;
case 'case_owner':
case 'case_mycases':
if (!empty($value)) {
if ($value == 2) {
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_relationship.contact_id_b", $op, $userID, 'Int');
$query->_qill[$grouping][] = ts('Case %1 My Cases', array(1 => $op));
$query->_tables['case_relationship'] = $query->_whereTables['case_relationship'] = 1;
}
elseif ($value == 1) {
$query->_qill[$grouping][] = ts('Case %1 All Cases', array(1 => $op));
$query->_where[$grouping][] = "civicrm_case_contact.contact_id = contact_a.id";
}
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
}
return;
case 'case_deleted':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.is_deleted", $op, $value, 'Boolean');
if ($value) {
$query->_qill[$grouping][] = ts("Find Deleted Cases");
}
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
return;
case 'case_activity_subject':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.subject", $op, $value, 'String');
$query->_qill[$grouping][] = ts("Activity Subject %1 '%2'", array(1 => $op, 2 => $value));
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_subject':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.subject", $op, $value, 'String');
$query->_qill[$grouping][] = ts("Case Subject %1 '%2'", array(1 => $op, 2 => $value));
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_source_contact_id':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case_reporter.sort_name", $op, $value, 'String');
$query->_qill[$grouping][] = ts("Activity Reporter %1 '%2'", array(1 => $op, 2 => $value));
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
$query->_tables['civicrm_case_reporter'] = $query->_whereTables['civicrm_case_reporter'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_recent_activity_date':
$date = CRM_Utils_Date::format($value);
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.activity_date_time", $op, $date, 'Date');
if ($date) {
$date = CRM_Utils_Date::customFormat($date);
$query->_qill[$grouping][] = ts("Activity Actual Date %1 %2", array(1 => $op, 2 => $date));
}
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_scheduled_activity_date':
$date = CRM_Utils_Date::format($value);
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.activity_date_time", $op, $date, 'Date');
if ($date) {
$date = CRM_Utils_Date::customFormat($date);
$query->_qill[$grouping][] = ts("Activity Schedule Date %1 %2", array(1 => $op, 2 => $date));
}
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_recent_activity_type':
$names = $value;
if (($activityType = CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'activity_type_id', $value)) != FALSE) {
$names = $activityType;
}
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.activity_type_id", $op, $value, 'Int');
$query->_qill[$grouping][] = ts("Activity Type %1 %2", array(1 => $op, 2 => $names));
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['case_activity_type'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_activity_status_id':
$names = $value;
if (($activityStatus = CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'status_id', $value)) != FALSE) {
$names = $activityStatus;
}
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.status_id", $op, $value, 'Int');
$query->_qill[$grouping][] = ts("Activity Type %1 %2", array(1 => $op, 2 => $names));
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['case_activity_status'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_activity_duration':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.duration", $op, $value, 'Int');
$query->_qill[$grouping][] = ts("Activity Duration %1 %2", array(1 => $op, 2 => $value));
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_activity_medium_id':
$names = $value;
if (($activityMedium = CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'medium_id', $value)) != FALSE) {
$names = $activityMedium;
}
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.medium_id", $op, $value, 'Int');
$query->_qill[$grouping][] = ts("Activity Medium %1 %2", array(1 => $op, 2 => $names));
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['case_activity_medium'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_activity_details':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.details", $op, $value, 'String');
$query->_qill[$grouping][] = ts("Activity Details %1 '%2'", array(1 => $op, 2 => $value));
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_activity_is_auto':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_activity.is_auto", $op, $value, 'Boolean');
$query->_qill[$grouping][] = ts("Activity Auto Genrated %1 '%2'", array(1 => $op, 2 => $value));
$query->_tables['case_activity'] = $query->_whereTables['case_activity'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
// adding where clause for case_role
case 'case_role':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("case_relation_type.name_b_a", $op, $value, 'String');
$query->_qill[$grouping][] = ts("Role in Case %1 '%2'", array(1 => $op, 2 => $value));
$query->_tables['case_relation_type'] = $query->_whereTables['case_relationship_type'] = 1;
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
return;
case 'case_from_start_date_low':
case 'case_from_start_date_high':
$query->dateQueryBuilder($values,
'civicrm_case', 'case_from_start_date', 'start_date', 'Start Date'
);
return;
case 'case_to_end_date_low':
case 'case_to_end_date_high':
$query->dateQueryBuilder($values,
'civicrm_case', 'case_to_end_date', 'end_date', 'End Date'
);
return;
case 'case_start_date':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.start_date", $op, $value, 'Int');
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
return;
case 'case_end_date':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.end_date", $op, $value, 'Int');
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
return;
case 'case_taglist':
$taglist = $value;
$value = array();
foreach ($taglist as $val) {
if ($val) {
$val = explode(',', $val);
foreach ($val as $tId) {
if (is_numeric($tId)) {
$value[$tId] = 1;
}
}
}
}
case 'case_tags':
$tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
if (!empty($value)) {
$val = explode(',', $value);
foreach ($val as $v) {
if ($v) {
$names[] = $tags[$v];
}
}
}
$query->_where[$grouping][] = " civicrm_case_tag.tag_id IN (" . implode(',', $val) . " )";
$query->_qill[$grouping][] = ts('Case Tags %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
$query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
$query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
$query->_tables['civicrm_case_tag'] = $query->_whereTables['civicrm_case_tag'] = 1;
return;
}
}
/**
* Build from clause.
*
* @param string $name
* @param string $mode
* @param string $side
*
* @return string
*/
public static function from($name, $mode, $side) {
$from = "";
switch ($name) {
case 'civicrm_case_contact':
$from .= " $side JOIN civicrm_case_contact ON civicrm_case_contact.contact_id = contact_a.id ";
break;
case 'civicrm_case_reporter':
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
$from .= " $side JOIN civicrm_activity_contact as case_activity_contact ON (case_activity.id = case_activity_contact.activity_id AND case_activity_contact.record_type_id = {$sourceID} ) ";
$from .= " $side JOIN civicrm_contact as civicrm_case_reporter ON case_activity_contact.contact_id = civicrm_case_reporter.id ";
break;
case 'civicrm_case':
$from .= " INNER JOIN civicrm_case ON civicrm_case_contact.case_id = civicrm_case.id";
break;
case 'case_status_id':
$from .= " $side JOIN civicrm_option_group option_group_case_status ON (option_group_case_status.name = 'case_status')";
$from .= " $side JOIN civicrm_option_value case_status ON (civicrm_case.status_id = case_status.value AND option_group_case_status.id = case_status.option_group_id ) ";
break;
case 'case_type':
$from .= " $side JOIN civicrm_case_type ON civicrm_case.case_type_id = civicrm_case_type.id ";
break;
case 'case_activity_type':
$from .= " $side JOIN civicrm_option_group option_group_activity_type ON (option_group_activity_type.name = 'activity_type')";
$from .= " $side JOIN civicrm_option_value rec_activity_type ON (case_activity.activity_type_id = rec_activity_type.value AND option_group_activity_type.id = rec_activity_type.option_group_id ) ";
break;
case 'recent_activity_status':
$from .= " $side JOIN civicrm_option_group option_group_activity_status ON (option_group_activity_status.name = 'activity_status')";
$from .= " $side JOIN civicrm_option_value rec_activity_status ON (case_activity.status_id = rec_activity_status.value AND option_group_activity_status.id = rec_activity_status.option_group_id ) ";
break;
case 'case_relationship':
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
$from .= " $side JOIN civicrm_relationship case_relationship ON ( case_relationship.contact_id_a = civicrm_case_contact.contact_id AND case_relationship.contact_id_b = {$userID} AND case_relationship.case_id = civicrm_case.id )";
break;
case 'case_relation_type':
$from .= " $side JOIN civicrm_relationship_type case_relation_type ON ( case_relation_type.id = case_relationship.relationship_type_id AND
case_relation_type.id = case_relationship.relationship_type_id )";
break;
case 'case_activity_medium':
$from .= " $side JOIN civicrm_option_group option_group_activity_medium ON (option_group_activity_medium.name = 'encounter_medium')";
$from .= " $side JOIN civicrm_option_value recent_activity_medium ON (case_activity.medium_id = recent_activity_medium.value AND option_group_activity_medium.id = recent_activity_medium.option_group_id ) ";
break;
case 'case_activity':
$from .= " INNER JOIN civicrm_case_activity ON civicrm_case_activity.case_id = civicrm_case.id ";
$from .= " INNER JOIN civicrm_activity case_activity ON ( civicrm_case_activity.activity_id = case_activity.id
AND case_activity.is_current_revision = 1 )";
break;
case 'civicrm_case_tag':
$from .= " $side JOIN civicrm_entity_tag as civicrm_case_tag ON ( civicrm_case_tag.entity_table = 'civicrm_case' AND civicrm_case_tag.entity_id = civicrm_case.id ) ";
break;
}
return $from;
}
/**
* Getter for the qill object.
*
* @return string
*/
public function qill() {
return (isset($this->_qill)) ? $this->_qill : "";
}
/**
* @param $mode
* @param bool $includeCustomFields
*
* @return array|null
*/
public static function defaultReturnProperties(
$mode,
$includeCustomFields = TRUE
) {
$properties = NULL;
if ($mode & CRM_Contact_BAO_Query::MODE_CASE) {
$properties = array(
'contact_type' => 1,
'contact_sub_type' => 1,
'contact_id' => 1,
'sort_name' => 1,
'display_name' => 1,
'case_id' => 1,
'case_activity_subject' => 1,
'case_subject' => 1,
'case_status' => 1,
'case_type' => 1,
'case_role' => 1,
'case_deleted' => 1,
'case_recent_activity_date' => 1,
'case_recent_activity_type' => 1,
'case_scheduled_activity_date' => 1,
'phone' => 1,
// 'case_scheduled_activity_type'=> 1
);
if ($includeCustomFields) {
// also get all the custom case properties
$fields = CRM_Core_BAO_CustomField::getFieldsForImport('Case');
if (!empty($fields)) {
foreach ($fields as $name => $dontCare) {
$properties[$name] = 1;
}
}
}
}
return $properties;
}
/**
* This includes any extra fields that might need for export etc.
*
* @param string $mode
*
* @return array|null
*/
public static function extraReturnProperties($mode) {
$properties = NULL;
if ($mode & CRM_Contact_BAO_Query::MODE_CASE) {
$properties = array(
'case_start_date' => 1,
'case_end_date' => 1,
'case_subject' => 1,
'case_source_contact_id' => 1,
'case_activity_status' => 1,
'case_activity_duration' => 1,
'case_activity_medium_id' => 1,
'case_activity_details' => 1,
'case_activity_is_auto' => 1,
);
}
return $properties;
}
/**
* @param $tables
*/
public static function tableNames(&$tables) {
if (!empty($tables['civicrm_case'])) {
$tables = array_merge(array('civicrm_case_contact' => 1), $tables);
}
if (!empty($tables['case_relation_type'])) {
$tables = array_merge(array('case_relationship' => 1), $tables);
}
}
/**
* Add all the elements shared between case search and advanced search.
*
* @param CRM_Core_Form $form
*/
public static function buildSearchForm(&$form) {
//validate case configuration.
$configured = CRM_Case_BAO_Case::isCaseConfigured();
$form->assign('notConfigured', !$configured['configured']);
$form->addField('case_type_id', array('context' => 'search', 'entity' => 'Case'));
$form->addField('case_status_id', array('context' => 'search', 'entity' => 'Case'));
CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE);
CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE);
$form->addElement('hidden', 'case_from_start_date_range_error');
$form->addElement('hidden', 'case_to_end_date_range_error');
$form->addFormRule(array('CRM_Case_BAO_Query', 'formRule'), $form);
$form->assign('validCiviCase', TRUE);
//give options when all cases are accessible.
$accessAllCases = FALSE;
if (CRM_Core_Permission::check('access all cases and activities')) {
$accessAllCases = TRUE;
$caseOwner = array(1 => ts('Search All Cases'), 2 => ts('Only My Cases'));
$form->addRadio('case_owner', ts('Cases'), $caseOwner);
}
$form->assign('accessAllCases', $accessAllCases);
$caseTags = CRM_Core_BAO_Tag::getColorTags('civicrm_case');
if ($caseTags) {
$form->add('select2', 'case_tags', ts('Case Tag(s)'), $caseTags, FALSE, array('class' => 'big', 'placeholder' => ts('- select -'), 'multiple' => TRUE));
}
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case');
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_case', NULL, TRUE, FALSE);
if (CRM_Core_Permission::check('administer CiviCase')) {
$form->addElement('checkbox', 'case_deleted', ts('Deleted Cases'));
}
$form->addElement('text',
'case_subject',
ts('Case Subject'),
array('class' => 'huge')
);
$form->addElement('text',
'case_id',
ts('Case ID')
);
self::addCustomFormFields($form, array('Case'));
$form->setDefaults(array('case_owner' => 1));
}
/**
* Custom form rules.
*
* @param array $fields
* @param array $files
* @param CRM_Core_Form $form
*
* @return bool|array
*/
public static function formRule($fields, $files, $form) {
$errors = array();
if ((empty($fields['case_from_start_date_low']) || empty($fields['case_from_start_date_high'])) && (empty($fields['case_to_end_date_low']) || empty($fields['case_to_end_date_high']))) {
return TRUE;
}
CRM_Utils_Rule::validDateRange($fields, 'case_from_start_date', $errors, ts('Case Start Date'));
CRM_Utils_Rule::validDateRange($fields, 'case_to_end_date', $errors, ts('Case End Date'));
return empty($errors) ? TRUE : $errors;
}
}

View file

@ -0,0 +1,68 @@
<?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 is used by the Search functionality.
*
* - the search controller is used for building/processing multiform
* searches.
*
* Typically the first form will display the search criteria and its results
*
* The second form is used to process search results with the associated actions
*
*/
class CRM_Case_Controller_Search extends CRM_Core_Controller {
/**
* Class constructor.
*
* @param string $title
* @param bool|int $action
* @param bool $modal
*/
public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) {
parent::__construct($title, $modal);
$this->_stateMachine = new CRM_Case_StateMachine_Search($this, $action);
// create and instantiate the pages
$this->addPages($this->_stateMachine, $action);
// add all the actions
$config = CRM_Core_Config::singleton();
$this->addActions();
}
}

View file

@ -0,0 +1,401 @@
<?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
*
* Generated from xml/schema/CRM/Case/Case.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:2a046fd795b19790f45c5d9dde06a538)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
/**
* CRM_Case_DAO_Case constructor.
*/
class CRM_Case_DAO_Case extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_case';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var boolean
*/
static $_log = true;
/**
* Unique Case ID
*
* @var int unsigned
*/
public $id;
/**
* FK to civicrm_case_type.id
*
* @var int unsigned
*/
public $case_type_id;
/**
* Short name of the case.
*
* @var string
*/
public $subject;
/**
* Date on which given case starts.
*
* @var date
*/
public $start_date;
/**
* Date on which given case ends.
*
* @var date
*/
public $end_date;
/**
* Details about the meeting (agenda, notes, etc).
*
* @var text
*/
public $details;
/**
* Id of case status.
*
* @var int unsigned
*/
public $status_id;
/**
*
* @var boolean
*/
public $is_deleted;
/**
* When was the case was created.
*
* @var timestamp
*/
public $created_date;
/**
* When was the case (or closely related entity) was created or modified or deleted.
*
* @var timestamp
*/
public $modified_date;
/**
* Class constructor.
*/
function __construct() {
$this->__table = 'civicrm_case';
parent::__construct();
}
/**
* Returns foreign keys and entity references.
*
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns() {
if (!isset(Civi::$statics[__CLASS__]['links'])) {
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'case_type_id', 'civicrm_case_type', 'id');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = array(
'case_id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Case ID') ,
'description' => 'Unique Case ID',
'required' => true,
'import' => true,
'where' => 'civicrm_case.id',
'headerPattern' => '',
'dataPattern' => '',
'export' => true,
'table_name' => 'civicrm_case',
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
) ,
'case_type_id' => array(
'name' => 'case_type_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Case Type') ,
'description' => 'FK to civicrm_case_type.id',
'required' => true,
'import' => true,
'where' => 'civicrm_case.case_type_id',
'headerPattern' => '',
'dataPattern' => '',
'export' => false,
'table_name' => 'civicrm_case',
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
'FKClassName' => 'CRM_Case_DAO_CaseType',
'html' => array(
'type' => 'Select',
) ,
'pseudoconstant' => array(
'table' => 'civicrm_case_type',
'keyColumn' => 'id',
'labelColumn' => 'title',
)
) ,
'case_subject' => array(
'name' => 'subject',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Case Subject') ,
'description' => 'Short name of the case.',
'maxlength' => 128,
'size' => CRM_Utils_Type::HUGE,
'import' => true,
'where' => 'civicrm_case.subject',
'headerPattern' => '',
'dataPattern' => '',
'export' => true,
'table_name' => 'civicrm_case',
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'case_start_date' => array(
'name' => 'start_date',
'type' => CRM_Utils_Type::T_DATE,
'title' => ts('Case Start Date') ,
'description' => 'Date on which given case starts.',
'import' => true,
'where' => 'civicrm_case.start_date',
'headerPattern' => '',
'dataPattern' => '',
'export' => true,
'table_name' => 'civicrm_case',
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
'html' => array(
'type' => 'Select Date',
) ,
) ,
'case_end_date' => array(
'name' => 'end_date',
'type' => CRM_Utils_Type::T_DATE,
'title' => ts('Case End Date') ,
'description' => 'Date on which given case ends.',
'import' => true,
'where' => 'civicrm_case.end_date',
'headerPattern' => '',
'dataPattern' => '',
'export' => true,
'table_name' => 'civicrm_case',
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
'html' => array(
'type' => 'Select Date',
) ,
) ,
'details' => array(
'name' => 'details',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Details') ,
'description' => 'Details about the meeting (agenda, notes, etc).',
'rows' => 8,
'cols' => 60,
'table_name' => 'civicrm_case',
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
'html' => array(
'type' => 'TextArea',
) ,
) ,
'case_status_id' => array(
'name' => 'status_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Case Status') ,
'description' => 'Id of case status.',
'required' => true,
'import' => true,
'where' => 'civicrm_case.status_id',
'headerPattern' => '',
'dataPattern' => '',
'export' => false,
'table_name' => 'civicrm_case',
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
'html' => array(
'type' => 'Select',
) ,
'pseudoconstant' => array(
'optionGroupName' => 'case_status',
'optionEditPath' => 'civicrm/admin/options/case_status',
)
) ,
'case_deleted' => array(
'name' => 'is_deleted',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Case is in the Trash') ,
'import' => true,
'where' => 'civicrm_case.is_deleted',
'headerPattern' => '',
'dataPattern' => '',
'export' => true,
'table_name' => 'civicrm_case',
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
) ,
'case_created_date' => array(
'name' => 'created_date',
'type' => CRM_Utils_Type::T_TIMESTAMP,
'title' => ts('Created Date') ,
'description' => 'When was the case was created.',
'required' => false,
'export' => true,
'where' => 'civicrm_case.created_date',
'headerPattern' => '',
'dataPattern' => '',
'default' => 'NULL',
'table_name' => 'civicrm_case',
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
) ,
'case_modified_date' => array(
'name' => 'modified_date',
'type' => CRM_Utils_Type::T_TIMESTAMP,
'title' => ts('Modified Date') ,
'description' => 'When was the case (or closely related entity) was created or modified or deleted.',
'required' => false,
'export' => true,
'where' => 'civicrm_case.modified_date',
'headerPattern' => '',
'dataPattern' => '',
'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
'table_name' => 'civicrm_case',
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName() {
return self::$_tableName;
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'case', $prefix, array());
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'case', $prefix, array());
return $r;
}
/**
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array(
'index_case_type_id' => array(
'name' => 'index_case_type_id',
'field' => array(
0 => 'case_type_id',
) ,
'localizable' => false,
'sig' => 'civicrm_case::0::case_type_id',
) ,
'index_is_deleted' => array(
'name' => 'index_is_deleted',
'field' => array(
0 => 'is_deleted',
) ,
'localizable' => false,
'sig' => 'civicrm_case::0::is_deleted',
) ,
);
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}

View file

@ -0,0 +1,208 @@
<?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
*
* Generated from xml/schema/CRM/Case/CaseActivity.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:80c6c66652f17c130b2eddcfb32c8f3d)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
/**
* CRM_Case_DAO_CaseActivity constructor.
*/
class CRM_Case_DAO_CaseActivity extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_case_activity';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var boolean
*/
static $_log = true;
/**
* Unique case-activity association id
*
* @var int unsigned
*/
public $id;
/**
* Case ID of case-activity association.
*
* @var int unsigned
*/
public $case_id;
/**
* Activity ID of case-activity association.
*
* @var int unsigned
*/
public $activity_id;
/**
* Class constructor.
*/
function __construct() {
$this->__table = 'civicrm_case_activity';
parent::__construct();
}
/**
* Returns foreign keys and entity references.
*
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns() {
if (!isset(Civi::$statics[__CLASS__]['links'])) {
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'case_id', 'civicrm_case', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'activity_id', 'civicrm_activity', 'id');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = array(
'id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Case Activity ID') ,
'description' => 'Unique case-activity association id',
'required' => true,
'table_name' => 'civicrm_case_activity',
'entity' => 'CaseActivity',
'bao' => 'CRM_Case_DAO_CaseActivity',
'localizable' => 0,
) ,
'case_id' => array(
'name' => 'case_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Case') ,
'description' => 'Case ID of case-activity association.',
'required' => true,
'table_name' => 'civicrm_case_activity',
'entity' => 'CaseActivity',
'bao' => 'CRM_Case_DAO_CaseActivity',
'localizable' => 0,
'FKClassName' => 'CRM_Case_DAO_Case',
) ,
'activity_id' => array(
'name' => 'activity_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Activity ID') ,
'description' => 'Activity ID of case-activity association.',
'required' => true,
'table_name' => 'civicrm_case_activity',
'entity' => 'CaseActivity',
'bao' => 'CRM_Case_DAO_CaseActivity',
'localizable' => 0,
'FKClassName' => 'CRM_Activity_DAO_Activity',
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName() {
return self::$_tableName;
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'case_activity', $prefix, array());
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'case_activity', $prefix, array());
return $r;
}
/**
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array(
'UI_case_activity_id' => array(
'name' => 'UI_case_activity_id',
'field' => array(
0 => 'case_id',
1 => 'activity_id',
) ,
'localizable' => false,
'sig' => 'civicrm_case_activity::0::case_id::activity_id',
) ,
);
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}

View file

@ -0,0 +1,212 @@
<?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
*
* Generated from xml/schema/CRM/Case/CaseContact.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:def2443e49db4d131c39c07e2045fbb3)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
/**
* CRM_Case_DAO_CaseContact constructor.
*/
class CRM_Case_DAO_CaseContact extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_case_contact';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var boolean
*/
static $_log = true;
/**
* Unique case-contact association id
*
* @var int unsigned
*/
public $id;
/**
* Case ID of case-contact association.
*
* @var int unsigned
*/
public $case_id;
/**
* Contact ID of contact record given case belongs to.
*
* @var int unsigned
*/
public $contact_id;
/**
* Class constructor.
*/
function __construct() {
$this->__table = 'civicrm_case_contact';
parent::__construct();
}
/**
* Returns foreign keys and entity references.
*
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns() {
if (!isset(Civi::$statics[__CLASS__]['links'])) {
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'case_id', 'civicrm_case', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contact_id', 'civicrm_contact', 'id');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = array(
'id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Case Contact ID') ,
'description' => 'Unique case-contact association id',
'required' => true,
'table_name' => 'civicrm_case_contact',
'entity' => 'CaseContact',
'bao' => 'CRM_Case_BAO_CaseContact',
'localizable' => 0,
) ,
'case_id' => array(
'name' => 'case_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Case') ,
'description' => 'Case ID of case-contact association.',
'required' => true,
'table_name' => 'civicrm_case_contact',
'entity' => 'CaseContact',
'bao' => 'CRM_Case_BAO_CaseContact',
'localizable' => 0,
'FKClassName' => 'CRM_Case_DAO_Case',
) ,
'contact_id' => array(
'name' => 'contact_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Contact ID') ,
'description' => 'Contact ID of contact record given case belongs to.',
'required' => true,
'table_name' => 'civicrm_case_contact',
'entity' => 'CaseContact',
'bao' => 'CRM_Case_BAO_CaseContact',
'localizable' => 0,
'FKClassName' => 'CRM_Contact_DAO_Contact',
'html' => array(
'type' => 'EntityRef',
) ,
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName() {
return self::$_tableName;
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'case_contact', $prefix, array());
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'case_contact', $prefix, array());
return $r;
}
/**
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array(
'UI_case_contact_id' => array(
'name' => 'UI_case_contact_id',
'field' => array(
0 => 'case_id',
1 => 'contact_id',
) ,
'localizable' => false,
'unique' => true,
'sig' => 'civicrm_case_contact::1::case_id::contact_id',
) ,
);
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}

View file

@ -0,0 +1,279 @@
<?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
*
* Generated from xml/schema/CRM/Case/CaseType.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:a9a547708dfca9da8c4421dd5edac6ac)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
/**
* CRM_Case_DAO_CaseType constructor.
*/
class CRM_Case_DAO_CaseType extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_case_type';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var boolean
*/
static $_log = true;
/**
* Autoincremented type id
*
* @var int unsigned
*/
public $id;
/**
* Machine name for Case Type
*
* @var string
*/
public $name;
/**
* Natural language name for Case Type
*
* @var string
*/
public $title;
/**
* Description of the Case Type
*
* @var string
*/
public $description;
/**
* Is this entry active?
*
* @var boolean
*/
public $is_active;
/**
* Is this case type a predefined system type?
*
* @var boolean
*/
public $is_reserved;
/**
* Ordering of the case types
*
* @var int
*/
public $weight;
/**
* xml definition of case type
*
* @var blob
*/
public $definition;
/**
* Class constructor.
*/
function __construct() {
$this->__table = 'civicrm_case_type';
parent::__construct();
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = array(
'id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Case Type ID') ,
'description' => 'Autoincremented type id',
'required' => true,
'table_name' => 'civicrm_case_type',
'entity' => 'CaseType',
'bao' => 'CRM_Case_BAO_CaseType',
'localizable' => 0,
) ,
'name' => array(
'name' => 'name',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Case Type Name') ,
'description' => 'Machine name for Case Type',
'required' => true,
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
'table_name' => 'civicrm_case_type',
'entity' => 'CaseType',
'bao' => 'CRM_Case_BAO_CaseType',
'localizable' => 0,
) ,
'title' => array(
'name' => 'title',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Case Type Title') ,
'description' => 'Natural language name for Case Type',
'required' => true,
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
'table_name' => 'civicrm_case_type',
'entity' => 'CaseType',
'bao' => 'CRM_Case_BAO_CaseType',
'localizable' => 1,
) ,
'description' => array(
'name' => 'description',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Case Type Description') ,
'description' => 'Description of the Case Type',
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_case_type',
'entity' => 'CaseType',
'bao' => 'CRM_Case_BAO_CaseType',
'localizable' => 1,
) ,
'is_active' => array(
'name' => 'is_active',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Case Type Is Active') ,
'description' => 'Is this entry active?',
'table_name' => 'civicrm_case_type',
'entity' => 'CaseType',
'bao' => 'CRM_Case_BAO_CaseType',
'localizable' => 0,
) ,
'is_reserved' => array(
'name' => 'is_reserved',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Case Type Is Reserved') ,
'description' => 'Is this case type a predefined system type?',
'table_name' => 'civicrm_case_type',
'entity' => 'CaseType',
'bao' => 'CRM_Case_BAO_CaseType',
'localizable' => 0,
) ,
'weight' => array(
'name' => 'weight',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Order') ,
'description' => 'Ordering of the case types',
'required' => true,
'default' => '1',
'table_name' => 'civicrm_case_type',
'entity' => 'CaseType',
'bao' => 'CRM_Case_BAO_CaseType',
'localizable' => 0,
) ,
'definition' => array(
'name' => 'definition',
'type' => CRM_Utils_Type::T_BLOB,
'title' => ts('Case Type Definition') ,
'description' => 'xml definition of case type',
'table_name' => 'civicrm_case_type',
'entity' => 'CaseType',
'bao' => 'CRM_Case_BAO_CaseType',
'localizable' => 0,
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName() {
return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'case_type', $prefix, array());
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'case_type', $prefix, array());
return $r;
}
/**
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array(
'case_type_name' => array(
'name' => 'case_type_name',
'field' => array(
0 => 'name',
) ,
'localizable' => false,
'unique' => true,
'sig' => 'civicrm_case_type::1::name',
) ,
);
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}

View file

@ -0,0 +1,656 @@
<?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 create activities for a case.
*/
class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
/**
* The default variable defined.
*
* @var int
*/
public $_caseId;
/**
* The default case type variable defined.
*
* @var int
*/
public $_caseType;
/**
* The array of releted contact info.
*
* @var array
*/
public $_relatedContacts;
/**
* Build the form object.
*/
public function preProcess() {
$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';
}
$this->_crmDir = 'Case';
$this->assign('context', $this->_context);
$result = parent::preProcess();
$scheduleStatusId = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name');
$this->assign('scheduleStatusId', $scheduleStatusId);
if (!$this->_caseId && $this->_activityId) {
$this->_caseId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $this->_activityId,
'case_id', 'activity_id'
);
}
if ($this->_caseId) {
$this->assign('caseId', $this->_caseId);
$this->assign('countId', count($this->_caseId));
$this->assign('caseID', CRM_Utils_Array::first($this->_caseId));
}
if (!$this->_caseId ||
(!$this->_activityId && !$this->_activityTypeId)
) {
CRM_Core_Error::fatal('required params missing.');
}
//check for case activity access.
if (!CRM_Case_BAO_Case::accessCiviCase()) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
//validate case id.
if ($this->_caseId &&
!CRM_Core_Permission::check('access all cases and activities')
) {
$session = CRM_Core_Session::singleton();
$allCases = CRM_Case_BAO_Case::getCases(TRUE, $session->get('userID'), 'any');
if (count(array_intersect($this->_caseId, array_keys($allCases))) == 0) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
}
//validate case activity id.
if ($this->_activityId &&
($this->_action & CRM_Core_Action::UPDATE)
) {
$valid = CRM_Case_BAO_Case::checkPermission($this->_activityId, 'edit',
$this->_activityTypeId
);
if (!$valid) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
}
foreach ($this->_caseId as $casePos => $caseId) {
$this->_caseType[$casePos] = CRM_Case_BAO_Case::getCaseType($caseId, 'name');
}
$this->assign('caseType', $this->_caseType);
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
$this->assign('multiClient', $isMultiClient);
foreach ($this->_caseId as $casePos => $caseId) {
$clients[] = CRM_Case_BAO_Case::getContactNames($caseId);
}
$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={$caseIds}&show=1&context={$this->_context}"
);
}
else {
$url = CRM_Utils_System::url('civicrm/contact/search/custom', 'force=1');
}
}
else {
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"
);
}
if (!$this->_activityId) {
$caseTypes = CRM_Case_PseudoConstant::caseType();
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={$caseIds}&show=1"
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
CRM_Core_Error::statusBounce(ts("You do not have any active Case Types"));
}
// check if activity count is within the limit
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
foreach ($this->_caseId as $casePos => $caseId) {
$caseType = $this->_caseType[$casePos];
$activityInst = $xmlProcessor->getMaxInstance($caseType);
// If not bounce back and also provide activity edit link
if (isset($activityInst[$this->_activityTypeName])) {
$activityCount = CRM_Case_BAO_Case::getCaseActivityCount($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($caseId,
$atArray,
$this->_currentUserId
);
$activities = array_keys($activities);
$activities = $activities[0];
$editUrl = CRM_Utils_System::url('civicrm/case/activity',
"reset=1&cid={$this->_currentlyViewedContactId}&caseid={$caseId}&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 => ts("Do you want to <a %1>edit the existing activity</a>?", array(1 => "href='$editUrl'")),
)
),
$url
);
}
}
}
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
/**
* Set default values for the form.
*/
public function setDefaultValues() {
$this->_defaults = parent::setDefaultValues();
$targetContactValues = array();
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);
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;
}
}
public function buildQuickForm() {
$this->_fields['source_contact_id']['label'] = ts('Reported By');
unset($this->_fields['status_id']['attributes']['required']);
if ($this->_caseType) {
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$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');
unset($aTypes[$openCaseID]);
asort($aTypes);
$this->_fields['followup_activity_type_id']['attributes'] = array('' => '- select activity type -') + $aTypes;
}
parent::buildQuickForm();
if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH | CRM_Core_Action::RENEW)) {
return;
}
$this->assign('urlPath', 'civicrm/case/activity');
$encounterMediums = CRM_Case_PseudoConstant::encounterMedium();
// Fixme: what's the justification for this? It seems like it is just re-adding an option in case it is the default and disabled.
// Is that really a big problem?
if ($this->_activityTypeFile == 'OpenCase') {
$this->_encounterMedium = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId,
'medium_id'
);
if (!array_key_exists($this->_encounterMedium, $encounterMediums)) {
$encounterMediums[$this->_encounterMedium] = CRM_Core_OptionGroup::getLabel('encounter_medium',
$this->_encounterMedium,
FALSE
);
}
}
$this->add('select', 'medium_id', ts('Medium'), $encounterMediums, TRUE);
$i = 0;
foreach ($this->_caseId as $key => $val) {
$this->_relatedContacts[] = $rgc = 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++;
}
//add case client in send a copy selector.CRM-4438.
foreach ($this->_caseId as $key => $val) {
$relatedContacts[] = $relCon = CRM_Case_BAO_Case::getContactNames($val);
}
if (!empty($relatedContacts)) {
foreach ($relatedContacts as $relatedContact) {
$this->_relatedContacts[] = $relatedContact;
}
}
if (!empty($this->_relatedContacts)) {
$checkBoxes = array();
foreach ($this->_relatedContacts as $id => $row) {
foreach ($row as $key => $value) {
$checkBoxes[$key] = $this->addElement('checkbox', $key, NULL, NULL, array('class' => 'select-row'));
}
}
$this->addGroup($checkBoxes, 'contact_check');
$this->addElement('checkbox', 'toggleSelect', NULL, NULL,
array('class' => 'select-rows')
);
$this->assign('searchRows', $this->_relatedContacts);
}
$this->_relatedContacts = $rgc + $relCon;
$this->addFormRule(array('CRM_Case_Form_Activity', 'formRule'), $this);
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param $self
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self) {
// skip form rule if deleting
if (CRM_Utils_Array::value('_qf_Activity_next_', $fields) == 'Delete' || CRM_Utils_Array::value('_qf_Activity_next_', $fields) == 'Restore') {
return TRUE;
}
return parent::formRule($fields, $files, $self);
}
/**
* Process the form submission.
*
* @param array $params
*/
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) {
// retrieve and include the custom data of old Activity
$oldActivity = civicrm_api3('Activity', 'getsingle', array('id' => $this->_activityId));
$params = array_merge($oldActivity, $params);
// 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_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
if (Civi::settings()->get('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');
}
}
}

View file

@ -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.');
}
}

View file

@ -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();
}
}
}
}

View file

@ -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.');
}
}

View 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);
}
}
}

View 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}"
));
}
}
}
}

View file

@ -0,0 +1,114 @@
<?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 building activity to a case.
*/
class CRM_Case_Form_ActivityToCase extends CRM_Core_Form {
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
$this->_activityId = CRM_Utils_Request::retrieve('activityId', 'Positive');
if (!$this->_activityId) {
CRM_Core_Error::fatal('required activity id is missing.');
}
$this->_currentCaseId = CRM_Utils_Request::retrieve('caseId', 'Positive');
$this->assign('currentCaseId', $this->_currentCaseId);
$this->assign('buildCaseActivityForm', TRUE);
}
/**
* Set default values for the form. For edit/view mode
* the default values are retrieved from the database
*
*
* @return array
*/
public function setDefaultValues() {
$defaults = array();
$params = array('id' => $this->_activityId);
CRM_Activity_BAO_Activity::retrieve($params, $defaults);
$defaults['file_on_case_activity_subject'] = $defaults['subject'];
$defaults['file_on_case_target_contact_id'] = $defaults['target_contact'];
// If this contact has an open case, supply it as a default
$cid = CRM_Utils_Request::retrieve('cid', 'Integer');
if (!$cid) {
$act = civicrm_api3('Activity', 'getsingle', array('id' => $this->_activityId, 'return' => 'target_contact_id'));
if (!empty($act['target_contact_id'])) {
$cid = $act['target_contact_id'][0];
}
}
if ($cid) {
$cases = civicrm_api3('CaseContact', 'get', array(
'contact_id' => $cid,
'case_id' => array('!=' => $this->_currentCaseId),
'case_id.status_id' => array('!=' => "Closed"),
'case_id.is_deleted' => 0,
'case_id.end_date' => array('IS NULL' => 1),
'options' => array('limit' => 1),
'return' => 'case_id',
));
foreach ($cases['values'] as $record) {
$defaults['file_on_case_unclosed_case_id'] = $record['case_id'];
break;
}
}
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addEntityRef('file_on_case_unclosed_case_id', ts('Select Case'), array(
'entity' => 'Case',
'api' => array(
'extra' => array('contact_id'),
'params' => array(
'case_id' => array('!=' => $this->_currentCaseId),
'case_id.is_deleted' => 0,
'case_id.status_id' => array('!=' => "Closed"),
'case_id.end_date' => array('IS NULL' => 1),
),
),
), TRUE);
$this->addEntityRef('file_on_case_target_contact_id', ts('With Contact(s)'), array('multiple' => TRUE));
$this->add('text', 'file_on_case_activity_subject', ts('Subject'), array('size' => 50));
}
}

View file

@ -0,0 +1,177 @@
<?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 does pre processing for viewing an activity or their revisions.
*/
class CRM_Case_Form_ActivityView extends CRM_Core_Form {
/**
* Process the view.
*/
public function preProcess() {
$contactID = CRM_Utils_Request::retrieve('cid', 'Integer', $this, TRUE);
$activityID = CRM_Utils_Request::retrieve('aid', 'Integer', $this, TRUE);
$revs = CRM_Utils_Request::retrieve('revs', 'Boolean');
$caseID = CRM_Utils_Request::retrieve('caseID', 'Boolean');
$activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity',
$activityID,
'subject'
);
//check for required permissions, CRM-6264
if ($activityID &&
!CRM_Activity_BAO_Activity::checkPermission($activityID, CRM_Core_Action::VIEW)
) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
$this->assign('contactID', $contactID);
$this->assign('caseID', $caseID);
// CRM-9145
$this->assign('activityID', $activityID);
$xmlProcessor = new CRM_Case_XMLProcessor_Report();
$report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE);
$attachmentUrl = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityID);
if ($attachmentUrl) {
$report['fields'][] = array(
'label' => 'Attachment(s)',
'value' => $attachmentUrl,
'type' => 'Link',
);
}
$tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity');
if (!empty($tags)) {
$allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
foreach ($tags as $tid) {
$tags[$tid] = $allTag[$tid];
}
$report['fields'][] = array(
'label' => 'Tags',
'value' => implode('<br />', $tags),
'type' => 'String',
);
}
$this->assign('report', $report);
$latestRevisionID = CRM_Activity_BAO_Activity::getLatestActivityId($activityID);
$viewPriorActivities = array();
$priorActivities = CRM_Activity_BAO_Activity::getPriorAcitivities($activityID);
foreach ($priorActivities as $activityId => $activityValues) {
if (CRM_Case_BAO_Case::checkPermission($activityId, 'view', NULL, $contactID)) {
$viewPriorActivities[$activityId] = $activityValues;
}
}
if ($revs) {
CRM_Utils_System::setTitle(ts('Activity Revision History'));
$this->assign('revs', $revs);
$this->assign('result', $viewPriorActivities);
$this->assign('subject', $activitySubject);
$this->assign('latestRevisionID', $latestRevisionID);
}
else {
if (count($viewPriorActivities) > 1) {
$this->assign('activityID', $activityID);
}
if ($latestRevisionID != $activityID) {
$this->assign('latestRevisionID', $latestRevisionID);
}
}
$parentID = CRM_Activity_BAO_Activity::getParentActivity($activityID);
if ($parentID) {
$this->assign('parentID', $parentID);
}
//viewing activity should get diplayed in recent list.CRM-4670
$activityTypeID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id');
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
$activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID);
if (!empty($activityTargetContacts)) {
$recentContactId = $activityTargetContacts[0];
}
else {
$recentContactId = $contactID;
}
if (!isset($caseID)) {
$caseID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id');
}
$url = CRM_Utils_System::url('civicrm/case/activity/view',
"reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home"
);
$recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId);
// add the recently created Activity
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE);
$title = "";
if (isset($activitySubject)) {
$title = $activitySubject . ' - ';
}
$title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')';
$recentOther = array();
if (CRM_Case_BAO_Case::checkPermission($activityID, 'edit')) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/case/activity',
"reset=1&action=update&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"
);
}
if (CRM_Case_BAO_Case::checkPermission($activityID, 'delete')) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/case/activity',
"reset=1&action=delete&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"
);
}
CRM_Utils_Recent::add($title,
$url,
$activityID,
'Activity',
$recentContactId,
$recentContactDisplay,
$recentOther
);
}
}

View file

@ -0,0 +1,410 @@
<?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 case activity.
*/
class CRM_Case_Form_Case extends CRM_Core_Form {
/**
* The context
*
* @var string
*/
public $_context = 'case';
/**
* Case Id
*/
public $_caseId = NULL;
/**
* Client Id
*/
public $_currentlyViewedContactId = NULL;
/**
* Activity Type File
*/
public $_activityTypeFile = NULL;
/**
* Logged in contact Id
*/
public $_currentUserId = NULL;
/**
* Activity type Id
*/
public $_activityTypeId = NULL;
/**
* Activity type Id
*/
public $_activityId = NULL;
/**
* Action
*/
public $_action;
/**
* Case type id
*/
public $_caseTypeId = NULL;
/**
* Build the form object.
*/
public function preProcess() {
$this->_caseId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
if ($this->_action & CRM_Core_Action::ADD && !$this->_currentlyViewedContactId) {
// check for add contacts permissions
if (!CRM_Core_Permission::check('add contacts')) {
CRM_Utils_System::permissionDenied();
return;
}
}
//CRM-4418
if (!CRM_Core_Permission::checkActionPermission('CiviCase', $this->_action)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
return TRUE;
}
if (!$this->_caseId) {
$caseAttributes = array(
'case_type_id' => ts('Case Type'),
'status_id' => ts('Case Status'),
'medium_id' => ts('Activity Medium'),
);
foreach ($caseAttributes as $key => $label) {
if (!CRM_Case_BAO_Case::buildOptions($key, 'create')) {
CRM_Core_Error::fatal(ts('You do not have any active %1', array(1 => $label)));
}
}
}
if ($this->_action & CRM_Core_Action::ADD) {
$this->_activityTypeId = CRM_Core_OptionGroup::getValue('activity_type',
'Open Case',
'name'
);
if (!$this->_activityTypeId) {
CRM_Core_Error::fatal(ts('The Open Case activity type is missing or disabled. Please have your site administrator check Administer > Option Lists > Activity Types for the CiviCase component.'));
}
}
//check for case permissions.
if (!CRM_Case_BAO_Case::accessCiviCase()) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
if (($this->_action & CRM_Core_Action::ADD) &&
(!CRM_Core_Permission::check('access all cases and activities') &&
!CRM_Core_Permission::check('add cases')
)
) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
if ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId,
'Case'
)
) {
$this->assign('activityTypeFile', $this->_activityTypeFile);
}
$details = CRM_Case_PseudoConstant::caseActivityType(FALSE);
CRM_Utils_System::setTitle($details[$this->_activityTypeId]['label']);
$this->assign('activityType', $details[$this->_activityTypeId]['label']);
$this->assign('activityTypeDescription', $details[$this->_activityTypeId]['description']);
if (isset($this->_currentlyViewedContactId)) {
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $this->_currentlyViewedContactId;
if (!$contact->find(TRUE)) {
CRM_Core_Error::statusBounce(ts('Client contact does not exist: %1', array(1 => $this->_currentlyViewedContactId)));
}
$this->assign('clientName', $contact->display_name);
}
$session = CRM_Core_Session::singleton();
$this->_currentUserId = $session->get('userID');
//when custom data is included in this page
CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity');
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$className::preProcess($this);
$activityGroupTree = $this->_groupTree;
// for case custom fields to populate with defaults
if (!empty($_POST['hidden_custom'])) {
$params = CRM_Utils_Request::exportValues();
CRM_Custom_Form_CustomData::preProcess($this, NULL, CRM_Utils_Array::value('case_type_id', $params, $this->_caseTypeId), 1, 'Case', $this->_caseId);
CRM_Custom_Form_CustomData::buildQuickForm($this);
}
// so that grouptree is not populated with case fields, since the grouptree is used
// for populating activity custom fields.
$this->_groupTree = $activityGroupTree;
}
/**
* Set default values for the form.
*/
public function setDefaultValues() {
if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
return TRUE;
}
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$defaults = $className::setDefaultValues($this);
$defaults = array_merge($defaults, CRM_Custom_Form_CustomData::setDefaultValues($this));
return $defaults;
}
public function buildQuickForm() {
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
$this->assign('multiClient', $isMultiClient);
if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
$title = 'Delete';
if ($this->_action & CRM_Core_Action::RENEW) {
$title = 'Restore';
}
$this->addButtons(array(
array(
'type' => 'next',
'name' => $title,
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
return;
}
//need to assign custom data type and subtype to the template
$this->assign('customDataType', 'Case');
CRM_Custom_Form_CustomData::buildQuickForm($this);
// we don't want to show button on top of custom form
$this->assign('noPreCustomButton', TRUE);
$s = CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'subject');
if (!is_array($s)) {
$s = array();
}
$this->add('text', 'activity_subject', ts('Subject'),
array_merge($s, array(
'maxlength' => '128',
)), TRUE
);
$tags = CRM_Core_BAO_Tag::getColorTags('civicrm_case');
if (!empty($tags)) {
$this->add('select2', 'tag', ts('Tags'), $tags, FALSE,
array('class' => 'huge', 'multiple' => 'multiple')
);
}
// build tag widget
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case');
CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', NULL, FALSE, TRUE);
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Save'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$className::buildQuickForm($this);
}
/**
* Add local and global form rules.
*
* @return bool
*/
public function addRules() {
if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
return TRUE;
}
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$this->addFormRule(array($className, 'formRule'), $this);
$this->addFormRule(array('CRM_Case_Form_Case', 'formRule'), $this);
}
/**
* 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.
*/
public function postProcess() {
$transaction = new CRM_Core_Transaction();
// check if dedupe button, if so return.
$buttonName = $this->controller->getButtonName();
if (isset($this->_dedupeButtonName) && $buttonName == $this->_dedupeButtonName) {
return;
}
if ($this->_action & CRM_Core_Action::DELETE) {
$caseDelete = CRM_Case_BAO_Case::deleteCase($this->_caseId, TRUE);
if ($caseDelete) {
CRM_Core_Session::setStatus(ts('You can view and / or restore deleted cases by checking the "Deleted Cases" option under Find Cases.'), ts('Case Deleted'), 'success');
}
return;
}
if ($this->_action & CRM_Core_Action::RENEW) {
$caseRestore = CRM_Case_BAO_Case::restoreCase($this->_caseId);
if ($caseRestore) {
CRM_Core_Session::setStatus(ts('The selected case has been restored.'), ts('Restored'), 'success');
}
return;
}
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$params['now'] = date("Ymd");
// 1. call begin post process
if ($this->_activityTypeFile) {
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$className::beginPostProcess($this, $params);
}
if (!empty($params['hidden_custom']) &&
!isset($params['custom'])
) {
$params['custom'] = CRM_Core_BAO_CustomField::postProcess(
$params,
NULL,
'Case'
);
}
// 2. create/edit case
if (!empty($params['case_type_id'])) {
$params['case_type'] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $params['case_type_id'], 'name', 'id');
$params['subject'] = $params['activity_subject'];
}
$caseObj = CRM_Case_BAO_Case::create($params);
$params['case_id'] = $caseObj->id;
// unset any ids, custom data
unset($params['id'], $params['custom']);
// add tags if exists
$tagParams = array();
if (!empty($params['tag'])) {
$tagParams = array();
if (!is_array($params['tag'])) {
$params['tag'] = explode(',', $params['tag']);
}
foreach ($params['tag'] as $tag) {
$tagParams[$tag] = 1;
}
}
CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_case', $caseObj->id);
//save free tags
if (isset($params['case_taglist']) && !empty($params['case_taglist'])) {
CRM_Core_Form_Tag::postProcess($params['case_taglist'], $caseObj->id, 'civicrm_case', $this);
}
// user context
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseObj->id}"
);
CRM_Core_Session::singleton()->pushUserContext($url);
// 3. format activity custom data
if (!empty($params['hidden_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'
);
}
// 4. call end post process
if ($this->_activityTypeFile) {
$className::endPostProcess($this, $params);
}
CRM_Core_Session::setStatus($params['statusMsg'], ts('Saved'), 'success');
}
}

View file

@ -0,0 +1,533 @@
<?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 view mode for CiviCase.
*/
class CRM_Case_Form_CaseView extends CRM_Core_Form {
/**
* Check for merge cases.
* @var bool
*/
private $_mergeCases = FALSE;
/**
* Set variables up before form is built.
*/
public function preProcess() {
$this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET);
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
$this->assign('multiClient', $isMultiClient);
//pull the related cases.
$this->assign('showRelatedCases', FALSE);
if ($this->_showRelatedCases) {
$relatedCases = $this->get('relatedCases');
if (!isset($relatedCases)) {
$cId = CRM_Utils_Request::retrieve('cid', 'Integer');
$caseId = CRM_Utils_Request::retrieve('id', 'Integer');
$relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId);
}
$this->assign('relatedCases', $relatedCases);
$this->assign('showRelatedCases', TRUE);
CRM_Utils_System::setTitle(ts('Related Cases'));
return;
}
$this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities');
$this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases);
$this->assign('contactID', $this->_contactID = (int) $this->get('cid'));
$this->assign('caseID', $this->_caseID = (int) $this->get('id'));
// Access check.
if (!CRM_Case_BAO_Case::accessCase($this->_caseID, FALSE)) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
$fulltext = CRM_Utils_Request::retrieve('context', 'String');
if ($fulltext == 'fulltext') {
$this->assign('fulltext', $fulltext);
}
$this->assign('contactType', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type'));
$this->assign('userID', CRM_Core_Session::getLoggedInContactID());
//retrieve details about case
$params = array('id' => $this->_caseID);
$returnProperties = array('case_type_id', 'subject', 'status_id', 'start_date');
CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties);
$statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE);
$caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name');
$caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID);
$this->_caseDetails = array(
'case_type' => $caseType,
'case_status' => CRM_Utils_Array::value($values['case_status_id'], $statuses),
'case_subject' => CRM_Utils_Array::value('subject', $values),
'case_start_date' => $values['case_start_date'],
);
$this->_caseType = $caseTypeName;
$this->assign('caseDetails', $this->_caseDetails);
$reportUrl = CRM_Utils_System::url('civicrm/case/report',
"reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=",
FALSE, NULL, FALSE
);
$this->assign('reportUrl', $reportUrl);
// add to recently viewed
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home"
);
$displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID);
$this->assign('displayName', $displayName);
CRM_Utils_System::setTitle($displayName . ' - ' . $caseType);
$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case',
"action=delete&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home"
);
}
// Add the recently viewed case
CRM_Utils_Recent::add($displayName . ' - ' . $caseType,
$url,
$this->_caseID,
'Case',
$this->_contactID,
NULL,
$recentOther
);
//get the related cases for given case.
$relatedCases = $this->get('relatedCases');
if (!isset($relatedCases)) {
$relatedCases = CRM_Case_BAO_Case::getRelatedCases($this->_caseID);
$relatedCases = empty($relatedCases) ? FALSE : $relatedCases;
$this->set('relatedCases', $relatedCases);
}
$this->assign('hasRelatedCases', (bool) $relatedCases);
if ($relatedCases) {
$this->assign('relatedCaseLabel', ts('%1 Related Case', array(
'count' => count($relatedCases),
'plural' => '%1 Related Cases',
)));
$this->assign('relatedCaseUrl', CRM_Utils_System::url('civicrm/contact/view/case', array(
'id' => $this->_caseID,
'cid' => $this->_contactID,
'relatedCases' => 1,
'action' => 'view',
)));
}
$entitySubType = !empty($values['case_type_id']) ? $values['case_type_id'] : NULL;
$this->assign('caseTypeID', $entitySubType);
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Case',
NULL,
$this->_caseID,
NULL,
$entitySubType
);
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_caseID);
}
/**
* Set default values for the form.
*
* @return array;
*/
public function setDefaultValues() {
$defaults = array();
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
//this call is for show related cases.
if ($this->_showRelatedCases) {
return;
}
$allowedRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactID);
CRM_Core_Resources::singleton()
->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header')
->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js', 2, 'html-header')
->addVars('relationshipTypes', CRM_Contact_Form_Relationship::getRelationshipTypeMetadata($allowedRelationshipTypes));
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles');
$reports = $xmlProcessor->get($this->_caseType, 'ActivitySets');
//adding case manager.CRM-4510.
$managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType);
if (!empty($managerRoleId)) {
$caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')';
}
$aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE);
$allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name');
$emailActivityType = array_search('Email', $allActTypes);
$pdfActivityType = array_search('Print PDF Letter', $allActTypes);
if ($pdfActivityType) {
$this->assign('exportDoc', CRM_Utils_System::url('civicrm/activity/pdf/add',
"action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$pdfActivityType"));
}
// remove Open Case activity type since we're inside an existing case
if ($openActTypeId = array_search('Open Case', $allActTypes)) {
unset($aTypes[$openActTypeId]);
}
// Only show "link cases" activity if other cases exist.
$linkActTypeId = array_search('Link Cases', $allActTypes);
if ($linkActTypeId) {
$count = civicrm_api3('Case', 'getcount', array(
'check_permissions' => TRUE,
'id' => array('!=' => $this->_caseID),
'is_deleted' => 0,
));
if (!$count) {
unset($aTypes[$linkActTypeId]);
}
}
if (!$xmlProcessor->getNaturalActivityTypeSort()) {
asort($aTypes);
}
$activityLinks = array('' => ts('Add Activity'));
foreach ($aTypes as $type => $label) {
if ($type == $emailActivityType) {
$url = CRM_Utils_System::url('civicrm/activity/email/add',
"action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype=$type",
FALSE, NULL, FALSE
);
}
elseif ($type == $pdfActivityType) {
$url = CRM_Utils_System::url('civicrm/activity/pdf/add',
"action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$type",
FALSE, NULL, FALSE);
}
else {
$url = CRM_Utils_System::url('civicrm/case/activity',
"action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$type",
FALSE, NULL, FALSE
);
}
$activityLinks[$url] = $label;
}
$this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu fa-calendar-check-o twenty'));
if ($this->_hasAccessToAllCases) {
$this->add('select', 'report_id', '',
array('' => ts('Activity Audit')) + $reports,
FALSE,
array('class' => 'crm-select2 crm-action-menu fa-list-alt')
);
$this->add('select', 'timeline_id', '',
array('' => ts('Add Timeline')) + $reports,
FALSE,
array('class' => 'crm-select2 crm-action-menu fa-list-ol')
);
}
$this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement'));
$this->buildMergeCaseForm();
//call activity form
self::activityForm($this, $aTypes);
//get case related relationships (Case Role)
$caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID);
//save special label because we unset it in the loop
$managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId];
foreach ($caseRelationships as $key => & $value) {
if (!empty($managerRoleId)) {
if ($managerRoleId == $value['relation_type']) {
$value['relation'] = $managerLabel;
}
}
//calculate roles that don't have relationships
if (!empty($caseRoles[$value['relation_type']])) {
unset($caseRoles[$value['relation_type']]);
}
}
$this->assign('caseRelationships', $caseRelationships);
//also add client as role. CRM-4438
$caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID);
$this->assign('caseRoles', $caseRoles);
// Retrieve ALL client relationships
$relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID,
CRM_Contact_BAO_Relationship::CURRENT,
0, 0, 0, NULL, NULL, FALSE
);
// Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles
// so they don't show up twice.
$clientRelationships = array();
foreach ($relClient as $r) {
if (!array_key_exists($r['id'], $caseRelationships)) {
$clientRelationships[] = $r;
}
}
$this->assign('clientRelationships', $clientRelationships);
// Now global contact list that appears on all cases.
$globalGroupInfo = array();
CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo);
$this->assign('globalGroupInfo', $globalGroupInfo);
// List relationship types for adding an arbitrary new role to the case
$this->add('select',
'role_type',
ts('Relationship Type'),
array('' => ts('- select type -')) + $allowedRelationshipTypes,
FALSE,
array('class' => 'crm-select2 twenty', 'data-select-params' => '{"allowClear": false}')
);
$hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID);
if (is_array($hookCaseSummary)) {
$this->assign('hookCaseSummary', $hookCaseSummary);
}
$allTags = CRM_Core_BAO_Tag::getColorTags('civicrm_case');
if (!empty($allTags)) {
$this->add('select2', 'case_tag', ts('Tags'), $allTags, FALSE,
array('id' => 'tags', 'multiple' => 'multiple')
);
$tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case');
foreach ($tags as $tid) {
$tagInfo = CRM_Utils_Array::findInTree($tid, $allTags);
if ($tagInfo) {
$tags[$tid] = $tagInfo;
}
else {
unset($tags[$tid]);
}
}
$this->setDefaults(array('case_tag' => implode(',', array_keys($tags))));
$this->assign('tags', $tags);
$this->assign('showTags', TRUE);
}
else {
$this->assign('showTags', FALSE);
}
// build tagset widget
// see if we have any tagsets which can be assigned to cases
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case');
$tagSetTags = array();
if ($parentNames) {
$this->assign('showTags', TRUE);
$tagSetItems = civicrm_api3('entityTag', 'get', array(
'entity_id' => $this->_caseID,
'entity_table' => 'civicrm_case',
'tag_id.parent_id.is_tagset' => 1,
'options' => array('limit' => 0),
'return' => array("tag_id.parent_id", "tag_id.parent_id.name", "tag_id.name"),
));
foreach ($tagSetItems['values'] as $tag) {
$tagSetTags += array(
$tag['tag_id.parent_id'] => array(
'name' => $tag['tag_id.parent_id.name'],
'items' => array(),
),
);
$tagSetTags[$tag['tag_id.parent_id']]['items'][] = $tag['tag_id.name'];
}
}
$this->assign('tagSetTags', $tagSetTags);
CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE);
$this->addButtons(array(
array(
'type' => 'cancel',
'name' => ts('Done'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
)
);
}
/**
* Process the form.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
$buttonName = $this->controller->getButtonName();
// user context
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_contactID}&id={$this->_caseID}&show=1"
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
if (!empty($params['timeline_id']) && !empty($_POST['_qf_CaseView_next'])) {
civicrm_api3('Case', 'addtimeline', array(
'case_id' => $this->_caseID,
'timeline' => $params['timeline_id'],
));
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$reports = $xmlProcessor->get($this->_caseType, 'ActivitySets');
CRM_Core_Session::setStatus(ts('Activities from the %1 activity set have been added to this case.',
array(1 => $reports[$params['timeline_id']])
), ts('Done'), 'success');
}
elseif ($this->_mergeCases &&
$buttonName == '_qf_CaseView_next_merge_case'
) {
$mainCaseId = $params['merge_case_id'];
$otherCaseId = $this->_caseID;
//merge two cases.
CRM_Case_BAO_Case::mergeCases($this->_contactID, $mainCaseId, NULL, $otherCaseId);
//redirect user to main case view.
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_contactID}&id={$mainCaseId}&show=1"
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
}
/**
* Build the activity selector/datatable
* @param CRM_Core_Form $form
* @param array $aTypes
* To include acivities related to current case id $form->_caseID.
*/
public static function activityForm($form, $aTypes = array()) {
$caseRelationships = CRM_Case_BAO_Case::getCaseRoles($form->_contactID, $form->_caseID);
//build reporter select
$reporters = array("" => ts(' - any reporter - '));
foreach ($caseRelationships as $key => & $value) {
$reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )";
}
$form->add('select', 'reporter_id', ts('Reporter/Role'), $reporters, FALSE, array('id' => 'reporter_id_' . $form->_caseID));
// take all case activity types for search filter, CRM-7187
$aTypesFilter = array();
$allCaseActTypes = CRM_Case_PseudoConstant::caseActivityType();
foreach ($allCaseActTypes as $typeDetails) {
if (!in_array($typeDetails['name'], array('Open Case'))) {
$aTypesFilter[$typeDetails['id']] = CRM_Utils_Array::value('label', $typeDetails);
}
}
$aTypesFilter = $aTypesFilter + $aTypes;
asort($aTypesFilter);
$form->add('select', 'activity_type_filter_id', ts('Activity Type'), array('' => ts('- select activity type -')) + $aTypesFilter, FALSE, array('id' => 'activity_type_filter_id_' . $form->_caseID));
$activityStatus = CRM_Core_PseudoConstant::activityStatus();
$form->add('select', 'status_id', ts('Status'), array("" => ts(' - any status - ')) + $activityStatus, FALSE, array('id' => 'status_id_' . $form->_caseID));
// activity dates
$form->addDate('activity_date_low_' . $form->_caseID, ts('Activity Dates - From'), FALSE, array('formatType' => 'searchDate'));
$form->addDate('activity_date_high_' . $form->_caseID, ts('To'), FALSE, array('formatType' => 'searchDate'));
if (CRM_Core_Permission::check('administer CiviCRM')) {
$form->add('checkbox', 'activity_deleted', ts('Deleted Activities'), '', FALSE, array('id' => 'activity_deleted_' . $form->_caseID));
}
}
/**
* Form elements for merging cases
*/
public function buildMergeCaseForm() {
$otherCases = array();
$result = civicrm_api3('Case', 'get', array(
'check_permissions' => TRUE,
'contact_id' => $this->_contactID,
'is_deleted' => 0,
'id' => array('!=' => $this->_caseID),
'return' => array('id', 'start_date', 'case_type_id.title'),
));
foreach ($result['values'] as $id => $case) {
$otherCases[$id] = "#$id: {$case['case_type_id.title']} " . ts('(opened %1)', array(1 => $case['start_date']));
}
$this->assign('mergeCases', $this->_mergeCases = (bool) $otherCases);
if ($otherCases) {
$this->add('select', 'merge_case_id',
ts('Select Case for Merge'),
array(
'' => ts('- select case -'),
) + $otherCases,
FALSE,
array('class' => 'crm-select2 huge')
);
$this->addElement('submit',
$this->getButtonName('next', 'merge_case'),
ts('Merge'),
array(
'class' => 'hiddenElement',
)
);
}
}
}

View file

@ -0,0 +1,158 @@
<?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 custom data
*
* It delegates the work to lower level subclasses and integrates the changes
* back in. It also uses a lot of functionality with the CRM API's, so any change
* made here could potentially affect the API etc. Be careful, be aware, use unit tests.
*/
class CRM_Case_Form_CustomData extends CRM_Core_Form {
/**
* The entity id, used when editing/creating custom data
*
* @var int
*/
protected $_entityID;
/**
* Entity sub type of the table id.
*
* @var string
*/
protected $_subTypeID;
/**
* Pre processing work done here.
*
* gets session variables for table name, id of entity in table, type of entity and stores them.
*/
public function preProcess() {
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE);
$this->_entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', $this, TRUE);
$this->_subTypeID = CRM_Utils_Request::retrieve('subType', 'Positive', $this, TRUE);
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Case',
NULL,
$this->_entityID,
$this->_groupID,
$this->_subTypeID
);
// simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
// Array contains only one item
foreach ($groupTree as $groupValues) {
$this->_customTitle = $groupValues['title'];
CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $groupValues['title'])));
}
$this->_defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults);
$this->setDefaults($this->_defaults);
CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree);
//need to assign custom data type and subtype to the template
$this->assign('entityID', $this->_entityID);
$this->assign('groupID', $this->_groupID);
$this->assign('subType', $this->_subTypeID);
$this->assign('contactID', $this->_contactID);
}
/**
* Build the form object.
*/
public function buildQuickForm() {
// make this form an upload since we dont know if the custom data injected dynamically
// is of type file etc
$this->addButtons(array(
array(
'type' => 'upload',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
}
/**
* Process the user submitted custom data values.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
$transaction = new CRM_Core_Transaction();
CRM_Core_BAO_CustomValueTable::postProcess($params,
'civicrm_case',
$this->_entityID,
'Case'
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&id={$this->_entityID}&cid={$this->_contactID}&action=view"));
$session = CRM_Core_Session::singleton();
$activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Change Custom Data', 'name');
$activityParams = array(
'activity_type_id' => $activityTypeID,
'source_contact_id' => $session->get('userID'),
'is_auto' => TRUE,
'subject' => $this->_customTitle . " : change data",
'status_id' => CRM_Core_OptionGroup::getValue('activity_status',
'Completed',
'name'
),
'target_contact_id' => $this->_contactID,
'details' => json_encode($this->_defaults),
'activity_date_time' => date('YmdHis'),
);
$activity = CRM_Activity_BAO_Activity::create($activityParams);
$caseParams = array(
'activity_id' => $activity->id,
'case_id' => $this->_entityID,
);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
$transaction->commit();
}
}

View file

@ -0,0 +1,130 @@
<?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 assigns the current case to another client.
*/
class CRM_Case_Form_EditClient extends CRM_Core_Form {
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
//get current client name.
$this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($cid));
//set the context.
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$cid}&selectedChild=case");
if ($context == 'search') {
$qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
//validate the qfKey
$urlParams = 'force=1';
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&qfKey=$qfKey";
}
$url = CRM_Utils_System::url('civicrm/case/search', $urlParams);
}
elseif ($context == 'dashboard') {
$url = CRM_Utils_System::url('civicrm/case', 'reset=1');
}
elseif (in_array($context, array(
'dashlet',
'dashletFullscreen',
))) {
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addEntityRef('reassign_contact_id', ts('Select Contact'), array('create' => TRUE), TRUE);
$this->addButtons(array(
array(
'type' => 'done',
'name' => ts('Reassign Case'),
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
// This form may change the url structure so should not submit via ajax
$this->preventAjaxSubmit();
}
public function addRules() {
$this->addFormRule(array(get_class($this), 'formRule'), $this);
}
/**
* @param $vals
* @param $rule
* @param CRM_Core_Form $form
*
* @return array
*/
public static function formRule($vals, $rule, $form) {
$errors = array();
if (empty($vals['reassign_contact_id']) || $vals['reassign_contact_id'] == $form->get('cid')) {
$errors['reassign_contact_id'] = ts("Please select a different contact.");
}
return $errors;
}
/**
* Process the form.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
//assign case to another client.
$mainCaseId = CRM_Case_BAO_Case::mergeCases($params['reassign_contact_id'], $this->get('id'), $this->get('cid'), NULL, TRUE);
// user context
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$params['reassign_contact_id']}&id={$mainCaseId[0]}&show=1"
);
CRM_Core_Session::singleton()->pushUserContext($url);
}
}

View file

@ -0,0 +1,132 @@
<?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 case report.
*/
class CRM_Case_Form_Report extends CRM_Core_Form {
/**
* Case Id
*/
public $_caseID = NULL;
/**
* Client Id
*/
public $_clientID = NULL;
/**
* Activity set name
*/
public $_activitySetName = NULL;
public $_report = NULL;
/**
* Build the form object.
*/
public function preProcess() {
$this->_caseID = CRM_Utils_Request::retrieve('caseid', 'Integer', $this, TRUE);
$this->_clientID = CRM_Utils_Request::retrieve('cid', 'Integer', $this, TRUE);
$this->_activitySetName = CRM_Utils_Request::retrieve('asn', 'String', $this, TRUE);
$this->_report = $this->get('report');
if ($this->_report) {
$this->assign_by_ref('report', $this->_report);
}
// user context
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_clientID}&id={$this->_caseID}&show=1"
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
public function buildQuickForm() {
if ($this->_report) {
return;
}
$includeActivites = array(
1 => ts('All Activities'),
2 => ts('Exclude Completed Activities'),
);
$includeActivitesGroup = $this->addRadio('include_activities',
NULL,
$includeActivites,
NULL,
'&nbsp;',
TRUE
);
$includeActivitesGroup->setValue(1);
$this->add('checkbox',
'is_redact',
ts('Redact (hide) Client and Service Provider Data')
);
$this->addButtons(array(
array(
'type' => 'refresh',
'name' => ts('Generate Report'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
// We want this form to redirect to a full page
$this->preventAjaxSubmit();
}
/**
* Process the form submission.
*/
public function postProcess() {
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$xmlProcessor = new CRM_Case_XMLProcessor_Report();
$contents = $xmlProcessor->run($this->_clientID,
$this->_caseID,
$this->_activitySetName,
$params
);
$this->set('report', $contents);
}
}

View file

@ -0,0 +1,434 @@
<?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 file is for Case search.
*/
class CRM_Case_Form_Search extends CRM_Core_Form_Search {
/**
* The params that are sent to the query
*
* @var array
*/
protected $_queryParams;
/**
* Are we restricting ourselves to a single contact
*
* @var boolean
*/
protected $_single = FALSE;
/**
* Are we restricting ourselves to a single contact
*
* @var boolean
*/
protected $_limit = NULL;
/**
* Prefix for the controller
*/
protected $_prefix = 'case_';
/**
* Processing needed for buildForm and later.
*/
public function preProcess() {
$this->set('searchFormName', 'Search');
//check for civicase access.
if (!CRM_Case_BAO_Case::accessCiviCase()) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
//validate case configuration.
$configured = CRM_Case_BAO_Case::isCaseConfigured();
$this->assign('notConfigured', !$configured['configured']);
if (!$configured['configured']) {
return;
}
/**
* set the button names
*/
$this->_searchButtonName = $this->getButtonName('refresh');
$this->_actionButtonName = $this->getButtonName('next', 'action');
$this->_done = FALSE;
$this->defaults = array();
/*
* we allow the controller to set force/reset externally, useful when we are being
* driven by the wizard framework
*/
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean');
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this);
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
$this->assign('context', $this->_context);
// get user submitted values
// get it from controller only if form has been submitted, else preProcess has set this
if (!empty($_POST) && !$this->controller->isModal()) {
$this->_formValues = $this->controller->exportValues($this->_name);
}
else {
$this->_formValues = $this->get('formValues');
}
if (empty($this->_formValues)) {
if (isset($this->_ssID)) {
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
}
}
if ($this->_force) {
$this->postProcess();
$this->set('force', 0);
}
$sortID = NULL;
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
);
}
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
$selector = new CRM_Case_Selector_Search($this->_queryParams,
$this->_action,
NULL,
$this->_single,
$this->_limit,
$this->_context
);
$prefix = NULL;
if ($this->_context == 'user') {
$prefix = $this->_prefix;
}
$this->assign("{$prefix}limit", $this->_limit);
$this->assign("{$prefix}single", $this->_single);
$controller = new CRM_Core_Selector_Controller($selector,
$this->get(CRM_Utils_Pager::PAGE_ID),
$sortID,
CRM_Core_Action::VIEW,
$this,
CRM_Core_Selector_Controller::TRANSFER,
$prefix
);
$controller->setEmbedded(TRUE);
$controller->moveFromSessionToTemplate();
$this->assign('summary', $this->get('summary'));
}
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
$this->addSortNameField();
CRM_Case_BAO_Query::buildSearchForm($this);
$rows = $this->get('rows');
if (is_array($rows)) {
if (!$this->_single) {
$this->addRowSelectors($rows);
}
$permission = CRM_Core_Permission::getPermission();
$tasks = CRM_Case_Task::permissionedTaskTitles($permission);
if (!empty($this->_formValues['case_deleted'])) {
unset($tasks[1]);
}
else {
unset($tasks[4]);
}
$this->addTaskMenu($tasks);
}
}
/**
* Get the label for the sortName field if email searching is on.
*
* (email searching is a setting under search preferences).
*
* @return string
*/
protected function getSortNameLabelWithEmail() {
return ts('Client Name or Email');
}
/**
* Get the label for the sortName field if email searching is off.
*
* (email searching is a setting under search preferences).
*
* @return string
*/
protected function getSortNameLabelWithOutEmail() {
return ts('Client Name');
}
/**
* The post processing of the form gets done here.
*
* Key things done during post processing are
* - check for reset or next request. if present, skip post procesing.
* - now check if user requested running a saved search, if so, then
* the form values associated with the saved search are used for searching.
* - if user has done a submit with new values the regular post submissing is
* done.
* The processing consists of using a Selector / Controller framework for getting the
* search results.
*/
public function postProcess() {
if ($this->_done) {
return;
}
$this->_done = TRUE;
$this->_formValues = $this->controller->exportValues($this->_name);
$this->fixFormValues();
if (isset($this->_ssID) && empty($_POST)) {
// if we are editing / running a saved search and the form has not been posted
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
}
//search for civicase
if (!$this->_force) {
if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner']) {
$this->_formValues['case_owner'] = 0;
}
}
if (empty($this->_formValues['case_deleted'])) {
$this->_formValues['case_deleted'] = 0;
}
CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
$this->set('formValues', $this->_formValues);
$this->set('queryParams', $this->_queryParams);
$buttonName = $this->controller->getButtonName();
if ($buttonName == $this->_actionButtonName) {
// check actionName and if next, then do not repeat a search, since we are going to the next page
// hack, make sure we reset the task values
$stateMachine = $this->controller->getStateMachine();
$formName = $stateMachine->getTaskFormName();
$this->controller->resetPage($formName);
return;
}
$sortID = NULL;
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
);
}
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
$selector = new CRM_Case_Selector_Search($this->_queryParams,
$this->_action,
NULL,
$this->_single,
$this->_limit,
$this->_context
);
$selector->setKey($this->controller->_key);
$prefix = NULL;
if ($this->_context == 'user') {
$prefix = $this->_prefix;
}
$this->assign("{$prefix}limit", $this->_limit);
$this->assign("{$prefix}single", $this->_single);
$controller = new CRM_Core_Selector_Controller($selector,
$this->get(CRM_Utils_Pager::PAGE_ID),
$sortID,
CRM_Core_Action::VIEW,
$this,
CRM_Core_Selector_Controller::SESSION,
$prefix
);
$controller->setEmbedded(TRUE);
$query = &$selector->getQuery();
if ($this->_context == 'user') {
$query->setSkipPermission(TRUE);
}
$controller->run();
}
/**
* Add the rules (mainly global rules) for form.
*
* All local rules are added near the element
*
* @see valid_date
*/
public function addRules() {
$this->addFormRule(array('CRM_Case_Form_Search', 'formRule'));
}
/**
* Global validation rules for the form.
*
* @param array $fields
* Posted values of the form.
*
* @return array|bool
*/
public static function formRule($fields) {
$errors = array();
if (!empty($errors)) {
return $errors;
}
return TRUE;
}
/**
* Set the default form values.
*
*
* @return array
* the default array reference
*/
public function setDefaultValues() {
$defaults = array();
$defaults = $this->_formValues;
return $defaults;
}
public function fixFormValues() {
if (!$this->_force) {
return;
}
$caseStatus = CRM_Utils_Request::retrieve('status', 'Positive');
if ($caseStatus) {
$this->_formValues['case_status_id'] = $caseStatus;
$this->_defaults['case_status_id'] = $caseStatus;
}
$caseType = CRM_Utils_Request::retrieve('type', 'Positive');
if ($caseType) {
$this->_formValues['case_type_id'] = (array) $caseType;
$this->_defaults['case_type_id'] = (array) $caseType;
}
$caseFromDate = CRM_Utils_Request::retrieve('pstart', 'Date');
if ($caseFromDate) {
list($date) = CRM_Utils_Date::setDateDefaults($caseFromDate);
$this->_formValues['case_start_date_low'] = $date;
$this->_defaults['case_start_date_low'] = $date;
}
$caseToDate = CRM_Utils_Request::retrieve('pend', 'Date');
if ($caseToDate) {
list($date) = CRM_Utils_Date::setDateDefaults($caseToDate);
$this->_formValues['case_start_date_high'] = $date;
$this->_defaults['case_start_date_high'] = $date;
}
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
if ($cid) {
$cid = CRM_Utils_Type::escape($cid, 'Integer');
if ($cid > 0) {
$this->_formValues['contact_id'] = $cid;
list($display, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($cid);
$this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid,
'sort_name'
);
// also assign individual mode to the template
$this->_single = TRUE;
}
}
else {
// First, if "all" is stored in the session, default to all cases, otherwise default to no selection.
$session = CRM_Core_Session::singleton();
if (CRM_Utils_Request::retrieve('all', 'Positive', $session)) {
$this->_formValues['case_owner'] = 1;
$this->_defaults['case_owner'] = 1;
}
else {
$this->_formValues['case_owner'] = 0;
$this->_defaults['case_owner'] = 0;
}
// Now if case_owner is set in the url/post, use that instead.
$caseOwner = CRM_Utils_Request::retrieve('case_owner', 'Positive');
if ($caseOwner) {
$this->_formValues['case_owner'] = $caseOwner;
$this->_defaults['case_owner'] = $caseOwner;
}
}
}
/**
* @return null
*/
public function getFormValues() {
return NULL;
}
/**
* Return a descriptive name for the page, used in wizard header
*
* @return string
*/
public function getTitle() {
return ts('Find Cases');
}
}

View file

@ -0,0 +1,170 @@
<?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 task actions for CiviEvent.
*/
class CRM_Case_Form_Task extends CRM_Core_Form {
/**
* The task being performed
*
* @var int
*/
protected $_task;
/**
* The additional clause that we restrict the search with
*
* @var string
*/
protected $_componentClause = NULL;
/**
* The array that holds all the component ids
*
* @var array
*/
protected $_componentIds;
/**
* The array that holds all the case ids
*
* @var array
*/
public $_caseIds;
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
self::preProcessCommon($this);
}
/**
* @param CRM_Core_Form $form
* @param bool $useTable
*/
public static function preProcessCommon(&$form, $useTable = FALSE) {
$form->_caseIds = array();
$values = $form->controller->exportValues($form->get('searchFormName'));
$form->_task = $values['task'];
$caseTasks = CRM_Case_Task::tasks();
$form->assign('taskName', $caseTasks[$form->_task]);
$ids = array();
if ($values['radio_ts'] == 'ts_sel') {
foreach ($values as $name => $value) {
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
$ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
}
}
}
else {
$queryParams = $form->get('queryParams');
$query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
CRM_Contact_BAO_Query::MODE_CASE
);
$query->_distinctComponentClause = " ( civicrm_case.id )";
$query->_groupByComponentClause = " GROUP BY civicrm_case.id ";
$result = $query->searchQuery(0, 0, NULL);
while ($result->fetch()) {
$ids[] = $result->case_id;
}
}
if (!empty($ids)) {
$form->_componentClause = ' civicrm_case.id IN ( ' . implode(',', $ids) . ' ) ';
$form->assign('totalSelectedCases', count($ids));
}
$form->_caseIds = $form->_componentIds = $ids;
//set the context for redirection for any task actions
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
$urlParams = 'force=1';
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&qfKey=$qfKey";
}
$session = CRM_Core_Session::singleton();
$searchFormName = strtolower($form->get('searchFormName'));
if ($searchFormName == 'search') {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/case/search', $urlParams));
}
else {
$session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/$searchFormName",
$urlParams
));
}
}
/**
* Given the signer id, compute the contact id
* since its used for things like send email
*/
public function setContactIDs() {
$this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_caseIds,
'civicrm_case_contact'
);
}
/**
* Simple shell that derived classes can call to add buttons to
* the form with a customized title for the main Submit
*
* @param string $title
* Title of the main button.
* @param string $nextType
* Button type for the form after processing.
* @param string $backType
* @param bool $submitOnce
*/
public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
$this->addButtons(array(
array(
'type' => $nextType,
'name' => $title,
'isDefault' => TRUE,
),
array(
'type' => $backType,
'name' => ts('Cancel'),
),
)
);
}
}

View file

@ -0,0 +1,100 @@
<?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 provides the functionality to delete a group of case records.
*/
class CRM_Case_Form_Task_Delete extends CRM_Case_Form_Task {
/**
* Are we operating in "single mode", i.e. deleting one
* specific case?
*
* @var boolean
*/
protected $_single = FALSE;
/**
* Are we moving case to Trash.
*
* @var boolean
*/
public $_moveToTrash = TRUE;
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
if (!CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
parent::preProcess();
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addDefaultButtons(ts('Delete cases'), 'done');
}
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess() {
$deleted = $failed = 0;
foreach ($this->_caseIds as $caseId) {
if (CRM_Case_BAO_Case::deleteCase($caseId, $this->_moveToTrash)) {
$deleted++;
}
else {
$failed++;
}
}
if ($deleted) {
if ($this->_moveToTrash) {
$msg = ts('%count case moved to trash.', array('plural' => '%count cases moved to trash.', 'count' => $deleted));
}
else {
$msg = ts('%count case permanently deleted.', array('plural' => '%count cases permanently 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');
}
}
}

View file

@ -0,0 +1,96 @@
<?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 provides the functionality to create PDF letter for a group of contacts.
*/
class CRM_Case_Form_Task_PDF extends CRM_Case_Form_Task {
/**
* All the existing templates in the system.
*
* @var array
*/
public $_templates = NULL;
public $_single = NULL;
public $_cid = NULL;
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
$this->skipOnHold = $this->skipDeceased = FALSE;
parent::preProcess();
$this->setContactIDs();
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
}
/**
* Set defaults for the pdf.
*
* @return array
*/
public function setDefaultValues() {
return CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
}
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
}
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess() {
CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
}
/**
* List available tokens for this form.
*
* @return array
*/
public function listTokens() {
$tokens = CRM_Core_SelectValues::contactTokens();
foreach ($this->_caseIds as $key => $caseId) {
$caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'case_type_id');
$tokens += CRM_Core_SelectValues::caseTokens($caseTypeId);
}
return $tokens;
}
}

View file

@ -0,0 +1,98 @@
<?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 provides the functionality to save a search
* Saved Searches are used for saving frequently used queries
*/
class CRM_Case_Form_Task_Print extends CRM_Case_Form_Task {
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
parent::preProcess();
// set print view, so that print templates are called
$this->controller->setPrint(1);
// get the formatted params
$queryParams = $this->get('queryParams');
$sortID = NULL;
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
);
}
$selector = new CRM_Case_Selector_Search($queryParams, $this->_action, $this->_componentClause);
$controller = new CRM_Core_Selector_Controller($selector, NULL, $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SCREEN);
$controller->setEmbedded(TRUE);
$controller->run();
}
/**
* Build the form object.
*
* It consists of
* - displaying the QILL (query in local language)
* - displaying elements for saving the search
*/
public function buildQuickForm() {
//
// just need to add a javacript to popup the window for printing
//
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Print Case List'),
'js' => array('onclick' => 'window.print()'),
'isDefault' => TRUE,
),
array(
'type' => 'back',
'name' => ts('Done'),
),
)
);
}
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess() {
// redirect to the main search page after printing is over
}
}

View file

@ -0,0 +1,88 @@
<?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 provides the functionality to restore a group of participations.
*/
class CRM_Case_Form_Task_Restore extends CRM_Case_Form_Task {
/**
* Are we operating in "single mode", i.e. deleting one
* specific case?
*
* @var boolean
*/
protected $_single = FALSE;
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
parent::preProcess();
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addDefaultButtons(ts('Restore Cases'), 'done');
}
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess() {
$restoredCases = $failed = 0;
foreach ($this->_caseIds as $caseId) {
if (CRM_Case_BAO_Case::restoreCase($caseId)) {
$restoredCases++;
}
else {
$failed++;
}
}
if ($restoredCases) {
$msg = ts('%count case restored from trash.', array(
'plural' => '%count cases restored from trash.',
'count' => $restoredCases,
));
CRM_Core_Session::setStatus($msg, ts('Restored'), 'success');
}
if ($failed) {
CRM_Core_Session::setStatus(ts('1 could not be restored.', array('plural' => '%count could not be restored.', 'count' => $failed)), ts('Error'), 'error');
}
}
}

View file

@ -0,0 +1,59 @@
<?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
*/
/**
* Used for displaying results.
*/
class CRM_Case_Form_Task_Result extends CRM_Case_Form_Task {
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addButtons(array(
array(
'type' => 'done',
'name' => ts('Done'),
'isDefault' => TRUE,
),
)
);
}
}

View file

@ -0,0 +1,85 @@
<?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 provides the functionality to save a search
* Saved Searches are used for saving frequently used queries
*/
class CRM_Case_Form_Task_SearchTaskHookSample extends CRM_Case_Form_Task {
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
parent::preProcess();
$rows = array();
// display name and email of all contact ids
$caseIDs = implode(',', $this->_caseIds);
$statusId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'case_status', 'id', 'name');
$query = "
SELECT ct.display_name as display_name,
cs.start_date as start_date,
ov.label as status
FROM civicrm_case cs
INNER JOIN civicrm_case_contact cc ON ( cs.id = cc.case_id)
INNER JOIN civicrm_contact ct ON ( cc.contact_id = ct.id)
LEFT JOIN civicrm_option_value ov ON (cs.status_id = ov.value AND ov.option_group_id = {$statusId} )
WHERE cs.id IN ( {$caseIDs} )";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$rows[] = array(
'display_name' => $dao->display_name,
'start_date' => CRM_Utils_Date::customFormat($dao->start_date),
'status' => $dao->status,
);
}
$this->assign('rows', $rows);
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addButtons(array(
array(
'type' => 'done',
'name' => ts('Done'),
'isDefault' => TRUE,
),
)
);
}
}

View file

@ -0,0 +1,284 @@
<?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 |
+--------------------------------------------------------------------+
*/
/**
* This class introduces component to the system and provides all the
* information about it. It needs to extend CRM_Core_Component_Info
* abstract class.
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Case_Info extends CRM_Core_Component_Info {
/**
* @inheritDoc
*/
protected $keyword = 'case';
/**
* @inheritDoc
* @return array
*/
public function getInfo() {
return array(
'name' => 'CiviCase',
'translatedName' => ts('CiviCase'),
'title' => ts('CiviCase Engine'),
'search' => 1,
'showActivitiesInCore' => 0,
);
}
/**
* @inheritDoc
*/
public function getAngularModules() {
global $civicrm_root;
$result = array();
$result['crmCaseType'] = include "$civicrm_root/ang/crmCaseType.ang.php";
return $result;
}
/**
* @inheritDoc
* @return array
* @throws CRM_Core_Exception
*/
public function getManagedEntities() {
$entities = array_merge(
CRM_Case_ManagedEntities::createManagedCaseTypes(),
CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()),
CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton())
);
return $entities;
}
/**
* @inheritDoc
* @param bool $getAllUnconditionally
* @param bool $descriptions
* Whether to return permission descriptions
*
* @return array
*/
public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
$permissions = array(
'delete in CiviCase' => array(
ts('delete in CiviCase'),
ts('Delete cases'),
),
'administer CiviCase' => array(
ts('administer CiviCase'),
ts('Define case types, access deleted cases'),
),
'access my cases and activities' => array(
ts('access my cases and activities'),
ts('View and edit only those cases managed by this user'),
),
'access all cases and activities' => array(
ts('access all cases and activities'),
ts('View and edit all cases (for visible contacts)'),
),
'add cases' => array(
ts('add cases'),
ts('Open a new case'),
),
);
if (!$descriptions) {
foreach ($permissions as $name => $attr) {
$permissions[$name] = array_shift($attr);
}
}
return $permissions;
}
/**
* @inheritDoc
*/
public function getReferenceCounts($dao) {
$result = array();
if ($dao instanceof CRM_Core_DAO_OptionValue) {
/** @var $dao CRM_Core_DAO_OptionValue */
$activity_type_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_type', 'id', 'name');
if ($activity_type_gid == $dao->option_group_id) {
$count = CRM_Case_XMLRepository::singleton()
->getActivityReferenceCount($dao->name);
if ($count > 0) {
$result[] = array(
'name' => 'casetypexml:activities',
'type' => 'casetypexml',
'count' => $count,
);
}
}
}
elseif ($dao instanceof CRM_Contact_DAO_RelationshipType) {
/** @var $dao CRM_Contact_DAO_RelationshipType */
$count = CRM_Case_XMLRepository::singleton()
->getRelationshipReferenceCount($dao->{CRM_Case_XMLProcessor::REL_TYPE_CNAME});
if ($count > 0) {
$result[] = array(
'name' => 'casetypexml:relationships',
'type' => 'casetypexml',
'count' => $count,
);
}
}
return $result;
}
/**
* @inheritDoc
* @return array
*/
public function getUserDashboardElement() {
return array();
}
/**
* @inheritDoc
* @return array
*/
public function registerTab() {
return array(
'title' => ts('Cases'),
'url' => 'case',
'weight' => 50,
);
}
/**
* @inheritDoc
* @return array
*/
public function registerAdvancedSearchPane() {
return array(
'title' => ts('Cases'),
'weight' => 50,
);
}
/**
* @inheritDoc
* @return null
*/
public function getActivityTypes() {
return NULL;
}
/**
* add shortcut to Create New.
* @param $shortCuts
*/
public function creatNewShortcut(&$shortCuts) {
if (CRM_Core_Permission::check('access all cases and activities') ||
CRM_Core_Permission::check('add cases')
) {
$activityType = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Open Case');
if ($activityType) {
$shortCuts = array_merge($shortCuts, array(
array(
'path' => 'civicrm/case/add',
'query' => "reset=1&action=add&atype={$activityType}&context=standalone",
'ref' => 'new-case',
'title' => ts('Case'),
),
));
}
}
}
/**
* (Setting Callback)
* Respond to changes in the "enable_components" setting
*
* If CiviCase is being enabled, load the case related sample data
*
* @param array $oldValue
* List of component names.
* @param array $newValue
* List of component names.
* @param array $metadata
* Specification of the setting (per *.settings.php).
*/
public static function onToggleComponents($oldValue, $newValue, $metadata) {
if (
in_array('CiviCase', $newValue)
&&
(!$oldValue || !in_array('CiviCase', $oldValue))
) {
$pathToCaseSampleTpl = __DIR__ . '/xml/configuration.sample/';
CRM_Admin_Form_Setting_Component::loadCaseSampleData($pathToCaseSampleTpl . 'case_sample.mysql.tpl');
if (!CRM_Case_BAO_Case::createCaseViews()) {
$msg = ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission");
CRM_Core_Error::fatal($msg);
}
}
}
/**
* @return array
* Array(string $value => string $label).
*/
public static function getRedactOptions() {
return array(
'default' => ts('Default'),
'0' => ts('Do not redact emails'),
'1' => ts('Redact emails'),
);
}
/**
* @return array
* Array(string $value => string $label).
*/
public static function getMultiClientOptions() {
return array(
'default' => ts('Default'),
'0' => ts('Single client per case'),
'1' => ts('Multiple client per case'),
);
}
/**
* @return array
* Array(string $value => string $label).
*/
public static function getSortOptions() {
return array(
'default' => ts('Default'),
'0' => ts('Definition order'),
'1' => ts('Alphabetical order'),
);
}
}

View file

@ -0,0 +1,154 @@
<?php
/**
* Class CRM_Case_ManagedEntities
*/
class CRM_Case_ManagedEntities {
/**
* Get a list of managed-entities representing auto-generated case-types
* using hook_civicrm_caseTypes.
*
* @return array
* @see CRM_Utils_Hook::managed
* @throws CRM_Core_Exception
*/
public static function createManagedCaseTypes() {
$entities = array();
// Use hook_civicrm_caseTypes to build a list of OptionValues
// In the long run, we may want more specialized logic for this, but
// this design is fairly convenient and will allow us to replace it
// without changing the hook_civicrm_caseTypes interface.
$caseTypes = array();
CRM_Utils_Hook::caseTypes($caseTypes);
$proc = new CRM_Case_XMLProcessor();
foreach ($caseTypes as $name => $caseType) {
$xml = $proc->retrieve($name);
if (!$xml) {
throw new CRM_Core_Exception("Failed to load XML for case type (" . $name . ")");
}
if (isset($caseType['module'], $caseType['name'], $caseType['file'])) {
$entities[] = array(
'module' => $caseType['module'],
'name' => $caseType['name'],
'entity' => 'CaseType',
'params' => array(
'version' => 3,
'name' => $caseType['name'],
'title' => (string) $xml->name,
'description' => (string) $xml->description,
'is_reserved' => 1,
'is_active' => 1,
'weight' => $xml->weight ? $xml->weight : 1,
),
);
}
else {
throw new CRM_Core_Exception("Invalid case type");
}
}
return $entities;
}
/**
* Get a list of managed activity-types by searching CiviCase XML files.
*
* @param \CRM_Case_XMLRepository $xmlRepo
* @param \CRM_Core_ManagedEntities $me
*
* @return array
* @see CRM_Utils_Hook::managed
*/
public static function createManagedActivityTypes(CRM_Case_XMLRepository $xmlRepo, CRM_Core_ManagedEntities $me) {
$result = array();
$validActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name');
$actTypes = $xmlRepo->getAllDeclaredActivityTypes();
foreach ($actTypes as $actType) {
$managed = array(
'module' => 'civicrm',
'name' => "civicase:act:$actType",
'entity' => 'OptionValue',
'update' => 'never',
'cleanup' => 'unused',
'params' => array(
'version' => 3,
'option_group_id' => 'activity_type',
'label' => $actType,
'name' => $actType,
'description' => $actType,
'component_id' => 'CiviCase',
),
);
// We'll create managed-entity if this record doesn't exist yet
// or if we previously decided to manage this record.
if (!in_array($actType, $validActTypes)) {
$result[] = $managed;
}
elseif ($me->get($managed['module'], $managed['name'])) {
$result[] = $managed;
}
}
return $result;
}
/**
* Get a list of managed relationship-types by searching CiviCase XML files.
*
* @param \CRM_Case_XMLRepository $xmlRepo
* @param \CRM_Core_ManagedEntities $me
*
* @return array
* @see CRM_Utils_Hook::managed
*/
public static function createManagedRelationshipTypes(CRM_Case_XMLRepository $xmlRepo, CRM_Core_ManagedEntities $me) {
$result = array();
if (!isset(Civi::$statics[__CLASS__]['reltypes'])) {
$relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE, NULL);
Civi::$statics[__CLASS__]['reltypes'] = CRM_Utils_Array::collect(CRM_Case_XMLProcessor::REL_TYPE_CNAME, $relationshipInfo);
}
$validRelTypes = Civi::$statics[__CLASS__]['reltypes'];
$relTypes = $xmlRepo->getAllDeclaredRelationshipTypes();
foreach ($relTypes as $relType) {
$managed = array(
'module' => 'civicrm',
'name' => "civicase:rel:$relType",
'entity' => 'RelationshipType',
'update' => 'never',
'cleanup' => 'unused',
'params' => array(
'version' => 3,
'name_a_b' => "$relType is",
'name_b_a' => $relType,
'label_a_b' => "$relType is",
'label_b_a' => $relType,
'description' => $relType,
'contact_type_a' => 'Individual',
'contact_type_b' => 'Individual',
'contact_sub_type_a' => NULL,
'contact_sub_type_b' => NULL,
),
);
// We'll create managed-entity if this record doesn't exist yet
// or if we previously decided to manage this record.
if (!in_array($relType, $validRelTypes)) {
$result[] = $managed;
}
elseif ($me->get($managed['module'], $managed['name'])) {
$result[] = $managed;
}
}
return $result;
}
}

View file

@ -0,0 +1,189 @@
<?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 contains all case related functions that are called using AJAX
*/
class CRM_Case_Page_AJAX {
/**
* @throws \CRM_Core_Exception
*/
public function processCaseTags() {
$caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Positive');
$tags = CRM_Utils_Type::escape($_POST['tag'], 'String');
$tagList = $_POST['taglist'];
if (!CRM_Case_BAO_Case::accessCase($caseId)) {
CRM_Utils_System::permissionDenied();
}
$tagIds = array();
if ($tags) {
$tagIds = explode(',', $tags);
}
$params = array(
'entity_id' => $caseId,
'entity_table' => 'civicrm_case',
);
CRM_Core_BAO_EntityTag::del($params);
foreach ($tagIds as $tagid) {
if (is_numeric($tagid)) {
$params['tag_id'] = $tagid;
CRM_Core_BAO_EntityTag::add($params);
}
}
if (!empty($tagList)) {
CRM_Core_Form_Tag::postProcess($tagList, $caseId, 'civicrm_case');
}
$session = CRM_Core_Session::singleton();
$activityParams = array();
$activityParams['source_contact_id'] = $session->get('userID');
$activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue('activity_type', 'Change Case Tags', 'name');
$activityParams['activity_date_time'] = date('YmdHis');
$activityParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
$activityParams['case_id'] = $caseId;
$activityParams['is_auto'] = 0;
$activityParams['subject'] = 'Change Case Tags';
$activity = CRM_Activity_BAO_Activity::create($activityParams);
$caseParams = array(
'activity_id' => $activity->id,
'case_id' => $caseId,
);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
echo 'true';
CRM_Utils_System::civiExit();
}
/**
* @throws \CiviCRM_API3_Exception
*/
public function caseDetails() {
$caseId = CRM_Utils_Type::escape($_GET['caseId'], 'Positive');
$case = civicrm_api3('Case', 'getsingle', array(
'id' => $caseId,
'check_permissions' => TRUE,
'return' => array('subject', 'case_type_id', 'status_id', 'start_date', 'end_date'))
);
$caseStatuses = CRM_Case_PseudoConstant::caseStatus();
$caseTypes = CRM_Case_PseudoConstant::caseType('title', FALSE);
$caseDetails = "<table><tr><td>" . ts('Case Subject') . "</td><td>{$case['subject']}</td></tr>
<tr><td>" . ts('Case Type') . "</td><td>{$caseTypes[$case['case_type_id']]}</td></tr>
<tr><td>" . ts('Case Status') . "</td><td>{$caseStatuses[$case['status_id']]}</td></tr>
<tr><td>" . ts('Case Start Date') . "</td><td>" . CRM_Utils_Date::customFormat($case['start_date']) . "</td></tr>
<tr><td>" . ts('Case End Date') . "</td><td></td></tr>" . CRM_Utils_Date::customFormat($case['end_date']) . "</table>";
if (CRM_Utils_Array::value('snippet', $_GET) == 'json') {
CRM_Core_Page_AJAX::returnJsonResponse($caseDetails);
}
echo $caseDetails;
CRM_Utils_System::civiExit();
}
/**
* @throws \CRM_Core_Exception
*/
public function addClient() {
$caseId = CRM_Utils_Type::escape($_POST['caseID'], 'Positive');
$contactId = CRM_Utils_Type::escape($_POST['contactID'], 'Positive');
if (!$contactId || !CRM_Case_BAO_Case::accessCase($caseId)) {
CRM_Utils_System::permissionDenied();
}
$params = array(
'case_id' => $caseId,
'contact_id' => $contactId,
);
CRM_Case_BAO_CaseContact::create($params);
// add case relationships
CRM_Case_BAO_Case::addCaseRelationships($caseId, $contactId);
$session = CRM_Core_Session::singleton();
$activityParams = array();
$activityParams['source_contact_id'] = $session->get('userID');
$activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue('activity_type', 'Add Client To Case', 'name');
$activityParams['activity_date_time'] = date('YmdHis');
$activityParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
$activityParams['case_id'] = $caseId;
$activityParams['is_auto'] = 0;
$activityParams['subject'] = 'Client Added To Case';
$activity = CRM_Activity_BAO_Activity::create($activityParams);
$caseParams = array(
'activity_id' => $activity->id,
'case_id' => $caseId,
);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
CRM_Utils_JSON::output(TRUE);
}
/**
* Delete relationships specific to case and relationship type.
*/
public static function deleteCaseRoles() {
$caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Positive');
$cid = CRM_Utils_Type::escape($_POST['cid'], 'Positive');
$relType = CRM_Utils_Request::retrieve('rel_type', 'String', CRM_Core_DAO::$_nullObject, TRUE);
if (!$cid || !CRM_Case_BAO_Case::accessCase($caseId)) {
CRM_Utils_System::permissionDenied();
}
list($relTypeId, $a, $b) = explode('_', $relType);
CRM_Case_BAO_Case::endCaseRole($caseId, $b, $cid, $relTypeId);
CRM_Utils_System::civiExit();
}
}

View file

@ -0,0 +1,62 @@
<?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
*/
class CRM_Case_Page_CaseDetails extends CRM_Core_Page {
/**
* The main function that is called when the page loads.
*
* It decides the which action has to be taken for the page.
*
* @return null
*/
public function run() {
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
$this->assign('action', $this->_action);
$this->assign('context', $this->_context);
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
$caseId = CRM_Utils_Request::retrieve('caseId', 'Positive', $this);
CRM_Case_Page_Tab::setContext($this);
$this->assign('caseID', $caseId);
$this->assign('contactID', $this->_contactId);
$this->assign('userID', CRM_Core_Session::singleton()->get('userID'));
return parent::run();
}
}

View file

@ -0,0 +1,115 @@
<?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 page is for Case Dashboard.
*/
class CRM_Case_Page_DashBoard extends CRM_Core_Page {
public $useLivePageJS = TRUE;
/**
* Heart of the viewing process.
*
* The runner gets all the meta data for the contact and calls the appropriate type of page to view.
*/
public function preProcess() {
//check for civicase access.
if (!CRM_Case_BAO_Case::accessCiviCase()) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
//validate case configuration.
$configured = CRM_Case_BAO_Case::isCaseConfigured();
$this->assign('notConfigured', !$configured['configured']);
$this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
if (!$configured['configured']) {
return;
}
$session = CRM_Core_Session::singleton();
$allCases = CRM_Utils_Request::retrieve('all', 'Positive', $session);
CRM_Utils_System::setTitle(ts('CiviCase Dashboard'));
$userID = $session->get('userID');
//validate access for all cases.
if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) {
$allCases = FALSE;
CRM_Core_Session::setStatus(ts('You are not authorized to access all cases and activities.'), ts('Sorry'), 'error');
}
if (!$allCases) {
$this->assign('myCases', TRUE);
}
else {
$this->assign('myCases', FALSE);
}
$this->assign('newClient', FALSE);
if (CRM_Core_Permission::check('add contacts') &&
CRM_Core_Permission::check('access all cases and activities')
) {
$this->assign('newClient', TRUE);
}
$summary = CRM_Case_BAO_Case::getCasesSummary($allCases, $userID);
$upcoming = CRM_Case_BAO_Case::getCases($allCases, $userID, 'upcoming');
$recent = CRM_Case_BAO_Case::getCases($allCases, $userID, 'recent');
foreach ($upcoming as $key => $value) {
if (strtotime($value['case_scheduled_activity_date']) < time()) {
$upcoming[$key]['activity_status'] = 'status-overdue';
}
}
$this->assign('casesSummary', $summary);
if (!empty($upcoming)) {
$this->assign('upcomingCases', $upcoming);
}
if (!empty($recent)) {
$this->assign('recentCases', $recent);
}
}
/**
* the main function that is called when the page loads,
* it decides the which action has to be taken for the page.
*
* @return null
*/
public function run() {
$this->preProcess();
return parent::run();
}
}

View file

@ -0,0 +1,318 @@
<?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 handle case related functions.
*/
class CRM_Case_Page_Tab extends CRM_Core_Page {
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
static $_links = NULL;
public $_permission = NULL;
public $_contactId = NULL;
public function preProcess() {
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
//validate case configuration.
$configured = CRM_Case_BAO_Case::isCaseConfigured($this->_contactId);
$this->assign('notConfigured', !$configured['configured']);
$this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
$this->assign('redirectToCaseAdmin', $configured['redirectToCaseAdmin']);
if (!$configured['configured'] || $configured['redirectToCaseAdmin']) {
return;
}
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
if ($this->_contactId) {
$this->assign('contactId', $this->_contactId);
// check logged in user permission
if ($this->_id && ($this->_action & CRM_Core_Action::VIEW)) {
//user might have special permissions to view this case, CRM-5666
if (!CRM_Core_Permission::check('access all cases and activities')) {
$session = CRM_Core_Session::singleton();
$userCases = CRM_Case_BAO_Case::getCases(FALSE, $session->get('userID'), 'any');
if (!array_key_exists($this->_id, $userCases)) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
}
}
else {
CRM_Contact_Page_View::checkUserPermission($this);
}
}
else {
if ($this->_action & CRM_Core_Action::VIEW) {
CRM_Core_Error::fatal('Contact Id is required for view action.');
}
}
$activityTypes = CRM_Case_PseudoConstant::caseActivityType();
$this->assign('openCaseId', $activityTypes['Open Case']['id']);
$this->assign('changeCaseTypeId', $activityTypes['Change Case Type']['id']);
$this->assign('changeCaseStatusId', $activityTypes['Change Case Status']['id']);
$this->assign('changeCaseStartDateId', $activityTypes['Change Case Start Date']['id']);
}
/**
* View details of a case.
*/
public function view() {
$controller = new CRM_Core_Controller_Simple(
'CRM_Case_Form_CaseView',
'View Case',
$this->_action,
FALSE,
FALSE,
TRUE
);
$controller->setEmbedded(TRUE);
$controller->set('id', $this->_id);
$controller->set('cid', $this->_contactId);
$controller->run();
$this->assign('caseId', $this->_id);
$output = CRM_Core_Selector_Controller::SESSION;
$selector = new CRM_Activity_Selector_Activity($this->_contactId, $this->_permission, FALSE, 'case');
$controller = new CRM_Core_Selector_Controller(
$selector,
$this->get(CRM_Utils_Pager::PAGE_ID),
NULL,
CRM_Core_Action::VIEW,
$this,
$output,
NULL,
$this->_id
);
$controller->setEmbedded(TRUE);
$controller->run();
$controller->moveFromSessionToTemplate();
$this->assign('context', 'case');
}
/**
* Called when action is browse.
*/
public function browse() {
$controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search', ts('Case'), CRM_Core_Action::BROWSE);
$controller->setEmbedded(TRUE);
$controller->reset();
$controller->set('limit', 20);
$controller->set('force', 1);
$controller->set('context', 'case');
$controller->process();
$controller->run();
if ($this->_contactId) {
$displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
$this->assign('displayName', $displayName);
$this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('case', $this->_contactId);
}
}
/**
* called when action is update or new.
*
* @return null
*/
public function edit() {
$config = CRM_Core_Config::singleton();
$controller = new CRM_Core_Controller_Simple(
'CRM_Case_Form_Case',
'Open Case',
$this->_action
);
$controller->setEmbedded(TRUE);
return $controller->run();
}
/**
* the main function that is called when the page loads,
* it decides the which action has to be taken for the page.
*
* @return null
*/
public function run() {
$contactID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullArray);
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
if ($context == 'standalone' && !$contactID) {
$this->_action = CRM_Core_Action::ADD;
}
else {
// we need to call parent preprocess only when we are viewing / editing / adding participant record
$this->preProcess();
}
$this->assign('action', $this->_action);
self::setContext($this);
if ($this->_action & CRM_Core_Action::VIEW) {
$this->view();
}
elseif (($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD |
CRM_Core_Action::DELETE | CRM_Core_Action::RENEW
)
) ||
!empty($_POST)
) {
$this->edit();
}
elseif ($this->_contactId) {
$this->browse();
}
return parent::run();
}
/**
* Get action links.
*
* @return array
* (reference) of action links
*/
static public function &links() {
$config = CRM_Core_Config::singleton();
if (!(self::$_links)) {
$deleteExtra = ts('Are you sure you want to delete this case?');
self::$_links = array(
CRM_Core_Action::VIEW => array(
'name' => ts('Manage'),
'url' => 'civicrm/contact/view/case',
'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%',
'class' => 'no-popup',
'title' => ts('Manage Case'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/contact/view/case',
'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%',
'title' => ts('Delete Case'),
),
);
}
return self::$_links;
}
/**
* @param CRM_Core_Form $form
*/
public static function setContext(&$form) {
$context = $form->get('context');
$url = NULL;
$qfKey = CRM_Utils_Request::retrieve('key', 'String', $form);
//validate the qfKey
if (!CRM_Utils_Rule::qfKey($qfKey)) {
$qfKey = NULL;
}
switch ($context) {
case 'activity':
if ($form->_contactId) {
$url = CRM_Utils_System::url('civicrm/contact/view',
"reset=1&force=1&cid={$form->_contactId}&selectedChild=activity"
);
}
break;
case 'dashboard':
$url = CRM_Utils_System::url('civicrm/case', "reset=1");
break;
case 'search':
$urlParams = 'force=1';
if ($qfKey) {
$urlParams .= "&qfKey=$qfKey";
}
$url = CRM_Utils_System::url('civicrm/case/search', $urlParams);
break;
case 'dashlet':
case 'dashletFullscreen':
case 'home':
case 'standalone':
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
break;
case 'fulltext':
$action = CRM_Utils_Request::retrieve('action', 'String', $form);
$urlParams = 'force=1';
$urlString = 'civicrm/contact/search/custom';
if ($action == CRM_Core_Action::RENEW) {
if ($form->_contactId) {
$urlParams .= '&cid=' . $form->_contactId;
}
$urlParams .= '&context=fulltext&action=view';
$urlString = 'civicrm/contact/view/case';
}
if ($qfKey) {
$urlParams .= "&qfKey=$qfKey";
}
$url = CRM_Utils_System::url($urlString, $urlParams);
break;
default:
if ($form->_contactId) {
$url = CRM_Utils_System::url('civicrm/contact/view',
"reset=1&force=1&cid={$form->_contactId}&selectedChild=case"
);
}
break;
}
if ($url) {
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
}
}

View file

@ -0,0 +1,215 @@
<?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 holds all the Pseudo constants that are specific for CiviCase.
*/
class CRM_Case_PseudoConstant extends CRM_Core_PseudoConstant {
/**
* Activity type
* @var array
*/
static $activityTypeList = array();
/**
* Get all the case statues.
*
*
* @param string $column
* @param bool $onlyActive
* @param null $condition
* @param bool $fresh
*
* @return array
* array reference of all case statues
*/
public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) {
if (!$condition) {
$condition = 'AND filter = 0';
}
return CRM_Core_OptionGroup::values('case_status',
FALSE, FALSE, FALSE, $condition,
$column, $onlyActive, $fresh
);
}
/**
* Get all the redaction rules.
*
*
* @param null $filter
*
* @return array
* array reference of all redaction rules
*/
public static function redactionRule($filter = NULL) {
$condition = NULL;
if ($filter === 0) {
$condition = " AND (v.filter = 0 OR v.filter IS NULL)";
}
elseif ($filter === 1) {
$condition = " AND v.filter = 1";
}
return CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition);
}
/**
* Get all the case type.
*
*
* @param string $column
* @param bool $onlyActive
*
* @return array
* array reference of all case type
*/
public static function caseType($column = 'title', $onlyActive = TRUE) {
if ($onlyActive) {
$condition = " is_active = 1 ";
}
else {
$condition = NULL;
}
$caseType = NULL;
// FIXME: deprecated?
CRM_Core_PseudoConstant::populate(
$caseType,
'CRM_Case_DAO_CaseType',
TRUE,
$column,
'',
$condition,
'weight',
'id'
);
return $caseType;
}
/**
* Get all the Encounter Medium.
*
*
* @param string $column
* @param bool $onlyActive
*
* @return array
* array reference of all Encounter Medium.
*/
public static function encounterMedium($column = 'label', $onlyActive = TRUE) {
return CRM_Core_OptionGroup::values('encounter_medium',
FALSE, FALSE, FALSE, NULL,
$column, $onlyActive
);
}
/**
* Get all Activity types for the CiviCase component.
*
* The static array activityType is returned
*
* @param bool $indexName
* True return activity name in array.
* key else activity id as array key.
*
* @param bool $all
*
*
* @return array
* array reference of all activity types.
*/
public static function &caseActivityType($indexName = TRUE, $all = FALSE) {
$cache = (int) $indexName . '_' . (int) $all;
if (!array_key_exists($cache, self::$activityTypeList)) {
self::$activityTypeList[$cache] = array();
$query = "
SELECT v.label as label ,v.value as value, v.name as name, v.description as description, v.icon
FROM civicrm_option_value v,
civicrm_option_group g
WHERE v.option_group_id = g.id
AND g.name = 'activity_type'
AND v.is_active = 1
AND g.is_active = 1";
if (!$all) {
$componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component',
'CiviCase',
'id', 'name'
);
$query .= " AND v.component_id = {$componentId} ";
}
$query .= " ORDER BY v.weight";
$dao = CRM_Core_DAO::executeQuery($query);
$activityTypes = array();
while ($dao->fetch()) {
if ($indexName) {
$index = $dao->name;
}
else {
$index = $dao->value;
}
$activityTypes[$index] = array();
$activityTypes[$index]['id'] = $dao->value;
$activityTypes[$index]['label'] = $dao->label;
$activityTypes[$index]['name'] = $dao->name;
$activityTypes[$index]['icon'] = $dao->icon;
$activityTypes[$index]['description'] = $dao->description;
}
self::$activityTypeList[$cache] = $activityTypes;
}
return self::$activityTypeList[$cache];
}
/**
* Flush given pseudoconstant so it can be reread from db
* next time it's requested.
*
*
* @param bool|string $name pseudoconstant to be flushed
*/
public static function flush($name = 'cache') {
if (isset(self::$$name)) {
self::$$name = NULL;
}
}
}

View file

@ -0,0 +1,487 @@
<?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 is used to retrieve and display a range of contacts that match the given criteria.
*/
class CRM_Case_Selector_Search extends CRM_Core_Selector_Base {
/**
* This defines two actions- View and Edit.
*
* @var array
*/
static $_links = NULL;
/**
* We use desc to remind us what that column is, name is used in the tpl
*
* @var array
*/
static $_columnHeaders;
/**
* Properties of contact we're interested in displaying
* @var array
*/
static $_properties = array(
'contact_id',
'contact_type',
'sort_name',
'display_name',
'case_id',
'case_subject',
'case_status_id',
'case_status',
'case_type_id',
'case_type',
'case_role',
'phone',
);
/**
* Are we restricting ourselves to a single contact
*
* @var boolean
*/
protected $_single = FALSE;
/**
* Are we restricting ourselves to a single contact
*
* @var boolean
*/
protected $_limit = NULL;
/**
* What context are we being invoked from
*
* @var string
*/
protected $_context = NULL;
/**
* QueryParams is the array returned by exportValues called on
* the HTML_QuickForm_Controller for that page.
*
* @var array
*/
public $_queryParams;
/**
* Represent the type of selector
*
* @var int
*/
protected $_action;
/**
* The additional clause that we restrict the search with
*
* @var string
*/
protected $_additionalClause = NULL;
/**
* The query object
*
* @var string
*/
protected $_query;
/**
* Class constructor.
*
* @param array $queryParams
* Array of parameters for query.
* @param \const|int $action - action of search basic or advanced.
* @param string $additionalClause
* If the caller wants to further restrict the search (used in participations).
* @param bool $single
* Are we dealing only with one contact?.
* @param int $limit
* How many signers do we want returned.
*
* @param string $context
*
* @return \CRM_Case_Selector_Search
*/
public function __construct(
&$queryParams,
$action = CRM_Core_Action::NONE,
$additionalClause = NULL,
$single = FALSE,
$limit = NULL,
$context = 'search'
) {
// submitted form values
$this->_queryParams = &$queryParams;
$this->_single = $single;
$this->_limit = $limit;
$this->_context = $context;
$this->_additionalClause = $additionalClause;
// type of selector
$this->_action = $action;
$this->_query = new CRM_Contact_BAO_Query($this->_queryParams,
CRM_Case_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CASE,
FALSE
),
NULL, FALSE, FALSE,
CRM_Contact_BAO_Query::MODE_CASE
);
$this->_query->_distinctComponentClause = " civicrm_case.id ";
$this->_query->_groupByComponentClause = " GROUP BY civicrm_case.id ";
}
/**
* This method returns the links that are given for each search row.
* currently the links added for each row are
*
* - View
* - Edit
*
* @param bool $isDeleted
* @param null $key
*
* @return array
*/
static public function &links($isDeleted = FALSE, $key = NULL) {
$extraParams = ($key) ? "&key={$key}" : NULL;
if ($isDeleted) {
self::$_links = array(
CRM_Core_Action::RENEW => array(
'name' => ts('Restore'),
'url' => 'civicrm/contact/view/case',
'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
'ref' => 'restore-case',
'title' => ts('Restore Case'),
),
);
}
else {
self::$_links = array(
CRM_Core_Action::VIEW => array(
'name' => ts('Manage'),
'url' => 'civicrm/contact/view/case',
'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=case' . $extraParams,
'ref' => 'manage-case',
'class' => 'no-popup',
'title' => ts('Manage Case'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/contact/view/case',
'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
'ref' => 'delete-case',
'title' => ts('Delete Case'),
),
CRM_Core_Action::UPDATE => array(
'name' => ts('Assign to Another Client'),
'url' => 'civicrm/contact/view/case/editClient',
'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
'ref' => 'reassign',
'class' => 'medium-popup',
'title' => ts('Assign to Another Client'),
),
);
}
$actionLinks = array();
foreach (self::$_links as $key => $value) {
$actionLinks['primaryActions'][$key] = $value;
}
return $actionLinks;
}
/**
* Getter for array of the parameters required for creating pager.
*
* @param $action
* @param array $params
*/
public function getPagerParams($action, &$params) {
$params['status'] = ts('Case') . ' %%StatusMessage%%';
$params['csvString'] = NULL;
if ($this->_limit) {
$params['rowCount'] = $this->_limit;
}
else {
$params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
}
$params['buttonTop'] = 'PagerTopButton';
$params['buttonBottom'] = 'PagerBottomButton';
}
/**
* Returns total number of rows for the query.
*
* @param
*
* @return int
* Total number of rows
*/
public function getTotalCount($action) {
return $this->_query->searchQuery(0, 0, NULL,
TRUE, FALSE,
FALSE, FALSE,
FALSE,
$this->_additionalClause
);
}
/**
* Returns all the rows in the given offset and rowCount.
*
* @param string $action
* The action being performed.
* @param int $offset
* The row number to start from.
* @param int $rowCount
* The number of rows to return.
* @param string $sort
* The sql string that describes the sort order.
* @param string $output
* What should the result set include (web/email/csv).
*
* @return int
* the total number of rows for this action
*/
public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
$result = $this->_query->searchQuery($offset, $rowCount, $sort,
FALSE, FALSE,
FALSE, FALSE,
FALSE,
$this->_additionalClause
);
// process the result of the query
$rows = array();
//CRM-4418 check for view, edit, delete
$permissions = array(CRM_Core_Permission::VIEW);
if (CRM_Core_Permission::check('access all cases and activities')
|| CRM_Core_Permission::check('access my cases and activities')
) {
$permissions[] = CRM_Core_Permission::EDIT;
}
if (CRM_Core_Permission::check('delete in CiviCase')) {
$permissions[] = CRM_Core_Permission::DELETE;
}
$mask = CRM_Core_Action::mask($permissions);
$caseStatus = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
$scheduledInfo = array();
while ($result->fetch()) {
$row = array();
// the columns we are interested in
foreach (self::$_properties as $property) {
if (isset($result->$property)) {
$row[$property] = $result->$property;
}
}
$isDeleted = FALSE;
if ($result->case_deleted) {
$isDeleted = TRUE;
$row['case_status_id'] = empty($row['case_status_id']) ? "" : $row['case_status_id'] . '<br />(deleted)';
}
$scheduledInfo['case_id'][] = $result->case_id;
$scheduledInfo['contact_id'][] = $result->contact_id;
$scheduledInfo['case_deleted'] = $result->case_deleted;
$row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->case_id;
$links = self::links($isDeleted, $this->_key);
$row['action'] = CRM_Core_Action::formLink($links['primaryActions'],
$mask, array(
'id' => $result->case_id,
'cid' => $result->contact_id,
'cxt' => $this->_context,
),
ts('more'),
FALSE,
'case.selector.actions',
'Case',
$result->case_id
);
$row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type
);
//adding case manager to case selector.CRM-4510.
$caseType = CRM_Case_BAO_Case::getCaseType($result->case_id, 'name');
$caseManagerContact = CRM_Case_BAO_Case::getCaseManagerContact($caseType, $result->case_id);
if (!empty($caseManagerContact)) {
$row['casemanager_id'] = CRM_Utils_Array::value('casemanager_id', $caseManagerContact);
$row['casemanager'] = CRM_Utils_Array::value('casemanager', $caseManagerContact);
}
if (isset($result->case_status_id) &&
array_key_exists($result->case_status_id, $caseStatus)
) {
$row['class'] = "status-urgent";
}
else {
$row['class'] = "status-normal";
}
$rows[$result->case_id] = $row;
}
//retrive the scheduled & recent Activity type and date for selector
if (!empty($scheduledInfo)) {
$schdeduledActivity = CRM_Case_BAO_Case::getNextScheduledActivity($scheduledInfo, 'upcoming');
foreach ($schdeduledActivity as $key => $value) {
$rows[$key]['case_scheduled_activity_date'] = $value['date'];
$rows[$key]['case_scheduled_activity_type'] = $value['type'];
}
$recentActivity = CRM_Case_BAO_Case::getNextScheduledActivity($scheduledInfo, 'recent');
foreach ($recentActivity as $key => $value) {
$rows[$key]['case_recent_activity_date'] = $value['date'];
$rows[$key]['case_recent_activity_type'] = $value['type'];
}
}
return $rows;
}
/**
* @inheritDoc
*/
public function getQILL() {
return $this->_query->qill();
}
/**
* Returns the column headers as an array of tuples:
* (name, sortName (key to the sort array))
*
* @param string $action
* The action being performed.
* @param string $output
* What should the result set include (web/email/csv).
*
* @return array
* the column headers that need to be displayed
*/
public function &getColumnHeaders($action = NULL, $output = NULL) {
if (!isset(self::$_columnHeaders)) {
self::$_columnHeaders = array(
array(
'name' => ts('Subject'),
'direction' => CRM_Utils_Sort::DONTCARE,
),
array(
'name' => ts('Status'),
'sort' => 'case_status',
'direction' => CRM_Utils_Sort::DONTCARE,
),
array(
'name' => ts('Case Type'),
'sort' => 'case_type',
'direction' => CRM_Utils_Sort::DONTCARE,
),
array(
'name' => ts('My Role'),
'sort' => 'case_role',
'direction' => CRM_Utils_Sort::DONTCARE,
),
array(
'name' => ts('Case Manager'),
'direction' => CRM_Utils_Sort::DONTCARE,
),
array(
'name' => ts('Most Recent'),
'sort' => 'case_recent_activity_date',
'direction' => CRM_Utils_Sort::DONTCARE,
),
array(
'name' => ts('Next Sched.'),
'sort' => 'case_scheduled_activity_date',
'direction' => CRM_Utils_Sort::DONTCARE,
),
array('name' => ts('Actions')),
);
if (!$this->_single) {
$pre = array(
array(
'name' => ts('Client'),
'sort' => 'sort_name',
'direction' => CRM_Utils_Sort::ASCENDING,
),
);
self::$_columnHeaders = array_merge($pre, self::$_columnHeaders);
}
}
return self::$_columnHeaders;
}
/**
* @return mixed
*/
public function alphabetQuery() {
return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
}
/**
* @return string
*/
public function &getQuery() {
return $this->_query;
}
/**
* Name of export file.
*
* @param string $output
* Type of output.
*
* @return string
* name of the file
*/
public function getExportFileName($output = 'csv') {
return ts('Case Search');
}
}

View file

@ -0,0 +1,114 @@
<?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
*/
class CRM_Case_StateMachine_Search extends CRM_Core_StateMachine {
/**
* The task that the wizard is currently processing.
*
* @var string
*/
protected $_task;
/**
* Class constructor.
*
* @param object $controller
* @param \const|int $action
*/
public function __construct($controller, $action = CRM_Core_Action::NONE) {
parent::__construct($controller, $action);
$this->_pages = array();
$this->_pages['CRM_Case_Form_Search'] = NULL;
list($task, $result) = $this->taskName($controller, 'Search');
$this->_task = $task;
if (is_array($task)) {
foreach ($task as $t) {
$this->_pages[$t] = NULL;
}
}
else {
$this->_pages[$task] = NULL;
}
if ($result) {
$this->_pages['CRM_Case_Form_Task_Result'] = NULL;
}
$this->addSequentialPages($this->_pages, $action);
}
/**
* Determine the form name based on the action. This allows us
* to avoid using conditional state machine, much more efficient
* and simpler
*
* @param CRM_Core_Controller $controller
* The controller object.
*
* @param string $formName
*
* @return string
* the name of the form that will handle the task
*/
public function taskName($controller, $formName = 'Search') {
// total hack, check POST vars and then session to determine stuff
$value = CRM_Utils_Array::value('task', $_POST);
if (!isset($value)) {
$value = $this->_controller->get('task');
}
$this->_controller->set('task', $value);
return CRM_Case_Task::getTask($value);
}
/**
* Return the form name of the task.
*
* @return string
*/
public function getTaskFormName() {
return CRM_Utils_String::getClassName($this->_task);
}
/**
* Since this is a state machine for search and we want to come back to the same state
* we dont want to issue a reset of the state session when we are done processing a task
*/
public function shouldReset() {
return FALSE;
}
}

View file

@ -0,0 +1,184 @@
<?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
*/
/**
* Class to represent the actions that can be performed on a group of contacts.
*
* Used by the search forms
*/
class CRM_Case_Task {
const DELETE_CASES = 1, PRINT_CASES = 2, EXPORT_CASES = 3, RESTORE_CASES = 4;
/**
* The task array
*
* @var array
*/
static $_tasks = NULL;
/**
* The optional task array
*
* @var array
*/
static $_optionalTasks = NULL;
/**
* These tasks are the core set of tasks that the user can perform
* on a contact / group of contacts
*
* @return array
* the set of tasks for a group of contacts
*/
public static function &tasks() {
if (!self::$_tasks) {
self::$_tasks = array(
1 => array(
'title' => ts('Delete cases'),
'class' => 'CRM_Case_Form_Task_Delete',
'result' => FALSE,
),
2 => array(
'title' => ts('Print selected rows'),
'class' => 'CRM_Case_Form_Task_Print',
'result' => FALSE,
),
3 => array(
'title' => ts('Export cases'),
'class' => array(
'CRM_Export_Form_Select',
'CRM_Export_Form_Map',
),
'result' => FALSE,
),
4 => array(
'title' => ts('Restore cases'),
'class' => 'CRM_Case_Form_Task_Restore',
'result' => FALSE,
),
5 => array(
'title' => ts('Print/merge Document'),
'class' => 'CRM_Case_Form_Task_PDF',
'result' => FALSE,
),
);
//CRM-4418, check for delete
if (!CRM_Core_Permission::check('delete in CiviCase')) {
unset(self::$_tasks[1]);
}
CRM_Utils_Hook::searchTasks('case', self::$_tasks);
asort(self::$_tasks);
}
return self::$_tasks;
}
/**
* These tasks are the core set of task titles.
*
* @return array
* the set of task titles
*/
public static function &taskTitles() {
self::tasks();
$titles = array();
foreach (self::$_tasks as $id => $value) {
$titles[$id] = $value['title'];
}
return $titles;
}
/**
* These tasks get added based on the context the user is in.
*
* @return array
* the set of optional tasks for a group of contacts
*/
public static function &optionalTaskTitle() {
$tasks = array();
return $tasks;
}
/**
* Show tasks selectively based on the permission level.
* of the user
*
* @param int $permission
*
* @return array
* set of tasks that are valid for the user
*/
public static function &permissionedTaskTitles($permission) {
$tasks = array();
if (($permission == CRM_Core_Permission::EDIT)
|| CRM_Core_Permission::check('access all cases and activities')
|| CRM_Core_Permission::check('access my cases and activities')
) {
$tasks = self::taskTitles();
}
else {
$tasks = array(
3 => self::$_tasks[3]['title'],
);
//CRM-4418,
if (CRM_Core_Permission::check('delete in CiviCase')) {
$tasks[1] = self::$_tasks[1]['title'];
}
}
return $tasks;
}
/**
* These tasks are the core set of tasks.
*
* @param int $value
*
* @return array
* the set of tasks for a group of contacts
*/
public static function getTask($value) {
self::tasks();
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
// make the print task by default
$value = 2;
}
return array(
self::$_tasks[$value]['class'],
self::$_tasks[$value]['result'],
);
}
}

View file

@ -0,0 +1,133 @@
<?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
*/
class CRM_Case_XMLProcessor {
/**
* FIXME: This does *NOT* belong in a static property, but we're too late in
* the 4.5-cycle to do the necessary cleanup.
*
* @var array|null array(int $id => string $relTypeCname)
*/
public static $activityTypes = NULL;
/**
* FIXME: This does *NOT* belong in a static property, but we're too late in
* the 4.5-cycle to do the necessary cleanup.
*
* @var array|null array(int $id => string $relTypeCname)
*/
public static $relationshipTypes = NULL;
/**
* Relationship-types have four name fields (name_a_b, name_b_a, label_a_b,
* label_b_a), but CiviCase XML refers to reltypes by a single name.
* REL_TYPE_CNAME identifies the canonical name field as used by CiviCase XML.
*
* This appears to be "label_b_a", but IMHO "name_b_a" would be more
* sensible.
*/
const REL_TYPE_CNAME = 'label_b_a';
/**
* @param $caseType
*
* @return FALSE|SimpleXMLElement
*/
public function retrieve($caseType) {
return CRM_Case_XMLRepository::singleton()->retrieve($caseType);
}
/**
* This function was previously used to convert a case-type's
* machine-name to a file-name. However, it's mind-boggling
* that the file-name might be a munged version of the
* machine-name (which is itself a munged version of the
* display-name), and naming is now a more visible issue (since
* the overhaul of CaseType admin UI).
*
* Usage note: This is called externally by civix stubs as a
* sort of side-ways validation of the case-type's name
* (validation which was needed because of the unintuitive
* double-munge). We should update civix templates and then
* remove this function in Civi 4.6 or 5.0.
*
* @param string $caseType
* @return string
* @deprecated
* @see CRM_Case_BAO_CaseType::isValidName
*/
public static function mungeCaseType($caseType) {
// trim all spaces from $caseType
$caseType = str_replace('_', ' ', $caseType);
$caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
return $caseType;
}
/**
* @param bool $indexName
* @param bool $all
*
* @return array
*/
public function &allActivityTypes($indexName = TRUE, $all = FALSE) {
if (self::$activityTypes === NULL) {
self::$activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
}
return self::$activityTypes;
}
/**
* @return array
*/
public function &allRelationshipTypes() {
if (self::$relationshipTypes === NULL) {
$relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE);
self::$relationshipTypes = array();
foreach ($relationshipInfo as $id => $info) {
self::$relationshipTypes[$id] = $info[CRM_Case_XMLProcessor::REL_TYPE_CNAME];
}
}
return self::$relationshipTypes;
}
/**
* FIXME: This should not exist
*/
public static function flushStaticCaches() {
self::$activityTypes = NULL;
self::$relationshipTypes = NULL;
}
}

View file

@ -0,0 +1,677 @@
<?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
*/
class CRM_Case_XMLProcessor_Process extends CRM_Case_XMLProcessor {
/**
* Run.
*
* @param string $caseType
* @param array $params
*
* @return bool
* @throws Exception
*/
public function run($caseType, &$params) {
$xml = $this->retrieve($caseType);
if ($xml === FALSE) {
$docLink = CRM_Utils_System::docURL2("user/case-management/set-up");
CRM_Core_Error::fatal(ts("Configuration file could not be retrieved for case type = '%1' %2.",
array(1 => $caseType, 2 => $docLink)
));
return FALSE;
}
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$this->_isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
$this->process($xml, $params);
}
/**
* @param $caseType
* @param $fieldSet
* @param bool $isLabel
* @param bool $maskAction
*
* @return array|bool|mixed
* @throws Exception
*/
public function get($caseType, $fieldSet, $isLabel = FALSE, $maskAction = FALSE) {
$xml = $this->retrieve($caseType);
if ($xml === FALSE) {
$docLink = CRM_Utils_System::docURL2("user/case-management/set-up");
CRM_Core_Error::fatal(ts("Unable to load configuration file for the referenced case type: '%1' %2.",
array(1 => $caseType, 2 => $docLink)
));
return FALSE;
}
switch ($fieldSet) {
case 'CaseRoles':
return $this->caseRoles($xml->CaseRoles);
case 'ActivitySets':
return $this->activitySets($xml->ActivitySets);
case 'ActivityTypes':
return $this->activityTypes($xml->ActivityTypes, FALSE, $isLabel, $maskAction);
}
}
/**
* @param $xml
* @param array $params
*
* @throws Exception
*/
public function process($xml, &$params) {
$standardTimeline = CRM_Utils_Array::value('standardTimeline', $params);
$activitySetName = CRM_Utils_Array::value('activitySetName', $params);
$activityTypeName = CRM_Utils_Array::value('activityTypeName', $params);
if ('Open Case' == CRM_Utils_Array::value('activityTypeName', $params)) {
// create relationships for the ones that are required
foreach ($xml->CaseRoles as $caseRoleXML) {
foreach ($caseRoleXML->RelationshipType as $relationshipTypeXML) {
if ((int ) $relationshipTypeXML->creator == 1) {
if (!$this->createRelationships((string ) $relationshipTypeXML->name,
$params
)
) {
CRM_Core_Error::fatal();
return FALSE;
}
}
}
}
}
if ('Change Case Start Date' == CRM_Utils_Array::value('activityTypeName', $params)) {
// delete all existing activities which are non-empty
$this->deleteEmptyActivity($params);
}
foreach ($xml->ActivitySets as $activitySetsXML) {
foreach ($activitySetsXML->ActivitySet as $activitySetXML) {
if ($standardTimeline) {
if ((boolean ) $activitySetXML->timeline) {
return $this->processStandardTimeline($activitySetXML,
$params
);
}
}
elseif ($activitySetName) {
$name = (string ) $activitySetXML->name;
if ($name == $activitySetName) {
return $this->processActivitySet($activitySetXML,
$params
);
}
}
}
}
}
/**
* @param $activitySetXML
* @param array $params
*/
public function processStandardTimeline($activitySetXML, &$params) {
if ('Change Case Type' == CRM_Utils_Array::value('activityTypeName', $params)
&& CRM_Utils_Array::value('resetTimeline', $params, TRUE)
) {
// delete all existing activities which are non-empty
$this->deleteEmptyActivity($params);
}
foreach ($activitySetXML->ActivityTypes as $activityTypesXML) {
foreach ($activityTypesXML as $activityTypeXML) {
$this->createActivity($activityTypeXML, $params);
}
}
}
/**
* @param $activitySetXML
* @param array $params
*/
public function processActivitySet($activitySetXML, &$params) {
foreach ($activitySetXML->ActivityTypes as $activityTypesXML) {
foreach ($activityTypesXML as $activityTypeXML) {
$this->createActivity($activityTypeXML, $params);
}
}
}
/**
* @param $caseRolesXML
* @param bool $isCaseManager
*
* @return array|mixed
*/
public function &caseRoles($caseRolesXML, $isCaseManager = FALSE) {
$relationshipTypes = &$this->allRelationshipTypes();
$result = array();
foreach ($caseRolesXML as $caseRoleXML) {
foreach ($caseRoleXML->RelationshipType as $relationshipTypeXML) {
$relationshipTypeName = (string ) $relationshipTypeXML->name;
$relationshipTypeID = array_search($relationshipTypeName,
$relationshipTypes
);
if ($relationshipTypeID === FALSE) {
continue;
}
if (!$isCaseManager) {
$result[$relationshipTypeID] = $relationshipTypeName;
}
elseif ($relationshipTypeXML->manager) {
return $relationshipTypeID;
}
}
}
return $result;
}
/**
* @param string $relationshipTypeName
* @param array $params
*
* @return bool
* @throws Exception
*/
public function createRelationships($relationshipTypeName, &$params) {
$relationshipTypes = &$this->allRelationshipTypes();
// get the relationship id
$relationshipTypeID = array_search($relationshipTypeName, $relationshipTypes);
if ($relationshipTypeID === FALSE) {
$docLink = CRM_Utils_System::docURL2("user/case-management/set-up");
CRM_Core_Error::fatal(ts('Relationship type %1, found in case configuration file, is not present in the database %2',
array(1 => $relationshipTypeName, 2 => $docLink)
));
return FALSE;
}
$client = $params['clientID'];
if (!is_array($client)) {
$client = array($client);
}
foreach ($client as $key => $clientId) {
$relationshipParams = array(
'relationship_type_id' => $relationshipTypeID,
'contact_id_a' => $clientId,
'contact_id_b' => $params['creatorID'],
'is_active' => 1,
'case_id' => $params['caseID'],
'start_date' => date("Ymd"),
);
if (!$this->createRelationship($relationshipParams)) {
CRM_Core_Error::fatal();
return FALSE;
}
}
return TRUE;
}
/**
* @param array $params
*
* @return bool
*/
public function createRelationship(&$params) {
$dao = new CRM_Contact_DAO_Relationship();
$dao->copyValues($params);
// only create a relationship if it does not exist
if (!$dao->find(TRUE)) {
$dao->save();
}
return TRUE;
}
/**
* @param $activityTypesXML
* @param bool $maxInst
* @param bool $isLabel
* @param bool $maskAction
*
* @return array
*/
public function activityTypes($activityTypesXML, $maxInst = FALSE, $isLabel = FALSE, $maskAction = FALSE) {
$activityTypes = &$this->allActivityTypes(TRUE, TRUE);
$result = array();
foreach ($activityTypesXML as $activityTypeXML) {
foreach ($activityTypeXML as $recordXML) {
$activityTypeName = (string ) $recordXML->name;
$maxInstances = (string ) $recordXML->max_instances;
$activityTypeInfo = CRM_Utils_Array::value($activityTypeName, $activityTypes);
if ($activityTypeInfo['id']) {
if ($maskAction) {
if ($maskAction == 'edit' && '0' === (string ) $recordXML->editable) {
$result[$maskAction][] = $activityTypeInfo['id'];
}
}
else {
if (!$maxInst) {
//if we want,labels of activities should be returned.
if ($isLabel) {
$result[$activityTypeInfo['id']] = $activityTypeInfo['label'];
}
else {
$result[$activityTypeInfo['id']] = $activityTypeName;
}
}
else {
if ($maxInstances) {
$result[$activityTypeName] = $maxInstances;
}
}
}
}
}
}
// call option value hook
CRM_Utils_Hook::optionValues($result, 'case_activity_type');
return $result;
}
/**
* @param SimpleXMLElement $caseTypeXML
* @return array<string> symbolic activity-type names
*/
public function getDeclaredActivityTypes($caseTypeXML) {
$result = array();
if (!empty($caseTypeXML->ActivityTypes) && $caseTypeXML->ActivityTypes->ActivityType) {
foreach ($caseTypeXML->ActivityTypes->ActivityType as $activityTypeXML) {
$result[] = (string) $activityTypeXML->name;
}
}
if (!empty($caseTypeXML->ActivitySets) && $caseTypeXML->ActivitySets->ActivitySet) {
foreach ($caseTypeXML->ActivitySets->ActivitySet as $activitySetXML) {
if ($activitySetXML->ActivityTypes && $activitySetXML->ActivityTypes->ActivityType) {
foreach ($activitySetXML->ActivityTypes->ActivityType as $activityTypeXML) {
$result[] = (string) $activityTypeXML->name;
}
}
}
}
$result = array_unique($result);
sort($result);
return $result;
}
/**
* @param SimpleXMLElement $caseTypeXML
* @return array<string> symbolic relationship-type names
*/
public function getDeclaredRelationshipTypes($caseTypeXML) {
$result = array();
if (!empty($caseTypeXML->CaseRoles) && $caseTypeXML->CaseRoles->RelationshipType) {
foreach ($caseTypeXML->CaseRoles->RelationshipType as $relTypeXML) {
$result[] = (string) $relTypeXML->name;
}
}
$result = array_unique($result);
sort($result);
return $result;
}
/**
* @param array $params
*/
public function deleteEmptyActivity(&$params) {
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
$query = "
DELETE a
FROM civicrm_activity a
INNER JOIN civicrm_activity_contact t ON t.activity_id = a.id
INNER JOIN civicrm_case_activity ca on ca.activity_id = a.id
WHERE t.contact_id = %1
AND t.record_type_id = $targetID
AND a.is_auto = 1
AND a.is_current_revision = 1
AND ca.case_id = %2
";
$sqlParams = array(1 => array($params['clientID'], 'Integer'), 2 => array($params['caseID'], 'Integer'));
CRM_Core_DAO::executeQuery($query, $sqlParams);
}
/**
* @param array $params
*
* @return bool
*/
public function isActivityPresent(&$params) {
$query = "
SELECT count(a.id)
FROM civicrm_activity a
INNER JOIN civicrm_case_activity ca on ca.activity_id = a.id
WHERE a.activity_type_id = %1
AND ca.case_id = %2
AND a.is_deleted = 0
";
$sqlParams = array(
1 => array($params['activityTypeID'], 'Integer'),
2 => array($params['caseID'], 'Integer'),
);
$count = CRM_Core_DAO::singleValueQuery($query, $sqlParams);
// check for max instance
$caseType = CRM_Case_BAO_Case::getCaseType($params['caseID'], 'name');
$maxInstance = self::getMaxInstance($caseType, $params['activityTypeName']);
return $maxInstance ? ($count < $maxInstance ? FALSE : TRUE) : FALSE;
}
/**
* @param $activityTypeXML
* @param array $params
*
* @return bool
* @throws CRM_Core_Exception
* @throws Exception
*/
public function createActivity($activityTypeXML, &$params) {
$activityTypeName = (string) $activityTypeXML->name;
$activityTypes = &$this->allActivityTypes(TRUE, TRUE);
$activityTypeInfo = CRM_Utils_Array::value($activityTypeName, $activityTypes);
if (!$activityTypeInfo) {
$docLink = CRM_Utils_System::docURL2("user/case-management/set-up");
CRM_Core_Error::fatal(ts('Activity type %1, found in case configuration file, is not present in the database %2',
array(1 => $activityTypeName, 2 => $docLink)
));
return FALSE;
}
$activityTypeID = $activityTypeInfo['id'];
if (isset($activityTypeXML->status)) {
$statusName = (string) $activityTypeXML->status;
}
else {
$statusName = 'Scheduled';
}
$client = (array) $params['clientID'];
//set order
$orderVal = '';
if (isset($activityTypeXML->order)) {
$orderVal = (string) $activityTypeXML->order;
}
if ($activityTypeName == 'Open Case') {
$activityParams = array(
'activity_type_id' => $activityTypeID,
'source_contact_id' => $params['creatorID'],
'is_auto' => FALSE,
'is_current_revision' => 1,
'subject' => CRM_Utils_Array::value('subject', $params) ? $params['subject'] : $activityTypeName,
'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', $statusName),
'target_contact_id' => $client,
'medium_id' => CRM_Utils_Array::value('medium_id', $params),
'location' => CRM_Utils_Array::value('location', $params),
'details' => CRM_Utils_Array::value('details', $params),
'duration' => CRM_Utils_Array::value('duration', $params),
'weight' => $orderVal,
);
}
else {
$activityParams = array(
'activity_type_id' => $activityTypeID,
'source_contact_id' => $params['creatorID'],
'is_auto' => TRUE,
'is_current_revision' => 1,
'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', $statusName),
'target_contact_id' => $client,
'weight' => $orderVal,
);
}
//parsing date to default preference format
$params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time']);
if ($activityTypeName == 'Open Case') {
// we don't set activity_date_time for auto generated
// activities, but we want it to be set for open case.
$activityParams['activity_date_time'] = $params['activity_date_time'];
if (array_key_exists('custom', $params) && is_array($params['custom'])) {
$activityParams['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])) {
$activityParams[$attachName] = $params[$attachName];
}
}
}
else {
$activityDate = NULL;
//get date of reference activity if set.
if ($referenceActivityName = (string) $activityTypeXML->reference_activity) {
//we skip open case as reference activity.CRM-4374.
if (!empty($params['resetTimeline']) && $referenceActivityName == 'Open Case') {
$activityDate = $params['activity_date_time'];
}
else {
$referenceActivityInfo = CRM_Utils_Array::value($referenceActivityName, $activityTypes);
if ($referenceActivityInfo['id']) {
$caseActivityParams = array('activity_type_id' => $referenceActivityInfo['id']);
//if reference_select is set take according activity.
if ($referenceSelect = (string) $activityTypeXML->reference_select) {
$caseActivityParams[$referenceSelect] = 1;
}
$referenceActivity = CRM_Case_BAO_Case::getCaseActivityDates($params['caseID'], $caseActivityParams, TRUE);
if (is_array($referenceActivity)) {
foreach ($referenceActivity as $aId => $details) {
$activityDate = CRM_Utils_Array::value('activity_date', $details);
break;
}
}
}
}
}
if (!$activityDate) {
$activityDate = $params['activity_date_time'];
}
list($activity_date, $activity_time) = CRM_Utils_Date::setDateDefaults($activityDate);
$activityDateTime = CRM_Utils_Date::processDate($activity_date, $activity_time);
//add reference offset to date.
if ((int) $activityTypeXML->reference_offset) {
$activityDateTime = CRM_Utils_Date::intervalAdd('day', (int) $activityTypeXML->reference_offset,
$activityDateTime
);
}
$activityParams['activity_date_time'] = CRM_Utils_Date::format($activityDateTime);
}
// if same activity is already there, skip and dont touch
$params['activityTypeID'] = $activityTypeID;
$params['activityTypeName'] = $activityTypeName;
if ($this->isActivityPresent($params)) {
return TRUE;
}
$activityParams['case_id'] = $params['caseID'];
if (!empty($activityParams['is_auto'])) {
$activityParams['skipRecentView'] = TRUE;
}
// @todo - switch to using api & remove the parameter pre-wrangling above.
$activity = CRM_Activity_BAO_Activity::create($activityParams);
if (!$activity) {
CRM_Core_Error::fatal();
return FALSE;
}
// create case activity record
$caseParams = array(
'activity_id' => $activity->id,
'case_id' => $params['caseID'],
);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
return TRUE;
}
/**
* @param $activitySetsXML
*
* @return array
*/
public static function activitySets($activitySetsXML) {
$result = array();
foreach ($activitySetsXML as $activitySetXML) {
foreach ($activitySetXML as $recordXML) {
$activitySetName = (string ) $recordXML->name;
$activitySetLabel = (string ) $recordXML->label;
$result[$activitySetName] = $activitySetLabel;
}
}
return $result;
}
/**
* @param $caseType
* @param null $activityTypeName
*
* @return array|bool|mixed
* @throws Exception
*/
public function getMaxInstance($caseType, $activityTypeName = NULL) {
$xml = $this->retrieve($caseType);
if ($xml === FALSE) {
CRM_Core_Error::fatal();
return FALSE;
}
$activityInstances = $this->activityTypes($xml->ActivityTypes, TRUE);
return $activityTypeName ? CRM_Utils_Array::value($activityTypeName, $activityInstances) : $activityInstances;
}
/**
* @param $caseType
*
* @return array|mixed
*/
public function getCaseManagerRoleId($caseType) {
$xml = $this->retrieve($caseType);
return $this->caseRoles($xml->CaseRoles, TRUE);
}
/**
* @param string $caseType
* @return array<\Civi\CCase\CaseChangeListener>
*/
public function getListeners($caseType) {
$xml = $this->retrieve($caseType);
$listeners = array();
if ($xml->Listeners && $xml->Listeners->Listener) {
foreach ($xml->Listeners->Listener as $listenerXML) {
$class = (string) $listenerXML;
$listeners[] = new $class();
}
}
return $listeners;
}
/**
* @return int
*/
public function getRedactActivityEmail() {
return $this->getBoolSetting('civicaseRedactActivityEmail', 'RedactActivityEmail');
}
/**
* Retrieves AllowMultipleCaseClients setting.
*
* @return string
* 1 if allowed, 0 if not
*/
public function getAllowMultipleCaseClients() {
return $this->getBoolSetting('civicaseAllowMultipleClients', 'AllowMultipleCaseClients');
}
/**
* Retrieves NaturalActivityTypeSort setting.
*
* @return string
* 1 if natural, 0 if alphabetic
*/
public function getNaturalActivityTypeSort() {
return $this->getBoolSetting('civicaseNaturalActivityTypeSort', 'NaturalActivityTypeSort');
}
/**
* @param string $settingKey
* @param string $xmlTag
* @param mixed $default
* @return int
*/
private function getBoolSetting($settingKey, $xmlTag, $default = 0) {
$setting = Civi::settings()->get($settingKey);
if ($setting !== 'default') {
return (int) $setting;
}
if ($xml = $this->retrieve("Settings")) {
return (string) $xml->{$xmlTag} ? 1 : 0;
}
return $default;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,64 @@
<?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
*/
class CRM_Case_XMLProcessor_Settings extends CRM_Case_XMLProcessor {
private $_settings = array();
/**
* Run.
*
* @param string $filename
* The base filename without the .xml extension
*
* @return array
* An array of settings.
*/
public function run($filename = 'settings') {
$xml = $this->retrieve($filename);
// For now it's not an error. In the future it might be a required file.
if ($xml !== FALSE) {
// There's only one setting right now, and only one value.
if ($xml->group[0]) {
if ($xml->group[0]->attributes()) {
$groupName = (string) $xml->group[0]->attributes()->name;
if ($groupName) {
$this->_settings['groupname'] = $groupName;
}
}
}
}
return $this->_settings;
}
}

View file

@ -0,0 +1,315 @@
<?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
*
* The XMLRepository is responsible for loading XML for case-types.
* It includes any bulk operations that apply across the list of all XML
* documents of all case-types.
*/
class CRM_Case_XMLRepository {
private static $singleton;
/**
* @var array<String,SimpleXMLElement>
*/
protected $xml = array();
/**
* @var array|NULL
*/
protected $hookCache = NULL;
/**
* @var array|NULL symbolic names of case-types
*/
protected $allCaseTypes = NULL;
/**
* @param bool $fresh
* @return CRM_Case_XMLRepository
*/
public static function singleton($fresh = FALSE) {
if (!self::$singleton || $fresh) {
self::$singleton = new static();
}
return self::$singleton;
}
public function flush() {
$this->xml = array();
$this->hookCache = NULL;
$this->allCaseTypes = NULL;
CRM_Core_DAO::$_dbColumnValueCache = array();
}
/**
* Class constructor.
*
* @param array $allCaseTypes
* @param array $xml
*/
public function __construct($allCaseTypes = NULL, $xml = array()) {
$this->allCaseTypes = $allCaseTypes;
$this->xml = $xml;
}
/**
* Retrieve case.
*
* @param string $caseType
*
* @return FALSE|\SimpleXMLElement
* @throws \CRM_Core_Exception
*/
public function retrieve($caseType) {
// check if xml definition is defined in db
$definition = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $caseType, 'definition', 'name');
if (!empty($definition)) {
list ($xml, $error) = CRM_Utils_XML::parseString($definition);
if (!$xml) {
throw new CRM_Core_Exception("Failed to parse CaseType XML: $error");
}
return $xml;
}
// TODO In 4.6 or 5.0, remove support for weird machine-names
//if (!CRM_Case_BAO_CaseType::isValidName($caseType)) {
// // perhaps caller provider a the label instead of the name?
// throw new CRM_Core_Exception("Cannot load caseType with malformed name [$caseType]");
//}
if (!CRM_Utils_Array::value($caseType, $this->xml)) {
$fileXml = $this->retrieveFile($caseType);
if ($fileXml) {
$this->xml[$caseType] = $fileXml;
}
else {
return FALSE;
}
}
return $this->xml[$caseType];
}
/**
* Retrieve file.
*
* @param string $caseType
* @return SimpleXMLElement|FALSE
*/
public function retrieveFile($caseType) {
$fileName = NULL;
$fileXml = NULL;
if (CRM_Case_BAO_CaseType::isValidName($caseType)) {
// Search for a file based directly on the $caseType name
$fileName = $this->findXmlFile($caseType);
}
// For backward compatibility, also search for double-munged file names
// TODO In 4.6 or 5.0, remove support for loading double-munged file names
if (!$fileName || !file_exists($fileName)) {
$fileName = $this->findXmlFile(CRM_Case_XMLProcessor::mungeCaseType($caseType));
}
if ($fileName && file_exists($fileName)) {
// read xml file
$dom = new DomDocument();
$xmlString = file_get_contents($fileName);
$dom->loadXML($xmlString);
$dom->documentURI = $fileName;
$dom->xinclude();
$fileXml = simplexml_import_dom($dom);
}
return $fileXml;
}
/**
* Find xml file.
*
* @param string $caseType
* @return null|string
* file path
*/
public function findXmlFile($caseType) {
// first check custom templates directory
$fileName = NULL;
if (!$fileName || !file_exists($fileName)) {
$caseTypesViaHook = $this->getCaseTypesViaHook();
if (isset($caseTypesViaHook[$caseType], $caseTypesViaHook[$caseType]['file'])) {
$fileName = $caseTypesViaHook[$caseType]['file'];
}
}
if (!$fileName || !file_exists($fileName)) {
$config = CRM_Core_Config::singleton();
if (isset($config->customTemplateDir) && $config->customTemplateDir) {
// check if the file exists in the custom templates directory
$fileName = implode(DIRECTORY_SEPARATOR,
array(
$config->customTemplateDir,
'CRM',
'Case',
'xml',
'configuration',
"$caseType.xml",
)
);
}
}
if (!$fileName || !file_exists($fileName)) {
if (!file_exists($fileName)) {
// check if file exists locally
$fileName = implode(DIRECTORY_SEPARATOR,
array(
dirname(__FILE__),
'xml',
'configuration',
"$caseType.xml",
)
);
}
if (!file_exists($fileName)) {
// check if file exists locally
$fileName = implode(DIRECTORY_SEPARATOR,
array(
dirname(__FILE__),
'xml',
'configuration.sample',
"$caseType.xml",
)
);
}
}
return file_exists($fileName) ? $fileName : NULL;
}
/**
* @return array
* @see CRM_Utils_Hook::caseTypes
*/
public function getCaseTypesViaHook() {
if ($this->hookCache === NULL) {
$this->hookCache = array();
CRM_Utils_Hook::caseTypes($this->hookCache);
}
return $this->hookCache;
}
/**
* @return array<string> symbolic names of case-types
*/
public function getAllCaseTypes() {
if ($this->allCaseTypes === NULL) {
$this->allCaseTypes = CRM_Case_PseudoConstant::caseType("name");
}
return $this->allCaseTypes;
}
/**
* @return array<string> symbolic-names of activity-types
*/
public function getAllDeclaredActivityTypes() {
$result = array();
$p = new CRM_Case_XMLProcessor_Process();
foreach ($this->getAllCaseTypes() as $caseTypeName) {
$caseTypeXML = $this->retrieve($caseTypeName);
$result = array_merge($result, $p->getDeclaredActivityTypes($caseTypeXML));
}
$result = array_unique($result);
sort($result);
return $result;
}
/**
* @return array<string> symbolic-names of relationship-types
*/
public function getAllDeclaredRelationshipTypes() {
$result = array();
$p = new CRM_Case_XMLProcessor_Process();
foreach ($this->getAllCaseTypes() as $caseTypeName) {
$caseTypeXML = $this->retrieve($caseTypeName);
$result = array_merge($result, $p->getDeclaredRelationshipTypes($caseTypeXML));
}
$result = array_unique($result);
sort($result);
return $result;
}
/**
* Determine the number of times a particular activity-type is
* referenced in CiviCase XML.
*
* @param string $activityType
* Symbolic-name of an activity type.
* @return int
*/
public function getActivityReferenceCount($activityType) {
$p = new CRM_Case_XMLProcessor_Process();
$count = 0;
foreach ($this->getAllCaseTypes() as $caseTypeName) {
$caseTypeXML = $this->retrieve($caseTypeName);
if (in_array($activityType, $p->getDeclaredActivityTypes($caseTypeXML))) {
$count++;
}
}
return $count;
}
/**
* Determine the number of times a particular activity-type is
* referenced in CiviCase XML.
*
* @param string $relationshipTypeName
* Symbolic-name of a relationship-type.
* @return int
*/
public function getRelationshipReferenceCount($relationshipTypeName) {
$p = new CRM_Case_XMLProcessor_Process();
$count = 0;
foreach ($this->getAllCaseTypes() as $caseTypeName) {
$caseTypeXML = $this->retrieve($caseTypeName);
if (in_array($relationshipTypeName, $p->getDeclaredRelationshipTypes($caseTypeXML))) {
$count++;
}
}
return $count;
}
}

View file

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<CaseType>
<name>Civil and Political</name>
<ActivityTypes>
<ActivityType>
<name>Open Case</name>
<max_instances>1</max_instances>
</ActivityType>
<ActivityType>
<name>Change Case Type</name>
</ActivityType>
<ActivityType>
<name>Change Case Status</name>
</ActivityType>
<ActivityType>
<name>Follow up</name>
</ActivityType>
<ActivityType>
<name>Source(incoming)</name>
</ActivityType>
<ActivityType>
<name>Incoming correspondence</name>
</ActivityType>
<ActivityType>
<name>Incoming Press Release</name>
</ActivityType>
<ActivityType>
<name>Complaint</name>
</ActivityType>
<ActivityType>
<name>Urgent Action(incoming)</name>
</ActivityType>
<ActivityType>
<name>Outgoing correspondence</name>
</ActivityType>
<ActivityType>
<name>Outgoing Press Release</name>
</ActivityType>
<ActivityType>
<name>FL Action(outgoing)</name>
</ActivityType>
<ActivityType>
<name>FL Urgent Action(outgoing)</name>
</ActivityType>
<ActivityType>
<name>Lobbying(outgoing)</name>
</ActivityType>
</ActivityTypes>
<ActivitySets>
<ActivitySet>
<name>standard_timeline</name>
<label>Standard Timeline</label>
<timeline>true</timeline>
<ActivityTypes>
<ActivityType>
<name>Open Case</name>
<status>Closed</status>
</ActivityType>
<ActivityType>
<name>Source(incoming)</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>2</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Follow up</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>14</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
</ActivityTypes>
</ActivitySet>
</ActivitySets>
<CaseRoles>
<RelationshipType>
<name>Case Coordinator</name>
<creator>1</creator>
</RelationshipType>
<RelationshipType>
<name>Supervisor</name>
</RelationshipType>
</CaseRoles>
</CaseType>

View file

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<CaseType>
<name>Economic, Social and Cultural</name>
<ActivityTypes>
<ActivityType>
<name>Open Case</name>
<max_instances>1</max_instances>
</ActivityType>
<ActivityType>
<name>Change Case Type</name>
</ActivityType>
<ActivityType>
<name>Change Case Status</name>
</ActivityType>
<ActivityType>
<name>Follow up</name>
</ActivityType>
<ActivityType>
<name>Source(incoming)</name>
</ActivityType>
<ActivityType>
<name>Incoming correspondence</name>
</ActivityType>
<ActivityType>
<name>Incoming Press Release</name>
</ActivityType>
<ActivityType>
<name>Complaint</name>
</ActivityType>
<ActivityType>
<name>Urgent Action(incoming)</name>
</ActivityType>
<ActivityType>
<name>Outgoing correspondence</name>
</ActivityType>
<ActivityType>
<name>Outgoing Press Release</name>
</ActivityType>
<ActivityType>
<name>FL Action(outgoing)</name>
</ActivityType>
<ActivityType>
<name>FL Urgent Action(outgoing)</name>
</ActivityType>
<ActivityType>
<name>Lobbying(outgoing)</name>
</ActivityType>
</ActivityTypes>
<ActivitySets>
<ActivitySet>
<name>standard_timeline</name>
<label>Standard Timeline</label>
<timeline>true</timeline>
<ActivityTypes>
<ActivityType>
<name>Open Case</name>
<status>Closed</status>
</ActivityType>
<ActivityType>
<name>Source(incoming)</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>2</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Follow up</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>14</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
</ActivityTypes>
</ActivitySet>
</ActivitySets>
<CaseRoles>
<RelationshipType>
<name>Case Coordinator</name>
<creator>1</creator>
</RelationshipType>
<RelationshipType>
<name>Supervisor</name>
</RelationshipType>
</CaseRoles>
</CaseType>

View file

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<CaseType>
<name>Gender Issues</name>
<ActivityTypes>
<ActivityType>
<name>Open Case</name>
<max_instances>1</max_instances>
</ActivityType>
<ActivityType>
<name>Change Case Type</name>
</ActivityType>
<ActivityType>
<name>Change Case Status</name>
</ActivityType>
<ActivityType>
<name>Follow up</name>
</ActivityType>
<ActivityType>
<name>Source(incoming)</name>
</ActivityType>
<ActivityType>
<name>Incoming correspondence</name>
</ActivityType>
<ActivityType>
<name>Incoming Press Release</name>
</ActivityType>
<ActivityType>
<name>Complaint</name>
</ActivityType>
<ActivityType>
<name>Urgent Action(incoming)</name>
</ActivityType>
<ActivityType>
<name>Outgoing correspondence</name>
</ActivityType>
<ActivityType>
<name>Outgoing Press Release</name>
</ActivityType>
<ActivityType>
<name>FL Action(outgoing)</name>
</ActivityType>
<ActivityType>
<name>FL Urgent Action(outgoing)</name>
</ActivityType>
<ActivityType>
<name>Lobbying(outgoing)</name>
</ActivityType>
</ActivityTypes>
<ActivitySets>
<ActivitySet>
<name>standard_timeline</name>
<label>Standard Timeline</label>
<timeline>true</timeline>
<ActivityTypes>
<ActivityType>
<name>Open Case</name>
<status>Closed</status>
</ActivityType>
<ActivityType>
<name>Source(incoming)</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>2</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Follow up</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>14</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
</ActivityTypes>
</ActivitySet>
</ActivitySets>
<CaseRoles>
<RelationshipType>
<name>Case Coordinator</name>
<creator>1</creator>
</RelationshipType>
<RelationshipType>
<name>Supervisor</name>
</RelationshipType>
</CaseRoles>
</CaseType>

View file

@ -0,0 +1,44 @@
-- /*******************************************************
-- *
-- * Configuration Data for CiviCase Component
-- * For: HRD
-- *
-- *******************************************************/
-- /*******************************************************
-- *
-- * Case Types
-- *
-- *******************************************************/
SELECT @caseCompId := id FROM `civicrm_component` where `name` like 'CiviCase';
INSERT INTO
`civicrm_case_type` (`title`, `name`, `weight`, `is_reserved`, `is_active`)
VALUES
('Civil and Political' , 'Civil and Political' , 1, NULL, 1, 1),
('Economic, Social and Cultural', 'Economic, Social and Cultural', 2, NULL, 1, 1),
('Gender Issues' , 'Gender Issues' , 3, NULL, 1, 1);
-- /*******************************************************
-- *
-- * Additional Case Activity Types
-- *
-- *******************************************************/
SELECT @option_group_id_activity_type := max(id) from civicrm_option_group where name = 'activity_type';
SELECT @max_val := MAX(ROUND(op.value)) FROM civicrm_option_value op WHERE op.option_group_id = @option_group_id_activity_type;
INSERT INTO
`civicrm_option_value` (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id` )
VALUES
(@option_group_id_activity_type, 'Source(incoming)', (SELECT @max_val := @max_val+1), 'Source(incoming)', NULL, 0, 0, (SELECT @max_val := @max_val+1), '', 0, 0, 1, @caseCompId ),
(@option_group_id_activity_type, 'Incoming correspondence', (SELECT @max_val := @max_val+1), 'Incoming correspondence', NULL, 0, 0, (SELECT @max_val := @max_val+1), '', 0, 0, 1, @caseCompId ),
(@option_group_id_activity_type, 'Incoming Press Release', (SELECT @max_val := @max_val+1), 'Incoming Press Release', NULL, 0, 0, (SELECT @max_val := @max_val+1), '', 0, 0, 1, @caseCompId ),
(@option_group_id_activity_type, 'Complaint', (SELECT @max_val := @max_val+1), 'Complaint', NULL, 0, 0, (SELECT @max_val := @max_val+1), '', 0, 0, 1, @caseCompId ),
(@option_group_id_activity_type, 'Urgent Action(incoming)', (SELECT @max_val := @max_val+1), 'Urgent Action(incoming)', NULL, 0, 0, (SELECT @max_val := @max_val+1), '', 0, 0, 1, @caseCompId ),
(@option_group_id_activity_type, 'Outgoing correspondence', (SELECT @max_val := @max_val+1), 'Outgoing correspondence', NULL, 0, 0, (SELECT @max_val := @max_val+1), '', 0, 0, 1, @caseCompId ),
(@option_group_id_activity_type, 'Outgoing Press Release', (SELECT @max_val := @max_val+1), 'Outgoing Press Release', NULL, 0, 0, (SELECT @max_val := @max_val+1), '', 0, 0, 1, @caseCompId ),
(@option_group_id_activity_type, 'FL Action(outgoing)', (SELECT @max_val := @max_val+1), 'FL Action(outgoing)', NULL, 0, 0, (SELECT @max_val := @max_val+1), '', 0, 0, 1, @caseCompId ),
(@option_group_id_activity_type, 'FL Urgent Action(outgoing)', (SELECT @max_val := @max_val+1), 'FL Urgent Action(outgoing)', NULL, 0, 0, (SELECT @max_val := @max_val+1), '', 0, 0, 1, @caseCompId ),
(@option_group_id_activity_type, 'Lobbying(outgoing)', (SELECT @max_val := @max_val+1), '', NULL, 0, 0, (SELECT @max_val := @max_val+1), '', 0, 0, 1, @caseCompId );

View file

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<menu>
<item>
<path>civicrm/case</path>
<title>CiviCase Dashboard</title>
<page_callback>CRM_Case_Page_DashBoard</page_callback>
<page_type>1</page_type>
<weight>900</weight>
<component>CiviCase</component>
</item>
<item>
<path>civicrm/case/add</path>
<title>Open Case</title>
<page_callback>CRM_Case_Form_Case</page_callback>
<page_type>1</page_type>
<component>CiviCase</component>
</item>
<item>
<path>civicrm/case/search</path>
<title>Find Cases</title>
<page_callback>CRM_Case_Controller_Search</page_callback>
<page_type>1</page_type>
<weight>910</weight>
</item>
<item>
<path>civicrm/case/activity</path>
<title>Case Activity</title>
<page_callback>CRM_Case_Form_Activity</page_callback>
</item>
<item>
<path>civicrm/case/report</path>
<title>Case Activity Audit</title>
<page_callback>CRM_Case_Form_Report</page_callback>
<access_arguments>access all cases and activities</access_arguments>
</item>
<item>
<path>civicrm/case/cd/edit</path>
<title>Case Custom Set</title>
<page_callback>CRM_Case_Form_CustomData</page_callback>
</item>
<item>
<path>civicrm/contact/view/case</path>
<title>Case</title>
<page_callback>CRM_Case_Page_Tab</page_callback>
</item>
<item>
<path>civicrm/case/activity/view</path>
<title>Activity View</title>
<page_callback>CRM_Case_Form_ActivityView</page_callback>
</item>
<item>
<path>civicrm/contact/view/case/editClient</path>
<title>Assign to Another Client</title>
<page_callback>CRM_Case_Form_EditClient</page_callback>
</item>
<item>
<path>civicrm/case/addToCase</path>
<title>File on Case</title>
<page_callback>CRM_Case_Form_ActivityToCase</page_callback>
</item>
<item>
<path>civicrm/case/details</path>
<title>Case Details</title>
<page_callback>CRM_Case_Page_CaseDetails</page_callback>
</item>
<item>
<path>civicrm/admin/setting/case</path>
<title>CiviCase Settings</title>
<page_callback>CRM_Admin_Form_Setting_Case</page_callback>
<adminGroup>CiviCase</adminGroup>
<icon>admin/small/36.png</icon>
<weight>380</weight>
</item>
<item>
<path>civicrm/admin/options/case_type</path>
<title>Case Types</title>
<desc>List of types which can be assigned to Cases. (Enable the Cases tab from System Settings - Enable Components if you want to track cases.)</desc>
<access_arguments>administer CiviCase</access_arguments>
<page_callback>CRM_Core_Page_Redirect</page_callback>
<page_arguments>url=civicrm/a/#/caseType</page_arguments>
<adminGroup>CiviCase</adminGroup>
<icon>admin/small/case_type.png</icon>
<weight>390</weight>
</item>
<item>
<path>civicrm/admin/options/redaction_rule</path>
<title>Redaction Rules</title>
<desc>List of rules which can be applied to user input strings so that the redacted output can be recognized as repeated instances of the same string or can be identified as a "semantic type of the data element" within case data.</desc>
<page_callback>CRM_Admin_Page_Options</page_callback>
<access_arguments>administer CiviCase</access_arguments>
<adminGroup>CiviCase</adminGroup>
<icon>admin/small/redaction_type.png</icon>
<weight>400</weight>
</item>
<item>
<path>civicrm/admin/options/case_status</path>
<title>Case Statuses</title>
<desc>List of statuses that can be assigned to a case.</desc>
<page_callback>CRM_Admin_Page_Options</page_callback>
<access_arguments>administer CiviCase</access_arguments>
<adminGroup>CiviCase</adminGroup>
<icon>admin/small/case_type.png</icon>
<weight>400</weight>
</item>
<item>
<path>civicrm/admin/options/encounter_medium</path>
<title>Encounter Mediums</title>
<desc>List of encounter mediums.</desc>
<page_callback>CRM_Admin_Page_Options</page_callback>
<access_arguments>administer CiviCase</access_arguments>
<adminGroup>CiviCase</adminGroup>
<icon>admin/small/case_type.png</icon>
<weight>400</weight>
</item>
<item>
<path>civicrm/case/report/print</path>
<page_callback>CRM_Case_XMLProcessor_Report::printCaseReport</page_callback>
<access_arguments>access all cases and activities</access_arguments>
</item>
<item>
<path>civicrm/case/ajax/addclient</path>
<page_callback>CRM_Case_Page_AJAX::addClient</page_callback>
</item>
<item>
<path>civicrm/case/ajax/processtags</path>
<page_callback>CRM_Case_Page_AJAX::processCaseTags</page_callback>
<access_arguments>access CiviCRM</access_arguments>
<page_type>3</page_type>
</item>
<item>
<path>civicrm/case/ajax/details</path>
<page_callback>CRM_Case_Page_AJAX::CaseDetails</page_callback>
</item>
<item>
<path>civicrm/ajax/delcaserole</path>
<page_callback>CRM_Case_Page_AJAX::deleteCaseRoles</page_callback>
</item>
</menu>

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<Settings>
<!--
DEPRECATED
The settings in this document should be migrated to the conventional settings framework, which allows
a greater variety of configuration-management practices (e.g. web-based config, API access, file overrides).
-->
<!-- List the group whose members should appear as contacts on all Manage Case screens.
Only one group name is supported for now.
It needs to match the name column in the civicrm_group table (not the title), so avoid using space characters. -->
<group name="Case_Resources" />
<!-- Set this to 1 if you want case activity emails to be redacted -->
<!-- SEE ALSO: Setting "civicaseRedactActivityEmail" -->
<RedactActivityEmail>0</RedactActivityEmail>
<!-- Set this to 1 if you want to allow multiple clients to be associated with a single case -->
<!-- SEE ALSO: Setting "civicaseAllowMultipleClients" -->
<AllowMultipleCaseClients>0</AllowMultipleCaseClients>
<!-- Set this to 1 if you want to have activity types on Manage Case
screen sorted in XML file order, default is alphabetical -->
<!-- SEE ALSO: Setting "civicaseNaturalActivityTypeSort" -->
<NaturalActivityTypeSort>0</NaturalActivityTypeSort>
<!-- Add activity types which should NOT be editable here with editable = 0 -->
<ActivityTypes>
<ActivityType>
<name>Change Case Status</name>
<editable>0</editable>
</ActivityType>
<ActivityType>
<name>Change Case Start Date</name>
<editable>0</editable>
</ActivityType>
</ActivityTypes>
</Settings>

View file

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<CaseType>
<name>Adult Day Care Referral</name>
<ActivityTypes>
<ActivityType>
<name>Open Case</name>
<max_instances>1</max_instances>
</ActivityType>
<ActivityType>
<name>Medical evaluation</name>
</ActivityType>
<ActivityType>
<name>Mental health evaluation</name>
</ActivityType>
<ActivityType>
<name>ADC referral</name>
</ActivityType>
<ActivityType>
<name>Follow up</name>
</ActivityType>
<ActivityType>
<name>Change Case Type</name>
</ActivityType>
<ActivityType>
<name>Change Case Status</name>
</ActivityType>
<ActivityType>
<name>Change Case Start Date</name>
</ActivityType>
<ActivityType>
<name>Link Cases</name>
</ActivityType>
</ActivityTypes>
<ActivitySets>
<ActivitySet>
<name>standard_timeline</name>
<label>Standard Timeline</label>
<timeline>true</timeline>
<ActivityTypes>
<ActivityType>
<name>Open Case</name>
<status>Completed</status>
</ActivityType>
<ActivityType>
<name>Medical evaluation</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>3</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Mental health evaluation</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>7</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>ADC referral</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>10</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Follow up</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>14</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
</ActivityTypes>
</ActivitySet>
</ActivitySets>
<CaseRoles>
<RelationshipType>
<name>Senior Services Coordinator</name>
<creator>1</creator>
<manager>1</manager>
</RelationshipType>
<RelationshipType>
<name>Health Services Coordinator</name>
</RelationshipType>
<RelationshipType>
<name>Benefits Specialist</name>
</RelationshipType>
</CaseRoles>
</CaseType>

View file

@ -0,0 +1,101 @@
-- /**********************************************************************
-- *
-- * Configuration Data for CiviCase Component
-- * For: Sample Case Types - Housing Support and Adult Day Care Referral
-- *
-- **********************************************************************/
SELECT @caseCompId := id FROM `civicrm_component` where `name` like 'CiviCase';
-- /*******************************************************
-- *
-- * Case Types
-- *
-- *******************************************************/
SELECT @max_wt := COALESCE( max(weight), 0 ) from civicrm_case_type;
INSERT IGNORE INTO `civicrm_case_type` ( {localize field='title'}`title`{/localize}, `name`, {localize field='description'}`description`{/localize}, `weight`, `is_reserved`, `is_active`) VALUES
({localize}'{ts escape="sql"}Housing Support{/ts}'{/localize}, 'housing_support', {localize}'{ts escape="sql"}Help homeless individuals obtain temporary and long-term housing{/ts}'{/localize}, @max_wt + 1, 0, 1),
({localize}'{ts escape="sql"}Adult Day Care Referral{/ts}'{/localize}, 'adult_day_care_referral', {localize}'{ts escape="sql"}Arranging adult day care for senior individuals{/ts}'{/localize}, @max_wt + 2, 0, 1);
-- CRM-15343 set the auto increment civicrm_case_type.id start point to max id to avoid conflict in future insertion
SELECT @max_case_type_id := max(id) from civicrm_case_type;
SET @query = CONCAT("ALTER TABLE civicrm_case_type AUTO_INCREMENT = ", IFNULL(@max_case_type_id,1));
PREPARE alter_case_type_auto_inc FROM @query;
EXECUTE alter_case_type_auto_inc;
DEALLOCATE PREPARE alter_case_type_auto_inc;
-- /*******************************************************
-- *
-- * Case Status - Set names for Open and Closed
-- *
-- *******************************************************/
SELECT @csgId := max(id) from civicrm_option_group where name = 'case_status';
{if $multilingual}
{foreach from=$locales item=locale}
UPDATE civicrm_option_value SET name = 'Open' where option_group_id = @csgId AND label_{$locale} = 'Ongoing';
UPDATE civicrm_option_value SET name = 'Closed' where option_group_id = @csgId AND label_{$locale} = 'Resolved';
{/foreach}
{else}
UPDATE civicrm_option_value SET name = 'Open' where option_group_id = @csgId AND label = 'Ongoing';
UPDATE civicrm_option_value SET name = 'Closed' where option_group_id = @csgId AND label = 'Resolved';
{/if}
-- /*******************************************************
-- *
-- * Activity Types
-- *
-- *******************************************************/
SELECT @option_group_id_activity_type := max(id) from civicrm_option_group where name = 'activity_type';
SELECT @max_val := MAX(ROUND(op.value)) FROM civicrm_option_value op WHERE op.option_group_id = @option_group_id_activity_type;
INSERT INTO `civicrm_option_value` ( `option_group_id`, {localize field='label'}`label`{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`, `component_id` )
(SELECT @option_group_id_activity_type, {localize}'{ts escape="sql"}Medical evaluation{/ts}'{/localize}, (SELECT @max_val := @max_val+1), 'Medical evaluation', NULL, 0, 0, (SELECT @max_val := @max_val+1), 0, 0, 1, @caseCompId
FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_option_value` WHERE `name` = 'Medical evaluation'));
INSERT INTO `civicrm_option_value` ( `option_group_id`, {localize field='label'}`label`{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`, `component_id` )
(SELECT @option_group_id_activity_type, {localize}'{ts escape="sql"}Mental health evaluation{/ts}'{/localize}, (SELECT @max_val := @max_val+1), 'Mental health evaluation', NULL, 0, 0, (SELECT @max_val := @max_val+1), 0, 0, 1, @caseCompId
FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_option_value` WHERE `name` = 'Mental health evaluation'));
INSERT INTO `civicrm_option_value` ( `option_group_id`, {localize field='label'}`label`{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`, `component_id` )
(SELECT @option_group_id_activity_type, {localize}'{ts escape="sql"}Secure temporary housing{/ts}'{/localize}, (SELECT @max_val := @max_val+1), 'Secure temporary housing', NULL, 0, 0, (SELECT @max_val := @max_val+1), 0, 0, 1, @caseCompId
FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_option_value` WHERE `name` = 'Secure temporary housing'));
INSERT INTO `civicrm_option_value` ( `option_group_id`, {localize field='label'}`label`{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`, `component_id` )
(SELECT @option_group_id_activity_type, {localize}'{ts escape="sql"}Income and benefits stabilization{/ts}'{/localize}, (SELECT @max_val := @max_val+1), 'Income and benefits stabilization', NULL, 0, 0, (SELECT @max_val := @max_val+1), 0, 0, 1, @caseCompId
FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_option_value` WHERE `name` = 'Income and benefits stabilization'));
INSERT INTO `civicrm_option_value` ( `option_group_id`, {localize field='label'}`label`{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`, `component_id` )
(SELECT @option_group_id_activity_type, {localize}'{ts escape="sql"}Long-term housing plan{/ts}'{/localize}, (SELECT @max_val := @max_val+1), 'Long-term housing plan', NULL, 0, 0, (SELECT @max_val := @max_val+1), 0, 0, 1, @caseCompId
FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_option_value` WHERE `name` = 'Long-term housing plan'));
INSERT INTO `civicrm_option_value` ( `option_group_id`, {localize field='label'}`label`{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`, `component_id` )
(SELECT @option_group_id_activity_type, {localize}'{ts escape="sql"}ADC referral{/ts}'{/localize}, (SELECT @max_val := @max_val+1), 'ADC referral', NULL, 0, 0, (SELECT @max_val := @max_val+1), 0, 0, 1, @caseCompId
FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_option_value` WHERE `name` = 'ADC referral'));
-- /*******************************************************
-- *
-- * Relationship Types
-- *
-- *******************************************************/
INSERT INTO `civicrm_relationship_type` ( `name_a_b`, {localize field='label_a_b'}`label_a_b`{/localize}, `name_b_a`, {localize field='label_b_a'}`label_b_a`{/localize}, {localize field='description'}`description`{/localize}, `contact_type_a`, `contact_type_b`, `is_reserved`, `is_active` ) (SELECT 'Homeless Services Coordinator is', {localize}'{ts escape="sql"}Homeless Services Coordinator is{/ts}'{/localize}, 'Homeless Services Coordinator', {localize}'{ts escape="sql"}Homeless Services Coordinator{/ts}'{/localize}, {localize}'{ts escape="sql"}Homeless Services Coordinator{/ts}'{/localize}, 'Individual', 'Individual', 0, 1 FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_relationship_type` WHERE `name_a_b` = 'Homeless Services Coordinator is'));
INSERT INTO `civicrm_relationship_type` ( `name_a_b`, {localize field='label_a_b'}`label_a_b`{/localize}, `name_b_a`, {localize field='label_b_a'}`label_b_a`{/localize}, {localize field='description'}`description`{/localize}, `contact_type_a`, `contact_type_b`, `is_reserved`, `is_active` ) (
SELECT 'Health Services Coordinator is', {localize}'{ts escape="sql"}Health Services Coordinator is{/ts}'{/localize}, 'Health Services Coordinator', {localize}'{ts escape="sql"}Health Services Coordinator{/ts}'{/localize}, {localize}'{ts escape="sql"}Health Services Coordinator{/ts}'{/localize}, 'Individual', 'Individual', 0, 1 FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_relationship_type` WHERE `name_a_b` = 'Health Services Coordinator is'));
INSERT INTO `civicrm_relationship_type` ( `name_a_b`, {localize field='label_a_b'}`label_a_b`{/localize}, `name_b_a`, {localize field='label_b_a'}`label_b_a`{/localize}, {localize field='description'}`description`{/localize}, `contact_type_a`, `contact_type_b`, `is_reserved`, `is_active` ) (
SELECT 'Senior Services Coordinator is', {localize}'{ts escape="sql"}Senior Services Coordinator is{/ts}'{/localize}, 'Senior Services Coordinator', {localize}'{ts escape="sql"}Senior Services Coordinator{/ts}'{/localize}, {localize}'{ts escape="sql"}Senior Services Coordinator{/ts}'{/localize}, 'Individual', 'Individual', 0, 1 FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_relationship_type` WHERE `name_a_b` = 'Senior Services Coordinator is'));
INSERT INTO `civicrm_relationship_type` ( `name_a_b`, {localize field='label_a_b'}`label_a_b`{/localize}, `name_b_a`, {localize field='label_b_a'}`label_b_a`{/localize}, {localize field='description'}`description`{/localize}, `contact_type_a`, `contact_type_b`, `is_reserved`, `is_active` ) (
SELECT 'Benefits Specialist is', {localize}'{ts escape="sql"}Benefits Specialist is{/ts}'{/localize}, 'Benefits Specialist', {localize}'{ts escape="sql"}Benefits Specialist{/ts}'{/localize}, {localize}'{ts escape="sql"}Benefits Specialist{/ts}'{/localize}, 'Individual', 'Individual', 0, 1 FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_relationship_type` WHERE `name_a_b` = 'Benefits Specialist is'));
-- /*******************************************************
-- *
-- * Case Resources Group
-- *
-- *******************************************************/
INSERT INTO `civicrm_group` ( `name`, {localize field='title'}`title`{/localize}, `description`, `source`, `saved_search_id`, `is_active`, `visibility`, `where_clause`, `select_tables`, `where_tables`, `group_type`, `cache_date`, `parents`, `children`, `is_hidden` ) (SELECT 'Case_Resources', {localize}'{ts escape="sql"}Case Resources{/ts}'{/localize}, 'Contacts in this group are listed with their phone number and email when viewing case. You also can send copies of case activities to these contacts.', NULL, NULL, 1, 'User and User Admin Only', ' ( `civicrm_group_contact-5`.group_id IN ( 5 ) AND `civicrm_group_contact-5`.status IN ("Added") ) ', '{literal}a:10:{s:15:"civicrm_contact";i:1;s:15:"civicrm_address";i:1;s:22:"civicrm_state_province";i:1;s:15:"civicrm_country";i:1;s:13:"civicrm_email";i:1;s:13:"civicrm_phone";i:1;s:10:"civicrm_im";i:1;s:19:"civicrm_worldregion";i:1;s:25:"`civicrm_group_contact-5`";s:114:" LEFT JOIN civicrm_group_contact `civicrm_group_contact-5` ON contact_a.id = `civicrm_group_contact-5`.contact_id ";s:6:"gender";i:1;}{/literal}', '{literal}a:2:{s:15:"civicrm_contact";i:1;s:25:"`civicrm_group_contact-5`";s:114:" LEFT JOIN civicrm_group_contact `civicrm_group_contact-5` ON contact_a.id = `civicrm_group_contact-5`.contact_id ";}{/literal}', '2', NULL, NULL, NULL, 0 FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_group` WHERE `name` = 'Case_Resources'));

View file

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<CaseType>
<name>Housing Support</name>
<ActivityTypes>
<ActivityType>
<name>Open Case</name>
<max_instances>1</max_instances>
</ActivityType>
<ActivityType>
<name>Medical evaluation</name>
</ActivityType>
<ActivityType>
<name>Mental health evaluation</name>
</ActivityType>
<ActivityType>
<name>Secure temporary housing</name>
</ActivityType>
<ActivityType>
<name>Income and benefits stabilization</name>
</ActivityType>
<ActivityType>
<name>Long-term housing plan</name>
</ActivityType>
<ActivityType>
<name>Follow up</name>
</ActivityType>
<ActivityType>
<name>Change Case Type</name>
</ActivityType>
<ActivityType>
<name>Change Case Status</name>
</ActivityType>
<ActivityType>
<name>Change Case Start Date</name>
</ActivityType>
<ActivityType>
<name>Link Cases</name>
</ActivityType>
</ActivityTypes>
<ActivitySets>
<ActivitySet>
<name>standard_timeline</name>
<label>Standard Timeline</label>
<timeline>true</timeline>
<ActivityTypes>
<ActivityType>
<name>Open Case</name>
<status>Completed</status>
</ActivityType>
<ActivityType>
<name>Medical evaluation</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>1</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Mental health evaluation</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>1</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Secure temporary housing</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>2</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Follow up</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>3</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Income and benefits stabilization</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>7</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Long-term housing plan</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>14</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
<ActivityType>
<name>Follow up</name>
<reference_activity>Open Case</reference_activity>
<reference_offset>21</reference_offset>
<reference_select>newest</reference_select>
</ActivityType>
</ActivityTypes>
</ActivitySet>
</ActivitySets>
<CaseRoles>
<RelationshipType>
<name>Homeless Services Coordinator</name>
<creator>1</creator>
<manager>1</manager>
</RelationshipType>
<RelationshipType>
<name>Health Services Coordinator</name>
</RelationshipType>
<RelationshipType>
<name>Benefits Specialist</name>
</RelationshipType>
</CaseRoles>
</CaseType>

View file

@ -0,0 +1,210 @@
<?xml version="1.0" encoding="UTF-8"?>
<Case>
<Client>Jack Smith, M.D.</Client>
<CaseType>Substance Abuse</CaseType>
<CaseSubject>Acute morphine addiction</CaseSubject>
<CaseStatus>Ongoing</CaseStatus>
<CaseOpen>2008-09-12</CaseOpen>
<CaseClose></CaseClose>
<ActivitySet>
<Label>15 Day Review</Label>
<IncludeActivities>All</IncludeActivities>
<Redact>false</Redact>
<Activity>
<EditURL>http://drupal.demo.civicrm.org/civicrm/activity?action=update&amp;id=13&amp;cid=201&amp;reset=1</EditURL>
<Fields>
<Field>
<Label>Activity Type</Label>
<Category>Case History</Category>
<Value>Open Case</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Created By</Label>
<Value>Ann Jones</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Reporter</Label>
<Value>Ann Jones</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Due Date</Label>
<Value>2008-09-12T11:00</Value>
<Type>Date</Type>
</Field>
<Field>
<Label>Activity Date</Label>
<Value>2008-09-12T11:00</Value>
<Type>Date</Type>
</Field>
<Field>
<Label>Subject</Label>
<Value>Opened the case during inbound phone call.</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Medium</Label>
<Value>Phone</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Duration</Label>
<Value>15</Value>
<Type>Int</Type>
</Field>
<Field>
<Label>Details</Label>
<Value>Client called very distressed and with suicidal thoughts.</Value>
<Type>Memo</Type>
</Field>
<Field>
<Label>Status</Label>
<Value>Completed</Value>
<Type>String</Type>
</Field>
</Fields>
</Activity>
<Activity>
<EditURL>http://drupal.demo.civicrm.org/civicrm/activity?action=update&amp;id=14&amp;cid=201&amp;reset=1</EditURL>
<Fields>
<Field>
<Label>Activity Type</Label>
<Category>Case History</Category>
<Value>Presenting Problem</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Created By</Label>
<Value>Ann Jones</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Reporter</Label>
<Value>Jack Smith, M.D.</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Due Date</Label>
<Value>2008-09-12</Value>
<Type>Date</Type>
</Field>
<Field>
<Label>Activity Date</Label>
<Value>2008-09-12T11:00</Value>
<Type>Date</Type>
</Field>
<Field>
<Label>Summary</Label>
<Value>Defined the problem as seen by the client.</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Medium</Label>
<Value>Phone</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Duration</Label>
<Value>30</Value>
<Type>Int</Type>
</Field>
<Field>
<Label>Details</Label>
<Value>Client admitted to heavy drug use and said he really needed help kicking the habit. Problem started after cycling accident in 2006.</Value>
<Type>Memo</Type>
</Field>
<Field>
<Label>Date First Noticed</Label>
<Value>2006-09-01</Value>
<Type>Date</Type>
</Field>
<Field>
<Label>Status</Label>
<Value>Completed</Value>
<Type>String</Type>
</Field>
</Fields>
</Activity>
<Activity>
<EditURL>http://drupal.demo.civicrm.org/civicrm/activity?action=update&amp;id=15&amp;cid=201&amp;reset=1</EditURL>
<Fields>
<Field>
<Label>Activity Type</Label>
<Category>Medications and Substance Use</Category>
<Value>Medication and Drug Use</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Created By</Label>
<Value>Ann Jones</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Reported By</Label>
<Value>Jack Smith, M.D.</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Due Date</Label>
<Value>2008-09-17</Value>
<Type>Date</Type>
</Field>
<Field>
<Label>Actual Date</Label>
<Value>2008-09-17T10:00</Value>
<Type>Date</Type>
</Field>
<Field>
<Label>Duration</Label>
<Value>50</Value>
<Type>Int</Type>
</Field>
<Field>
<Label>Details</Label>
<Value>Went through a list of all the client's prescribed and non-prescribed medication and drug usage, focusing on the last 2 years. Usage trends are significantly upward for the primary problem drug.</Value>
<Type>Memo</Type>
</Field>
<Field>
<Label>Medium</Label>
<Value>In-Person</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Prescribed Medication Listing</Label>
<Value>http://drupal.demo.civicrm.org/civicrm/file?reset=1&amp;id=1&amp;eid=102</Value>
<Type>File</Type>
</Field>
<CustomGroup>
<GroupName>Drug Usage</GroupName>
<Field>
<Label>Drug 1 - Drug Name</Label>
<Value>Morphine</Value>
<Type>String</Type>
</Field>
<Field>
<Label>Drug 1 - Preferred Drug</Label>
<Value>Yes</Value>
<Type>Boolean</Type>
</Field>
<Field>
<Label>Drug 1 - Date First Used</Label>
<Value>2006-09-01</Value>
<Type>Date</Type>
</Field>
<Field>
<Label>Drug 1 -Date Most Recently Used</Label>
<Value>2008-09-15</Value>
<Type>Date</Type>
</Field>
</CustomGroup>
<Field>
<Label>Status</Label>
<Value>Completed</Value>
<Type>String</Type>
</Field>
</Fields>
</Activity>
</ActivitySet>
</Case>