Commit | Line | Data |
---|---|---|
1720f579 M |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.4 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * | |
33 | */ | |
34 | ||
e364fc74 | 35 | class CRM_Wci_BAO_ProgressBarFormula extends CRM_Wci_DAO_ProgressBarFormula { |
1720f579 M |
36 | |
37 | /** | |
38 | * class constructor | |
39 | */ | |
40 | function __construct() { | |
41 | parent::__construct(); | |
42 | } | |
43 | ||
44 | /** | |
45 | * Function to create a ProgressBar | |
46 | * takes an associative array and creates a ProgressBar object | |
47 | * | |
48 | * This function is invoked from within the web form layer and also from the api layer | |
49 | * | |
50 | * @param array $params (reference ) an assoc array of name/value pairs | |
51 | * | |
e364fc74 | 52 | * @return object CRM_Wci_BAO_ProgressBarFormula object |
1720f579 M |
53 | * @access public |
54 | * @static | |
55 | */ | |
56 | static function create(array $params) { | |
57 | ||
58 | // check required params | |
59 | if (!self::dataExists($params)) { | |
60 | CRM_Core_Error::fatal('Not enough data to create a progress bar formula entry.'); | |
61 | } | |
62 | ||
e364fc74 | 63 | $progress_bar_formula = new CRM_Wci_BAO_ProgressBarFormula(); |
1720f579 M |
64 | $progress_bar_formula->copyValues($params); |
65 | ||
66 | $progress_bar_formula->save(); | |
67 | ||
68 | return $progress_bar_formula; | |
69 | } | |
70 | ||
71 | /** | |
72 | * Get a list of Widgets matching the params, where params keys are column | |
73 | * names of civicrm_wci_widget. | |
74 | * | |
75 | * @param array $params | |
e364fc74 | 76 | * @return array of CRM_Wci_BAO_ProgressBarFormula objects |
1720f579 M |
77 | */ |
78 | static function retrieve(array $params) { | |
79 | $result = array(); | |
80 | ||
e364fc74 | 81 | $progress_bar_formula = new CRM_Wci_BAO_ProgressBarFormula(); |
1720f579 M |
82 | $progress_bar_formula->copyValues($params); |
83 | $progress_bar_formula->find(); | |
84 | ||
85 | while ($progress_bar_formula->fetch()) { | |
86 | $result[(int) $progress_bar_formula->id] = clone $progress_bar_formula; | |
87 | } | |
88 | ||
89 | $progress_bar_formula->free(); | |
90 | ||
91 | return $result; | |
92 | } | |
93 | ||
94 | /** | |
95 | * Wrapper method for retrieve | |
96 | * | |
97 | * @param mixed $id Int or int-like string representing widget ID | |
e364fc74 | 98 | * @return CRM_Wci_BAO_ProgressBarFormula |
1720f579 M |
99 | */ |
100 | static function retrieveByID($id) { | |
101 | if (!is_int($id) && !ctype_digit($id)) { | |
102 | CRM_Core_Error::fatal(__CLASS__ . '::' . __FUNCTION__ . ' expects an integer.'); | |
103 | } | |
104 | $id = (int) $id; | |
105 | ||
106 | $progress_bar_formulas = self::retrieve(array('id' => $id)); | |
107 | ||
108 | if (!array_key_exists($id, $progress_bar_formulas)) { | |
109 | CRM_Core_Error::fatal("No formula entry with ID $id exists."); | |
110 | } | |
111 | ||
112 | return $progress_bar_formulas[$id]; | |
113 | } | |
114 | ||
115 | /** | |
116 | * Check if there is absolute minimum of data to add the object | |
117 | * | |
118 | * @param array $params (reference ) an assoc array of name/value pairs | |
119 | * | |
120 | * @return boolean | |
121 | * @access public | |
122 | */ | |
123 | public static function dataExists($params) { | |
124 | if (CRM_Utils_Array::value('contribution_page_id', $params) && CRM_Utils_Array::value('progress_bar_id', $params)) { | |
125 | return TRUE; | |
126 | } | |
127 | return FALSE; | |
128 | } | |
129 | } |