Timeteable.php
4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* @package anc_lib
* @category magento
* @mailto code [at] netz.coop
* @author netz.coop eG*
* @copyright (c) 2014, netz.coop eG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class Anc_Lib_Helper_Timetable extends Mage_Core_Helper_Abstract {
public function insertTimetable($p_name, $p_comment = False, $p_admin_user_id = NULL, $p_customer_id = NULL, $p_start = FALSE, $p_stop = FALSE, $p_starthour = 0, $p_stophour = 23, $p_startmin = 0, $p_stopmin = 59, $p_monday = 1, $p_tuesday = 1, $p_wednesday = 1, $p_thursday = 1, $p_friday = 1, $p_saturday = 1, $p_sunday = 1) {
$timeteable = Mage::getModel('anc_lib/timetable');
$timeteable->setData('name', $p_name);
if ($p_comment) {
$timeteable->setData('comment', $p_comment);
}
if ($p_admin_user_id) {
$timeteable->setData('admin_user_id', $p_admin_user_id);
}
if ($p_customer_id) {
$timeteable->setData('customer_id', $p_customer_id);
}
if ($p_start) {
$timeteable->setData('start', $p_start);
} else {
$time = time();
$timeteable->setData('start', $p_start);
}
if ($p_stop) {
$timeteable->setData('stop', $p_stop);
} else {
// Wochen /Tage/ Stunden / Min / Sek
$time = time() + (4 * 7 * 24 * 60 * 60);
$timeteable->setData('stop', $p_stop);
}
$timeteable->setData('starthour', $p_starthour);
$timeteable->setData('stophour', $p_stophour);
$timeteable->setData('startmin', $p_startmin);
$timeteable->setData('stopmin', $p_stopmin);
$timeteable->setData('monday', $p_monday);
$timeteable->setData('tuesday', $p_tuesday);
$timeteable->setData('wednesday', $p_wednesday);
$timeteable->setData('thursday', $p_thursday);
$timeteable->setData('friday', $p_friday);
$timeteable->setData('saturday', $p_saturday);
$timeteable->setData('sunday', $p_sunday);
$newId = $timeteable->save()->getId();
return $newId;
}
public function updateTimetable($p_id, $p_name=FALSE, $p_comment = False, $p_start = FALSE, $p_stop = FALSE, $p_starthour =FALSE, $p_stophour =FALSE, $p_startmin =FALSE, $p_stopmin =FALSE, $p_monday =FALSE, $p_tuesday=FALSE, $p_wednesday =FALSE, $p_thursday =FALSE, $p_friday =FALSE, $p_saturday =FALSE, $p_sunday =FALSE) {
$data = array();
if ($p_name !== FALSE) {
$data['name'] = $p_name;
}
if ($p_comment !== FALSE) {
$data['comment'] = $p_comment;
}
if ($p_start !== FALSE) {
$data['start'] = $p_start;
}
if ($p_stop !== FALSE) {
$data['stop'] = $p_stop;
}
if ($p_starthour !== FALSE) {
$data['starthour'] = $p_starthour;
}
if ($p_stophour !== FALSE) {
$data['stophour'] = $p_stophour;
}
if ($p_startmin !== FALSE) {
$data['startmin'] = $p_startmin;
}
if ($p_stopmin !== FALSE) {
$data['stopmin'] = $p_stopmin;
}
if ($p_monday !== FALSE) {
$data['monday'] = $p_monday;
}
if ($p_tuesday !== FALSE) {
$data['tuesday'] = $p_tuesday;
}
if ($p_wednesday !== FALSE) {
$data['wednesday'] = $p_wednesday;
}
if ($p_thursday !== FALSE) {
$data['thursday'] = $p_thursday;
}
if ($p_friday !== FALSE) {
$data['friday'] = $p_friday;
}
if ($p_saturday !== FALSE) {
$data['saturday'] = $p_saturday;
}
if ($p_sunday !== FALSE) {
$data['sunday'] = $p_sunday;
}
$timeteable = Mage::getModel('anc_lib/timetable')->load($p_id)->addData($data);
try {
$timeteable->setId($p_id)->save();
echo "Data updated successfully.";
return TRUE;
} catch (Exception $e) {
echo $e->getMessage();
return FALSE;
}
}
public function deleteTimetable($p_id) {
$timeteable = Mage::getModel('anc_lib/timetable');
try {
$timeteable->setId($p_id)->delete();
echo "Data deleted successfully.";
return TRUE;
} catch (Exception $e) {
echo $e->getMessage();
return False;
}
}
}