/**
 * Write documents
 *
 * @param \PhpOffice\PhpWord\PhpWord $phpWord
 * @param string $filename
 * @param array $writers
 *
 * @return string
 */
function write($phpWord, $filename, $writers)
{
    $result = '';
    // Write documents
    foreach ($writers as $format => $extension) {
        $result .= date('H:i:s') . " Write to {$format} format";
        if (null !== $extension) {
            $targetFile = __DIR__ . "/results/{$filename}.{$extension}";
            $phpWord->save($targetFile, $format);
        } else {
            $result .= ' ... NOT DONE!';
        }
        $result .= EOL;
    }
    $result .= getEndingNotes($writers);
    return $result;
}
Esempio n. 2
0
/**
 * Write documents
 *
 * @param \PhpOffice\PhpWord\PhpWord $phpWord
 * @param string $filename
 * @param array $writers
 *
 * @return string
 */
function write($phpWord, $filename, $writers)
{
    // $result = '';
    // Write documents
    foreach ($writers as $format => $extension) {
        // $result .= date('H:i:s') . " Write to {$format} format";
        if (null !== $extension) {
            // $targetFile = __DIR__ . "/results/{$filename}.{$extension}";
            $targetFile = generateRealPathDocxFileLocation() . "{$filename}.{$extension}";
            $phpWord->save($targetFile, $format);
        }
        // else {
        //     $result .= ' ... NOT DONE!';
        // }
        // $result .= EOL;
    }
    // $result .= getEndingNotes($writers);
    // return $result;
    return '';
}
Esempio n. 3
0
 /**
  * Test save
  */
 public function testSave()
 {
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     $section->addText('Hello world!');
     $this->assertTrue($phpWord->save('test.docx', 'Word2007', true));
 }
Esempio n. 4
0
 public function export($path)
 {
     $phpWord = new PhpWord();
     $phpWord->setDefaultFontName('Times New Roman');
     $phpWord->setDefaultFontSize(12);
     $phpWord->addTitleStyle(1, ['size' => 26, 'bold' => true], []);
     $phpWord->addTitleStyle(2, ['size' => 22, 'bold' => true], []);
     $phpWord->addTitleStyle(3, ['size' => 18, 'bold' => true], []);
     $phpWord->addTitleStyle(4, ['size' => 16, 'bold' => true], []);
     $phpWord->addFontStyle('f_timeAndPlace', ['size' => 16, 'bold' => false]);
     $phpWord->addFontStyle('f_bold', ['bold' => true]);
     $phpWord->addFontStyle('f_italic', ['italic' => true]);
     $phpWord->addFontStyle('f_label', []);
     $phpWord->addFontStyle('f_chairName', []);
     $phpWord->addFontStyle('f_chairOrganisation', []);
     $phpWord->addFontStyle('f_presentationAuthor', ['bold' => true]);
     $phpWord->addFontStyle('f_presentationOrganisation', []);
     $phpWord->addFontStyle('f_presentationName', ['italic' => true]);
     $phpWord->addFontStyle('f_contributionPaperLabel', []);
     $phpWord->addParagraphStyle('p_contributionPaperLabel', ['lineHeight' => 1]);
     $phpWord->addParagraphStyle('p_presentation', ['lineHeight' => 1]);
     $phpWord->addParagraphStyle('p_presentationContributionPaper', ['lineHeight' => 1, 'basedOn' => 'presentation']);
     $phpWord->addParagraphStyle('p_chairs', []);
     $phpWord->addParagraphStyle('p_timeAndPlace', []);
     $section = $phpWord->addSection();
     $section->addTitle($this->text('Research Network / Research Stream Sessions'));
     foreach ($this->getTypes() as $type) {
         if (!$this->isExportType($type)) {
             continue;
         }
         $section->addTitle($this->text(sprintf('%s - %s', $type, static::$typeNames[$type])), 2);
         foreach ($this->getSessions($type) as $session) {
             $start = new \DateTime($session['start']);
             $end = new \DateTime($session['end']);
             $timeAndPlace = sprintf('%s - %s / %s / %s', $start->format('H:i'), $end->format('H:i'), $start->format('jS l'), $session['room']);
             $section->addText($timeAndPlace, 'f_timeAndPlace', 'p_timeAndPlace');
             $section->addTitle($this->text(sprintf('%s / %s', $session['short'], $session['title'])), 3);
             $chairs = $this->getChairs($session);
             if ($chairs) {
                 $textRun = $section->addTextRun('p_chairs');
                 $text = count($chairs) == 1 ? 'Chair: ' : 'Chairs: ';
                 $textRun->addText($this->text($text), 'f_label', null);
                 foreach ($chairs as $chair) {
                     $textRun->addText($this->text(sprintf('%s ', $chair['name'])), 'f_chairName', null);
                     $textRun->addText($this->text(sprintf('(%s)', $chair['organisation'])), 'f_chairOrganisation', null);
                 }
             }
             $presentations = $this->getPresentations($session['id']);
             $contributingPapers = array_filter($presentations, function ($p) {
                 return $p['acceptance'] === 'Contributing Paper';
             });
             $otherPresentations = array_filter($presentations, function ($p) {
                 return $p['acceptance'] !== 'Contributing Paper';
             });
             foreach ($otherPresentations as $presentation) {
                 $textRun = $section->addTextRun('p_presentation');
                 foreach ($this->getAuthors($presentation) as $author) {
                     $textRun->addText($this->text(sprintf('%s ', $author['name'])), 'f_presentationAuthor');
                     $textRun->addText($this->text(sprintf('(%s)', $author['organisation'])), 'f_presentationOrganisation');
                     $textRun->addText(', ');
                 }
                 $textRun->addText($this->text($presentation['title']), 'f_presentationName');
             }
             if ($contributingPapers) {
                 $section->addText('Contributed papers', 'f_contributionPaperLabel', 'p_contributionPaperLabel');
                 foreach ($contributingPapers as $presentation) {
                     $textRun = $section->addTextRun('p_presentationContributionPaper');
                     foreach ($this->getAuthors($presentation) as $author) {
                         $textRun->addText($this->text(sprintf('%s ', $author['name'])), 'f_presentationAuthor');
                         $textRun->addText($this->text(sprintf('(%s)', $author['organisation'])), 'f_presentationOrganisation');
                         $textRun->addText(', ');
                     }
                     $textRun->addText($this->text($presentation['title']), 'f_presentationName');
                 }
             }
         }
         $section->addPageBreak();
     }
     $phpWord->save($path);
 }