Commit | Line | Data |
---|---|---|
8ffdec17 ARW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.5 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2014 | | |
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-2014 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class contains the functions for Case Type management | |
38 | * | |
39 | */ | |
40 | class CRM_Case_BAO_CaseType extends CRM_Case_DAO_CaseType { | |
41 | ||
42 | /** | |
43 | * static field for all the case information that we can potentially export | |
44 | * | |
45 | * @var array | |
46 | * @static | |
47 | */ | |
48 | static $_exportableFields = NULL; | |
49 | ||
50 | /** | |
51 | * takes an associative array and creates a Case Type object | |
52 | * | |
53 | * the function extract all the params it needs to initialize the create a | |
54 | * case type object. the params array could contain additional unused name/value | |
55 | * pairs | |
56 | * | |
57 | * @param array $params (reference ) an assoc array of name/value pairs | |
58 | * @param array $ids the array that holds all the db ids | |
59 | * | |
60 | * @return object CRM_Case_BAO_CaseType object | |
61 | * @access public | |
62 | * @static | |
63 | */ | |
64 | static function add(&$params) { | |
65 | $caseTypeDAO = new CRM_Case_DAO_CaseType(); | |
66 | $caseTypeDAO->copyValues($params); | |
67 | return $caseTypeDAO->save(); | |
68 | } | |
69 | ||
70 | /** | |
71 | * Given the list of params in the params array, fetch the object | |
72 | * and store the values in the values array | |
73 | * | |
74 | * @param array $params input parameters to find object | |
75 | * @param array $values output values of the object | |
76 | * @param array $ids the array that holds all the db ids | |
77 | * | |
78 | * @return CRM_Case_BAO_CaseType|null the found object or null | |
79 | * @access public | |
80 | * @static | |
81 | */ | |
82 | static function &getValues(&$params, &$values) { | |
83 | $caseType = new CRM_Case_BAO_CaseType(); | |
84 | ||
85 | $caseType->copyValues($params); | |
86 | ||
87 | if ($caseType->find(TRUE)) { | |
88 | CRM_Core_DAO::storeValues($caseType, $values); | |
89 | return $caseType; | |
90 | } | |
91 | return NULL; | |
92 | } | |
93 | ||
94 | /** | |
95 | * takes an associative array and creates a case type object | |
96 | * | |
97 | * @param array $params (reference ) an assoc array of name/value pairs | |
98 | * @param array $ids the array that holds all the db ids | |
99 | * | |
100 | * @return object CRM_Case_BAO_CaseType object | |
101 | * @access public | |
102 | * @static | |
103 | */ | |
104 | static function &create(&$params) { | |
105 | $transaction = new CRM_Core_Transaction(); | |
106 | ||
107 | if (!empty($params['id'])) { | |
108 | CRM_Utils_Hook::pre('edit', 'CaseType', $params['id'], $params); | |
109 | } | |
110 | else { | |
111 | CRM_Utils_Hook::pre('create', 'CaseType', NULL, $params); | |
112 | } | |
113 | ||
114 | $caseType = self::add($params); | |
115 | ||
116 | if (is_a($caseType, 'CRM_Core_Error')) { | |
117 | $transaction->rollback(); | |
118 | return $caseType; | |
119 | } | |
120 | ||
121 | if (!empty($params['id'])) { | |
122 | CRM_Utils_Hook::post('edit', 'CaseType', $caseType->id, $case); | |
123 | } | |
124 | else { | |
125 | CRM_Utils_Hook::post('create', 'CaseType', $caseType->id, $case); | |
126 | } | |
127 | $transaction->commit(); | |
128 | ||
129 | return $caseType; | |
130 | } | |
131 | ||
132 | /** | |
133 | * Takes a bunch of params that are needed to match certain criteria and | |
134 | * retrieves the relevant objects. We'll tweak this function to be more | |
135 | * full featured over a period of time. This is the inverse function of | |
136 | * create. It also stores all the retrieved values in the default array | |
137 | * | |
138 | * @param array $params (reference ) an assoc array of name/value pairs | |
139 | * @param array $defaults (reference ) an assoc array to hold the name / value pairs | |
140 | * in a hierarchical manner | |
141 | * @param array $ids (reference) the array that holds all the db ids | |
142 | * | |
143 | * @return object CRM_Case_BAO_CaseType object | |
144 | * @access public | |
145 | * @static | |
146 | */ | |
147 | static function retrieve(&$params, &$defaults) { | |
148 | $caseType = CRM_Case_BAO_CaseType::getValues($params, $defaults); | |
149 | return $caseType; | |
150 | } | |
151 | ||
152 | static function del($caseTypeId) { | |
153 | $caseType = new CRM_Case_DAO_CaseType(); | |
154 | $caseType->id = $caseTypeId; | |
155 | return $caseType->delete(); | |
156 | } | |
157 | } |