1<?php 2 3require_once DOKU_PLUGIN.'odt/ODT/elements/ODTStateElement.php'; 4 5/** 6 * ODTElementTableColumn: 7 * Class for handling the table column element. 8 * 9 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 10 * @author LarsDW223 11 */ 12class ODTElementTableColumn extends ODTStateElement 13{ 14 // Which column number in the corresponding table is this? 15 // [Is set on enter() ==> determineParent()] 16 protected $columnNumber = 0; 17 18 /** 19 * Constructor. 20 */ 21 public function __construct() { 22 parent::__construct(); 23 $this->setClass ('table-column'); 24 } 25 26 /** 27 * Return the elements name. 28 * 29 * @return string The ODT XML element name. 30 */ 31 public function getElementName () { 32 return ('table:table-column'); 33 } 34 35 /** 36 * Return string with encoded opening tag. 37 * 38 * @return string The ODT XML code to open this element. 39 */ 40 public function getOpeningTag () { 41 return '<table:table-column table:style-name="'.$this->getStyleName().'"/>'; 42 } 43 44 /** 45 * Return string with encoded closing tag. 46 * 47 * @return string The ODT XML code to close this element. 48 */ 49 public function getClosingTag () { 50 return '</table:table-column>'; 51 } 52 53 /** 54 * Are we in a paragraph or not? 55 * As a table column we are not. 56 * 57 * @return boolean 58 */ 59 public function getInParagraph() { 60 return false; 61 } 62 63 /** 64 * Determine and set the parent for this element. 65 * As a table column our parent is the table element. 66 * 67 * @param ODTStateElement $previous 68 */ 69 public function determineParent(ODTStateElement $previous) { 70 $table = $previous; 71 while (isset($table)) { 72 if ($table->getClass() == 'table') { 73 break; 74 } 75 $table = $table->getParent(); 76 } 77 $this->setParent($table); 78 79 if (!isset($table)) { 80 // ??? Should not be... 81 return; 82 } 83 84 // Overwrite/Create column style for actual column if $properties has any 85 // meaningful params for a column-style (e.g. width). 86 $table_column_styles = $table->getTableColumnStyles(); 87 $auto_columns = $table->getTableAutoColumns(); 88 $max_columns = $table->getTableMaxColumns(); 89 $row_count = $table->getRowCount(); 90 $curr_column = $table->getTableCurrentColumn(); 91 if ($row_count > 0) { 92 $curr_column--; 93 } 94 95 // Set our column number. 96 $this->columnNumber = $curr_column; 97 98 // Set our style name to a predefined name 99 // and also set it in the table (if not done yet) 100 $style_name = $table->getTableColumnStyleName($curr_column); 101 if (empty($style_name)) { 102 $style_name = 'odt_auto_style_table_column_'.$table->getCount().'_'.($curr_column+1); 103 $table->setTableColumnStyleName($curr_column, $style_name); 104 } 105 $this->setStyleName ($style_name); 106 107 if ($row_count == 0) { 108 // Only count columns here if not already a row has been opened. 109 // Otherwise counting will be done in ODTElementTableCell! 110 $curr_column++; 111 $table->setTableCurrentColumn($curr_column); 112 113 // Eventually increase max columns if out range 114 if ( $curr_column > $max_columns ) { 115 $table->setTableMaxColumns($max_columns + 1); 116 } 117 } 118 } 119 120 /** 121 * Set the style name. 122 * The method is overwritten to make the column also set the new 123 * column style name in its corresponding table. 124 * 125 * FIXME: it would be better to just have an array of object 126 * pointers in the table and use them to query the names. 127 * 128 * @param string $value Style name, e.g. 'body' 129 */ 130 public function setStyleName($value) { 131 parent::setStyleName($value); 132 $table = $this->getParent(); 133 if (isset($table)) { 134 $table->setTableColumnStyleName($this->columnNumber, $value); 135 } else { 136 // FIXME: some error logging would be nice... 137 } 138 } 139 140 /** 141 * Return the table to which this column belongs. 142 * 143 * @return ODTStateElement 144 */ 145 public function getTable () { 146 return $this->getParent(); 147 } 148} 149