INFRA-132 - CRM/Mailing - phpcbf
[civicrm-core.git] / CRM / Mailing / Form / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components for relationship
38 *
39 */
40 class CRM_Mailing_Form_Task extends CRM_Core_Form {
41
42 /**
43 * The task being performed
44 *
45 * @var int
46 */
47 protected $_task;
48
49 /**
50 * The additional clause that we restrict the search with
51 *
52 * @var string
53 */
54 protected $_componentClause = NULL;
55
56 /**
57 * The array that holds all the component ids
58 *
59 * @var array
60 */
61 protected $_componentIds;
62
63 /**
64 * Build all the data structures needed to build the form
65 *
66 * @param
67 *
68 * @return void
69 */
70 public function preProcess() {
71 self::preProcessCommon($this);
72 }
73
74 /**
75 * @param CRM_Core_Form $form
76 * @param bool $useTable
77 */
78 public static function preProcessCommon(&$form, $useTable = FALSE) {
79 $values = $form->controller->exportValues($form->get('searchFormName'));
80
81 $form->_task = CRM_Utils_Array::value('task', $values);
82 $mailingTasks = CRM_Mailing_Task::tasks();
83 $form->assign('taskName', CRM_Utils_Array::value('task', $values));
84
85 // ids are mailing event queue ids
86 $ids = array();
87 if ($values['radio_ts'] == 'ts_sel') {
88 foreach ($values as $name => $value) {
89 if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
90 $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
91 }
92 }
93 }
94 else {
95 $queryParams = $form->get('queryParams');
96 $sortOrder = NULL;
97 if ( $form->get( CRM_Utils_Sort::SORT_ORDER ) ) {
98 $sortOrder = $form->get( CRM_Utils_Sort::SORT_ORDER );
99 }
100
101 $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
102 CRM_Contact_BAO_Query::MODE_MAILING
103 );
104
105 $result = $query->searchQuery(0, 0, $sortOrder);
106 while ($result->fetch()) {
107 $ids[] = $result->mailing_recipients_id;
108 }
109 $form->assign('totalSelectedMailingRecipients', $form->get('rowCount'));
110 }
111
112 if (!empty($ids)) {
113 $form->_componentClause = ' civicrm_mailing_recipients.id IN ( ' . implode(',', $ids) . ' ) ';
114 }
115
116 //set the context for redirection for any task actions
117 $session = CRM_Core_Session::singleton();
118
119 $fragment = 'search';
120 if ($form->_action == CRM_Core_Action::ADVANCED) {
121 $fragment .= '/advanced';
122 }
123
124 $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
125 $urlParams = 'force=1';
126 if (CRM_Utils_Rule::qfKey($qfKey)) {
127 $urlParams .= "&qfKey=$qfKey";
128 }
129
130 $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
131 $session = CRM_Core_Session::singleton();
132 $session->replaceUserContext($url);
133 }
134
135 /**
136 * Simple shell that derived classes can call to add buttons to
137 * the form with a customized title for the main Submit
138 *
139 * @param string $title
140 * Title of the main button.
141 * @param string $nextType
142 * @param string $backType
143 * @param bool $submitOnce
144 *
145 *
146 * @return void
147 */
148 public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
149 $this->addButtons(array(
150 array(
151 'type' => $nextType,
152 'name' => $title,
153 'isDefault' => TRUE,
154 ),
155 array(
156 'type' => $backType,
157 'name' => ts('Cancel'),
158 ),
159 )
160 );
161 }
162 }