Sie sind nicht angemeldet.

Marc

Entwickler

(116)

  • »Marc« ist ein Kunde
  • »Marc« ist der Autor dieses Themas

Beiträge: 678

Wohnort: nähe Freiburg

Renommeemodifikator: 7

  • Nachricht senden

1

Donnerstag, 17. März 2011, 02:03

Report API Beispiel

reportobjecttype.xml

XML

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
<data xmlns="http://www.web-produktion.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.web-produktion.com/XSD/report.xsd">
	<import>
		<type>
			<name>demo</name> <!-- objectType name -->
			<classfile>lib/data/demo/DemoReportObjectType.class.php</classfile> <!-- objectType file and file path -->
		</type>
	</import>
</data>


DemoReportObjectType.class.php

PHP-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
// wcf imports
require_once(WCF_DIR.'lib/data/report/object/ReportObjectType.class.php');
require_once(WCF_DIR.'lib/data/demo/DemoReportObject.class.php');

/**
 * @author        Jean-Marc Licht
 * @copyright    (c) 2011 by Jean-Marc Licht
 * @package        com.web-produktion.report.demo
 */
class DemoReportObjectType implements ReportObjectType {

    /**
     * @see ReportObjectType::getObjectByID()
     */
    public function getObjectByID($objectID) {
        if (is_array($objectID)) {
            $demo = array();
            $sql "SELECT  *
                    FROM    wcf".WCF_N."_report_demo
                    WHERE   demoID IN (".implode(','$objectID).")";
            $result WCF::getDB()->sendQuery($sql);
            while ($row WCF::getDB()->fetchArray($result)) {
                $demo[$row['demoID']] = new DemoReportObject(null$row);
            }

            return (count($demo) > $demo null);
        }
        else {
            // get object
            $demo = new DemoReportObject($objectID);
            if (!$demo->demoID) return null;

            // return object
            return $demo;
        }
    }
}
?>


DemoReportObject.class.php

PHP-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
// wcf imports
require_once(WCF_DIR.'lib/data/report/object/ReportObject.class.php');
require_once(WCF_DIR.'lib/data/demo/ViewableDemo.class.php');

/**
 * @author        Jean-Marc Licht
 * @copyright    (c) 2011 by Jean-Marc Licht
 * @package        com.web-produktion.report.demo
 */
class DemoReportObject extends ViewableDemo implements ReportObject {

    /**
     * @see ReportObject::getTitle()
     */
    public function getTitle() {
        return $this->subject;
    }

    /**
     * @see ReportObject::getUserID()
     */
    public function getUserID() {
        return $this->userID;
    }

    /**
     * @see ReportObject::getUsername()
     */
    public function getUsername() {
        return $this->username;
    }

    /**
     * @see ReportObject::getURL()
     */
    public function getURL() {
        return 'index.php?page=Demo';
    }

    /**
     * @see ReportObject::getLanguage()
     */
    public function getLanguage() {
        return 'wcf.report.demo.add';
    }
}


demo.tpl (Benutzung im Template)

Template-Quelltext

1
2
3
{if MODULE_REPORT && $this->user->getPermission('user.message.canReport')}
	<li><a href="index.php?form=Report&amp;objectID={@$demo->demoID}&amp;objectType=demo{@SID_ARG_2ND}" title="{lang}wcf.demo.button.report{/lang}"><img src="{icon}reportS.png{/icon}" alt="" /> <span>{lang}wcf.demo.button.report{/lang}</span></a></li>
{/if}

Verwendete Tags

API, Beispiel, Report