2 namespace Stock\Entity;
4 use Doctrine\ORM\Mapping as ORM;
10 * @ORM\HasLifecycleCallbacks
11 * @ORM\Table(name="vehicle_model")
17 * Can archive records.
21 * Pull Synchronization Strategy for this table.
23 const PULL_SYNCH_STRATEGY = 'Update';
25 * Push Synchronization Strategy for this table.
27 const PUSH_SYNCH_STRATEGY = 'Update';
31 * @ORM\Column(type="integer");
32 * @ORM\GeneratedValue(strategy="AUTO")
37 * @ORM\ManyToOne(targetEntity="Make", inversedBy="models")
38 * @ORM\JoinColumn(name="vehicle_make_id", referencedColumnName="id")
43 * @ORM\Column(type="string", length=75)
48 * @ORM\Column(type="datetime");
53 * @ORM\Column(type="datetime", nullable=true);
58 * @ORM\Column(type="smallint", nullable=true, name="create_version", options={"unsigned"=true})
60 protected $createVersion;
63 * @ORM\Column(type="smallint", nullable=true, name="update_version", options={"unsigned"=true})
65 protected $updateVersion;
68 * @ORM\Column(type="boolean");
70 protected $archived = false;
73 * @ORM\OneToMany(targetEntity="Type", mappedBy="model", fetch="EXTRA_LAZY")
79 * Initialize collections.
81 public function __construct()
83 $this->types = new \Doctrine\Common\Collections\ArrayCollection();
87 * Add a new Region to this Country.
89 * @return \Stock\Entity\Region
91 public function addType(Type $type)
93 $this->types[] = $type;
98 * Magic getter to expose protected properties.
99 * @param string $property
102 public function __get($property)
104 return $this->$property;
108 * Magic setter to save protected properties.
109 * @param string $property
110 * @param mixed $value
112 public function __set($property, $value)
114 $this->$property = $value;
120 public function setCreateTime()
122 $this->created = new \DateTime("now");
128 public function setUpdateTime()
130 $this->updated = new \DateTime("now");
134 * Convert the object to an array.
135 * @param array $expand
136 * @param array $intersect
139 public function toArray(array $expand = array(), array $intersect = array())
141 $includeAll = empty($intersect);
143 ($includeAll || isset($intersect['id']))
144 && $data['id'] = $this->id;
145 ($includeAll || isset($intersect['make']))
146 && in_array('make', $expand)
147 && $data['make'] = $this->make->toArray($expand, $intersect);
148 ($includeAll || isset($intersect['name']))
149 && $data['name'] = $this->name;
154 * Convert the object to an array for synchronization.
157 public function toSynchArray()
161 'make' => $this->make->id,
162 'name' => $this->name
167 * Populate from an array.
170 public function fromArray($data = array())
173 && $this->id = $data['id'];
175 && $this->make = $data['make'];
177 && $this->name = $data['name'];
178 isset($data['createVersion'])
179 && $this->createVersion = $data['createVersion'];
180 isset($data['updateVersion'])
181 && $this->updateVersion = $data['updateVersion'];