Project.php (4636B)
1 <?php 2 3 namespace PartKeepr\ProjectBundle\Entity; 4 5 use Doctrine\Common\Collections\ArrayCollection; 6 use Doctrine\ORM\Mapping as ORM; 7 use PartKeepr\AuthBundle\Entity\User; 8 use PartKeepr\CoreBundle\Entity\BaseEntity; 9 use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService; 10 use PartKeepr\UploadedFileBundle\Annotation\UploadedFileCollection; 11 use Symfony\Component\Serializer\Annotation\Groups; 12 13 /** 14 * Represents a project. 15 * 16 * @ORM\Entity 17 * @TargetService("/api/projects") 18 */ 19 class Project extends BaseEntity 20 { 21 /** 22 * Specifies the name of the project. 23 * 24 * @ORM\Column(type="string") 25 * @Groups({"default"}) 26 * 27 * @var string 28 */ 29 private $name; 30 31 /** 32 * Specifies the user this project belongs to. 33 * 34 * @ORM\ManyToOne(targetEntity="PartKeepr\AuthBundle\Entity\User") 35 * 36 * @var User 37 */ 38 private $user; 39 40 /** 41 * Holds the parts needed for this project. 42 * 43 * @ORM\OneToMany(targetEntity="PartKeepr\ProjectBundle\Entity\ProjectPart",mappedBy="project",cascade={"persist", "remove"}, orphanRemoval=true) 44 * @Groups({"default"}) 45 * 46 * @var ArrayCollection 47 */ 48 private $parts; 49 50 /** 51 * Holds the description of this project. 52 * 53 * @ORM\Column(type="string",nullable=true) 54 * @Groups({"default"}) 55 * 56 * @var string 57 */ 58 private $description; 59 60 /** 61 * Holds the project attachments. 62 * 63 * @ORM\OneToMany(targetEntity="PartKeepr\ProjectBundle\Entity\ProjectAttachment",mappedBy="project",cascade={"persist", "remove"}, orphanRemoval=true) 64 * @UploadedFileCollection() 65 * @Groups({"default"}) 66 * 67 * @var ArrayCollection 68 */ 69 private $attachments; 70 71 public function __construct() 72 { 73 $this->parts = new ArrayCollection(); 74 $this->attachments = new ArrayCollection(); 75 } 76 77 /** 78 * Sets the user for this project. 79 * 80 * @param User $user 81 */ 82 public function setUser(User $user) 83 { 84 $this->user = $user; 85 } 86 87 /** 88 * Gets the user for this project. 89 * 90 * @return User 91 */ 92 public function getUser() 93 { 94 return $this->user; 95 } 96 97 /** 98 * Sets the name for this project. 99 * 100 * @param string $name 101 */ 102 public function setName($name) 103 { 104 $this->name = $name; 105 } 106 107 /** 108 * Returns the name of this project. 109 * 110 * @return string 111 */ 112 public function getName() 113 { 114 return $this->name; 115 } 116 117 /** 118 * Sets the description of this project. 119 * 120 * @param string $description The description to set 121 */ 122 public function setDescription($description) 123 { 124 $this->description = $description; 125 } 126 127 /** 128 * Returns the description of this project. 129 * 130 * @return string The description 131 */ 132 public function getDescription() 133 { 134 return $this->description; 135 } 136 137 /** 138 * Returns the project parts array. 139 * 140 * @return ProjectPart[] An array of ProjectPart objects 141 */ 142 public function getParts() 143 { 144 return $this->parts->getValues(); 145 } 146 147 /** 148 * Adds a Project Part. 149 * 150 * @param ProjectPart $projectPart A part to add 151 */ 152 public function addPart($projectPart) 153 { 154 $projectPart->setProject($this); 155 $this->parts->add($projectPart); 156 } 157 158 /** 159 * Removes a Project Part. 160 * 161 * @param ProjectPart $projectPart A part to remove 162 */ 163 public function removePart($projectPart) 164 { 165 $projectPart->setProject(null); 166 $this->parts->removeElement($projectPart); 167 } 168 169 /** 170 * Returns the attachments for this project. 171 * 172 * @return ProjectAttachment[] The attachments 173 */ 174 public function getAttachments() 175 { 176 return $this->attachments->getValues(); 177 } 178 179 /** 180 * Adds a Project Attachment. 181 * 182 * @param ProjectAttachment $projectAttachment An attachment to add 183 */ 184 public function addAttachment($projectAttachment) 185 { 186 if ($projectAttachment instanceof ProjectAttachment) { 187 $projectAttachment->setProject($this); 188 } 189 $this->attachments->add($projectAttachment); 190 } 191 192 /** 193 * Removes a Project Attachment. 194 * 195 * @param ProjectAttachment $projectAttachment An attachment to remove 196 */ 197 public function removeAttachment($projectAttachment) 198 { 199 if ($projectAttachment instanceof ProjectAttachment) { 200 $projectAttachment->setProject(null); 201 } 202 $this->attachments->removeElement($projectAttachment); 203 } 204 }