Constraint.php 2.24 KB
Newer Older
arnaudbey's avatar
add app  
arnaudbey committed
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
<?php

namespace MagicWordBundle\Entity\ObjectiveType;

use Doctrine\ORM\Mapping as ORM;
use MagicWordBundle\Entity\Objective;

/**
 * Constraint.
 *
 * @ORM\Entity
 * @ORM\Table(name="objective_type_constraint")
 */
class Constraint extends Objective
{
    protected $discr = 'constraint';

    public function getDiscr()
    {
        return $this->discr;
    }

    /**
     * @var int
     *
     * @ORM\Column(name="numberToFind", type="integer")
     */
    private $numberToFind;

    /**
Arnaud Bey's avatar
Arnaud Bey committed
31
     * @ORM\ManyTomany(targetEntity="LexiconBundle\Entity\Feature")
arnaudbey's avatar
add app  
arnaudbey committed
32
     */
Arnaud Bey's avatar
Arnaud Bey committed
33
    private $features;
arnaudbey's avatar
add app  
arnaudbey committed
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

    /**
     * Set numberToFind.
     *
     * @param int $numberToFind
     *
     * @return Constraint
     */
    public function setNumberToFind($numberToFind)
    {
        $this->numberToFind = $numberToFind;

        return $this;
    }

    /**
     * Get numberToFind.
     *
     * @return int
     */
    public function getNumberToFind()
    {
        return $this->numberToFind;
    }



    public function export()
    {
        $jsonArray = array(
            'type' => $this->discr,
            'numberToFind' => $this->numberToFind,
Arnaud Bey's avatar
Arnaud Bey committed
66
            'features' => []
arnaudbey's avatar
add app  
arnaudbey committed
67 68
        );

Arnaud Bey's avatar
Arnaud Bey committed
69 70 71 72
        foreach ($this->features as $feature) {
            $jsonArray["features"][] = $feature->getId();
        }

arnaudbey's avatar
add app  
arnaudbey committed
73 74
        return $jsonArray;
    }
Arnaud Bey's avatar
Arnaud Bey committed
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
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->features = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Add feature.
     *
     * @param \LexiconBundle\Entity\Feature $feature
     *
     * @return Constraint
     */
    public function addFeature(\LexiconBundle\Entity\Feature $feature)
    {
        $this->features[] = $feature;

        return $this;
    }

    /**
     * Remove feature.
     *
     * @param \LexiconBundle\Entity\Feature $feature
     *
     * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
     */
    public function removeFeature(\LexiconBundle\Entity\Feature $feature)
    {
        return $this->features->removeElement($feature);
    }

    /**
     * Get features.
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getFeatures()
    {
        return $this->features;
    }
arnaudbey's avatar
add app  
arnaudbey committed
118
}