public function getProjectXml(\Sirprize\Basecamp\Project\Entity $project, $useRelativeDates = true, $referenceMilestone = null) { $project->startSubElements(); if ($referenceMilestone === null) { $referenceMilestone = self::REFERENCE_EXTREMITY_LAST; } $referenceDate = $this->_getReferenceDate($project->getMilestones(), $referenceMilestone); if ($useRelativeDates && $referenceDate === null) { throw new Exception("milestone '{$referenceMilestone}' does not exist"); } $xml = "<?xml version=\"1.0\"?>\n"; $xml .= "<project>\n"; $xml .= "<id>" . $project->getId() . "</id>\n"; $xml .= "<name>" . htmlspecialchars($project->getName(), ENT_NOQUOTES) . "</name>\n"; $xml .= "<announcement>" . htmlspecialchars($project->getAnnouncement(), ENT_NOQUOTES) . "</announcement>\n"; $xml .= "<status>" . $project->getStatus() . "</status>\n"; $xml .= "<company>" . htmlspecialchars(trim($project->getCompany()), ENT_NOQUOTES) . "</company>\n"; foreach ($project->getMilestones() as $milestone) { $xml .= "<milestone>\n"; $xml .= "<title>" . htmlspecialchars($milestone->getTitle(), ENT_NOQUOTES) . "</title>\n"; $xml .= "<responsible-party-id>" . htmlspecialchars($milestone->getResponsiblePartyId(), ENT_NOQUOTES) . "</responsible-party-id>\n"; if ($useRelativeDates) { $xml .= "<offset-days-to-reference-date>"; $xml .= $this->_calculateOffsetDays($referenceDate, $milestone->getDeadline(), $referenceMilestone, true); $xml .= "</offset-days-to-reference-date>\n"; } else { $xml .= "<deadline>" . $milestone->getDeadline() . "</deadline>\n"; } $todoLists = $project->findTodoListsByMilestoneId($milestone->getId()); foreach ($todoLists as $todoList) { $xml .= "<todo-list>\n"; $xml .= "<name>" . htmlspecialchars($todoList->getName(), ENT_NOQUOTES) . "</name>\n"; $xml .= "<description>" . htmlspecialchars($todoList->getDescription(), ENT_NOQUOTES) . "</description>\n"; $xml .= "<private type=\"boolean\">" . ($todoList->getIsPrivate() ? 'true' : 'false') . "</private>\n"; foreach ($todoList->getTodoItems() as $todoItem) { $xml .= "<todo-item>\n"; $xml .= "<content>" . htmlspecialchars($todoItem->getContent(), ENT_NOQUOTES) . "</content>\n"; if ($todoItem->getResponsiblePartyId()) { $xml .= "<responsible-party-id>" . htmlspecialchars($todoItem->getResponsiblePartyId(), ENT_NOQUOTES) . "</responsible-party-id>\n"; } if ($todoItem->getDueAt()) { if ($useRelativeDates) { $xml .= "<offset-days-to-reference-date>"; $xml .= $this->_calculateOffsetDays($referenceDate, $todoItem->getDueAt(), $referenceMilestone, false); $xml .= "</offset-days-to-reference-date>\n"; } else { $xml .= "<due-at>" . htmlspecialchars($todoItem->getDueAt(), ENT_NOQUOTES) . "</due-at>\n"; } } $xml .= "</todo-item>\n"; } $xml .= "</todo-list>\n"; } $xml .= "</milestone>\n"; } $xml .= "</project>"; return $xml; }
/** * Instantiate a new project entity * * @return \Sirprize\Basecamp\Project\Entity */ public function getProjectInstance() { $project = new Entity(); $project->setHttpClient($this->_getHttpClient())->setService($this->_getService()); return $project; }