Example #1
0
 public function addGameRow(Game $oGame, $includeField = true)
 {
     $oGame = Game::getByNefubId($oGame->nefub_id);
     $field = $oGame->field ? $oGame->field : 1;
     $gameType = $oGame->getCompetition()->getGender()->name . ' ' . $oGame->getCompetition()->getGenre()->name;
     $team1 = utf8_decode($oGame->getTeam1()->name);
     $team2 = utf8_decode($oGame->getTeam2()->name);
     if ($oGame->getFirstReferee()) {
         $oGame = new Game($oGame->getId());
         $oReferee = $oGame->getFirstReferee();
         $referee = utf8_decode($oReferee->getName());
         if (!$oReferee->getPerson()) {
             $referee .= ' (' . $oReferee->getTeam()->getCompetition()->getGender()->name;
             $referee .= ' ' . $oReferee->getTeam()->getCompetition()->getGenre()->name . ')';
         }
     } else {
         $referee = 'Onbekend';
     }
     $text = $oGame->getFormattedTime();
     $text .= "\t";
     $text .= $team1;
     $text .= "\t";
     $text .= $team2;
     $text .= "\n";
     $text .= $gameType;
     if ($includeField) {
         $text .= $field;
     }
     $this->section->addText($text, array('name' => 'Arial', 'size' => 10, 'bold' => false));
 }
Example #2
0
 /**
  *
  * @return boolean 
  */
 protected function _addGraphs()
 {
     $xpath = new DOMXPath($this->_dom);
     $graphs = $xpath->query('//div[@class="graphs"]', $this->_content);
     if (empty($graphs->length)) {
         return false;
     }
     $images = $graphs->item(0)->getElementsByTagName('img');
     foreach ($images as $img) {
         $src = $img->getAttribute('src');
         $src = preg_replace('/^.+image\\/id\\//i', '', $src);
         $src = preg_replace('/\\/image.png$/i', '', $src);
         $contents = App_Cache::load($src);
         $randomName = App_General_String::randomHash();
         $fileName = $this->_tempDir . DIRECTORY_SEPARATOR . $randomName . '.png';
         file_put_contents($fileName, $contents);
         $size = getimagesize($fileName);
         $this->_mainSection->addImage($fileName, array('align' => 'center', 'width' => 675, 'height' => $size[1]));
     }
     return true;
 }
Example #3
0
 private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section)
 {
     $_settings = $section->getSettings();
     $_header = $section->getHeader();
     $_footer = $section->getFooter();
     $pgSzW = $_settings->getPageSizeW();
     $pgSzH = $_settings->getPageSizeH();
     $orientation = $_settings->getOrientation();
     $marginTop = $_settings->getMarginTop();
     $marginLeft = $_settings->getMarginLeft();
     $marginRight = $_settings->getMarginRight();
     $marginBottom = $_settings->getMarginBottom();
     $borders = $_settings->getBorderSize();
     $objWriter->startElement('w:sectPr');
     if (!is_null($_header)) {
         $rId = $_header->getRelationId();
         $objWriter->startElement('w:headerReference');
         $objWriter->writeAttribute('w:type', 'default');
         $objWriter->writeAttribute('r:id', 'rId' . $rId);
         $objWriter->endElement();
     }
     if (!is_null($_footer)) {
         $rId = $_footer->getRelationId();
         $objWriter->startElement('w:footerReference');
         $objWriter->writeAttribute('w:type', 'default');
         $objWriter->writeAttribute('r:id', 'rId' . $rId);
         $objWriter->endElement();
     }
     $objWriter->startElement('w:pgSz');
     $objWriter->writeAttribute('w:w', $pgSzW);
     $objWriter->writeAttribute('w:h', $pgSzH);
     if (!is_null($orientation) && strtolower($orientation) != 'portrait') {
         $objWriter->writeAttribute('w:orient', $orientation);
     }
     $objWriter->endElement();
     $objWriter->startElement('w:pgMar');
     $objWriter->writeAttribute('w:top', $marginTop);
     $objWriter->writeAttribute('w:right', $marginRight);
     $objWriter->writeAttribute('w:bottom', $marginBottom);
     $objWriter->writeAttribute('w:left', $marginLeft);
     $objWriter->writeAttribute('w:header', '720');
     $objWriter->writeAttribute('w:footer', '720');
     $objWriter->writeAttribute('w:gutter', '0');
     $objWriter->endElement();
     if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) {
         $borderColor = $_settings->getBorderColor();
         $objWriter->startElement('w:pgBorders');
         $objWriter->writeAttribute('w:offsetFrom', 'page');
         if (!is_null($borders[0])) {
             $objWriter->startElement('w:top');
             $objWriter->writeAttribute('w:val', 'single');
             $objWriter->writeAttribute('w:sz', $borders[0]);
             $objWriter->writeAttribute('w:space', '24');
             $objWriter->writeAttribute('w:color', $borderColor[0]);
             $objWriter->endElement();
         }
         if (!is_null($borders[1])) {
             $objWriter->startElement('w:left');
             $objWriter->writeAttribute('w:val', 'single');
             $objWriter->writeAttribute('w:sz', $borders[1]);
             $objWriter->writeAttribute('w:space', '24');
             $objWriter->writeAttribute('w:color', $borderColor[1]);
             $objWriter->endElement();
         }
         if (!is_null($borders[2])) {
             $objWriter->startElement('w:right');
             $objWriter->writeAttribute('w:val', 'single');
             $objWriter->writeAttribute('w:sz', $borders[2]);
             $objWriter->writeAttribute('w:space', '24');
             $objWriter->writeAttribute('w:color', $borderColor[2]);
             $objWriter->endElement();
         }
         if (!is_null($borders[3])) {
             $objWriter->startElement('w:bottom');
             $objWriter->writeAttribute('w:val', 'single');
             $objWriter->writeAttribute('w:sz', $borders[3]);
             $objWriter->writeAttribute('w:space', '24');
             $objWriter->writeAttribute('w:color', $borderColor[3]);
             $objWriter->endElement();
         }
         $objWriter->endElement();
     }
     $objWriter->startElement('w:cols');
     $objWriter->writeAttribute('w:space', '720');
     $objWriter->endElement();
     $objWriter->endElement();
 }
/**
 * Function to print all blocks (parts) of a question or answer text in one textrun.
 * Blocks can be of type string, newline or image.
 * If the first block is a string it is printed as a listitem using the numbering and depth provided.
 * Otherwise, the empty string is used as the list item string.
 *
 * @param PHPWord_Section $section A PHP Word section
 * @param array $blocks The array of blocks as created by the conversion functions.
 * @param PHPWord_Numbering_AbstractNumbering $numbering The numbering used for the list item
 * @param int $depth The depth in the enumeration (0 for questions, 1 for answers).
 */
function offlinequiz_print_blocks_docx(PHPWord_Section $section, $blocks, $numbering = null, $depth = 0)
{
    // We skip leading newlines.
    while ($blocks[0]['type'] == 'newline') {
        array_shift($blocks);
    }
    // First print the list item string.
    if (!empty($numbering)) {
        $itemstring = ' ';
        $style = 'nStyle';
        if ($blocks[0]['type'] == 'string') {
            $itemstring = $blocks[0]['value'];
            if (array_key_exists('style', $blocks[0])) {
                $style = $blocks[0]['style'];
            }
            array_shift($blocks);
        }
        $section->addListItem($itemstring, $depth, $numbering, $style);
        // We also skip the first sequential newline because we got a newline with addListItem.
        if (!empty($blocks) && $blocks[0]['type'] == 'newline') {
            array_shift($blocks);
        }
    }
    // Now we go through the rest of the blocks (if there are any) and print them to a textrun.
    if (!empty($blocks)) {
        if (empty($numbering)) {
            $textrun = $section->createTextRun();
        } else {
            $textrun = $section->createTextRun('questionTab');
            $textrun->addText("\t", 'nStyle');
        }
        $counter = count($blocks);
        foreach ($blocks as $block) {
            $counter--;
            if ($block['type'] == 'string') {
                // Skip empty string at the end of the text block.
                if ($counter == 0 && strlen(trim($block['value']) == '')) {
                    continue;
                }
                if (array_key_exists('style', $block) && !empty($block['style'])) {
                    $textrun->addText($block['value'], $block['style']);
                } else {
                    $textrun->addText($block['value'], 'nStyle');
                }
            } else {
                if ($block['type'] == 'newline') {
                    if (empty($numbering)) {
                        $textrun = $section->createTextRun();
                    } else {
                        $textrun = $section->createTextRun('questionTab');
                        $textrun->addText("\t", 'nStyle');
                    }
                } else {
                    if ($block['type'] == 'image') {
                        // Retrieve the style info.
                        $style = array();
                        $style['width'] = 200;
                        $style['height'] = 100;
                        $style['align'] = 'center';
                        if ($block['width']) {
                            $style['width'] = intval($block['width']);
                        }
                        if ($block['height']) {
                            $style['height'] = intval($block['height']);
                        }
                        if ($block['align']) {
                            $style['align'] = $block['align'];
                            if ($style['align'] == 'middle') {
                                $style['align'] = 'center';
                            }
                        }
                        // Now add the image and start a new textrun.
                        $section->addImage($block['value'], $style);
                        if ($counter > 0) {
                            if (empty($numbering)) {
                                $textrun = $section->createTextRun();
                            } else {
                                $textrun = $section->createTextRun('questionTab');
                                $textrun->addText("\t", 'nStyle');
                            }
                        }
                    }
                }
            }
        }
    }
}