00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00035 class ilMediaAliasItem
00036 {
00037 var $dom;
00038 var $hier_id;
00039 var $purpose;
00040 var $item_node;
00041
00042 function ilMediaAliasItem(&$a_dom, $a_hier_id, $a_purpose)
00043 {
00044 $this->dom =& $a_dom;
00045 $this->hier_id = $a_hier_id;
00046 $this->purpose = $a_purpose;
00047
00048 $xpc = xpath_new_context($this->dom);
00049 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='$a_purpose']";
00050 $res =& xpath_eval($xpc, $path);
00051 if (count($res->nodeset) > 0)
00052 {
00053 $this->item_node =& $res->nodeset[0];
00054 }
00055 }
00056
00062 function exists()
00063 {
00064 if (is_object($this->item_node))
00065 {
00066 return true;
00067 }
00068 else
00069 {
00070 return false;
00071 }
00072 }
00073
00077 function insert()
00078 {
00079 $xpc = xpath_new_context($this->dom);
00080 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject";
00081 $res =& xpath_eval($xpc, $path);
00082 if (count($res->nodeset) > 0)
00083 {
00084 $obj_node =& $res->nodeset[0];
00085 $item_node =& $this->dom->create_element("MediaAliasItem");
00086 $item_node =& $obj_node->append_child($item_node);
00087 $item_node->set_attribute("Purpose", $this->purpose);
00088 $this->item_node =& $item_node;
00089 }
00090 }
00091
00092 function setWidth($a_width)
00093 {
00094 ilDOMUtil::setFirstOptionalElement($this->dom, $this->item_node, "Layout",
00095 array("Caption", "Parameter"),
00096 "", array("Width" => $a_width), false);
00097 }
00098
00099
00100 function getWidth()
00101 {
00102 $xpc = xpath_new_context($this->dom);
00103 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Layout";
00104 $res =& xpath_eval($xpc, $path);
00105 if (count($res->nodeset) == 1)
00106 {
00107 $layout_node =& $res->nodeset[0];
00108 return $layout_node->get_attribute("Width");
00109 }
00110 }
00111
00117 function definesSize()
00118 {
00119 $xpc = xpath_new_context($this->dom);
00120 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Layout";
00121 $res =& xpath_eval($xpc, $path);
00122 if (count($res->nodeset) == 1)
00123 {
00124 $layout_node =& $res->nodeset[0];
00125 return $layout_node->has_attribute("Width");
00126 }
00127 return false;
00128 }
00129
00133 function deriveSize()
00134 {
00135 $xpc = xpath_new_context($this->dom);
00136 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Layout";
00137 $res =& xpath_eval($xpc, $path);
00138 if (count($res->nodeset) == 1)
00139 {
00140 $layout_node =& $res->nodeset[0];
00141 if ($layout_node->has_attribute("Width"))
00142 {
00143 $layout_node->remove_attribute("Width");
00144 }
00145 if ($layout_node->has_attribute("Height"))
00146 {
00147 $layout_node->remove_attribute("Height");
00148 }
00149 }
00150 }
00151
00152 function setHeight($a_height)
00153 {
00154 ilDOMUtil::setFirstOptionalElement($this->dom, $this->item_node, "Layout",
00155 array("Caption", "Parameter"),
00156 "", array("Height" => $a_height), false);
00157 }
00158
00159
00160 function getHeight()
00161 {
00162 $xpc = xpath_new_context($this->dom);
00163 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Layout";
00164 $res =& xpath_eval($xpc, $path);
00165 if (count($res->nodeset) == 1)
00166 {
00167 $layout_node =& $res->nodeset[0];
00168 return $layout_node->get_attribute("Height");
00169 }
00170 }
00171
00172
00173 function setCaption($a_caption)
00174 {
00175 ilDOMUtil::setFirstOptionalElement($this->dom, $this->item_node, "Caption",
00176 array("Parameter"),
00177 $a_caption, array("Align" => "bottom"));
00178 }
00179
00180
00181 function getCaption()
00182 {
00183 $xpc = xpath_new_context($this->dom);
00184 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Caption";
00185 $res =& xpath_eval($xpc, $path);
00186 if (count($res->nodeset) == 1)
00187 {
00188 $caption_node =& $res->nodeset[0];
00189 return $caption_node->get_content();
00190 }
00191 }
00192
00198 function definesCaption()
00199 {
00200 $xpc = xpath_new_context($this->dom);
00201 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Caption";
00202 $res =& xpath_eval($xpc, $path);
00203 if (count($res->nodeset) > 0)
00204 {
00205 return true;
00206 }
00207 return false;
00208 }
00209
00213 function deriveCaption()
00214 {
00215 $xpc = xpath_new_context($this->dom);
00216 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Caption";
00217 $res =& xpath_eval($xpc, $path);
00218 if (count($res->nodeset) > 0)
00219 {
00220 $caption_node =& $res->nodeset[0];
00221 $caption_node->unlink_node($caption_node);
00222 }
00223 }
00224
00225 function setHorizontalAlign($a_halign)
00226 {
00227 ilDOMUtil::setFirstOptionalElement($this->dom, $this->item_node, "Layout",
00228 array("Caption", "Parameter"),
00229 "", array("HorizontalAlign" => $a_halign), false);
00230 }
00231
00232
00233 function getHorizontalAlign()
00234 {
00235 $xpc = xpath_new_context($this->dom);
00236 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Layout";
00237 $res =& xpath_eval($xpc, $path);
00238 if (count($res->nodeset) == 1)
00239 {
00240 $layout_node =& $res->nodeset[0];
00241 return $layout_node->get_attribute("HorizontalAlign");
00242 }
00243 }
00244
00245
00253 function setParameters($a_par_array)
00254 {
00255 $xpc = xpath_new_context($this->dom);
00256 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Parameter";
00257 $res =& xpath_eval($xpc, $path);
00258 $par_arr = array();
00259 for($i=0; $i < count($res->nodeset); $i++)
00260 {
00261 $par_node =& $res->nodeset[$i];
00262 $par_node->unlink_node($par_node);
00263 }
00264
00265 if (is_array($a_par_array))
00266 {
00267 foreach($a_par_array as $par => $val)
00268 {
00269 $par_node =& $this->dom->create_element("Parameter");
00270 $par_node =& $this->item_node->append_child($par_node);
00271 $par_node->set_attribute("Name", $par);
00272 $par_node->set_attribute("Value", $val);
00273 }
00274 }
00275 }
00276
00277
00281 function getParameterString()
00282 {
00283 $xpc = xpath_new_context($this->dom);
00284 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Parameter";
00285 $res =& xpath_eval($xpc, $path);
00286 $par_arr = array();
00287 for($i=0; $i < count($res->nodeset); $i++)
00288 {
00289 $par_node =& $res->nodeset[$i];
00290 $par_arr[] = $par_node->get_attribute("Name")."=\"".$par_node->get_attribute("Value")."\"";
00291 }
00292 return implode($par_arr, ", ");
00293 }
00294
00295
00299 function getParameter($a_name)
00300 {
00301 }
00302
00308 function definesParameters()
00309 {
00310 $xpc = xpath_new_context($this->dom);
00311 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Parameter";
00312 $res =& xpath_eval($xpc, $path);
00313 if (count($res->nodeset) > 0)
00314 {
00315 return true;
00316 }
00317 return false;
00318 }
00319
00323 function deriveParameters()
00324 {
00325 $xpc = xpath_new_context($this->dom);
00326 $path = "//PageContent[@HierId = '".$this->hier_id."']/MediaObject/MediaAliasItem[@Purpose='".$this->purpose."']/Parameter";
00327 $res =& xpath_eval($xpc, $path);
00328 if (count($res->nodeset) > 0)
00329 {
00330 for($i=0; $i < count($res->nodeset); $i++)
00331 {
00332 $par_node =& $res->nodeset[$i];
00333 $par_node->unlink_node($par_node);
00334 }
00335 }
00336 }
00337
00341 function delete()
00342 {
00343 if (is_object($this->item_node))
00344 {
00345 $this->item_node->unlink_node($this->item_node);
00346 }
00347 }
00348 }
00349 ?>