Update api_automation.php
[bugdar.git] / includes / api_automation.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 require_once ISSO . '/Api.php';
23 require_once('./includes/functions_datastore.php');
24
25 /**
26 * API: Automation
27 *
28 * @author Blue Static
29 * @copyright Copyright ©2002 - 2007, Blue Static
30 * @version $Revision$
31 * @package Bugdar
32 *
33 */
34 class AutomationAPI extends BSApi
35 {
36 /**
37 * Fields
38 * @var array
39 */
40 protected $fields = array(
41 'actionid' => array(TYPE_UINT, REQ_AUTO),
42 'name' => array(TYPE_STR, REQ_YES),
43 'description' => array(TYPE_STR, REQ_NO),
44 'fieldchanges' => array(TYPE_NONE, REQ_YES),
45 'comment' => array(TYPE_STR, REQ_NO)
46 );
47
48 /**
49 * Table
50 * @var string
51 */
52 protected $table = 'automation';
53
54 /**
55 * Table prefix
56 * @var string
57 */
58 protected $prefix = TABLE_PREFIX;
59
60 /**
61 * Post-insert
62 */
63 protected function post_insert()
64 {
65 build_automations();
66 }
67
68 /**
69 * Post-update
70 */
71 protected function post_update()
72 {
73 build_automations();
74 }
75
76 /**
77 * Post-delete
78 */
79 protected function post_delete()
80 {
81 build_automations();
82 }
83
84 /**
85 * Validate: actionid
86 */
87 protected function validate_actionid($field)
88 {
89 return $this->_verifyIsNotZero($field);
90 }
91
92 /**
93 * Validate: name
94 */
95 protected function validate_name($field)
96 {
97 return $this->_verifyIsNotEmpty($field);
98 }
99
100 /**
101 * Validate: fieldchanges
102 */
103 protected function validate_fieldchanges()
104 {
105 if (!is_array($this->values['fieldchanges']) || sizeof($this->values['fieldchanges']) != 2 || !is_array($this->values['fieldchanges']['custom']) || !is_array($this->values['fieldchanges']['builtin']))
106 {
107 return T('Invalid array type passed. The fieldchaneges array must be a two-dimensional array: array("builtin" => array("fieldname" => "newvalue" ...), "custom" => array("fieldname" => "fieldvalue" ...))');
108 }
109
110 if (sizeof($this->values['fieldchanges']['custom']) < 1 && sizeof($this->values['fieldchanges']['builtin']) < 1)
111 {
112 return T('You need to specify some fields to change.');
113 }
114
115 $this->values['fieldchanges'] = serialize($this->values['fieldchanges']);
116
117 return true;
118 }
119 }
120
121 /*=====================================================================*\
122 || ###################################################################
123 || # $HeadURL$
124 || # $Id$
125 || ###################################################################
126 \*=====================================================================*/
127 ?>