1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Services/Xml/classes/class.ilXmlWriter.php";
5
6/**
7 * Class for container reference export
8 *
9 * @author Stefan Meyer <smeyer.ilias@gmx.de>
10 * $Id$
11 */
12class ilContainerReferenceXmlWriter extends ilXmlWriter
13{
14    /**
15     * @var ilSetting
16     */
17    protected $settings;
18
19    const MODE_SOAP = 1;
20    const MODE_EXPORT = 2;
21
22    private $mode = self::MODE_SOAP;
23    private $xml;
24    private $ref;
25
26    /**
27    * constructor
28    * @param	string	xml version
29    * @param	string	output encoding
30    * @param	string	input encoding
31    * @access	public
32    */
33    public function __construct(ilContainerReference $ref = null)
34    {
35        global $DIC;
36
37        $this->settings = $DIC->settings();
38        parent::__construct();
39        $this->ref = $ref;
40    }
41
42    /**
43     * Set export mode
44     * @param int $a_mode
45     */
46    public function setMode($a_mode)
47    {
48        $this->mode = $a_mode;
49    }
50
51    /**
52     * get export mode
53     * @return int
54     */
55    public function getMode()
56    {
57        return $this->mode;
58    }
59
60    /**
61     * Get category object
62     * @return ilContainerReference
63     */
64    public function getReference()
65    {
66        return $this->ref;
67    }
68
69
70    /**
71     * Start wrting xml
72     */
73    public function export($a_with_header = true)
74    {
75        if ($this->getMode() == self::MODE_EXPORT) {
76            if ($a_with_header) {
77                $this->buildHeader();
78            }
79            $this->buildReference();
80            $this->buildTarget();
81            $this->buildTitle();
82            $this->buildFooter();
83        }
84    }
85
86    /**
87     * get XML
88     * @return string
89     */
90    public function getXml()
91    {
92        return $this->xmlDumpMem(false);
93    }
94
95    /**
96     * Build xml header
97     * @return bool
98     */
99    protected function buildHeader()
100    {
101        $ilSetting = $this->settings;
102
103        $this->xmlSetDtdDef("<!DOCTYPE container reference PUBLIC \"-//ILIAS//DTD Group//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_container_reference_4_3.dtd\">");
104        $this->xmlSetGenCmt("Export of ILIAS container reference " . $this->getReference()->getId() . " of installation " . $ilSetting->get('inst_id') . ".");
105        $this->xmlHeader();
106
107        return true;
108    }
109
110    /**
111     * Build target element
112     */
113    protected function buildTarget()
114    {
115        $this->xmlElement('Target', array('id' => $this->getReference()->getTargetId()));
116    }
117
118    /**
119     * Build title element
120     */
121    protected function buildTitle()
122    {
123        $title = '';
124        if ($this->getReference()->getTitleType() == ilContainerReference::TITLE_TYPE_CUSTOM) {
125            $title = $this->getReference()->getTitle();
126        }
127
128        $this->xmlElement(
129            'Title',
130            array(
131                    'type' => $this->getReference()->getTitleType()
132                ),
133            $title
134        );
135    }
136
137    /**
138     * Build category xml
139     */
140    protected function buildReference()
141    {
142        $this->xmlStartTag('ContainerReference');
143    }
144
145    /**
146     * Add footer elements
147     */
148    protected function buildFooter()
149    {
150        $this->xmlEndTag('ContainerReference');
151    }
152}
153