-
Notifications
You must be signed in to change notification settings - Fork 1
/
classCat.php
390 lines (342 loc) · 9.47 KB
/
classCat.php
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<?php
/**
* class Cat
* parent class for Cat
*/
namespace Cat;
require_once 'classDatabase.php';
class Cat {
//main variables
private $catName;//string name of cat
private $catWeight;//number weight of cat
private $catGender;//string gender of cat
private $catColoring = [];//array color of cat
private $catCurrentMood;//string mood of cat
private $catHairLength;//string of hair length of cat
private $catCattitude = false;//bool
private $database;
private $catID;
/**
* Cat constructor.
* @param $name
*/
public function __construct($name = null)
{
//pass in name, if no name then set to null
$this->catName = $name ?? null;
//create new db connection
//$this->database = Database::getFactory()->getConnection();
$newCatData = [];
return $newCatData;
}
/**
* Return name of cat
* @param none
*/
public function getName() {
return $this->catName ?? '';
}
/**
* Set weight of cat
* @param $weight
*/
public function setWeight($weight) {
//check input to make sure it is numeric
if ( !is_numeric($weight) ) {
echo "ERROR 34343: Your input is not numeric. Please fix.";
} //check if input is exactly zero
elseif ( $weight == 0 ) {
echo "ERROR 98998: The weight of your cat should be more than zero. Please update.";
} //if input is ok, then set the input to the variable
else {
$this->catWeight = $weight;
}
}
/**
* Return weight of cat
* @return mixed
*/
public function getWeight() {
return $this->catWeight;
}
/**
* Set gender of the cat
* @param $gender
*/
public function setGender($gender) {
$this->catGender = strtolower($gender);
//check and make sure input matches array of
//approved genders in the approved gender method
if ( !isset( $this->setAllowedGenders()[$this->catGender] ) ) {
echo "ERROR 90990: Your gender <strong>$gender</strong> is not an approved gender. Please fix. ";
return;
}
}
/**
* Return gender of the cat
*/
public function getGender() {
return $this->catGender;
}
/**
* Set list approved genders
* @return array
*/
//@todo: change to returnAllowedGenders
public function setAllowedGenders() {
//list approved genders
$approved_gender = [
//gender => pronoun usage
'Male' => 'him',
'Female' => 'her',
'Genderfluid' => 'it'
];
return $approved_gender;
}
/**
* Check current Gender to return pronoun to be used
* @return null|string
*/
public function returnGenderPronounUsage() {
//note: i guess instead of writing a switch to determine proper pronoun usage, i could change the setAllowedGender $approved_gender array to be 'male' => 'him' - but for now i am happy with this implementation
//var to get the current gender
$existing_pronoun = $this->getGender();
//var to be used in our switch and to be returned
$current_gender = NULL;
switch ($existing_pronoun) {
case 'female':
$current_gender = "her";
return $current_gender;
break;
case 'male':
$current_gender = "him";
return $current_gender;
break;
case 'gender fluid':
$current_gender = "it";
return $current_gender;
break;
}
}
/**
* Check if the supplied gender matches approved genders
* @return bool
*/
public function checkIsGenderApproved() {
return isset( $this->setAllowedGenders()[$this->catGender] );
}
/**
* Set color of cat
* @param $coloring
*/
public function setColoring($coloring) {
$this->catColoring = $coloring;
}
/**
* Set list of allowed cat colorings
*/
public function setAllowedColorings() {
//list of approved cat colors
//related to hex colors
$allowed_colorings = [
'Black' => '#000000',
'Gray' => '#808080',
'Brown' => '#A5682A',
'Calico' => '#D5B185',
'White' => '#FFFFFF'
];
return $allowed_colorings;
}
/**
* Return color of cat
*/
public function getColoring() {
return $this->catColoring;
}
/**
* Check if the supplied color matches the approved cat colors
* @return bool
*/
public function checkIsColorApproved() {
return isset( $this->setAllowedColorings()[$this->catColoring] );
}
/**
* Set the mood of the cat
* @param $mood
*/
public function setMood($mood) {
$this->catCurrentMood = $mood;
}
/**
* Set list of approved moods
* @return array
*/
public function setApprovedMood() {
//list of approved moods
$approved_moods = [
'grumpy' => '0',
'sleepy' => '1',
'rowdy' => '2',
'thirsty' => '3',
'hungry' => '4'
];
return $approved_moods;
}
/**
* Return current mood of cat
* @return mixed
*/
public function getMood() {
return $this->catCurrentMood;
}
/**
* Check if supplied mood matches approved mood list
* @return bool
*/
public function checkIsMoodApproved() {
return isset( $this->setApprovedMood()[$this->catCurrentMood] );
}
/**
* Set length of hair for cat
* @param $hairlength
* @return mixed
*/
public function setHairLength($hairlength) {
//if $hairlength matches the approved lengths
//then set it to the class var
//otherwise produce error
//@TODO:do the if statement below, based off of
//@TODO setgenders
return $this->catHairLength = $hairlength;
}
/**
* Check if supplied hair length is approved
* @return array
*/
public function checkIsHairLengthApproved() {
$approved_hairlength = [
'Short',
'Long',
'Hairless'
];
return $approved_hairlength;
}
/**
* Return hair length
* @return mixed
*/
public function getHairLength() {
return $this->catHairLength;
}
/**
* Set if cat has catitude or not
* @param $catitude
* @return mixed
* @reference http://pink73.tripod.com/cats/catitude2.jpg
*/
public function setHasCatitude($catitude) {
return $this->catCattitude = $catitude;
}
/**
* Return if cat has catitude
* @return int
*/
public function getCatitudeStatus() {
return $this->catCattitude;
}
/**
* Add A Cat Record
* @param $catData
* @return string
*/
public function addCatRecord($catData) {
$db = Database::getFactory();
$db->insertRow($catData);
}
/**
* Update/Edit A Cat Record
* @param $catData
* @param $catID
*/
public function editCatRecord($catData, $catID) {
$db = Database::getFactory();
$db->updateRow($catData, ['id' => $catID]);
}
public function deleteCat($catID)
{
$catID = $this->catID;
$db = Database::getFactory()->getConnection();
try
{
$stmt = $db->prepare("DELETE FROM users WHERE id = :catID");
$stmt->bindValue(':catID', $catID);
$stmt->execute();
return 'record deleted successfully';
} catch (\PDOException $e) {
return 'Deleting record failed' . $e->getMessage();
}
}
/**
* Return All Cat Records
* @return array
*/
public function getAllCats() {
$getAllRows = Database::getFactory()->getConnection();
try
{
$stmt = $getAllRows->prepare("SELECT * FROM users ORDER BY id DESC");
$stmt->execute();
return $stmt->fetchAll();
} catch (\PDOException $e) {
echo $e->getMessage();
}
}
/**
* Delete Single Cat Record
* @param $id
* @return string
*/
public function deleteCatRecord($id) {
return $this->database->deleteRow($id);
}
/**
* Get Single Cat Using ID
* @param $id
* @return mixed|string
*/
public function getSingleCatByID($id) {
$getCatRow = Database::getFactory()->getConnection();
try
{
$stmt = $getCatRow->prepare("SELECT * FROM users WHERE id=$id");
$stmt->execute();
return $stmt->fetch();
} catch (\PDOException $e) {
return $e->getMessage();
}
}
/**
* Cat Record Data from ID
* @param $id
* @return mixed|string
*/
public static function fromID($id)
{
//@TODO:bind id
$getCatRow = Database::getFactory()->getConnection();
try
{
$stmt = $getCatRow->prepare("SELECT * FROM users WHERE id=$id");
$stmt->execute();
return $stmt->fetchObject();
} catch (\PDOException $e) {
return $e->getMessage();
}
}
public function getAllCatsBy($params)
{
//get cat specific data
//i.e., get all cats that are male,
//get all cats that are adopted, etc
}
}