Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Doctrine\Common\Collections\ArrayCollection;
- /**
- * @Entity @Table(name="User")
- */
- class User
- {
- /**
- * @Id @Column(type="integer") @GeneratedValue
- * @var integer
- */
- private $id;
- /**
- * @Column()
- * @var string
- */
- private $username;
- /**
- * @Column()
- * @var string
- */
- private $password;
- /**
- * @Column()
- * @var string
- */
- private $email;
- /**
- * @Column()
- * @var string
- */
- private $verificationcode;
- /**
- * @Column(length="2")
- * @var integer
- */
- private $status; // logged in? Banned?
- /**
- * @Column()
- * @var string
- */
- private $ip;
- /**
- * NOT-OWNING SIDE
- * @OneToMany(targetEntity="Transaction", mappedBy="user", cascade={"persist"})
- * @var array List of transactions
- */
- private $transactions;
- /****************************************************************************/
- public function __construct() {
- $this->transactions = new \Doctrine\Common\Collections\ArrayCollection;
- }
- public function getId() { return $this->id; }
- public function getUsername() { return $this->username; }
- public function setUsername($username) { $this->username = $username; }
- public function getPassword() { return $this->password; }
- public function setPassword($password) { $this->password = $password; }
- public function getEmail() { return $this->email; }
- public function setEmail($email) { $this->email = $email; }
- public function getVerificationcode() { return $this->verificationcode; }
- public function setVerificationcode($verificationcode) { $this->verificationcode = $verificationcode; }
- public function getStatus() { return $this->status; }
- public function setStatus($status) { $this->status = $status; }
- public function getIp() { return $this->ip; }
- public function setIp($ip) { $this->ip = $ip; }
- public function addTransaction(Transaction $transaction) {
- $transaction->setUser($this->getId());
- $this->transactions[] = $transaction;
- }
- public function getTransactions() { return $this->transactions; }
- public function getTransaction($index) { return $this->transactions[$index]; }
- }
- /**
- * @Entity @Table(name="Transaction")
- */
- class Transaction
- {
- /**
- * @ID @Column(type = "integer") @GeneratedValue
- *
- * @var integer
- */
- private $id;
- /**
- * OWNING SIDE because it's the Many part
- * @ManyToOne(targetEntity="User", inversedBy="transactions")
- *
- * @var integer
- */
- private $user;
- /**
- * @Column
- *
- * @var string
- */
- private $message;
- /***************************************************************/
- public function getMessage() { return $this->message; }
- public function setMessage($message) { $this->message = $message; }
- public function setUser($user) { $this->user = $user; }
- }
- // calling code:
- $oUser = $em->find('User', 1);
- $oTransaction = new Transaction();
- $oTransaction->setMessage('Test ' . date("H:i:s"));
- $oUser->addTransaction($oTransaction);
- $em->persist($oUser);
- $em->flush();
Add Comment
Please, Sign In to add comment