Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-07-15-32-51
[civicrm-core.git] / CRM / Badge / BAO / Layout.php
index f7c5fc1d7b2cdceb577b9d81a594aab780b82393..8ceb633f68f3b34b08ec9ca88fffe48e607c042b 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -134,5 +134,53 @@ class CRM_Badge_BAO_Layout extends CRM_Core_DAO_PrintLabel {
     $printLabel->id = $printLabelId;
     $printLabel->delete();
   }
+
+  /**
+   *  get the list of print labels
+   *
+   * @return array list of labels
+   * @access public
+   * @static
+   */
+  static function getList() {
+    $printLabel = new CRM_Core_DAO_PrintLabel();
+    $printLabel->find();
+
+    $labels = array();
+    while($printLabel->fetch()) {
+      $labels[$printLabel->id] = $printLabel->title;
+    }
+    return $labels;
+  }
+
+  /**
+   * build layout structure
+   *
+   * @param array $params associated array of submitted values
+   *
+   * @return array $formattedLayout array formatted array
+   * @access public
+   */
+  static function buildLayout(&$params) {
+    $layoutParams = array('id' => $params['badge_id']);
+    CRM_Badge_BAO_Layout::retrieve($layoutParams, $layoutInfo);
+
+    $formatProperties = CRM_Core_OptionGroup::getValue('name_badge', $layoutInfo['label_format_name'], 'name');
+    $layoutInfo['format'] = json_decode($formatProperties, true);
+    $layoutInfo['data'] = CRM_Badge_BAO_Layout::getDecodedData($layoutInfo['data']);
+    return $layoutInfo;
+  }
+
+  /**
+   * Function to decode encoded data and return as an array
+   *
+   * @param json $jsonData json object
+   *
+   * @return array associated array of decoded elements
+   * @static
+   */
+  static public function getDecodedData($jsonData) {
+    return json_decode($jsonData, true);
+  }
 }