*/
protected $_id = NULL;
+ /**
+ * Group name, label format or name badge
+ */
+ protected $_group = NULL;
+
+ function preProcess() {
+ $this->_id = $this->get('id');
+ $this->_group = CRM_Utils_Request::retrieve('group', 'String', $this, FALSE, 'label_format');
+ $this->_values = array();
+ if (isset($this->_id)) {
+ $params = array('id' => $this->_id);
+ CRM_Core_BAO_LabelFormat::retrieve($params, $this->_values, $this->_group);
+ }
+ }
+
/**
* Function to build the form
*
return;
}
- $disabled = array();
- $required = TRUE;
+ $disabled = array();
+ $required = TRUE;
$is_reserved = $this->_id ? CRM_Core_BAO_LabelFormat::getFieldValue('CRM_Core_BAO_LabelFormat', $this->_id, 'is_reserved') : FALSE;
if ($is_reserved) {
$disabled['disabled'] = 'disabled';
$this->add('checkbox', 'is_default', ts('Is this Label Format the default?'));
$this->add('select', 'paper_size', ts('Sheet Size'),
array(
- 0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE,
+ 0 => ts('- default -')
+ ) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE,
array(
- 'onChange' => "selectPaper( this.value );") + $disabled
+ 'onChange' => "selectPaper( this.value );"
+ ) + $disabled
);
$this->add('static', 'paper_dimensions', NULL, ts('Sheet Size (w x h)'));
$this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_LabelFormat::getPageOrientations(), FALSE,
array(
- 'onChange' => "updatePaperDimensions();") + $disabled
+ 'onChange' => "updatePaperDimensions();"
+ ) + $disabled
);
- $this->add('select', 'font_name', ts('Font Name'), CRM_Core_BAO_LabelFormat::getFontNames());
+ $this->add('select', 'font_name', ts('Font Name'), CRM_Core_BAO_LabelFormat::getFontNames($this->_group));
$this->add('select', 'font_size', ts('Font Size'), CRM_Core_BAO_LabelFormat::getFontSizes());
$this->add('static', 'font_style', ts('Font Style'));
$this->add('checkbox', 'bold', ts('Bold'));
$this->add('text', 'tPadding', ts('Top Padding'), array('size' => 8, 'maxlength' => 8), $required);
$this->add('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_LabelFormat', 'weight'), TRUE);
- $this->addRule('label', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_BAO_LabelFormat', $this->_id));
+ $this->addRule('label', ts('Name already exists in Database.'), 'objectExists', array(
+ 'CRM_Core_BAO_LabelFormat',
+ $this->_id
+ ));
$this->addRule('NX', ts('Must be an integer'), 'integer');
$this->addRule('NY', ts('Must be an integer'), 'integer');
$this->addRule('tMargin', ts('Must be numeric'), 'numeric');
function setDefaultValues() {
if ($this->_action & CRM_Core_Action::ADD) {
- $defaults['weight'] = CRM_Utils_Array::value('weight', CRM_Core_BAO_LabelFormat::getDefaultValues(), 0);
+ $defaults['weight'] = CRM_Utils_Array::value('weight', CRM_Core_BAO_LabelFormat::getDefaultValues($this->_group), 0);
}
else {
$defaults = $this->_values;
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
// delete Label Format
- CRM_Core_BAO_LabelFormat::del($this->_id);
+ 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);
- $list = CRM_Core_BAO_LabelFormat::getList(TRUE);
- $count = 1;
- $prefix = ts('Copy of ');
+ $labelFormat = CRM_Core_BAO_LabelFormat::getById($this->_id, $this->_group);
+ $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['grouping'] = CRM_Core_BAO_LabelFormat::customGroupName();
$labelFormat['is_default'] = 0;
$labelFormat['is_reserved'] = 0;
+
$bao = new CRM_Core_BAO_LabelFormat();
- $bao->saveLabelFormat($labelFormat);
+ $bao->saveLabelFormat($values, NULL, $this->_group);
CRM_Core_Session::setStatus($labelFormat['label'] . ts(' has been created.'), ts('Saved'), 'success');
return;
}
$values['font-style'] = $style;
$bao = new CRM_Core_BAO_LabelFormat();
- $bao->saveLabelFormat($values, $this->_id);
+ $bao->saveLabelFormat($values, $this->_id, $this->_group);
$status = ts('Your new Label Format titled <strong>%1</strong> has been saved.', array(1 => $values['label']));
if ($this->_action & CRM_Core_Action::UPDATE) {
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/admin/labelFormats',
- 'qs' => 'action=update&id=%%id%%&reset=1',
+ 'qs' => 'action=update&id=%%id%%&group=%%group%%&reset=1',
'title' => ts('Edit Label Format'),
),
CRM_Core_Action::COPY => array(
'name' => ts('Copy'),
'url' => 'civicrm/admin/labelFormats',
- 'qs' => 'action=copy&id=%%id%%',
+ 'qs' => 'action=copy&id=%%id%%&group=%%group%%&reset=1',
'title' => ts('Copy Label Format'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/labelFormats',
- 'qs' => 'action=delete&id=%%id%%',
+ 'qs' => 'action=delete&id=%%id%%&group=%%group%%&reset=1',
'title' => ts('Delete Label Format'),
),
);
*/
function browse($action = NULL) {
// Get list of configured Label Formats
- $labelFormatList = CRM_Core_BAO_LabelFormat::getList();
+ $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) {
if (CRM_Utils_Array::value('is_reserved', $format)) {
$action -= CRM_Core_Action::DELETE;
}
- $format['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $format['id']));
+ $format['action'] = CRM_Core_Action::formLink(self::links(), $action,
+ array('id' => $format['id'], 'group' => 'label_format'));
}
+ // Add action links to each of the Label Formats
+ foreach ($nameFormatList as & $format) {
+ $action = array_sum(array_keys($this->links()));
+ if (CRM_Utils_Array::value('is_reserved', $format)) {
+ $action -= CRM_Core_Action::DELETE;
+ }
+ $format['action'] = CRM_Core_Action::formLink(self::links(), $action,
+ array('id' => $format['id'], 'group' => '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);
/**
* Get font names supported by the TCPDF package used to create PDF labels.
*
- * @param void
+ * @param string $name group name
*
* @return array array of font names
* @access public
* @static
*/
- public static function getFontNames() {
- $label = new CRM_Utils_PDF_Label(self::getDefaultValues());
+ public static function getFontNames($name='label_format') {
+ $label = new CRM_Utils_PDF_Label(self::getDefaultValues($name));
return $label->getFontNames();
}
* @return int Group ID (null if Group ID doesn't exist)
* @access private
*/
- private static function _getGid() {
- if (!self::$_gid) {
- self::$_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'label_format', 'id', 'name');
- if (!self::$_gid) {
+ private static function _getGid($name='label_format') {
+ if (!isset(self::$_gid[$name]) || !self::$_gid[$name]) {
+ self::$_gid[$name] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $name, 'id', 'name');
+ if (!self::$_gid[$name]) {
CRM_Core_Error::fatal(ts('Label Format Option Group not found in database.'));
}
}
- return self::$_gid;
+ return self::$_gid[$name];
}
/**
* Retrieve list of Label Formats.
*
* @param bool $namesOnly return simple list of names
+ * @param string $name name of the option group
*
* @return array (reference) label format list
* @static
* @access public
*/
- static function &getList($namesOnly = FALSE) {
+ static function &getList($namesOnly = FALSE, $name='label_format') {
static $list = array();
- if (self::_getGid()) {
+ if (self::_getGid($name)) {
// get saved label formats from Option Value table
$dao = new CRM_Core_DAO_OptionValue();
- $dao->option_group_id = self::_getGid();
+ $dao->option_group_id = self::_getGid($name);
$dao->is_active = 1;
$dao->orderBy('weight');
$dao->find();
while ($dao->fetch()) {
if ($namesOnly) {
- $list[$dao->name] = $dao->label;
+ $list[$name][$dao->name] = $dao->label;
}
else {
- CRM_Core_DAO::storeValues($dao, $list[$dao->id]);
+ CRM_Core_DAO::storeValues($dao, $list[$name][$dao->id]);
}
}
}
- return $list;
+ return $list[$name];
}
/**
* retrieve the default Label Format values
*
- * @param NULL
+ * @param string $groupName label format group name
*
* @return array Name/value pairs containing the default Label Format values.
* @static
* @access public
*/
- static function &getDefaultValues() {
+ static function &getDefaultValues($groupName = 'label_format') {
$params = array('is_active' => 1, 'is_default' => 1);
$defaults = array();
- if (!self::retrieve($params, $defaults)) {
+ if (!self::retrieve($params, $defaults, $groupName)) {
foreach (self::$optionValueFields as $name => $field) {
$defaults[$name] = $field['default'];
}
- $filter = array('option_group_id' => self::_getGid());
+ $filter = array('option_group_id' => self::_getGid($groupName));
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $filter);
}
return $defaults;
* @return array $values (reference) associative array of name/value pairs
* @access public
*/
- static function &getLabelFormat($field, $val) {
+ static function &getLabelFormat($field, $val, $groupName = 'label_format') {
$params = array('is_active' => 1, $field => $val);
$labelFormat = array();
- if (self::retrieve($params, $labelFormat)) {
+ if (self::retrieve($params, $labelFormat, $groupName)) {
return $labelFormat;
}
else {
- return self::getDefaultValues();
+ return self::getDefaultValues($groupName);
}
}
* Get Label Format by ID
*
* @param int $id label format id. 0 = get default label format
+ * @param string $groupName group name
*
* @return array $values (reference) associative array of name/value pairs
* @access public
*/
- static function &getById($id) {
- return self::getLabelFormat('id', $id);
+ static function &getById($id, $groupName = 'label_format') {
+ return self::getLabelFormat('id', $id, $groupName);
}
/**
* @access public
* @static
*/
- static function retrieve(&$params, &$values) {
+ static function retrieve(&$params, &$values, $groupName='label_format') {
$optionValue = new CRM_Core_DAO_OptionValue();
$optionValue->copyValues($params);
- $optionValue->option_group_id = self::_getGid();
+ $optionValue->option_group_id = self::_getGid($groupName);
if ($optionValue->find(TRUE)) {
// Extract fields that have been serialized in the 'value' column of the Option Value table.
$values = json_decode($optionValue->value, TRUE);
*
* @param array (reference) $values associative array of name/value pairs
* @param int $id id of the database record (null = new record)
+ * @param string $groupName group name of the label format
*
* @return void
* @access public
*/
- function saveLabelFormat(&$values, $id = NULL) {
+ function saveLabelFormat(&$values, $id = NULL, $groupName = 'label_format') {
// get the Option Group ID for Label Formats (create one if it doesn't exist)
- $group_id = self::_getGid();
+ $group_id = self::_getGid($groupName);
// clear other default if this is the new default label format
if ($values['is_default']) {
}
else {
// new record
- $list = self::getList(TRUE);
+ $list = self::getList(TRUE,$groupName);
$cnt = 1;
while (array_key_exists("custom_$cnt", $list)) $cnt++;
$values['name'] = "custom_$cnt";
* Function to delete a Label Format
*
* @param int $id ID of the label format to be deleted.
- *
+ * @param string $groupName group name
* @access public
* @static
*/
- static function del($id) {
+ static function del($id, $groupName) {
if ($id) {
$dao = new CRM_Core_DAO_OptionValue();
$dao->id = $id;
if ($dao->find(TRUE)) {
- if ($dao->option_group_id == self::_getGid()) {
- $filter = array('option_group_id' => self::_getGid());
+ if ($dao->option_group_id == self::_getGid($groupName)) {
+ $filter = array('option_group_id' => self::_getGid($groupName));
CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $id, $filter);
$dao->delete();
return;