|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Nette\Database\Context; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Meal |
|
9
|
|
|
* |
|
10
|
|
|
* class for handling meals |
|
11
|
|
|
* |
|
12
|
|
|
* @created 2012-11-11 |
|
13
|
|
|
* @author Tomas Litera <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class MealModel extends BaseModel |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $dayMeal = [ |
|
22
|
|
|
"páteční večeře" => "fry_dinner", |
|
|
|
|
|
|
23
|
|
|
"sobotní snídaně" => "sat_breakfast", |
|
|
|
|
|
|
24
|
|
|
"sobotní oběd" => "sat_lunch", |
|
|
|
|
|
|
25
|
|
|
"sobotní večeře" => "sat_dinner", |
|
|
|
|
|
|
26
|
|
|
"nedělní snídaně" => "sun_breakfast", |
|
|
|
|
|
|
27
|
|
|
"nedělní oběd" => "sun_lunch" |
|
|
|
|
|
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $table = 'kk_meals'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $columns = [ |
|
39
|
|
|
"visitor", |
|
|
|
|
|
|
40
|
|
|
"fry_dinner", |
|
|
|
|
|
|
41
|
|
|
"sat_breakfast", |
|
|
|
|
|
|
42
|
|
|
"sat_lunch", |
|
|
|
|
|
|
43
|
|
|
"sat_dinner", |
|
|
|
|
|
|
44
|
|
|
"sun_breakfast", |
|
|
|
|
|
|
45
|
|
|
"sun_lunch" |
|
|
|
|
|
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param Context $database |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct(Context $database) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->setDatabase($database); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getColumns() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->columns; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param integer $visitorId |
|
66
|
|
|
* @param array $data |
|
67
|
|
|
* @return ActiveRow |
|
68
|
|
|
*/ |
|
69
|
|
|
public function update($visitorId, array $data) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->getDatabase() |
|
72
|
|
|
->table($this->getTable()) |
|
73
|
|
|
->where('visitor', $visitorId) |
|
74
|
|
|
->update($data); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
function getMeals($visitorId) |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
$meals = "<tr>"; |
|
|
|
|
|
|
80
|
|
|
$meals .= " <td class='progPart'>"; |
|
81
|
|
|
|
|
82
|
|
|
$result = $this->database |
|
83
|
|
|
->table($this->dbTable) |
|
|
|
|
|
|
84
|
|
|
->where('visitor', $visitorId) |
|
85
|
|
|
->fetchAll(); |
|
86
|
|
|
|
|
87
|
|
|
if(!$result){ |
|
|
|
|
|
|
88
|
|
|
$meals .= "<div class='emptyTable' style='width:400px;'>Nejsou žádná aktuální data.</div>\n"; |
|
89
|
|
|
} else { |
|
90
|
|
|
foreach($result as $mealData){ |
|
91
|
|
|
$meals .= "<div class='block'>".$mealData['fry_dinner'].", ".$mealData['sat_breakfast']." - ".$mealData['sat_lunch']." : ".$mealData['sat_dinner']."</div>\n"; |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$meals .= "</td>"; |
|
|
|
|
|
|
97
|
|
|
$meals .= "</tr>"; |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
return $meals; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Render HTML Meals <select> |
|
104
|
|
|
* |
|
105
|
|
|
* @param string value of selected meal |
|
106
|
|
|
* @param string if select is disabled |
|
107
|
|
|
* @return string html <select> |
|
108
|
|
|
*/ |
|
109
|
|
|
public function renderHtmlMealsSelect($mealsValue, $disabled) |
|
110
|
|
|
{ |
|
111
|
|
|
// order must be firtsly NO and then YES |
|
112
|
|
|
// first value is displayed in form as default |
|
113
|
|
|
$mealArray = array("ne" => "ne","ano" => "ano"); |
|
|
|
|
|
|
114
|
|
|
$yesNoArray = array("ne", "ano"); |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
$htmlSelect = ""; |
|
|
|
|
|
|
117
|
|
|
foreach($this->dayMeal as $title => $varName){ |
|
118
|
|
|
if(preg_match("/breakfast/", $varName)) $mealIcon = "breakfast"; |
|
|
|
|
|
|
119
|
|
|
if(preg_match("/lunch/", $varName)) $mealIcon = "lunch"; |
|
|
|
|
|
|
120
|
|
|
if(preg_match("/dinner/", $varName)) $mealIcon = "dinner"; |
|
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
$htmlSelect .= "<span style='display:block;font-size:11px;'>".$title.":</span>\n"; |
|
123
|
|
|
$htmlSelect .= "<img style='width:18px;' src='".IMG_DIR."icons/".$mealIcon.".png' />\n"; |
|
|
|
|
|
|
124
|
|
|
$htmlSelect .= "<select ".$disabled." style='width:195px; font-size:11px;margin-left:5px;' name='".$varName."'>\n"; |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
foreach ($yesNoArray as $key){ |
|
127
|
|
|
if($key == $mealsValue[$varName]){ |
|
128
|
|
|
$selected = "selected"; |
|
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
else $selected = ""; |
|
|
|
|
|
|
131
|
|
|
$htmlSelect .= "<option value='".$key."' ".$selected.">".$key."</option>"; |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
$htmlSelect .= "</select><br />\n"; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return $htmlSelect; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Get meals data by visitor id |
|
141
|
|
|
* |
|
142
|
|
|
* @param integer visitor id |
|
143
|
|
|
* @return mixed |
|
144
|
|
|
*/ |
|
145
|
|
|
public function findByVisitorId($visitorId) |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->getDatabase() |
|
148
|
|
|
->table($this->getTable()) |
|
149
|
|
|
->where('visitor', $visitorId) |
|
150
|
|
|
->limit(1) |
|
151
|
|
|
->fetch(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'or with double quotes"literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\') and the backslash (\\). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is ValueIf your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.