5 require_once(
"./Services/COPage/classes/class.ilPageContent.php");
33 parent::setNode($a_node);
34 $this->tab_node = $a_node->first_child();
37 public function create(&$a_pg_obj, $a_hier_id, $a_pc_id =
"")
41 $this->tab_node = $this->dom->create_element(
"Table");
42 $this->tab_node = $this->node->append_child($this->tab_node);
43 $this->tab_node->set_attribute(
"Language",
"");
48 $new_tr = $this->dom->create_element(
"TableRow");
49 $new_tr = &$this->tab_node->append_child($new_tr);
53 public function &
addCell(&$aRow, $a_data =
"", $a_lang =
"")
55 $new_td = $this->dom->create_element(
"TableData");
56 $new_td = $aRow->append_child($new_td);
61 $new_par = $this->dom->create_element(
"Paragraph");
62 $new_par = $new_pg->append_child($new_par);
63 $new_par->set_attribute(
"Language", $a_lang);
64 $new_par->set_attribute(
"Characteristic",
"TableContent");
65 $new_par->set_content($a_data);
66 $new_td->append_child($new_pg);
79 if (is_object($cell_par)) {
81 $childs = $cell_par->child_nodes();
82 for (
$i = 0;
$i < count($childs);
$i++) {
83 $content .= $this->dom->dump_node($childs[
$i]);
97 $path =
"//PageContent[@HierId='" . $this->
getHierId() .
"']" .
98 "/Table/TableRow[$i+1]/TableData[$j+1]/PageContent[1]/Paragraph[1]";
103 if (is_object(
$res->nodeset[0])) {
104 return $res->nodeset[0];
106 if (!$create_if_not_exists) {
110 $path2 =
"//PageContent[@HierId='" . $this->
getHierId() .
"']" .
111 "/Table/TableRow[" . (
$i + 1) .
"]/TableData[" . ($j + 1) .
"]";
116 $td_node = $res2->nodeset[0];
118 if (is_object($td_node)) {
120 $children = $td_node->child_nodes();
121 for (
$i = 0;
$i < count($children);
$i++) {
122 $td_node->remove_child($children[
$i]);
127 $pc_node = $td_node->append_child($pc_node);
128 $par_node = $this->dom->create_element(
"Paragraph");
129 $par_node = $pc_node->append_child($par_node);
130 $par_node->set_attribute(
"Characteristic",
"TableContent");
131 $par_node->set_attribute(
146 public function addRows($a_nr_rows, $a_nr_cols)
148 for (
$i = 1;
$i <= $a_nr_rows;
$i++) {
150 for ($j = 1; $j <= $a_nr_cols; $j++) {
161 str_replace($a_data,
"\r",
"\n");
162 str_replace($a_data,
"\n\n",
"\n");
163 $target_rows = array();
164 $rows = explode(
"\n", $a_data);
168 foreach (
$rows as $row) {
169 $cells = explode(
"\t", $row);
170 $max_cols = ($max_cols > count($cells))
173 $target_rows[] = $cells;
177 foreach ($target_rows as $row) {
179 for ($j = 0; $j < $max_cols; $j++) {
181 $data = str_replace(
"&",
"&", $row[$j]);
287 $this->tab_node->set_attribute(
"HorizontalAlign", $a_halign);
301 public function setTDWidth($a_hier_id, $a_width, $a_pc_id =
"")
305 if ($a_pc_id ==
"") {
306 $path =
"//TableData[@HierId = '" . $a_hier_id .
"']";
308 $path =
"//TableData[@PCID = '" . $a_pc_id .
"']";
312 if (count(
$res->nodeset) == 1) {
313 if ($a_width !=
"") {
314 $res->nodeset[0]->set_attribute(
"Width", $a_width);
316 if (
$res->nodeset[0]->has_attribute(
"Width")) {
317 $res->nodeset[0]->remove_attribute(
"Width");
329 $rows = $this->tab_node->child_nodes();
330 foreach (
$rows as $row) {
331 if ($row->node_name() ==
"TableRow") {
333 $cells = $row->child_nodes();
334 foreach ($cells as $cell) {
335 if ($cell->node_name() ==
"TableData") {
336 $ckey = $cell->get_attribute(
"HierId") .
":" . $cell->get_attribute(
"PCID");
337 if ((
int) $a_colspans[$ckey] > 1) {
338 $cell->set_attribute(
"ColSpan", (
int) $a_colspans[$ckey]);
340 if ($cell->has_attribute(
"ColSpan")) {
341 $cell->remove_attribute(
"ColSpan");
344 if ((
int) $a_rowspans[$ckey] > 1) {
345 $cell->set_attribute(
"RowSpan", (
int) $a_rowspans[$ckey]);
347 if ($cell->has_attribute(
"RowSpan")) {
348 $cell->remove_attribute(
"RowSpan");
371 $rows = $this->tab_node->child_nodes();
373 foreach (
$rows as $row) {
374 if ($row->node_name() ==
"TableRow") {
376 $cells = $row->child_nodes();
377 foreach ($cells as $cell) {
378 if ($cell->node_name() ==
"TableData") {
379 $max_x = max($max_x, $x);
380 $max_y = max($max_y, $y);
390 $rows = $this->tab_node->child_nodes();
391 foreach (
$rows as $row) {
392 if ($row->node_name() ==
"TableRow") {
394 $cells = $row->child_nodes();
395 foreach ($cells as $cell) {
396 if ($cell->node_name() ==
"TableData") {
397 $cspan = max(1, (
int) $cell->get_attribute(
"ColSpan"));
398 $rspan = max(1, (
int) $cell->get_attribute(
"RowSpan"));
401 if ($cspan > $max_x - $x + 1) {
402 $cell->set_attribute(
"ColSpan", $max_x - $x + 1);
403 $cspan = $max_x - $x + 1;
405 if ($rspan > $max_y - $y + 1) {
406 $cell->set_attribute(
"RowSpan", $max_y - $y + 1);
407 $rspan = $max_y - $y + 1;
413 $cell->set_attribute(
"Hidden",
"Y");
416 if ($cell->has_attribute(
"ColSpan")) {
417 $cell->remove_attribute(
"ColSpan");
419 if ($cell->has_attribute(
"RowSpan")) {
420 $cell->remove_attribute(
"RowSpan");
425 if ($cell->has_attribute(
"Hidden")) {
426 $cell->remove_attribute(
"Hidden");
430 $colspans[$x][$y] = $cspan;
431 $rowspans[$x][$y] = $rspan;
447 $children = $td_node->child_nodes();
448 for (
$i = 0;
$i < count($children);
$i++) {
449 $td_node->remove_child($children[
$i]);
458 for (
$i = 0;
$i <= $x;
$i++) {
459 for ($j = 0; $j <= $y; $j++) {
460 if (
$i != $x || $j != $y) {
461 if (((
$i + $colspans[
$i][$j] > $x) &&
462 ($j + $rowspans[
$i][$j] > $y))) {
479 $rows = $this->tab_node->child_nodes();
480 foreach (
$rows as $row) {
481 if ($row->node_name() ==
"TableRow") {
482 $cells = $row->child_nodes();
483 foreach ($cells as $cell) {
484 if ($cell->node_name() ==
"TableData") {
485 $classes[$cell->get_attribute(
"HierId") .
":" . $cell->get_attribute(
"PCID")]
486 = $cell->get_attribute(
"Class");
503 $rows = $this->tab_node->child_nodes();
504 foreach (
$rows as $row) {
505 if ($row->node_name() ==
"TableRow") {
506 $cells = $row->child_nodes();
507 foreach ($cells as $cell) {
508 if ($cell->node_name() ==
"TableData") {
509 $classes[$cell->get_attribute(
"HierId") .
":" . $cell->get_attribute(
"PCID")]
510 = $cell->get_attribute(
"HorizontalAlign");
527 $rows = $this->tab_node->child_nodes();
531 foreach (
$rows as $row) {
532 if ($row->node_name() ==
"TableRow") {
534 $cells = $row->child_nodes();
535 foreach ($cells as $cell) {
536 if ($cell->node_name() ==
"TableData") {
537 $spans[$cell->get_attribute(
"HierId") .
":" . $cell->get_attribute(
"PCID")]
538 = array(
"x" => $x,
"y" => $y,
"colspan" => $cell->get_attribute(
"ColSpan"),
539 "rowspan" => $cell->get_attribute(
"RowSpan"));
540 $max_x = max($max_x, $x);
541 $max_y = max($max_y, $y);
548 foreach ($spans as $k => $v) {
549 $spans[$k][
"max_x"] = $max_x;
550 $spans[$k][
"max_y"] = $max_y;
564 $rows = $this->tab_node->child_nodes();
565 foreach (
$rows as $row) {
566 if ($row->node_name() ==
"TableRow") {
567 $cells = $row->child_nodes();
568 foreach ($cells as $cell) {
569 if ($cell->node_name() ==
"TableData") {
570 $widths[$cell->get_attribute(
"HierId") .
":" . $cell->get_attribute(
"PCID")]
571 = $cell->get_attribute(
"Width");
583 public function setTDClass($a_hier_id, $a_class, $a_pc_id =
"")
586 if ($a_pc_id ==
"") {
587 $path =
"//TableData[@HierId = '" . $a_hier_id .
"']";
589 $path =
"//TableData[@PCID = '" . $a_pc_id .
"']";
592 if (count(
$res->nodeset) == 1) {
593 if ($a_class !=
"") {
594 $res->nodeset[0]->set_attribute(
"Class", $a_class);
596 if (
$res->nodeset[0]->has_attribute(
"Class")) {
597 $res->nodeset[0]->remove_attribute(
"Class");
609 if ($a_pc_id ==
"") {
610 $path =
"//TableData[@HierId = '" . $a_hier_id .
"']";
612 $path =
"//TableData[@PCID = '" . $a_pc_id .
"']";
615 if (count(
$res->nodeset) == 1) {
616 if ($a_class !=
"") {
617 $res->nodeset[0]->set_attribute(
"HorizontalAlign", $a_class);
619 if (
$res->nodeset[0]->has_attribute(
"HorizontalAlign")) {
620 $res->nodeset[0]->remove_attribute(
"HorizontalAlign");
634 $path =
"//PageContent[@HierId = '" .
$hier_id .
"']/Table/Caption";
637 if (count(
$res->nodeset) == 1) {
638 return $res->nodeset[0]->get_content();
651 $path =
"//PageContent[@HierId = '" .
$hier_id .
"']/Table/Caption";
653 if (count(
$res->nodeset) == 1) {
654 return $res->nodeset[0]->get_attribute(
"Align");
664 if ($a_content !=
"") {
669 array(
"Summary",
"TableRow"),
671 array(
"Align" => $a_align)
683 if (
$node->has_attributes()) {
684 foreach (
$node->attributes() as
$n) {
685 switch (strtolower(
$n->node_name())) {
712 if (
$node->has_attributes()) {
713 foreach (
$node->attributes() as
$n) {
714 switch (strtolower(
$n->node_name())) {
734 if (
$node->has_child_nodes()) {
735 foreach (
$node->child_nodes() as
$n) {
736 if (
$n->node_type() == XML_ELEMENT_NODE &&
737 strcasecmp(
$n->node_name(),
"td") == 0) {
748 $aCell = $this->
addCell($aRow);
750 $par->createAtNode($aCell);
751 $par->setText($par->input2xml($this->extractText($cellNode)));
752 $par->setCharacteristic(
"TableContent");
753 $par->setLanguage(
$lng);
759 $owner_document =
$node->owner_document();
760 $children =
$node->child_nodes();
761 $total_children = count($children);
762 for (
$i = 0;
$i < $total_children;
$i++) {
763 $cur_child_node = $children[
$i];
764 $output .= $owner_document->dump_node($cur_child_node);
778 $path =
"//table[1] | //Table[1]";
781 if (count(
$res->nodeset) == 0) {
782 $error =
"Could not find a table root node";
786 for (
$i = 0;
$i < count(
$res->nodeset);
$i++) {
791 if (
$node->has_child_nodes()) {
792 foreach (
$node->child_nodes() as
$n) {
793 if (
$n->node_type() == XML_ELEMENT_NODE &&
794 strcasecmp(
$n->node_name(),
"tr") == 0) {
803 if (is_array($error)) {
805 foreach ($error as $errorline) { # Loop through all errors
806 $errmsg .=
"[" . $errorline[
'line'] .
", " . $errorline[
'col'] .
"]: " . $errorline[
'errormessage'] .
" at Node '" . $errorline[
'nodename'] .
"'<br />";
812 if (empty($errmsg)) {
825 $childs = $this->tab_node->child_nodes();
826 foreach ($childs as $child) {
827 if ($child->node_name() ==
"TableRow") {
828 $gchilds = $child->child_nodes();
829 foreach ($gchilds as $gchild) {
830 if ($gchild->node_name() ==
"TableData") {
831 $gchild->set_attribute(
"Class", $a_class);
967 if (!empty($a_value)) {
968 $this->tab_node->set_attribute($a_attr, $a_value);
970 if ($this->tab_node->has_attribute($a_attr)) {
971 $this->tab_node->remove_attribute($a_attr);
983 if (is_object($this->tab_node)) {
984 return $this->tab_node->get_attribute($a_attr);
994 return array(
"ed_insert_dtable",
"ed_insert_atable",
"ed_new_row_after",
"ed_new_row_before",
995 "ed_new_col_after",
"ed_new_col_before",
"ed_delete_col",
996 "ed_delete_row",
"ed_edit_data",
"ed_row_up",
"ed_row_down",
997 "ed_col_left",
"ed_col_right");
1009 $xpath =
new DOMXPath($a_domdoc);
1010 $nodes = $xpath->query(
"//Table");
1011 foreach ($nodes as
$node) {
1012 $node->removeAttribute(
"Id");
1021 $model = new \stdClass();
1023 $rows = $this->tab_node->child_nodes();
1026 foreach (
$rows as $row) {
1027 if ($row->node_name() ==
"TableRow") {
1029 $cells = $row->child_nodes();
1030 foreach ($cells as $cell) {
1031 if ($cell->node_name() ==
"TableData") {
1038 $model->content[$y][$x] = $text;
getFooterRows()
Get footer rows.
setTDSpans($a_colspans, $a_rowspans)
Set TDSpans.
static getLangVars()
Get lang vars needed for editing.
getTableAttribute($a_attr)
Get table tag attribute.
setHeaderRows($a_nr)
Set header rows.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
getWidth()
get table width
xpath_new_context($dom_document)
setTDWidth($a_hier_id, $a_width, $a_pc_id="")
set width of table data cell
setHeaderCols($a_nr)
Set header cols.
static xml2outputJS($s_text)
Prepare content for js output.
domxml_open_mem($str, $mode=0, &$error=null)
xpath_eval($xpath_context, $eval_str, $contextnode=null)
static deleteAllChildsByName($a_parent, $a_node_names)
delete all childs of a node by names in $a_node_names
importCell($lng, &$cellNode, &$aRow)
static handleCopiedContent(DOMDocument $a_domdoc, $a_self_ass=true, $a_clone_mobs=false)
Handle copied content.
setType($a_type)
Set Type.
setLanguage($a_lang)
set table language
setCaption($a_content, $a_align)
set table caption
importCellAttributes(&$node, &$par)
init()
Init page content component.
static xml2output($a_text, $a_wysiwyg=false, $a_replace_lists=true, $unmask=true)
Converts xml from DB to output in edit textarea.
getCellText($i, $j)
Get cell text of row $i and cell $j.
& addCell(&$aRow, $a_data="", $a_lang="")
getTemplate()
Get template.
getClass()
Get characteristic of section.
addRows($a_nr_rows, $a_nr_cols)
add rows to table
importHtml($lng, $htmlTable)
setTableAttribute($a_attr, $a_value)
Set attribute of table tag.
setHorizontalAlign($a_halign)
set horizontal align
foreach($_POST as $key=> $value) $res
setTemplate($a_template)
Set template.
setCellSpacing($a_spacing)
set table cell spacing
setFirstRowStyle($a_class)
Set first row td style.
setWidth($a_width)
set table width
getHorizontalAlign()
get table cell padding
setTDAlignment($a_hier_id, $a_class, $a_pc_id="")
set alignment of table data cell
getFooterCols()
Get footer cols.
importSpreadsheet($a_lang, $a_data)
import from table
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
checkCellHidden($colspans, $rowspans, $x, $y)
Check hidden status.
getHeaderCols()
Get header cols.
getCellNode($i, $j, $create_if_not_exists=false)
Get cell paragraph node of row $i and cell $j.
getHierId()
Get hierarchical id.
setBorder($a_border)
set table border
makeEmptyCell($td_node)
Make cell empty.
getAllCellWidths()
Get all cell widhts.
getCellPadding()
get table cell padding
getCaptionAlign()
get caption alignment (Top | Bottom)
importTableAttributes(&$node)
getBorder()
get table border width
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
getAllCellSpans()
Get all cell spans.
setFooterRows($a_nr)
Set footer rows.
setCellPadding($a_padding)
set table cell padding
getAllCellAlignments()
Get all cell alignments.
const DOMXML_LOAD_PARSING
static setFirstOptionalElement( $doc, $parent_node, $a_node_name, $a_successors, $a_content, $a_attributes, $a_remove_childs=true)
searches for an element $a_node_name within the childs of $parent_node if no node is found...
getCellSpacing()
get table cell spacing
setFooterCols($a_nr)
Set footer cols.
getHeaderRows()
Get header rows.
getAllCellClasses()
Get all cell classes.
setClass($a_class)
Set Style Class of table.
getLanguage()
get table language
setTDClass($a_hier_id, $a_class, $a_pc_id="")
set class of table data cell
fixHideAndSpans()
Fix Hide and Spans.