File size: 2,100 Bytes
6ed81b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php
class Place
{
    private $idPlace;
    private $namePlace;
    private $frondPage;
    private $timeTransport;
    private $listCategoryPlace;

    public function __construct($id, $name, $frond)
    {
        $this->idPlace = $id;
        $this->namePlace = $name;
        $this->frondPage = $frond;
        $this->timeTransport = array();
        $this->listCategoryPlace = array();
    }

    public function getRawPlace() : array
    {
        $arrRawTimeTransport = array();
        foreach ($this->timeTransport as $trasnport) {
            if ($trasnport->getNameTransport() != null) {
                array_push($arrRawTimeTransport, $trasnport->getTransportTime());
            }
        }

        $arrRawCategory = array();
        foreach ($this->listCategoryPlace as $category) {
            if ($category->getNameCategory() != null) {
                array_push($arrRawCategory, $category->getNameCategory());
            }
        }

        $data = [
            "id_lugar" => $this->idPlace,
            "nombre_lugar" => $this->namePlace,
            "portada" => $this->frondPage,
            "tiempos_llegada" => $arrRawTimeTransport,
            "categorias" => $arrRawCategory
        ];

        return $data;
    }

    public function addTransport($newTransport)
    {
        array_push($this->timeTransport, $newTransport);
    }

    public function addCategory($newCategory)
    {
        array_push($this->listCategoryPlace, $newCategory);
    }

    public function isExistTransports($nameToCompare) : bool
    {
        $namesTrasnports = array();

        foreach ($this->timeTransport as $transport) {
            array_push($namesTrasnports, $transport->getNameTransport());
        }

        return in_array($nameToCompare, $namesTrasnports);
    }

    public function isExistCategory($nameToCompare) : bool
    {
        $namesCategorys = array();

        foreach ($this->listCategoryPlace as $category) {
            array_push($namesCategorys, $category->getNameCategory());
        }

        return in_array($nameToCompare, $namesCategorys);
    }
}