Merge branch 4.6 into master
[civicrm-core.git] / CRM / Core / BAO / LabelFormat.php
index 092d85964c81caa167b51f2adde929f987f4887a..50057a3e401da53f8d330097c1137cb203c3ae99 100644 (file)
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -40,7 +40,7 @@
 class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
 
   /**
-   * Static holder for the Label Formats Option Group ID
+   * Static holder for the Label Formats Option Group ID.
    */
   private static $_gid = NULL;
 
@@ -157,11 +157,8 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   /**
    * Get page orientations recognized by the DOMPDF package used to create PDF letters.
    *
-   * @param void
-   *
-   * @return array   array of page orientations
-   * @access public
-   * @static
+   * @return array
+   *   array of page orientations
    */
   public static function getPageOrientations() {
     return array(
@@ -173,13 +170,13 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   /**
    * Get font names supported by the TCPDF package used to create PDF labels.
    *
-   * @param string $name group name
+   * @param string $name
+   *   Group name.
    *
-   * @return array   array of font names
-   * @access public
-   * @static
+   * @return array
+   *   array of font names
    */
-  public static function getFontNames($name='label_format') {
+  public static function getFontNames($name = 'label_format') {
     $label = new CRM_Utils_PDF_Label(self::getDefaultValues($name));
     return $label->getFontNames();
   }
@@ -187,11 +184,8 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   /**
    * Get font sizes supported by the TCPDF package used to create PDF labels.
    *
-   * @param void
-   *
-   * @return array   array of font sizes
-   * @access public
-   * @static
+   * @return array
+   *   array of font sizes
    */
   public static function getFontSizes() {
     $fontSizes = array();
@@ -205,11 +199,8 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   /**
    * Get measurement units recognized by the TCPDF package used to create PDF labels.
    *
-   * @param void
-   *
-   * @return array   array of measurement units
-   * @access public
-   * @static
+   * @return array
+   *   array of measurement units
    */
   public static function getUnits() {
     return array(
@@ -223,11 +214,8 @@ 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
+   * @return array
+   *   array of alignments
    */
   public static function getTextAlignments() {
     return array(
@@ -240,11 +228,8 @@ 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
+   * @return array
+   *   array of alignments
    */
   public static function getFontStyles() {
     return array(
@@ -255,14 +240,14 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   }
 
   /**
-   * Get Option Group ID for Label Formats
+   * Get Option Group ID for Label Formats.
    *
    * @param string $name
    *
-   * @return int  Group ID (null if Group ID doesn't exist)
-   * @access private
+   * @return int
+   *   Group ID (null if Group ID doesn't exist)
    */
-  private static function _getGid($name='label_format') {
+  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]) {
@@ -273,31 +258,33 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   }
 
   /**
-   * Add ordering fields to Label Format list
+   * Add ordering fields to Label Format list.
    *
-   * @param array (reference)   $list         List of Label Formats
-   * @param string              $returnURL    URL of page calling this function
+   * @param array (reference) $list List of Label Formats
+   * @param string $returnURL
+   *   URL of page calling this function.
    *
-   * @return array  (reference)   List of Label Formats
-   * @static
-   * @access public
+   * @return array
+   *   (reference)   List of Label Formats
    */
-  static function addOrder(&$list, $returnURL) {
+  public static function addOrder(&$list, $returnURL) {
     $filter = "option_group_id = " . self::_getGid();
     CRM_Utils_Weight::addOrder($list, 'CRM_Core_DAO_OptionValue', 'id', $returnURL, $filter);
+    return $list;
   }
 
   /**
    * Retrieve list of Label Formats.
    *
-   * @param bool    $namesOnly    return simple list of names
-   * @param string  $groupName    group name of the label format option group
+   * @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
+   * @return array
+   *   (reference)   label format list
    */
-  static function &getList($namesOnly = FALSE, $groupName='label_format') {
+  public static function &getList($namesOnly = FALSE, $groupName = 'label_format') {
     static $list = array();
     if (self::_getGid($groupName)) {
       // get saved label formats from Option Value table
@@ -319,15 +306,15 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   }
 
   /**
-   * Retrieve the default Label Format values
+   * Retrieve the default Label Format values.
    *
-   * @param string $groupName label format group name
+   * @param string $groupName
+   *   Label format group name.
    *
-   * @return array   Name/value pairs containing the default Label Format values.
-   * @static
-   * @access public
+   * @return array
+   *   Name/value pairs containing the default Label Format values.
    */
-  static function &getDefaultValues($groupName = 'label_format') {
+  public static function &getDefaultValues($groupName = 'label_format') {
     $params = array('is_active' => 1, 'is_default' => 1);
     $defaults = array();
     if (!self::retrieve($params, $defaults, $groupName)) {
@@ -341,17 +328,19 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   }
 
   /**
-   * Get Label Format from the DB
+   * Get Label Format from the DB.
    *
-   * @param string $field Field name to search by
-   * @param int $val Field value to search for
+   * @param string $field
+   *   Field name to search by.
+   * @param int $val
+   *   Field value to search for.
    *
    * @param string $groupName
    *
-   * @return array  $values (reference) associative array of name/value pairs
-   * @access public
+   * @return array
+   *   (reference) associative array of name/value pairs
    */
-  static function &getLabelFormat($field, $val, $groupName = 'label_format') {
+  public static function &getLabelFormat($field, $val, $groupName = 'label_format') {
     $params = array('is_active' => 1, $field => $val);
     $labelFormat = array();
     if (self::retrieve($params, $labelFormat, $groupName)) {
@@ -363,48 +352,50 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   }
 
   /**
-   * Get Label Format by Name
+   * Get Label Format by Name.
    *
-   * @param int    $name   Label format name. Empty = get default label format
+   * @param int $name
+   *   Label format name. Empty = get default label format.
    *
-   * @return array  $values (reference) associative array of name/value pairs
-   * @access public
+   * @return array
+   *   (reference) associative array of name/value pairs
    */
-  static function &getByName($name) {
+  public static function &getByName($name) {
     return self::getLabelFormat('name', $name);
   }
 
   /**
-   * Get Label Format by ID
+   * Get Label Format by ID.
    *
-   * @param int    $id   label format id. 0 = get default label format
-   * @param string $groupName group name
+   * @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
+   * @return array
+   *   (reference) associative array of name/value pairs
    */
-  static function &getById($id, $groupName = 'label_format') {
+  public static function &getById($id, $groupName = 'label_format') {
     return self::getLabelFormat('id', $id, $groupName);
   }
 
   /**
-   * Get Label Format field from associative array
+   * Get Label Format field from associative array.
    *
-   * @param string $field name of a label format field
+   * @param string $field
+   *   Name of a label format field.
    * @param array (reference) $values associative array of name/value pairs containing
    *                                           label format field selections
    *
    * @param null $default
    *
    * @return value
-   * @access public
-   * @static
    */
-  static function getValue($field, &$values, $default = NULL) {
+  public static function getValue($field, &$values, $default = NULL) {
     if (array_key_exists($field, self::$optionValueFields)) {
       switch (self::$optionValueFields[$field]['type']) {
         case CRM_Utils_Type::T_INT:
-          return (int)CRM_Utils_Array::value($field, $values, $default);
+          return (int) CRM_Utils_Array::value($field, $values, $default);
 
         case CRM_Utils_Type::T_FLOAT:
           // Round float values to three decimal places and trim trailing zeros.
@@ -412,7 +403,7 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
           $f = sprintf('%05.3f', $values[$field]);
           $f = rtrim($f, '0');
           $f = rtrim($f, '.');
-          return (float)(empty($f) ? '0' : $f);
+          return (float) (empty($f) ? '0' : $f);
       }
       return CRM_Utils_Array::value($field, $values, $default);
     }
@@ -420,20 +411,20 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   }
 
   /**
-   * Takes a bunch of params that are needed to match certain criteria and
-   * retrieves the relevant objects. Typically the valid params are only
-   * label id. It also stores all the retrieved values in the default array.
+   * Retrieve DB object based on input parameters.
+   *
+   * It also stores all the retrieved values in the default array.
    *
-   * @param array $params (reference ) an assoc array of name/value pairs
-   * @param array $values (reference ) an assoc array to hold the flattened values
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
+   * @param array $values
+   *   (reference ) an assoc array to hold the flattened values.
    *
    * @param string $groupName
    *
-   * @return CRM_Core_DAO_OptionValue object
-   * @access public
-   * @static
+   * @return CRM_Core_DAO_OptionValue
    */
-  static function retrieve(&$params, &$values, $groupName='label_format') {
+  public static function retrieve(&$params, &$values, $groupName = 'label_format') {
     $optionValue = new CRM_Core_DAO_OptionValue();
     $optionValue->copyValues($params);
     $optionValue->option_group_id = self::_getGid($groupName);
@@ -460,28 +451,26 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   }
 
   /**
-   * Return the name of the group for customized labels
-   *
-   * @param void
+   * Return the name of the group for customized labels.
    *
    * @return void
-   * @access public
    */
   public static function customGroupName() {
     return ts('Custom');
   }
 
   /**
-   * Save the Label Format in the DB
+   * Save the Label Format in the DB.
    *
-   * @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
+   * @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, $groupName = 'label_format') {
+  public 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($groupName);
 
@@ -499,9 +488,11 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
     }
     else {
       // new record
-      $list = self::getList(TRUE,$groupName);
+      $list = self::getList(TRUE, $groupName);
       $cnt = 1;
-      while (array_key_exists("custom_$cnt", $list)) $cnt++;
+      while (array_key_exists("custom_$cnt", $list)) {
+        $cnt++;
+      }
       $values['name'] = "custom_$cnt";
       $values['grouping'] = self::customGroupName();
     }
@@ -539,14 +530,14 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
   }
 
   /**
-   * Delete a Label Format
+   * Delete a Label Format.
    *
-   * @param  int  $id     ID of the label format to be deleted.
-   * @param  string $groupName group name
-   * @access public
-   * @static
+   * @param int $id
+   *   ID of the label format to be deleted.
+   * @param string $groupName
+   *   Group name.
    */
-  static function del($id, $groupName) {
+  public static function del($id, $groupName) {
     if ($id) {
       $dao = new CRM_Core_DAO_OptionValue();
       $dao->id = $id;
@@ -561,5 +552,5 @@ class CRM_Core_BAO_LabelFormat extends CRM_Core_DAO_OptionValue {
     }
     CRM_Core_Error::fatal(ts('Invalid value passed to delete function.'));
   }
-}
 
+}