public function testResource() { $object = new PhpProject(); // Start $this->assertEquals(0, $object->getResourceCount()); $this->assertCount(0, $object->getAllResources()); $this->assertInternalType('array', $object->getAllResources()); $this->assertNull($object->getActiveResource()); // Add a resource $this->assertInstanceOf('PhpOffice\\PhpProject\\Resource', $object->createResource()); $this->assertEquals(1, $object->getResourceCount()); $this->assertCount(1, $object->getAllResources()); $this->assertInternalType('array', $object->getAllResources()); $this->assertInstanceOf('PhpOffice\\PhpProject\\Resource', $object->getActiveResource()); }
/** * @return multitype:Ambigous <number, unknown> */ private function sanitizeProject() { // Info Project $minDate = 0; // Browse all tasks $arrTasks = $this->phpProject->getAllTasks(); foreach ($arrTasks as $oTask) { if ($oTask->getTaskCount() == 0) { $this->sanitizeTask($oTask); } else { $this->sanitizeTaskParent($oTask); } $tStartDate = $oTask->getStartDate(); if ($minDate == 0 || $tStartDate < $minDate) { $minDate = $tStartDate; } } // Browse all Resources $numResource = 0; foreach ($this->phpProject->getAllResources() as $oResource) { $oResource->setIndex($numResource); $numResource++; } return array('date_start' => (int) $minDate); }
/** * * @param string $pFilename * @throws Exception */ public function save($pFilename) { $arrProjectInfo = $this->sanitizeProject(); // Create XML Object $oXML = new XMLWriter(XMLWriter::STORAGE_DISK); $oXML->startDocument('1.0', 'UTF-8'); // project $oXML->startElement('project'); if (isset($arrProjectInfo['date_start']) && $arrProjectInfo['date_start'] != 0) { $oXML->writeAttribute('view-date', date('Y-m-d', $arrProjectInfo['date_start'])); } $oXML->writeAttribute('version', '2.0'); // view $oXML->startElement('view'); $oXML->writeAttribute('id', 'resource-table'); // field $oXML->startElement('field'); $oXML->writeAttribute('id', '0'); $oXML->writeAttribute('name', 'Nom'); $oXML->writeAttribute('width', '56'); $oXML->writeAttribute('valuetype', '0'); $oXML->endElement(); $oXML->startElement('field'); $oXML->writeAttribute('id', '1'); $oXML->writeAttribute('name', 'Rôle par défaut'); $oXML->writeAttribute('width', '43'); $oXML->writeAttribute('valuetype', '1'); $oXML->endElement(); // >view $oXML->endElement(); // tasks $oXML->startElement('tasks'); // tasksproperties $oXML->startElement('tasksproperties'); // taskproperty $oXML->startElement('taskproperty'); $oXML->writeAttribute('id', 'tpd0'); $oXML->writeAttribute('name', 'type'); $oXML->writeAttribute('type', 'default'); $oXML->writeAttribute('valuetype', 'icon'); $oXML->endElement(); $oXML->startElement('taskproperty'); $oXML->writeAttribute('id', 'tpd1'); $oXML->writeAttribute('name', 'priority'); $oXML->writeAttribute('type', 'default'); $oXML->writeAttribute('valuetype', 'icon'); $oXML->endElement(); $oXML->startElement('taskproperty'); $oXML->writeAttribute('id', 'tpd2'); $oXML->writeAttribute('name', 'info'); $oXML->writeAttribute('type', 'default'); $oXML->writeAttribute('valuetype', 'icon'); $oXML->endElement(); $oXML->startElement('taskproperty'); $oXML->writeAttribute('id', 'tpd3'); $oXML->writeAttribute('name', 'name'); $oXML->writeAttribute('type', 'default'); $oXML->writeAttribute('valuetype', 'text'); $oXML->endElement(); $oXML->startElement('taskproperty'); $oXML->writeAttribute('id', 'tpd4'); $oXML->writeAttribute('name', 'begindate'); $oXML->writeAttribute('type', 'default'); $oXML->writeAttribute('valuetype', 'date'); $oXML->endElement(); $oXML->startElement('taskproperty'); $oXML->writeAttribute('id', 'tpd5'); $oXML->writeAttribute('name', 'enddate'); $oXML->writeAttribute('type', 'default'); $oXML->writeAttribute('valuetype', 'date'); $oXML->endElement(); $oXML->startElement('taskproperty'); $oXML->writeAttribute('id', 'tpd6'); $oXML->writeAttribute('name', 'duration'); $oXML->writeAttribute('type', 'default'); $oXML->writeAttribute('valuetype', 'int'); $oXML->endElement(); $oXML->startElement('taskproperty'); $oXML->writeAttribute('id', 'tpd7'); $oXML->writeAttribute('name', 'completion'); $oXML->writeAttribute('type', 'default'); $oXML->writeAttribute('valuetype', 'int'); $oXML->endElement(); $oXML->startElement('taskproperty'); $oXML->writeAttribute('id', 'tpd8'); $oXML->writeAttribute('name', 'coordinator'); $oXML->writeAttribute('type', 'default'); $oXML->writeAttribute('valuetype', 'text'); $oXML->endElement(); $oXML->startElement('taskproperty'); $oXML->writeAttribute('id', 'tpd9'); $oXML->writeAttribute('name', 'predecessorsr'); $oXML->writeAttribute('type', 'default'); $oXML->writeAttribute('valuetype', 'text'); $oXML->endElement(); // >taskproperty // >tasksproperties $oXML->endElement(); // task $iTaskIndex = 0; foreach ($this->phpProject->getAllTasks() as $oTask) { $iTaskIndex = $this->writeTask($oXML, $oTask, $iTaskIndex); } // >tasks $oXML->endElement(); // resources $oXML->startElement('resources'); // resource foreach ($this->phpProject->getAllResources() as $oResource) { $this->writeResource($oXML, $oResource); } // >resources $oXML->endElement(); // allocations $oXML->startElement('allocations'); if (count($this->arrAllocations) > 0) { foreach ($this->arrAllocations as $itmAllocation) { $this->writeAllocation($oXML, $itmAllocation['id_task'], $itmAllocation['id_res']); } } // >allocations $oXML->endElement(); // taskdisplaycolumns $oXML->startElement('tasksproperties'); // displaycolumn $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd2'); $oXML->writeAttribute('order', '-1'); $oXML->writeAttribute('width', '75'); $oXML->writeAttribute('visible', 'false'); $oXML->endElement(); $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd7'); $oXML->writeAttribute('order', '-1'); $oXML->writeAttribute('width', '75'); $oXML->writeAttribute('visible', 'false'); $oXML->endElement(); $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd6'); $oXML->writeAttribute('order', '-1'); $oXML->writeAttribute('width', '75'); $oXML->writeAttribute('visible', 'false'); $oXML->endElement(); $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd10'); $oXML->writeAttribute('order', '-1'); $oXML->writeAttribute('width', '75'); $oXML->writeAttribute('visible', 'false'); $oXML->endElement(); $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd1'); $oXML->writeAttribute('order', '-1'); $oXML->writeAttribute('width', '75'); $oXML->writeAttribute('visible', 'false'); $oXML->endElement(); $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd9'); $oXML->writeAttribute('order', '-1'); $oXML->writeAttribute('width', '75'); $oXML->writeAttribute('visible', 'false'); $oXML->endElement(); $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd8'); $oXML->writeAttribute('order', '-1'); $oXML->writeAttribute('width', '75'); $oXML->writeAttribute('visible', 'false'); $oXML->endElement(); $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd0'); $oXML->writeAttribute('order', '-1'); $oXML->writeAttribute('width', '75'); $oXML->writeAttribute('visible', 'false'); $oXML->endElement(); $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd3'); $oXML->writeAttribute('order', '0'); $oXML->writeAttribute('width', '199'); $oXML->writeAttribute('visible', 'true'); $oXML->endElement(); $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd4'); $oXML->writeAttribute('order', '1'); $oXML->writeAttribute('width', '75'); $oXML->writeAttribute('visible', 'true'); $oXML->endElement(); $oXML->startElement('displaycolumn'); $oXML->writeAttribute('property-id', 'tpd5'); $oXML->writeAttribute('order', '2'); $oXML->writeAttribute('width', '75'); $oXML->writeAttribute('visible', 'true'); $oXML->endElement(); // >displaycolumn // >taskdisplaycolumns $oXML->endElement(); // >project $oXML->endElement(); // Writing XML Object in file // Open file if (file_exists($pFilename) && !is_writable($pFilename)) { throw new \Exception("Could not open file {$pFilename} for writing."); } $fileHandle = fopen($pFilename, 'wb+'); // Write XML Content fwrite($fileHandle, $oXML->getData()); // Close file fclose($fileHandle); }