1
0
mirror of synced 2024-12-15 23:56:02 +03:00
doctrine2/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php

95 lines
2.0 KiB
PHP
Raw Normal View History

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")
*/
private $id;
2009-07-01 13:18:08 +04:00
/**
* @Column(type="string", length=50)
*/
private $name;
2009-07-01 13:18:08 +04:00
/**
* @OneToOne(targetEntity="ECommerceCart", mappedBy="customer", cascade={"persist"})
2009-07-01 13:18:08 +04:00
*/
private $cart;
/**
* 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.
*
* @OneToOne(targetEntity="ECommerceCustomer", cascade={"persist"})
* @JoinColumn(name="mentor_id", referencedColumnName="id")
*/
private $mentor;
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)
{
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;
}
public function getCart() {
return $this->cart;
2009-07-01 13:18:08 +04:00
}
public function removeCart()
{
if ($this->cart !== null) {
$cart = $this->cart;
$this->cart = null;
2009-07-01 17:08:24 +04:00
$cart->removeCustomer();
}
2009-07-01 13:18:08 +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
}