Offre.php 7.19 KB
Newer Older
1 2 3 4
<?php

namespace PotageBundle\Entity;

Mat's avatar
Mat committed
5
use JMS\Serializer\Annotation as Serializer;
6
use Doctrine\Common\Collections\ArrayCollection;
7 8 9 10 11 12 13
use Doctrine\ORM\Mapping as ORM;

/**
 * Offre
 *
 * @ORM\Table(name="offre")
 * @ORM\Entity(repositoryClass="PotageBundle\Repository\OffreRepository")
Mat's avatar
Mat committed
14 15
 * @ORM\HasLifecycleCallbacks()
 *
16 17 18 19 20 21 22 23 24
 */
class Offre
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
25
     * @Serializer\Groups({"readLettres", "readOffres", "readOffreLegumes"})
26 27
     */
    private $id;
28 29 30 31
    
    /**
     * @var OffreLegumes[]
     * @ORM\OneToMany(targetEntity="PotageBundle\Entity\OffreLegumes", mappedBy="offre")
32
     * @Serializer\Groups({"readOffres", "readOffreLegumes"})
33 34 35
     */
    private $offreLegumes;
    
Mat's avatar
Mat committed
36 37 38 39 40 41
    /**
     * @var Lettre[]
     * @ORM\OneToMany(targetEntity="PotageBundle\Entity\Lettre", mappedBy="offre")
     */
    private $lettres;
    
42 43 44 45 46 47
    /**
     * @var Commande[]
     * @ORM\OneToMany(targetEntity="PotageBundle\Entity\Commande", mappedBy="offre")
     */
    private $commandes;
    
48 49 50 51
    /**
     * @var string
     *
     * @ORM\Column(name="reference", type="string", length=16, unique=true)
Mat's avatar
Mat committed
52
     * @Serializer\Groups({"readLettres", "readOffres"})
53 54 55 56 57 58
     */
    private $reference;

    /**
     * @var \DateTime
     *
59
     * @ORM\Column(name="created_at", type="datetime")
Mat's avatar
Mat committed
60
     * @Serializer\Groups({"readOffres"})
61 62 63 64 65 66
     */
    private $createdAt;

    /**
     * @var \DateTime
     *
67
     * @ORM\Column(name="updated_at", type="datetime", nullable=true)
Mat's avatar
Mat committed
68
     * @Serializer\Groups({"readOffres"})
69 70
     */
    private $updatedAt;
71 72 73 74 75
    
    /**
     * @var \DateTime
     *
     * @ORM\Column(name="ended_at", type="datetime")
Mat's avatar
Mat committed
76
     * @Serializer\Groups({"readOffres"})
77 78
     */
    private $endedAt;
79 80

    /**
81
     * @var string
82
     *
Mat's avatar
Mat committed
83
     * @ORM\Column(name="status", type="string", columnDefinition="enum('draft', 'current', 'closed', 'trash')")
Mat's avatar
Mat committed
84
     * @Serializer\Groups({"readOffres"})
85
     */
Mat's avatar
Mat committed
86
    private $status;
87
    
88
    /**
Mat's avatar
Mat committed
89
     * @var string
Mat's avatar
hop  
Mat committed
90
     * @ORM\Column(name="sorted", type="string", nullable=true)
Mat's avatar
Mat committed
91
     * @Serializer\Groups({"readOffres"})
92
     */
93
    private $sorted;
94 95 96 97 98 99 100 101 102 103
    
    
    /**
     *
     * @ORM\PrePersist()
     */
    public function prePersist()
    {
        $this->createdAt = new \DateTime();
    }
104
    
105 106 107 108 109 110 111 112 113
    /**
     *
     * @ORM\PreUpdate()
     */
    public function preUpdate()
    {
        $this->updatedAt = new \DateTime();
    }
    
114 115 116
    /**
     * Offre constructor.
     *
117
     * @param $reference
118 119 120
     */
    public function __construct($reference)
    {
121 122
        $this->offreLegumes = new ArrayCollection();
        $this->lettres = new ArrayCollection();
123 124
        $this->status = 'draft';
        $this->reference = $reference;
125
        
126
    }
127

Mat's avatar
Mat committed
128
    
129 130 131
    /**
     * Get id
     *
Mat's avatar
Mat committed
132
     * @return integer
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
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set reference
     *
     * @param string $reference
     *
     * @return Offre
     */
    public function setReference($reference)
    {
        $this->reference = $reference;

        return $this;
    }

    /**
     * Get reference
     *
     * @return string
     */
    public function getReference()
    {
        return $this->reference;
    }
162 163 164 165 166 167 168
    
    
    /**
     * @return string
     */
    public function getReferenceMore()
    {
169
        return $this->reference . '  [ ' . ($this->status === 'draft' ? 'en préparation' : 'publié') . ' ][ ' . count($this->offreLegumes) . ' légumes ]';
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
    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     *
     * @return Offre
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     *
     * @return Offre
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
Mat's avatar
Mat committed
221
     * Set status
222
     *
Mat's avatar
Mat committed
223
     * @param string $status
224 225 226
     *
     * @return Offre
     */
Mat's avatar
Mat committed
227
    public function setStatus($status)
228
    {
Mat's avatar
Mat committed
229
        $this->status = $status;
230 231 232 233 234

        return $this;
    }

    /**
Mat's avatar
Mat committed
235
     * Get status
236
     *
Mat's avatar
Mat committed
237
     * @return string
238
     */
Mat's avatar
Mat committed
239
    public function getStatus()
240
    {
Mat's avatar
Mat committed
241
        return $this->status;
242 243 244 245 246 247 248 249 250 251 252
    }

    /**
     * Set endedAt
     *
     * @param \DateTime $endedAt
     *
     * @return Offre
     */
    public function setEndedAt($endedAt)
    {
253
        $s_time = ' 12:00:00'; // TODO une constante à fixer qqpart
254 255 256 257
        $s_date = $endedAt->format('Y-m-d');
        $string = $s_date . $s_time;
        $endedAt = date_create_from_format('Y-m-d H:i:s', $string);
        
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
        $this->endedAt = $endedAt;

        return $this;
    }

    /**
     * Get endedAt
     *
     * @return \DateTime
     */
    public function getEndedAt()
    {
        return $this->endedAt;
    }

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
    /**
     * Add offreLegume
     *
     * @param \PotageBundle\Entity\OffreLegumes $offreLegume
     *
     * @return Offre
     */
    public function addOffreLegume(\PotageBundle\Entity\OffreLegumes $offreLegume)
    {
        $this->offreLegumes[] = $offreLegume;

        return $this;
    }

    /**
     * Remove offreLegume
     *
     * @param \PotageBundle\Entity\OffreLegumes $offreLegume
     */
    public function removeOffreLegume(\PotageBundle\Entity\OffreLegumes $offreLegume)
    {
        $this->offreLegumes->removeElement($offreLegume);
    }

    /**
     * Get offreLegumes
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getOffreLegumes()
    {
        return $this->offreLegumes;
    }
Mat's avatar
Mat committed
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

    /**
     * Add lettre
     *
     * @param \PotageBundle\Entity\Lettre $lettre
     *
     * @return Offre
     */
    public function addLettre(\PotageBundle\Entity\Lettre $lettre)
    {
        $this->lettres[] = $lettre;

        return $this;
    }

    /**
     * Remove lettre
     *
     * @param \PotageBundle\Entity\Lettre $lettre
     */
    public function removeLettre(\PotageBundle\Entity\Lettre $lettre)
    {
        $this->lettres->removeElement($lettre);
    }

    /**
     * Get lettres
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getLettres()
    {
        return $this->lettres;
    }
340 341 342 343 344


    /**
     * Set sorted
     *
Mat's avatar
hop  
Mat committed
345
     * @param string $sorted
346 347 348
     *
     * @return Offre
     */
Mat's avatar
hop  
Mat committed
349
    public function setSorted($sorted)
350
    {
Mat's avatar
hop  
Mat committed
351
        $this->sorted = $sorted;
352 353 354 355 356 357 358

        return $this;
    }

    /**
     * Get sorted
     *
Mat's avatar
hop  
Mat committed
359
     * @return string
360 361 362 363 364
     */
    public function getSorted()
    {
        return $this->sorted;
    }
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
    
    /**
     * @return Commande[]
     */
    public function getCommandes()
    {
        return $this->commandes;
    }
    
    /**
     * @param Commande[] $commandes
     * @return Offre
     */
    public function setCommandes($commandes)
    {
        $this->commandes = $commandes;
        return $this;
    }
    
    
    
386
}