3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * This class helps to print the labels for contacts
40 class CRM_Member_Form_Task_Label
extends CRM_Member_Form_Task
{
43 * Build all the data structures needed to build the form.
47 public function preProcess() {
49 $this->setContactIDs();
50 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'templates/CRM/Member/Form/Task/Label.js');
54 * Build the form object.
59 public function buildQuickForm() {
60 CRM_Contact_Form_Task_Label
::buildQuickForm($this);
61 $this->addElement('checkbox', 'per_membership', ts('Print one label per Membership (rather than per contact)'));
65 * Set default values for the form.
68 * array of default values
70 public function setDefaultValues() {
72 $format = CRM_Core_BAO_LabelFormat
::getDefaultValues();
73 $defaults['label_name'] = CRM_Utils_Array
::value('name', $format);
74 $defaults['merge_same_address'] = 0;
75 $defaults['merge_same_household'] = 0;
76 $defaults['do_not_mail'] = 1;
81 * Process the form after the input has been submitted and validated.
86 public function postProcess() {
87 $formValues = $this->controller
->exportValues($this->_name
);
88 $locationTypeID = $formValues['location_type_id'];
89 $respectDoNotMail = CRM_Utils_Array
::value('do_not_mail', $formValues);
90 $labelName = $formValues['label_name'];
91 $mergeSameAddress = CRM_Utils_Array
::value('merge_same_address', $formValues);
92 $mergeSameHousehold = CRM_Utils_Array
::value('merge_same_household', $formValues);
93 $isPerMembership = CRM_Utils_Array
::value('per_membership', $formValues);
94 if ($isPerMembership && ($mergeSameAddress ||
$mergeSameHousehold)) {
95 // this shouldn't happen - perhaps is could if JS is disabled
96 CRM_Core_Session
::setStatus(ts('As you are printing one label per membership your merge settings are being ignored'));
97 $mergeSameAddress = $mergeSameHousehold = FALSE;
99 // so no-one is tempted to refer to this again after relevant values are extracted
102 list($rows, $tokenFields) = CRM_Contact_Form_Task_LabelCommon
::getRows($this->_contactIds
, $locationTypeID, $respectDoNotMail, $mergeSameAddress, $mergeSameHousehold);
104 $individualFormat = FALSE;
105 if ($mergeSameAddress) {
106 CRM_Core_BAO_Address
::mergeSameAddress($rows);
107 $individualFormat = TRUE;
109 if ($mergeSameHousehold) {
110 $rows = CRM_Contact_Form_Task_LabelCommon
::mergeSameHousehold($rows);
111 $individualFormat = TRUE;
113 // format the addresses according to CIVICRM_ADDRESS_FORMAT (CRM-1327)
114 foreach ($rows as $id => $row) {
115 if ($commMethods = CRM_Utils_Array
::value('preferred_communication_method', $row)) {
116 $val = array_filter(explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $commMethods));
117 $comm = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
119 foreach ($val as $vals) {
120 $temp[] = $comm[$vals];
122 $row['preferred_communication_method'] = implode(', ', $temp);
125 $formatted = CRM_Utils_Address
::format($row, 'mailing_format', FALSE, TRUE, $individualFormat, $tokenFields);
126 $rows[$id] = array($formatted);
129 if ($isPerMembership) {
130 $labelRows = array();
131 $memberships = civicrm_api3('membership', 'get', array(
132 'id' => array('IN' => $this->_memberIds
),
133 'return' => 'contact_id',
135 foreach ($memberships['values'] as $id => $membership) {
136 $labelRows[$id] = $rows[$membership['contact_id']];
142 //call function to create labels
143 CRM_Contact_Form_Task_LabelCommon
::createLabel($labelRows, $labelName);
144 CRM_Utils_System
::civiExit(1);