/** * This function sets the default values for the form. * * @param null * * @return array array of default values * @access public */ function setDefaultValues() { $defaults = array(); $format = CRM_Core_BAO_LabelFormat::getDefaultValues(); $defaults['label_name'] = CRM_Utils_Array::value('name', $format); $defaults['do_not_mail'] = 1; return $defaults; }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } $config = CRM_Core_Config::singleton(); $resources = CRM_Core_Resources::singleton(); $resources->addSetting(array('kcfinderPath' => $config->userFrameworkResourceURL . 'packages' . DIRECTORY_SEPARATOR)); $resources->addScriptFile('civicrm', 'templates/CRM/Badge/Form/Layout.js'); $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'), true); $labelStyle = CRM_Core_BAO_LabelFormat::getList(TRUE, 'name_badge'); $this->add('select', 'label_format_name', ts('Label Format'), array('' => ts('- select -')) + $labelStyle, TRUE); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title')); // get the tokens $contactTokens = CRM_Core_SelectValues::contactTokens(); $eventTokens = array('{event.event_id}' => ts('Event ID'), '{event.title}' => ts('Event Title'), '{event.start_date}' => ts('Event Start Date'), '{event.end_date}' => ts('Event End Date')); $participantTokens = CRM_Core_SelectValues::participantTokens(); $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'); $textAlignment = CRM_Core_BAO_LabelFormat::getTextAlignments(); $rowCount = self::FIELD_ROWCOUNT; for ($i = 1; $i <= $rowCount; $i++) { $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); $this->add('select', "text_alignment[{$i}]", ts('Alignment'), $textAlignment); } $rowCount++; $this->assign('rowCount', $rowCount); $barcodeTypes = CRM_Core_SelectValues::getBarcodeTypes(); $this->add('checkbox', 'add_barcode', ts('Barcode?')); $this->add('select', "barcode_type", ts('Type'), $barcodeTypes); $this->add('select', "barcode_alignment", ts('Alignment'), $textAlignment); $attributes = array('readonly' => true); $this->add('text', 'image_1', ts('Image (top left)'), $attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title')); $this->add('text', 'width_image_1', ts('Width (mm)'), array('size' => 6)); $this->add('text', 'height_image_1', ts('Height (mm)'), array('size' => 6)); $this->add('text', 'image_2', ts('Image (top right)'), $attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title')); $this->add('text', 'width_image_2', ts('Width (mm)'), array('size' => 6)); $this->add('text', 'height_image_2', ts('Height (mm)'), array('size' => 6)); $this->add('checkbox', 'is_default', ts('Default?')); $this->add('checkbox', 'is_active', ts('Enabled?')); $this->add('checkbox', 'is_reserved', ts('Reserved?')); $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('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'refresh', 'name' => ts('Save and Preview')), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Set default values for the form. * * @return array * array of default values */ public function setDefaultValues() { $defaults = array(); $format = CRM_Core_BAO_LabelFormat::getDefaultValues(); $defaults['label_name'] = CRM_Utils_Array::value('name', $format); $defaults['merge_same_address'] = 0; $defaults['merge_same_household'] = 0; $defaults['do_not_mail'] = 1; return $defaults; }
/** * Process the form submission. * * * @return void */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { // delete Label Format CRM_Core_BAO_LabelFormat::del($this->_id, $this->_group); CRM_Core_Session::setStatus(ts('Selected Label Format has been deleted.'), ts('Record Deleted'), 'success'); return; } if ($this->_action & CRM_Core_Action::COPY) { // make a copy of the Label Format $labelFormat = CRM_Core_BAO_LabelFormat::getById($this->_id, $this->_group); $newlabel = ts('Copy of %1', array(1 => $labelFormat['label'])); $list = CRM_Core_BAO_LabelFormat::getList(TRUE, $this->_group); $count = 1; while (in_array($newlabel, $list)) { $count++; $newlabel = ts('Copy %1 of %2', array(1 => $count, 2 => $labelFormat['label'])); } $labelFormat['label'] = $newlabel; $labelFormat['grouping'] = CRM_Core_BAO_LabelFormat::customGroupName(); $labelFormat['is_default'] = 0; $labelFormat['is_reserved'] = 0; $bao = new CRM_Core_BAO_LabelFormat(); $bao->saveLabelFormat($labelFormat, NULL, $this->_group); CRM_Core_Session::setStatus(ts('%1 has been created.', array(1 => $labelFormat['label'])), ts('Saved'), 'success'); return; } $values = $this->controller->exportValues($this->getName()); // since we currently support only mailing label format $values['label_type'] = 'label_format'; $values['is_default'] = isset($values['is_default']); // Restore field names that were converted because they are illegal PHP/SMARTY variable names if (isset($values['paper_size'])) { $values['paper-size'] = $values['paper_size']; unset($values['paper_size']); } if (isset($values['font_name'])) { $values['font-name'] = $values['font_name']; unset($values['font_name']); } if (isset($values['font_size'])) { $values['font-size'] = $values['font_size']; unset($values['font_size']); } $style = ''; if (isset($values['bold'])) { $style .= 'B'; } if (isset($values['italic'])) { $style .= 'I'; } $values['font-style'] = $style; $bao = new CRM_Core_BAO_LabelFormat(); $bao->saveLabelFormat($values, $this->_id, $values['label_type']); $status = ts('Your new Label Format titled <strong>%1</strong> has been saved.', array(1 => $values['label'])); if ($this->_action & CRM_Core_Action::UPDATE) { $status = ts('Your Label Format titled <strong>%1</strong> has been updated.', array(1 => $values['label'])); } CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); }
/** * initialize label format settings. * * @param $format * @param $unit */ public function LabelSetFormat(&$format, $unit) { $this->defaults = CRM_Core_BAO_LabelFormat::getDefaultValues(); $this->format =& $format; $this->formatName = $this->getFormatValue('name'); $this->paperSize = $this->getFormatValue('paper-size'); $this->orientation = $this->getFormatValue('orientation'); $this->fontName = $this->getFormatValue('font-name'); $this->charSize = $this->getFormatValue('font-size'); $this->fontStyle = $this->getFormatValue('font-style'); $this->xNumber = $this->getFormatValue('NX'); $this->yNumber = $this->getFormatValue('NY'); $this->metricDoc = $unit; $this->marginLeft = $this->getFormatValue('lMargin', TRUE); $this->marginTop = $this->getFormatValue('tMargin', TRUE); $this->xSpace = $this->getFormatValue('SpaceX', TRUE); $this->ySpace = $this->getFormatValue('SpaceY', TRUE); $this->width = $this->getFormatValue('width', TRUE); $this->height = $this->getFormatValue('height', TRUE); $this->paddingLeft = $this->getFormatValue('lPadding', TRUE); $this->paddingTop = $this->getFormatValue('tPadding', TRUE); $paperSize = CRM_Core_BAO_PaperSize::getByName($this->paperSize); $w = CRM_Utils_PDF_Utils::convertMetric($paperSize['width'], $paperSize['metric'], $this->metricDoc); $h = CRM_Utils_PDF_Utils::convertMetric($paperSize['height'], $paperSize['metric'], $this->metricDoc); $this->paper_dimensions = array($w, $h); }
/** * Browse all Label Format settings. * * @param null $action * * @return void */ public function browse($action = NULL) { // Get list of configured Label Formats $labelFormatList = CRM_Core_BAO_LabelFormat::getList(); $nameFormatList = CRM_Core_BAO_LabelFormat::getList(FALSE, 'name_badge'); // Add action links to each of the Label Formats foreach ($labelFormatList as &$format) { $action = array_sum(array_keys($this->links())); if (!empty($format['is_reserved'])) { $action -= CRM_Core_Action::DELETE; } $format['groupName'] = ts('Mailing Label'); $format['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $format['id'], 'group' => 'label_format'), ts('more'), FALSE, 'labelFormat.manage.action', 'LabelFormat', $format['id']); } // Add action links to each of the Label Formats foreach ($nameFormatList as &$format) { $format['groupName'] = ts('Name Badge'); } $labelFormatList = array_merge($labelFormatList, $nameFormatList); // Order Label Formats by weight $returnURL = CRM_Utils_System::url(self::userContext()); CRM_Core_BAO_LabelFormat::addOrder($labelFormatList, $returnURL); $this->assign('rows', $labelFormatList); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { // delete Label Format CRM_Core_BAO_LabelFormat::del($this->_id); CRM_Core_Session::setStatus(ts('Selected Label Format has been deleted.')); return; } if ($this->_action & CRM_Core_Action::COPY) { // make a copy of the Label Format $labelFormat = CRM_Core_BAO_LabelFormat::getById($this->_id); $list = CRM_Core_BAO_LabelFormat::getList(TRUE); $count = 1; $prefix = ts('Copy of '); while (in_array($prefix . $labelFormat['label'], $list)) { $prefix = ts('Copy') . ' (' . ++$count . ') ' . ts('of '); } $labelFormat['label'] = $prefix . $labelFormat['label']; $labelFormat['grouping'] = CRM_Core_BAO_LabelFormat::customGroupName(); $labelFormat['is_default'] = 0; $labelFormat['is_reserved'] = 0; $bao = new CRM_Core_BAO_LabelFormat(); $bao->saveLabelFormat($labelFormat); CRM_Core_Session::setStatus($labelFormat['label'] . ts(' has been created.')); return; } $values = $this->controller->exportValues($this->getName()); $values['is_default'] = isset($values['is_default']); // Restore field names that were converted because they are illegal PHP/SMARTY variable names if (isset($values['paper_size'])) { $values['paper-size'] = $values['paper_size']; unset($values['paper_size']); } if (isset($values['font_name'])) { $values['font-name'] = $values['font_name']; unset($values['font_name']); } if (isset($values['font_size'])) { $values['font-size'] = $values['font_size']; unset($values['font_size']); } $style = ''; if (isset($values['bold'])) { $style .= 'B'; } if (isset($values['italic'])) { $style .= 'I'; } $values['font-style'] = $style; $bao = new CRM_Core_BAO_LabelFormat(); $bao->saveLabelFormat($values, $this->_id); $status = ts('Your new Label Format titled <strong>%1</strong> has been saved.', array(1 => $values['label'])); if ($this->_action & CRM_Core_Action::UPDATE) { $status = ts('Your Label Format titled <strong>%1</strong> has been updated.', array(1 => $values['label'])); } CRM_Core_Session::setStatus($status); }
/** * Browse all Label Format settings. * * @return void * @access public * @static */ function browse($action = NULL) { // Get list of configured Label Formats $labelFormatList = CRM_Core_BAO_LabelFormat::getList(); // Add action links to each of the Label Formats foreach ($labelFormatList as &$format) { $action = array_sum(array_keys($this->links())); if ($format['is_reserved']) { $action -= CRM_Core_Action::DELETE; } $format['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $format['id'])); } // Order Label Formats by weight $returnURL = CRM_Utils_System::url(self::userContext()); CRM_Core_BAO_LabelFormat::addOrder($labelFormatList, $returnURL); $this->assign('rows', $labelFormatList); }
/** * Get Option Group ID for Label Formats * * @param void * * @return int Group ID (null if Group ID doesn't exist) * @access private */ private function _getGid() { if (!self::$_gid) { self::$_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'label_format', 'id', 'name'); if (!self::$_gid) { CRM_Core_Error::fatal(ts('Label Format Option Group not found in database.')); } } return self::$_gid; }