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.
|
2009-07-18 15:41:37 +04:00
|
|
|
*
|
2009-07-25 20:33:29 +04:00
|
|
|
* @OneToOne(targetEntity="ECommerceCustomer", cascade={"persist"})
|
2009-07-06 16:42:14 +04:00
|
|
|
* @JoinColumn(name="mentor_id", referencedColumnName="id")
|
|
|
|
*/
|
|
|
|
private $mentor;
|
2009-07-01 14:04:22 +04:00
|
|
|
|
|
|
|
public function getId() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
$cart->setCustomer($this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|