summaryrefslogtreecommitdiff
path: root/src/Model/Menu.php
blob: 3fea03f6ef045f87425ced7f8eface52dd4e34d7 (plain)
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
<?php

namespace App\Model;

use App\Model\Model;

/**
 * Menu Model
 *
 * @author Phil Burton <phil@pgburton.com>
 */
class Menu extends Model
{
    /**
     * Name of this menu
     *
     * @var string
     */
    protected $name;

    /**
     * Allergies string
     *
     * @var string
     */
    protected $allergies;

    /**
     * Required advanced notice time in horus for this menu
     *
     * @var int
     */
    protected $advanceTime;

    /**
     * Set the class attributes
     *
     * @author Phil Burton <phil@pgburton.com>
     * @param $name
     * @param $allergies
     * @param $advanceTime
     */
    public function __construct($name, $allergies, $advanceTime)
    {
        $this->name = $name;
        $this->allergies = $allergies;
        $this->setTime($advanceTime);
    }

    /**
     * Set the time removing the `h` if given
     * e.g. 12h becomes 12
     *
     * @author Phil Burton <phil@pgburton.com>
     * @param mixed $time
     */
    public function setTime($time)
    {
        $this->advanceTime = str_replace('h', '', $time);
    }

    /**
     * Returbn the advancedd time
     *
     * @author Phil Burton <phil@pgburton.com>
     * @return int
     */
    public function getAdvanceTime(): int
    {
        return $this->advanceTime;
    }

    /**
     * Return a string representation of this menu
     *
     * @author Phil Burton <phil@pgburton.com>
     * @return string
     */
    public function toString(): string
    {
        return $this->name . ';' . $this->allergies;
    }
}