From 50f52554f125be745151888c6c2742b1c7220fef Mon Sep 17 00:00:00 2001 From: kurund Date: Tue, 10 Sep 2013 11:27:13 +0530 Subject: [PATCH] CRM-13329, added spacer ---------------------------------------- * CRM-13329: Add 2 more rows to the Badge Layout form (for a total of 6 rows) http://issues.civicrm.org/jira/browse/CRM-13329 --- CRM/Badge/BAO/Badge.php | 35 +++++++++++++++++++++-------------- CRM/Badge/Form/Layout.php | 39 +++++++-------------------------------- 2 files changed, 28 insertions(+), 46 deletions(-) diff --git a/CRM/Badge/BAO/Badge.php b/CRM/Badge/BAO/Badge.php index 34d2bee27f..2e897bfdd2 100644 --- a/CRM/Badge/BAO/Badge.php +++ b/CRM/Badge/BAO/Badge.php @@ -101,6 +101,7 @@ class CRM_Badge_BAO_Badge { 'font_size' => $layout['data']['font_size'][$key], 'font_style' => $layout['data']['font_style'][$key], 'text_alignment' => $layout['data']['text_alignment'][$key], + 'token' => $layout['data']['token'][$key], ); } } @@ -181,25 +182,31 @@ class CRM_Badge_BAO_Badge { $titleWidth = $titleRightMargin; } + // first row is a special row because we have images on the side + $value = ''; + if ($formattedRow['token'][1]['token'] != 'spacer') { + $value = $formattedRow['token'][1]['value']; + } + $this->pdf->SetFont($formattedRow['token'][1]['font_name'], $formattedRow['token'][1]['font_style'], $formattedRow['token'][1]['font_size']); - $this->pdf->MultiCell($this->pdf->width - $titleWidth, 0, $formattedRow['token'][1]['value'], + $this->pdf->MultiCell($this->pdf->width - $titleWidth, 0, $value, $this->border, $formattedRow['token'][1]['text_alignment'], 0, 1, $x + $titleLeftMargin, $y); - $this->pdf->SetFont($formattedRow['token'][2]['font_name'], $formattedRow['token'][2]['font_style'], - $formattedRow['token'][2]['font_size']); - $this->pdf->MultiCell($this->pdf->width, 10, $formattedRow['token'][2]['value'], - $this->border, $formattedRow['token'][2]['text_alignment'], 0, 1, $x, $y + $this->tMarginName); - - $this->pdf->SetFont($formattedRow['token'][3]['font_name'], $formattedRow['token'][3]['font_style'], - $formattedRow['token'][3]['font_size']); - $this->pdf->MultiCell($this->pdf->width, 0, $formattedRow['token'][3]['value'], - $this->border, $formattedRow['token'][3]['text_alignment'], 0, 1, $x, $this->pdf->getY()); + $rowCount = CRM_Badge_Form_Layout::FIELD_ROWCOUNT; + for ($i = 2; $i <= $rowCount; $i++) { + if (!empty($formattedRow['token'][$i]['token'])) { + $value = ''; + if ($formattedRow['token'][$i]['token'] != 'spacer') { + $value = $formattedRow['token'][$i]['value']; + } - $this->pdf->SetFont($formattedRow['token'][4]['font_name'], $formattedRow['token'][4]['font_style'], - $formattedRow['token'][4]['font_size']); - $this->pdf->MultiCell($this->pdf->width, 0, $formattedRow['token'][4]['value'], - $this->border, $formattedRow['token'][4]['text_alignment'], 0, 1, $x, $y + $this->pdf->height - 5); + $this->pdf->SetFont($formattedRow['token'][$i]['font_name'], $formattedRow['token'][$i]['font_style'], + $formattedRow['token'][$i]['font_size']); + $this->pdf->MultiCell($this->pdf->width, 0, $value, + $this->border, $formattedRow['token'][$i]['text_alignment'], 0, 1, $x, $this->pdf->getY()); + } + } if (CRM_Utils_Array::value('barcode', $formattedRow)) { $data = $formattedRow['values']; diff --git a/CRM/Badge/Form/Layout.php b/CRM/Badge/Form/Layout.php index 9c6963ec88..d70cca65b3 100644 --- a/CRM/Badge/Form/Layout.php +++ b/CRM/Badge/Form/Layout.php @@ -90,6 +90,8 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form { $tokens = array_merge($contactTokens, $eventTokens, $participantTokens); asort($tokens); + $tokens = array_merge(array('spacer' => ts('- spacer -')) + $tokens); + $fontSizes = CRM_Core_BAO_LabelFormat::getFontSizes(); $fontStyles = CRM_Core_BAO_LabelFormat::getFontStyles(); $fontNames = CRM_Core_BAO_LabelFormat::getFontNames('name_badge'); @@ -97,7 +99,7 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form { $rowCount = self::FIELD_ROWCOUNT; for ( $i =1; $i <= $rowCount; $i++ ) { - $this->add('select', "token[$i]", ts('Token'), array('' => ts('- none -')) + $tokens); + $this->add('select', "token[$i]", ts('Token'), array('' => ts('- skip -')) + $tokens); $this->add('select', "font_name[$i]", ts('Font Name'), $fontNames); $this->add('select', "font_size[$i]", ts('Font Size'), $fontSizes); $this->add('select', "font_style[$i]", ts('Font Style'), $fontStyles); @@ -127,11 +129,10 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form { $this->add('checkbox', 'is_active', ts('Enabled?')); $this->add('checkbox', 'is_reserved', ts('Reserved?')); - $this->addRule('width_image_1', ts('Width not valid'), 'positiveInteger'); - $this->addRule('width_image_2', ts('Width not valid'), 'positiveInteger'); - $this->addRule('height_image_1', ts('Height not valid'), 'positiveInteger'); - $this->addRule('height_image_2', ts('Height not valid'), 'positiveInteger'); - $this->addFormRule(array('CRM_Badge_Form_Layout', 'formRule')); + $this->addRule('width_image_1', ts('Enter valid width'), 'positiveInteger'); + $this->addRule('width_image_2', ts('Enter valid width'), 'positiveInteger'); + $this->addRule('height_image_1', ts('Enter valid height'), 'positiveInteger'); + $this->addRule('height_image_2', ts('Enter valid height'), 'positiveInteger'); $this->addButtons(array( array( @@ -151,32 +152,6 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form { ); } - /** - * form rule - * - * @param array $fields the input form values - * - * @return true if no errors, else array of errors - * @access public - * @static - */ - static function formRule($fields) { - $errors = array(); - - if (CRM_Utils_Array::value(4, $fields['token']) - && CRM_Utils_Array::value('add_barcode', $fields) - && (CRM_Utils_Array::value('barcode_alignment', $fields) == CRM_Utils_Array::value(4, $fields['text_alignment'])) - ) { - $errors['barcode_alignment'] = ts('You cannot have same alignment for barcode and #4 row.'); - } - - if (!empty($errors)) { - return $errors; - } - - return empty($errors) ? TRUE : $errors; - } - /** * This function sets the default values for the form. MobileProvider that in edit/view mode * the default values are retrieved from the database -- 2.25.1