CRM-17606 - Add 'Print Document' button on manage case screen
[civicrm-core.git] / CRM / Case / Form / CaseView.php
index 315972c160e1bd3e49fc9106ff18e50b5a33de52..3932eed6c8be61463cd0ea17d8bfc8c1837bec86 100644 (file)
  *
  * @package CRM
  * @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
  */
 
 /**
- * This class generates view mode for CiviCase
- *
+ * This class generates view mode for CiviCase.
  */
 class CRM_Case_Form_CaseView extends CRM_Core_Form {
   /**
@@ -46,8 +43,6 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
 
   /**
    * Set variables up before form is built.
-   *
-   * @return void
    */
   public function preProcess() {
     $this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET);
@@ -88,6 +83,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
 
     $this->assign('caseID', $this->_caseID);
     $this->assign('contactID', $this->_contactID);
+    $this->assign('contactType', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type'));
 
     //validate case id.
     $this->_userCases = array();
@@ -194,11 +190,9 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
   }
 
   /**
-   * Set default values for the form. For edit/view mode
-   * the default values are retrieved from the database
+   * Set default values for the form.
    *
-   *
-   * @return void
+   * @return array;
    */
   public function setDefaultValues() {
     $defaults = array();
@@ -207,8 +201,6 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
 
   /**
    * Build the form object.
-   *
-   * @return void
    */
   public function buildQuickForm() {
     //this call is for show related cases.
@@ -216,9 +208,12 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
       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');
+      ->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');
@@ -237,6 +232,11 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
     $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]);
@@ -274,17 +274,17 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
       $activityLinks[$url] = $label;
     }
 
-    $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-plus twenty'));
+    $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 action-icon-clipboard')
+        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 action-icon-play')
+        array('class' => 'crm-select2 crm-action-menu fa-list-ol')
       );
     }
     $this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement'));
@@ -377,14 +377,14 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
     CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo);
     $this->assign('globalGroupInfo', $globalGroupInfo);
 
-    // List of relationship types
-    $baoRel = new CRM_Contact_BAO_Relationship();
-    $relType = $baoRel->getRelationType('Individual');
-    $roleTypes = array();
-    foreach ($relType as $k => $v) {
-      $roleTypes[substr($k, 0, strpos($k, '_'))] = $v;
-    }
-    $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes, FALSE, array('class' => 'crm-select2 twenty'));
+    // 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)) {
@@ -444,8 +444,6 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
 
   /**
    * Process the form.
-   *
-   * @return void
    */
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);