/** * Set the decision letter using a template * * @param \Jazzee\Entity\Template $template */ protected function setDecisionLetterFromTemplate(Template $template) { if (is_null($this->applicant)) { throw new \Jazzee\Exception('Missing applicant when attemtping to set decision letter from a template'); } $search = array('_Admit_Date_', '_Deny_Date_', '_Offer_Response_Deadline_', '_Applicant_Name_'); $replace = array(); switch ($template->getType()) { case \Jazzee\Entity\Template::DECISION_ADMIT: if (is_null($this->finalAdmit) or is_null($this->offerResponseDeadline)) { throw new \Jazzee\Exception('Missing final decision or offer response deadline when attemtping to set decision letter from a template'); } $replace[] = $this->finalAdmit->format('F jS Y'); $replace[] = null; $replace[] = $this->offerResponseDeadline->format('F jS Y g:ia'); break; case \Jazzee\Entity\Template::DECISION_DENY: if (is_null($this->finalDeny)) { throw new \Jazzee\Exception('Missing final decision when attemtping to set decision letter from a template'); } $replace[] = null; $replace[] = $this->finalDeny->format('F jS Y'); $replace[] = null; break; default: throw new \Jazzee\Exception('Template is not a decision template'); } $replace[] = $this->applicant->getFullName(); $this->decisionLetter = $template->renderText($search, $replace); }