<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright (C) 2011 Marty Wright |
| Licensed to CiviCRM under the Academic Free License version 3.0. |
/**
* 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();
}
* @static
*/
public static function getFontSizes() {
- return array(
- 6 => ts('6 pt'),
- 7 => ts('7 pt'),
- 8 => ts('8 pt'),
- 9 => ts('9 pt'),
- 10 => ts('10 pt'),
- 11 => ts('11 pt'),
- 12 => ts('12 pt'),
- 13 => ts('13 pt'),
- 14 => ts('14 pt'),
- 15 => ts('15 pt'),
- );
+ $fontSizes = array();
+ for ($i = 6; $i <= 60; $i++) {
+ $fontSizes[$i] = ts('%1 pt', array(1 => $i));
+ }
+
+ return $fontSizes;
}
/**
);
}
+ /**
+ * Get text alignment recognized by the TCPDF package used to create PDF labels.
+ *
+ * @param void
+ *
+ * @return array array of alignments
+ * @access public
+ * @static
+ */
+ public static function getTextAlignments() {
+ return array(
+ 'R' => ts('Right'),
+ 'L' => ts('Left'),
+ 'C' => ts('Center'),
+ );
+ }
+
+ /**
+ * Get text alignment recognized by the TCPDF package used to create PDF labels.
+ *
+ * @param void
+ *
+ * @return array array of alignments
+ * @access public
+ * @static
+ */
+ public static function getFontStyles() {
+ return array(
+ '' => ts('Normal'),
+ 'B' => ts('Bold'),
+ 'I' => ts('Italic'),
+ );
+ }
+
/**
* Get Option Group ID for Label Formats
*
* @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 $groupName group name of the label format option group
*
* @return array (reference) label format list
* @static
* @access public
*/
- static function &getList($namesOnly = FALSE) {
+ static function &getList($namesOnly = FALSE, $groupName='label_format') {
static $list = array();
- if (self::_getGid()) {
+ if (self::_getGid($groupName)) {
// 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($groupName);
$dao->is_active = 1;
$dao->orderBy('weight');
$dao->find();
while ($dao->fetch()) {
if ($namesOnly) {
- $list[$dao->name] = $dao->label;
+ $list[$groupName][$dao->name] = $dao->label;
}
else {
- CRM_Core_DAO::storeValues($dao, $list[$dao->id]);
+ CRM_Core_DAO::storeValues($dao, $list[$groupName][$dao->id]);
}
}
}
- return $list;
+ return $list[$groupName];
}
/**
* 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);
* @return void
* @access public
*/
- function customGroupName() {
+ public static function customGroupName() {
return ts('Custom');
}
*
* @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";
// serialize label format fields into a single string to store in the 'value' column of the Option Value table
$v = json_decode($this->value, TRUE);
foreach (self::$optionValueFields as $name => $field) {
+ if (!isset($v[$name])) {
+ $v[$name] = NULL;
+ }
$v[$name] = self::getValue($name, $values, $v[$name]);
}
$this->value = json_encode($v);
* 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;