/** * This function creates a table table style using the style as set in the assoziative array $properties. * The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'. * Properties which shall not be used in the style can be disabled by setting the value in disabled_props * to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property. * * The currently supported properties are: * width, border-collapse, background-color * * The function returns the name of the new style or NULL if all relevant properties are empty. * * @author LarsDW223 * @param $properties * @param null $disabled_props * @param int $max_width_cm * @return ODTTableStyle or NULL */ public static function createTableTableStyle(array $properties, array $disabled_props = NULL, $max_width_cm = 17) { // If we want to change the table width we must set table:align to something else // than "margins". Otherwise the width will not be changed. // Also we set a fixed default width of 100%. Otherwise setting the width of the columns // will have no effect in case the user does not specify any width for the whole table. // FIXME: This will always produce at least one attribute. // It would be more elegant to change the style if we find any width attributes // in the headers/columns. Maybe later. $properties['align'] = 'center'; $table_width = $max_width_cm . 'cm'; if (!empty($properties['width'])) { // If width has a percentage value we need to use the rel-width attribute, // otherwise the width attribute $width = $properties['width']; if ($width[strlen($width) - 1] != '%') { $properties['width'] = $table_width; } else { // Better calculate absolute width and use it instead of relative width. // Some applications might not support relative width. $table_width = $max_width_cm * trim($width, '%') / 100 . 'cm'; $properties['width'] = $table_width; } } // Convert property 'border-model' to ODT if (!empty($properties['border-model'])) { if ($properties['border-model'] == 'collapse') { $properties['border-model'] = 'collapsing'; } else { $properties['border-model'] = 'separating'; } } // Create style name (if not given). $style_name = $properties['style-name']; if (empty($style_name)) { $style_name = self::getNewStylename('Table'); $properties['style-name'] = $style_name; } // Create empty table style. $object = new ODTTableStyle(); if ($object == NULL) { return NULL; } // Import our properties $object->importProperties($properties, $disabled_props); return $object; }