CRM-17606 - Add 'Print Document' button on manage case screen
[civicrm-core.git] / CRM / Case / Form / Task.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 */
33
34/**
df371444 35 * This class generates task actions for CiviEvent.
6a488035
TO
36 */
37class CRM_Case_Form_Task extends CRM_Core_Form {
38
39 /**
100fef9d 40 * The task being performed
6a488035
TO
41 *
42 * @var int
43 */
44 protected $_task;
45
46 /**
47 * The additional clause that we restrict the search with
48 *
49 * @var string
50 */
51 protected $_componentClause = NULL;
52
53 /**
54 * The array that holds all the component ids
55 *
56 * @var array
57 */
58 protected $_componentIds;
59
60 /**
61 * The array that holds all the case ids
62 *
63 * @var array
64 */
65 protected $_caseIds;
66
67 /**
fe482240 68 * Build all the data structures needed to build the form.
6a488035 69 */
00be9182 70 public function preProcess() {
6a488035
TO
71 self::preProcessCommon($this);
72 }
73
4c6ce474 74 /**
c490a46a 75 * @param CRM_Core_Form $form
4c6ce474
EM
76 * @param bool $useTable
77 */
00be9182 78 public static function preProcessCommon(&$form, $useTable = FALSE) {
6a488035
TO
79 $form->_caseIds = array();
80
81 $values = $form->controller->exportValues($form->get('searchFormName'));
82
83 $form->_task = $values['task'];
84 $caseTasks = CRM_Case_Task::tasks();
85 $form->assign('taskName', $caseTasks[$form->_task]);
86
87 $ids = array();
88 if ($values['radio_ts'] == 'ts_sel') {
89 foreach ($values as $name => $value) {
90 if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
91 $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
92 }
93 }
94 }
95 else {
96 $queryParams = $form->get('queryParams');
97 $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
98 CRM_Contact_BAO_Query::MODE_CASE
99 );
100 $query->_distinctComponentClause = " ( civicrm_case.id )";
101 $query->_groupByComponentClause = " GROUP BY civicrm_case.id ";
102 $result = $query->searchQuery(0, 0, NULL);
103 while ($result->fetch()) {
104 $ids[] = $result->case_id;
105 }
106 }
107
108 if (!empty($ids)) {
109 $form->_componentClause = ' civicrm_case.id IN ( ' . implode(',', $ids) . ' ) ';
110 $form->assign('totalSelectedCases', count($ids));
111 }
112
113 $form->_caseIds = $form->_componentIds = $ids;
114
115 //set the context for redirection for any task actions
116 $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
117 $urlParams = 'force=1';
118 if (CRM_Utils_Rule::qfKey($qfKey)) {
119 $urlParams .= "&qfKey=$qfKey";
120 }
121
122 $session = CRM_Core_Session::singleton();
123 $searchFormName = strtolower($form->get('searchFormName'));
124 if ($searchFormName == 'search') {
125 $session->replaceUserContext(CRM_Utils_System::url('civicrm/case/search', $urlParams));
126 }
127 else {
128 $session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/$searchFormName",
353ffa53
TO
129 $urlParams
130 ));
6a488035
TO
131 }
132 }
133
134 /**
135 * Given the signer id, compute the contact id
136 * since its used for things like send email
137 */
138 public function setContactIDs() {
139 $this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_caseIds,
140 'civicrm_case'
141 );
142 }
143
144 /**
100fef9d 145 * Simple shell that derived classes can call to add buttons to
6a488035
TO
146 * the form with a customized title for the main Submit
147 *
64bd5a0e
TO
148 * @param string $title
149 * Title of the main button.
150 * @param string $nextType
151 * Button type for the form after processing.
dd244018
EM
152 * @param string $backType
153 * @param bool $submitOnce
6a488035 154 */
00be9182 155 public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
6a488035
TO
156 $this->addButtons(array(
157 array(
158 'type' => $nextType,
159 'name' => $title,
160 'isDefault' => TRUE,
161 ),
162 array(
163 'type' => $backType,
164 'name' => ts('Cancel'),
165 ),
166 )
167 );
168 }
96025800 169
6a488035 170}