X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FLabelFormat.php;h=b2fdccf6d7373cc3cc92651baf3c5e4724eb3719;hb=442df34b5f4c02d27af8d51f657deff0e00f240c;hp=535ad47db93c753861c7b9cd4035301388e9a86a;hpb=01d7cdd88aa557d1facb0a61dcbd68143f250417;p=civicrm-core.git diff --git a/CRM/Core/BAO/LabelFormat.php b/CRM/Core/BAO/LabelFormat.php index 535ad47db9..b2fdccf6d7 100644 --- a/CRM/Core/BAO/LabelFormat.php +++ b/CRM/Core/BAO/LabelFormat.php @@ -1,7 +1,7 @@ getFontNames(); } @@ -194,18 +194,12 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { * @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; } /** @@ -226,6 +220,40 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { ); } + /** + * 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 * @@ -234,14 +262,14 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { * @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]; } /** @@ -263,49 +291,50 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { * 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; @@ -320,14 +349,14 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { * @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); } } @@ -347,12 +376,13 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { * 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); } /** @@ -397,10 +427,10 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { * @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); @@ -431,7 +461,7 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { * @return void * @access public */ - function customGroupName() { + public static function customGroupName() { return ts('Custom'); } @@ -440,13 +470,14 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { * * @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']) { @@ -462,7 +493,7 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { } 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"; @@ -482,6 +513,9 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { // 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); @@ -502,17 +536,17 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue { * 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;