Project

General

Profile

Feature #5456 » twig.patch

Carsten Rose, 02.07.2018 15:43

View differences:

qfq/qfq/Constants.php
1103 1103

  
1104 1104
// Report, BodyText
1105 1105
const TOKEN_SQL = 'sql';
1106
const TOKEN_TWIG = 'twig';
1106 1107
const TOKEN_HEAD = 'head';
1107 1108
const TOKEN_ALT_HEAD = 'althead';
1108 1109
const TOKEN_ALT_SQL = 'altsql';
......
1122 1123
const TOKEN_RECORD_ID = CLIENT_RECORD_ID;
1123 1124
const TOKEN_DEBUG_BODYTEXT = TYPO3_DEBUG_SHOW_BODY_TEXT;
1124 1125

  
1125
const TOKEN_VALID_LIST = 'sql|head|althead|altsql|tail|shead|stail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText|sqlLog|sqlLogMode';
1126
const TOKEN_VALID_LIST = 'sql|twig|head|althead|altsql|tail|shead|stail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText|sqlLog|sqlLogMode';
1126 1127

  
1127 1128
const TOKEN_COLUMN_CTRL = '_';
1128 1129

  
qfq/qfq/report/Report.php
430 430
            unset($this->variables->resultArray[$full_level . ".line."]["total"]);
431 431
            unset($this->variables->resultArray[$full_level . ".line."]["count"]);
432 432

  
433

  
433 434
            $sql = $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_SQL]);
434 435

  
435 436
            $this->store->setVar(SYSTEM_SQL_FINAL, $sql, STORE_SYSTEM);
436 437

  
438
            $twig_template = $this->frArray[$full_level. "." . TOKEN_TWIG];
439
            if ($twig_template !== '') {
440
                $mode = ROW_REGULAR;
441
            } else {
442
                $mode = ROW_KEYS;
443
            }
437 444
            //Execute SQL. All errors have been already catched.
438 445
            unset($result);
439
            $result = $this->db->sql($sql, ROW_KEYS, array(), '', $keys, $stat);
446
            $result = $this->db->sql($sql, $mode, array(), '', $keys, $stat);
440 447

  
441 448
            // If an array is returned, $sql was a query, otherwise an 'insert', 'update', 'delete', ...
442 449
            // Query: total nummber of rows
......
447 454
            $this->variables->resultArray[$full_level . ".line."]["count"] = is_array($result) ? 1 : 0;
448 455
            $this->variables->resultArray[$full_level . ".line."]["insertId"] = isset($stat[DB_INSERT_ID]) ? $stat[DB_INSERT_ID] : 0;
449 456

  
457
	    if ($twig_template !== '') { // twig start
458
                require_once '/usr/share/php/Twig/autoload.php';
459
		require_once 'TwigExtLink.php';
460
		if (in_array(substr($twig_template, 0, 1), array('"', "'"))) {
461
			$loader = new \Twig_Loader_Array(array(
462
				"string_template" => trim($twig_template, '"\''))
463
			);
464
			$twig_template = "string_template";
465
		} else {
466
			$loader = new \Twig_Loader_Filesystem(".");
467
		}
468
                $twig = new \Twig_Environment($loader, array());
469
                $twig->addExtension(new QfqLink_Twig_Extension($this->link));
470
                $content .= $twig->render($twig_template, array('context' => $result));
471
	    } else { // twig else
472

  
450 473
            $content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_SHEAD]);
451 474
            // HEAD: If there is at least one record, do 'head'.
452 475
            if ($rowTotal > 0) {
......
520 543
                }
521 544
            }
522 545
            $content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_STAIL]);
523

  
546
	    } // twig end
524 547
            ++$counter;
525 548
            if (isset($this->indexArray[$counter]) && is_array($this->indexArray[$counter])) {
526 549
                $full_level = implode(".", $this->indexArray[$counter]);
qfq/qfq/report/TwigExtLink.php
1
<?php
2

  
3
/** LaTeX Filter for Twig
4
 *
5
 * Based on Code by Seth Fischer
6
 * http://seth.fischer.nz/symfony-2-latex-pdf-service.html
7
 *
8
 */
9

  
10
//use Twig_Extension;
11
//use Twig_Filter_Method;
12
//use Twig_Test_Method;
13

  
14
namespace qfq;
15

  
16
class QfqLink_Twig_Extension extends \Twig_Extension
17
{
18
    //private $kernelBundles;
19

  
20
    public function __construct($linkobj)
21
    {
22
        $this->linkobj = $linkobj;
23
    }
24

  
25
    /**
26
     * Returns a list of filters to add to the existing list.
27
     *
28
     * @return array An array of filters
29
     */
30
    public function getFilters()
31
    {
32
        return array(
33
		'qfqlink'     => new \Twig_Filter_Method($this, 'qfqLink', 
34
		    array('is_safe' => array('html'))),
35
        );
36
    }
37

  
38
    /**
39
     * Escape LaTeX special characters
40
     *
41
     * @return string
42
     */
43
    public function qfqLink($str = null)
44
    {
45
	    return $this->linkobj->renderLink($str);
46
    }
47

  
48
    /**
49
     * Returns the name of the extension
50
     *
51
     * @return string The extension name
52
     */
53
    public function getName()
54
    {
55
        return 'qfq_link_extension';
56
    }
57

  
58
}
(4-4/7)