2009-07-01 13:18:08 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\Models\ECommerce;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ECommerceCustomer
|
|
|
|
* Represents a registered user of a shopping application.
|
|
|
|
*
|
|
|
|
* @author Giorgio Sironi
|
|
|
|
* @Entity
|
|
|
|
* @Table(name="ecommerce_customers")
|
|
|
|
*/
|
|
|
|
class ECommerceCustomer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Column(type="integer")
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue(strategy="AUTO")
|
|
|
|
*/
|
2009-07-01 14:04:22 +04:00
|
|
|
private $id;
|
2009-07-01 13:18:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(type="string", length=50)
|
|
|
|
*/
|
2009-07-01 14:04:22 +04:00
|
|
|
private $name;
|
2009-07-01 13:18:08 +04:00
|
|
|
|
|
|
|
/**
|
2009-07-25 20:33:29 +04:00
|
|
|
* @OneToOne(targetEntity="ECommerceCart", mappedBy="customer", cascade={"persist"})
|
2009-07-01 13:18:08 +04:00
|
|
|
*/
|
2009-07-01 14:04:22 +04:00
|
|
|
private $cart;
|
2009-07-06 16:42:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Example of a one-one self referential association. A mentor can follow
|
|
|
|
* only one customer at the time, while a customer can choose only one
|
|
|
|
* mentor. Not properly appropriate but it works.
|
2011-12-20 01:56:19 +04:00
|
|
|
*
|
2011-07-09 17:40:10 +04:00
|
|
|
* @OneToOne(targetEntity="ECommerceCustomer", cascade={"persist"}, fetch="EAGER")
|
2009-07-06 16:42:14 +04:00
|
|
|
* @JoinColumn(name="mentor_id", referencedColumnName="id")
|
|
|
|
*/
|
|
|
|
private $mentor;
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-07-01 14:04:22 +04:00
|
|
|
public function getId() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-07-01 14:04:22 +04:00
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-07-01 14:04:22 +04:00
|
|
|
public function setName($name) {
|
|
|
|
$this->name = $name;
|
|
|
|
}
|
2009-07-01 13:18:08 +04:00
|
|
|
|
|
|
|
public function setCart(ECommerceCart $cart)
|
|
|
|
{
|
2009-07-01 14:04:22 +04:00
|
|
|
if ($this->cart !== $cart) {
|
|
|
|
$this->cart = $cart;
|
2011-12-20 01:56:19 +04:00
|
|
|
$cart->setCustomer($this);
|
2009-07-01 14:04:22 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-07-01 14:04:22 +04:00
|
|
|
/* Does not properly maintain the bidirectional association! */
|
|
|
|
public function brokenSetCart(ECommerceCart $cart) {
|
2009-07-01 13:18:08 +04:00
|
|
|
$this->cart = $cart;
|
2009-07-01 14:04:22 +04:00
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-07-01 14:04:22 +04:00
|
|
|
public function getCart() {
|
|
|
|
return $this->cart;
|
2009-07-01 13:18:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function removeCart()
|
|
|
|
{
|
2009-07-01 14:04:22 +04:00
|
|
|
if ($this->cart !== null) {
|
|
|
|
$cart = $this->cart;
|
|
|
|
$this->cart = null;
|
2009-07-01 17:08:24 +04:00
|
|
|
$cart->removeCustomer();
|
2009-07-01 14:04:22 +04:00
|
|
|
}
|
2009-07-01 13:18:08 +04:00
|
|
|
}
|
2009-07-06 16:42:14 +04:00
|
|
|
|
|
|
|
public function setMentor(ECommerceCustomer $mentor)
|
|
|
|
{
|
|
|
|
$this->mentor = $mentor;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeMentor()
|
|
|
|
{
|
|
|
|
$this->mentor = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMentor()
|
|
|
|
{
|
|
|
|
return $this->mentor;
|
|
|
|
}
|
2009-07-01 13:18:08 +04:00
|
|
|
}
|