/application/model/Work.php
PHP | 1054 lines | 745 code | 84 blank | 225 comment | 137 complexity | f21ec1b174343d6d558862bd32260150 MD5 | raw file
- <?php
- require_once ('IWork.php');
- require_once ('DomainEntity.php');
- require_once ('WorkType.php');
- class Work extends DomainEntity implements IWork
- {
- /**
- * @var The title of the work.
- */
- private $title;
- /**
- * @var An optional subtitle of the work.
- */
- private $subtitle;
- /**
- * @var An optional subject of the work,
- * e.g. when the work is of a thesis type.
- */
- private $subject;
-
- /**
- * @var The year the work has been created.
- */
- private $yearOfOrigin;
-
- /**
- * @var The type of the work.
- * @see WorkType */
- private $type;
-
- /**
- * @var The detailed description of the work.
- */
- private $description;
-
- /**
- * @var The authors of the work.
- * In the current implementation these are names,
- * but they could also be the ids of persons
- * or person domain objects in the future.
- */
- private $authors;
-
- /**
- * @var The tutors supporting the work.
- * In the current implementation these are names,
- * but they could also be the ids of persons
- * or person domain objects in the future.
- */
- private $tutors;
-
- /**
- * @var The study courses involved in the work.
- * In the current implementation these are names,
- * but they could also be the ids of study courses
- * or domain objects in the future.
- */
- private $studyCourses;
-
- /**
- * @var The awards the work has won.
- * In the current implementation these are titles,
- * but they could also be the ids of awards
- * or domain objects in the future.
- */
- private $awards;
-
- /**
- * @var The publications of the work.
- * In the current implementation these are titles,
- * but they could also be the ids of publications
- * or domain objects in the future.
- */
- private $publications;
-
- /**
- * @var The cooperations to partners involved
- * in the creation of the work.
- * In the current implementation these are just
- * names of the partners, but they could also be the ids
- * of a cooperation partner (name, role, contribution etc.)
- * or domain objects in the future.
- */
- private $cooperations;
-
- /**
- * @var Urls to images associated with the work.
- */
- private $imageUrls;
-
- /**
- * @var The url to an image used as the title thumbnail for the work.
- */
- private $titleImageThumbnailUrl;
-
- /**
- * @var The url to an image used as the title for the work.
- */
- private $titleImageUrl;
-
- /**
- * @var Urls to videos (flv) associated with the work.
- */
- private $videoUrls;
-
- /**
- * @var Url to a website dedicated to the work or the work itself
- * if it is online.
- */
- private $websiteUrl;
-
- /**
- * @var The tags applied to this work.
- */
- private $tags;
-
- /**
- * Creates a new representation of a work of the portfolio.
- *
- * @return
- * @param object $id[optional]
- * @param object $title[optional]
- */
- public function __construct($id = null, $title = null)
- {
- $this->setId($id);
- $this->setTitle($title);
-
- }
-
- public function getName()
- {
- return $this->getId();
- }
-
- public function getAuthors()
- {
- // this is a copy of the original array so
- // the aggregate (this domain object) is safe
- // from the modification of its aggregated
- // value objects (the authors names).
- return $this->authors;
- }
- public function setAuthors($value)
- {
- if (is_array($value) && sizeof($value) > 0)
- {
- $value = array_unique($value);
- $maxIndex = sizeof($value) - 1;
- for ($i = $maxIndex; $i >= 0; $i--)
- {
- $value[$i] = trim((string) $value[$i]);
-
- if (empty($value[$i]))
- {
- array_splice($value, $i, 1);
- }
- }
- $this->authors = $value;
- }
- else if ($value === null || (is_array($value) && sizeof($value) == 0))
- {
- $this->authors = null;
- }
- }
- /**
- * @return Work
- * @param string $name
- */
- public function addAuthor($name)
- {
- $name = trim((string) $name);
- if ($name)
- {
- if ($this->authors === null)
- {
- $this->authors = array($name);
- }
- else
- {
- if (array_search($name, $this->authors) === false)
- {
- array_push($this->authors, $name);
- }
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- * @param string $name
- */
- public function removeAuthor($name)
- {
- if ($name)
- {
- $index = array_search($name, $this->authors);
- if ($index !== false)
- {
- // use splice instead of unset to preserve continuous indexes
- array_splice($this->authors, $index, 1);
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- */
- public function removeAllAuthors()
- {
- $this->authors = null;
-
- return $this;
- }
-
-
- public function getStudyCourses()
- {
- return $this->studyCourses;
- }
- public function setStudyCourses($value)
- {
- if (is_array($value) && sizeof($value) > 0)
- {
- $value = array_unique($value);
- $maxIndex = sizeof($value) - 1;
- for ($i = $maxIndex; $i >= 0; $i--)
- {
- $value[$i] = trim((string) $value[$i]);
- if (empty($value[$i]))
- {
- array_splice($value, $i, 1);
- }
- }
- $this->studyCourses = $value;
- }
- else if ($value === null || (is_array($value) && sizeof($value) == 0))
- {
- $this->studyCourses = null;
- }
- }
- /**
- * @return Work
- * @param string $name
- */
- public function addStudyCourse($name)
- {
- $name = trim((string) $name);
- if ($name)
- {
- if ($this->studyCourses === null)
- {
- $this->studyCourses = array($name);
- }
- else
- {
- if (array_search($name, $this->studyCourses) === false)
- {
- array_push($this->studyCourses, $name);
- }
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- * @param string $name
- */
- public function removeStudyCourse($name)
- {
- if ($name)
- {
- $index = array_search($name, $this->studyCourses);
- if ($index !== false)
- {
- array_splice($this->studyCourses, $index, 1);
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- */
- public function removeAllStudyCourses()
- {
- $this->studyCourses = null;
-
- return $this;
- }
-
- public function getTutors()
- {
- return $this->tutors;
- }
- public function setTutors($value)
- {
- if (is_array($value) && sizeof($value) > 0)
- {
- $value = array_unique($value);
- $maxIndex = sizeof($value) - 1;
- for ($i = $maxIndex; $i >= 0; $i--)
- {
- $value[$i] = trim((string) $value[$i]);
- if (empty($value[$i]))
- {
- array_splice($value, $i, 1);
- }
- }
- $this->tutors = $value;
- }
- else if ($value === null || (is_array($value) && sizeof($value) == 0))
- {
- $this->tutors = null;
- }
- }
- /**
- * @return Work
- * @param string $name
- */
- public function addTutor($name)
- {
- $name = trim((string) $name);
- if ($name)
- {
- if ($this->tutors === null)
- {
- $this->tutors = array($name);
- }
- else
- {
- if (array_search($name, $this->tutors) === false)
- {
- array_push($this->tutors, $name);
- }
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- * @param string $name
- */
- public function removeTutor($name)
- {
- if ($name)
- {
- $index = array_search($name, $this->tutors);
- if ($index !== false)
- {
- array_splice($this->tutors, $index, 1);
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- */
- public function removeAllTutors()
- {
- $this->tutors = null;
-
- return $this;
- }
-
- public function getAwards()
- {
- return $this->awards;
- }
- public function setAwards($value)
- {
- if (is_array($value) && sizeof($value) > 0)
- {
- $value = array_unique($value);
- $maxIndex = sizeof($value) - 1;
- for ($i = $maxIndex; $i >= 0; $i--)
- {
- $value[$i] = trim((string) $value[$i]);
- if (empty($value[$i]))
- {
- array_splice($value, $i, 1);
- }
- }
- $this->awards = $value;
- }
- else if ($value === null || (is_array($value) && sizeof($value) == 0))
- {
- $this->awards = null;
- }
- }
- /**
- * @return Work
- * @param string $name
- */
- public function addAward($name)
- {
- $name = trim((string) $name);
- if ($name)
- {
- if ($this->awards === null)
- {
- $this->awards = array($name);
- }
- else
- {
- if (array_search($name, $this->awards) === false)
- {
- array_push($this->awards, $name);
- }
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- * @param string $name
- */
- public function removeAward($name)
- {
- if ($name)
- {
- $index = array_search($name, $this->awards);
- if ($index !== false)
- {
- array_splice($this->awards, $index, 1);
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- */
- public function removeAllAwards()
- {
- $this->awards = null;
-
- return $this;
- }
-
- function getPublications()
- {
- return $this->publications;
- }
- public function setPublications($value)
- {
- if (is_array($value) && sizeof($value) > 0)
- {
- $value = array_unique($value);
- $maxIndex = sizeof($value) - 1;
- for ($i = $maxIndex; $i >= 0; $i--)
- {
- $value[$i] = trim((string) $value[$i]);
- if (empty($value[$i]))
- {
- array_splice($value, $i, 1);
- }
- }
- $this->publications = $value;
- }
- else if ($value === null || (is_array($value) && sizeof($value) == 0))
- {
- $this->publications = null;
- }
- }
- /**
- * @return Work
- * @param string $name
- */
- public function addPublication($name)
- {
- $name = trim((string) $name);
- if ($name)
- {
- if ($this->publications === null)
- {
- $this->publications = array($name);
- }
- else
- {
- if (array_search($name, $this->publications) === false)
- {
- array_push($this->publications, $name);
- }
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- * @param string $name
- */
- public function removePublication($name)
- {
- if ($name)
- {
- $index = array_search($name, $this->publications);
- if ($index !== false)
- {
- array_splice($this->publications, $index, 1);
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- */
- public function removeAllPublications()
- {
- $this->publications = null;
-
- return $this;
- }
-
- public function getCooperations()
- {
- return $this->cooperations;
- }
- public function setCooperations($value)
- {
- if (is_array($value) && sizeof($value) > 0)
- {
- $value = array_unique($value);
- $maxIndex = sizeof($value) - 1;
- for ($i = $maxIndex; $i >= 0; $i--)
- {
- $value[$i] = trim((string) $value[$i]);
- if (empty($value[$i]))
- {
- array_splice($value, $i, 1);
- }
- }
- $this->cooperations = $value;
- }
- else if ($value === null || (is_array($value) && sizeof($value) == 0))
- {
- $this->cooperations = null;
- }
- }
- /**
- * @return Work
- * @param string $partnerName
- */
- public function addCooperation($partnerName)
- {
- $partnerName = trim((string) $partnerName);
- if ($partnerName)
- {
- if ($this->cooperations === null)
- {
- $this->cooperations = array($partnerName);
- }
- else
- {
- if (array_search($partnerName, $this->cooperations) === false)
- {
- array_push($this->cooperations, $partnerName);
- }
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- * @param string $partnerName
- */
- public function removeCooperation($partnerName)
- {
- if ($partnerName)
- {
- $index = array_search($partnerName, $this->cooperations);
- if ($index !== false)
- {
- array_splice($this->cooperations, $index, 1);
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- */
- public function removeAllCooperations()
- {
- $this->cooperations = null;
-
- return $this;
- }
-
- public function getImageUrls()
- {
- return $this->imageUrls;
- }
- public function setImageUrls($value)
- {
- if (is_array($value) && sizeof($value) > 0)
- {
- $value = array_unique($value);
- $maxIndex = sizeof($value) - 1;
- for ($i = $maxIndex; $i >= 0; $i--)
- {
- $value[$i] = trim((string) $value[$i]);
- if (empty($value[$i]))
- {
- array_splice($value, $i, 1);
- }
- }
- $this->imageUrls = $value;
- }
- else if ($value === null || (is_array($value) && sizeof($value) == 0))
- {
- $this->imageUrls = null;
- }
- }
- /**
- * @return Work
- * @param string $url
- */
- public function addImageUrl($url)
- {
- $url = trim((string) $url);
- if ($url)
- {
- if ($this->imageUrls === null)
- {
- $this->imageUrls = array($url);
- }
- else
- {
- if (array_search($url, $this->imageUrls) === false)
- {
- array_push($this->imageUrls, $url);
- }
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- * @param string $url
- */
- public function removeImageUrl($url)
- {
- if ($url)
- {
- $index = array_search($url, $this->imageUrls);
- if ($index !== false)
- {
- array_splice($this->imageUrls, $index, 1);
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- */
- public function removeAllImageUrls()
- {
- $this->imageUrls = null;
-
- return $this;
- }
-
- public function getVideoUrls()
- {
- return $this->videoUrls;
- }
- public function setVideoUrls($value)
- {
- if (is_array($value) && sizeof($value) > 0)
- {
- $value = array_unique($value);
- $maxIndex = sizeof($value) - 1;
- for ($i = $maxIndex; $i >= 0; $i--)
- {
- $value[$i] = trim((string) $value[$i]);
- if (empty($value[$i]))
- {
- array_splice($value, $i, 1);
- }
- }
- $this->videoUrls = $value;
- }
- else if ($value === null || (is_array($value) && sizeof($value) == 0))
- {
- $this->videoUrls = null;
- }
- }
- /**
- * @return Work
- * @param string $url
- */
- public function addVideoUrl($url)
- {
- $url = trim((string) $url);
- if ($url)
- {
- if ($this->videoUrls === null)
- {
- $this->videoUrls = array($url);
- }
- else
- {
- if (array_search($url, $this->videoUrls) === false)
- {
- array_push($this->videoUrls, $url);
- }
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- * @param string $url
- */
- public function removeVideoUrl($url)
- {
- if ($url)
- {
- $index = array_search($url, $this->videoUrls);
- if ($index !== false)
- {
- array_splice($this->videoUrls, $index, 1);
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- */
- public function removeAllVideoUrls()
- {
- $this->videoUrls = null;
-
- return $this;
- }
-
-
- public function getDescription()
- {
- return $this->description;
- }
- /**
- * @return Work
- * @param string $value
- */
- public function setDescription($value)
- {
- $value = trim((string) $value);
- if ($value)
- {
- $this->description = $value;
- }
- else
- {
- $this->description = null;
- }
-
- return $this;
- }
-
- public function getSubject()
- {
- return $this->subject;
- }
- /**
- * @return Work
- * @param string $value
- */
- public function setSubject($value)
- {
- $value = trim((string) $value);
- if ($value)
- {
- $this->subject = $value;
- }
- else
- {
- $this->subject = null;
- }
-
- return $this;
- }
-
- public function getTitle()
- {
- return $this->title;
- }
- /**
- * @return Work
- * @param string $value
- */
- public function setTitle($value)
- {
- $value = trim((string) $value);
- if ($value)
- {
- $this->title = $value;
- }
- else
- {
- $this->title = null;
- }
-
- return $this;
- }
-
- public function getSubtitle()
- {
- return $this->subtitle;
- }
- /**
- * @return Work
- * @param string $value
- */
- public function setSubtitle($value)
- {
- $value = trim((string) $value);
- if ($value)
- {
- $this->subtitle = $value;
- }
- else
- {
- $this->subtitle = null;
- }
-
- return $this;
- }
-
-
- public function getTitleImageThumbnailUrl()
- {
- return $this->titleImageThumbnailUrl;
- }
- /**
- * @return Work
- * @param string $value
- */
- public function setTitleImageThumbnailUrl($value)
- {
- $value = trim((string) $value);
- if ($value)
- {
- $this->titleImageThumbnailUrl = $value;
- }
- else
- {
- $this->titleImageThumbnailUrl = null;
- }
-
- return $this;
- }
-
- public function getTitleImageUrl()
- {
- return $this->titleImageUrl;
- }
- /**
- * @return Work
- * @param string $value
- */
- public function setTitleImageUrl($value)
- {
- $value = trim((string) $value);
- if ($value)
- {
- $this->titleImageUrl = $value;
- }
- else
- {
- $this->titleImageUrl = null;
- }
-
- return $this;
- }
-
- public function getType()
- {
- return $this->type;
- }
- /**
- * @return Work
- * @param string $value
- */
- public function setType($value)
- {
- $value = trim((string) $value);
- if (WorkType::defines($value))
- {
- $this->type = $value;
- }
- else
- {
- Registry::getInstance()->getRootLogger()->log("The type [$value] was not accepted as a type for work [{$this->getId()}]", Zend_Log::INFO);
- }
-
- return $this;
- }
-
- public function getYearOfOrigin()
- {
- return $this->yearOfOrigin;
- }
- /**
- * @return Work
- * @param string $value
- */
- public function setYearOfOrigin($value)
- {
- $this->yearOfOrigin = (int) $value;
-
- return $this;
- }
-
- /**
- * Returns $websiteUrl.
- * @see Work::$websiteUrl
- */
- public function getWebsiteUrl()
- {
- return $this->websiteUrl;
- }
-
- /**
- * Sets $websiteUrl.
- * @return Work
- * @param object $websiteUrl
- * @see Work::$websiteUrl
- */
- public function setWebsiteUrl($value)
- {
- $value = trim((string) $value);
- if ($value)
- {
- $this->websiteUrl = $value;
- }
- else
- {
- $this->websiteUrl = null;
- }
-
- return $this;
- }
-
- public function getTags()
- {
- return $this->tags;
- }
- public function setTags($value)
- {
- if (is_array($value) && sizeof($value) > 0)
- {
- $value = array_unique($value);
- $maxIndex = sizeof($value) - 1;
- for ($i = $maxIndex; $i >= 0; $i--)
- {
- if (!($value[$i] instanceof ICategoryTag))
- {
- array_splice($value, $i, 1);
- }
- }
- $this->tags = $value;
- }
- else if ($value === null || (is_array($value) && sizeof($value) == 0))
- {
- $this->tags = null;
- }
- }
-
- public function addTag($tag)
- {
- if ($tag instanceof ICategoryTag)
- {
- if ($this->tags === null)
- {
- $this->tags = array($tag);
- }
- else
- {
- if (array_search($tag, $this->tags, true) === false)
- {
- array_push($this->tags, $tag);
- }
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- * @param mixed $idOrTag The tag or the id of the tag to remove.
- */
- public function removeTag($idOrTag)
- {
- if ($idOrTag)
- {
- if ($idOrTag instanceof ITag)
- {
- $idOrTag = $idOrTag->getId();
- }
-
- foreach ($this->tags as $key => $tag)
- {
- if ($idOrTag === $tag->getId())
- {
- if (is_int($key))
- {
- array_splice($this->tags, $key, 1);
- }
- else
- {
- unset($this->tags[$key]);
- }
-
- break;
- }
- }
- }
-
- return $this;
- }
- /**
- * @return Work
- */
- public function removeAllTags()
- {
- $this->tags = null;
-
- return $this;
- }
-
- public function __toString()
- {
- return '{'.__CLASS__.'} '. $this->id .', '. $this->title;
- }
- }
- ?>