3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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
48 function preProcess() {
50 $this->setContactIDs();
51 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'templates/CRM/Member/Form/Task/Label.js');
61 function buildQuickForm() {
62 CRM_Contact_Form_Task_Label
::buildQuickForm($this);
63 $this->addElement('checkbox', 'per_membership', ts('Print one label per Membership (rather than per contact)'));
67 * This function sets the default values for the form.
71 * @return array array of default values
74 function setDefaultValues() {
76 $format = CRM_Core_BAO_LabelFormat
::getDefaultValues();
77 $defaults['label_name'] = CRM_Utils_Array
::value('name', $format);
78 $defaults['merge_same_address'] = 0;
79 $defaults['merge_same_household'] = 0;
80 $defaults['do_not_mail'] = 1;
85 * process the form after the input has been submitted and validated
91 public function postProcess() {
92 $formValues = $this->controller
->exportValues($this->_name
);
93 $locationTypeID = $formValues['location_type_id'];
94 $respectDoNotMail = CRM_Utils_Array
::value('do_not_mail', $formValues);
95 $labelName = $formValues['label_name'];
96 $mergeSameAddress = CRM_Utils_Array
::value('merge_same_address', $formValues);
97 $mergeSameHousehold = CRM_Utils_Array
::value('merge_same_household', $formValues);
98 $isPerMembership = CRM_Utils_Array
::value('per_membership', $formValues);
99 if($isPerMembership && ($mergeSameAddress ||
$mergeSameHousehold)) {
100 // this shouldn't happen - perhaps is could if JS is disabled
101 CRM_Core_Session
::setStatus(ts('As you are printing one label per membership your merge settings are being ignored'));
102 $mergeSameAddress = $mergeSameHousehold = FALSE;
104 // so no-one is tempted to refer to this again after relevant values are extracted
107 list($rows, $tokenFields) = CRM_Contact_Form_Task_LabelCommon
::getRows($this->_contactIds
, $locationTypeID, $respectDoNotMail, $mergeSameAddress, $mergeSameHousehold);
109 $individualFormat = FALSE;
110 if ($mergeSameAddress) {
111 CRM_Contact_Form_Task_LabelCommon
::mergeSameAddress($rows);
112 $individualFormat = TRUE;
114 if ($mergeSameHousehold) {
115 $rows = CRM_Contact_Form_Task_LabelCommon
::mergeSameHousehold($rows);
116 $individualFormat = TRUE;
118 // format the addresses according to CIVICRM_ADDRESS_FORMAT (CRM-1327)
119 foreach ($rows as $id => $row) {
120 if ($commMethods = CRM_Utils_Array
::value('preferred_communication_method', $row)) {
121 $val = array_filter(explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $commMethods));
122 $comm = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
124 foreach ($val as $vals) {
125 $temp[] = $comm[$vals];
127 $row['preferred_communication_method'] = implode(', ', $temp);
130 $formatted = CRM_Utils_Address
::format($row, 'mailing_format', FALSE, TRUE, $individualFormat, $tokenFields);
131 $rows[$id] = array($formatted);
134 if($isPerMembership) {
135 $labelRows = array();
136 $memberships = civicrm_api3('membership', 'get', array('id' => array('IN' => $this->_memberIds
), 'return' => 'contact_id'));
137 foreach ($memberships['values'] as $id => $membership) {
138 $labelRows[$id] = $rows[$membership['contact_id']];
144 //call function to create labels
145 CRM_Contact_Form_Task_LabelCommon
::createLabel($labelRows, $labelName);
146 CRM_Utils_System
::civiExit(1);