[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZMatrix class 4 // 5 // Created on: <30-May-2003 16:46:50 sp> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezmatrix.php 30 */ 31 32 /*! 33 \class eZMatrix ezmatrix.php 34 \ingroup eZDatatype 35 \brief The class eZMatrix does 36 37 */ 38 39 include_once ( "lib/ezxml/classes/ezxml.php" ); 40 41 class eZMatrix 42 { 43 /*! 44 Constructor 45 */ 46 function eZMatrix( $name, $numRows = false, $matrixColumnDefinition = false ) 47 { 48 $this->Name = $name; 49 $this->Matrix = array(); 50 51 if ( $numRows !== false && $matrixColumnDefinition !== false ) 52 { 53 $columns = $matrixColumnDefinition->attribute( 'columns' ); 54 $numColumns = count( $columns ); 55 $this->NumColumns = $numColumns; 56 57 $sequentialColumns = array(); 58 foreach ( $columns as $column ) 59 { 60 $sequentialColumns[] = array( 'identifier' => $column['identifier'], 61 'index' => $column['index'], 62 'name' => $column['name'] ); 63 64 } 65 $this->Matrix['columns'] = array(); 66 $this->Matrix['columns']['sequential'] =& $sequentialColumns; 67 68 $this->NumRows = $numRows; 69 $cells = array(); 70 for ( $i = 0; $i < $numColumns; ++$i ) 71 { 72 for ( $j = 0; $j < $numRows; ++$j ) 73 { 74 $cells[] = ''; 75 } 76 } 77 $this->Cells =& $cells; 78 79 80 $xmlString =& $this->xmlString(); 81 $this->decodeXML( $xmlString ); 82 } 83 } 84 85 /*! 86 Checks current eZMatrix object against definition. 87 If columns ids are wrong or 88 there are additional/redundant columns in definition/eZMatrix object 89 then current eZMatix object will be adjusted according to \a $matrixColumnDefinition. 90 Note: if id of some column was changed form "old_id" to "new_id" 91 then a column with "old_id" will be removed(all data of this column 92 will be lost) and an empty column with "new_id" will be created. 93 Returns \a true if adjustment(matrix modification) was performed. Otherwise - \a false. 94 */ 95 function adjustColumnsToDefinition( $classColumnsDefinition ) 96 { 97 $matrixWasModified = false; 98 99 $matrixWasModified |= $this->removeUselessColumns( $classColumnsDefinition ); 100 $matrixWasModified |= $this->updateColumns ( $classColumnsDefinition, true, true ); 101 102 if ( $matrixWasModified ) 103 { 104 $this->reorderColumns(); 105 106 $columns =& $classColumnsDefinition->attribute( 'columns' ); 107 $numColumns = count( $columns ); 108 $this->NumColumns = $numColumns; 109 110 $xmlString =& $this->xmlString(); 111 $this->decodeXML( $xmlString ); 112 } 113 114 return $matrixWasModified; 115 } 116 117 /*! 118 \a static 119 */ 120 function buildReorderChains( &$chain, &$columns, &$curPos, &$startPos ) 121 { 122 $column =& $columns[$curPos]; 123 $toPos = $column['index']; 124 $chain[] = $toPos; 125 126 $curPos = $toPos; 127 $column =& $columns[$curPos]; 128 if ( $column['index'] != $startPos ) 129 { 130 eZMatrix::buildReorderChains( $chain, $columns, $curPos, $startPos ); 131 } 132 } 133 134 /*! 135 \a static 136 */ 137 function &buildReorderRuleForColumn( &$columns, $curPos, $startPos ) 138 { 139 $rule = array( $curPos ); 140 eZMatrix::buildReorderChains( $rule, $columns, $curPos, $startPos ); 141 return $rule; 142 } 143 144 /*! 145 \a static 146 */ 147 function &buildReorderRules( &$columns ) 148 { 149 $rules = array(); 150 $positions = array_keys( $columns ); 151 152 foreach ( $positions as $pos ) 153 { 154 if ( eZMatrix::hasRuleForColumn( $rules, $pos ) ) 155 { 156 continue; 157 } 158 159 $column =& $columns[$pos]; 160 if ( $column['index'] != $pos ) 161 { 162 $rules[] =& eZMatrix::buildReorderRuleForColumn( $columns, $pos, $pos ); 163 } 164 } 165 return $rules; 166 } 167 168 /*! 169 */ 170 function reorderColumns() 171 { 172 $matrix =& $this->attribute( 'matrix' ); 173 $columns =& $matrix['columns']['sequential']; 174 175 $rules =& eZMatrix::buildReorderRules( $columns ); 176 177 /* 178 example rule: ( 0, 3, 2, 1 ) 179 reorder way: 180 move( 1 -> buffer ) 181 move( 2 -> 1 ) 182 move( 3 -> 2 ) 183 move( 0 -> 3 ) 184 move( buffer -> 0 ) 185 */ 186 foreach( $rules as $rule ) 187 { 188 $buffer = array( 'columnDefinition' => array(), 189 'cellsData' => array() ); 190 191 // last column in rule 192 $pos = count( $rule ) - 1; 193 194 $this->copyColumn( $rule[$pos], $buffer, true ); 195 196 while ( $pos != 0 ) 197 { 198 $this->copyDataBetweenColumns( $rule[$pos - 1], $rule[$pos]); 199 --$pos; 200 } 201 202 // first column in rule 203 $this->copyColumn( $rule[0], $buffer, false ); 204 } 205 } 206 207 /*! 208 \a static 209 */ 210 function hasRuleForColumn( &$rules, $pos ) 211 { 212 $keys = array_keys( $rules ); 213 214 foreach ( $keys as $key ) 215 { 216 $rule =& $rules[$key]; 217 foreach ( $rule as $columnPos ) 218 { 219 if ( $columnPos == $pos ) 220 { 221 return true; 222 } 223 } 224 } 225 return false; 226 } 227 228 /*! 229 */ 230 function copyColumn( $colIdx, &$buffer, $toBuffer ) 231 { 232 $this->copyColumnDefinition( $colIdx, $buffer['columnDefinition'], $toBuffer ); 233 $this->copyColumnCellsData ( $colIdx, $buffer['cellsData'], $toBuffer ); 234 } 235 236 /*! 237 */ 238 function copyColumnDefinition( $colIdx, &$buffer, $toBuffer ) 239 { 240 $matrix =& $this->attribute( 'matrix' ); 241 $columns =& $matrix['columns']['sequential']; 242 243 if ( $toBuffer ) 244 $buffer = $columns[$colIdx]; 245 else 246 $columns[$colIdx] = $buffer; 247 } 248 249 /*! 250 */ 251 function copyColumnCellsData( $colIdx, &$buffer, $toBuffer ) 252 { 253 $columnCount = $this->attribute( 'columnCount' ); 254 $rowCount = $this->attribute( 'rowCount' ); 255 $cells =& $this->attribute( 'cells' ); 256 $pos = $colIdx; 257 $i = 0; 258 259 // walk through rows and add elements one by one. 260 while ( $rowCount > 0 ) 261 { 262 if ( $toBuffer ) 263 { 264 $buffer[] = $cells[$pos]; 265 } 266 else 267 { 268 $cells[$pos] = $buffer[$i]; 269 ++$i; 270 } 271 272 $pos += $columnCount; 273 --$rowCount; 274 } 275 } 276 277 /*! 278 */ 279 function copyDataBetweenColumns( $firstColIdx, $secondColIdx, $toSecondCol = true ) 280 { 281 $this->copyDefinitionBetweenColumns( $firstColIdx, $secondColIdx, $toSecondCol ); 282 $this->copyCellsDataBetweenColumns ( $firstColIdx, $secondColIdx, $toSecondCol ); 283 } 284 285 /*! 286 */ 287 function copyDefinitionBetweenColumns( $firstColIdx, $secondColIdx, $toSecondCol ) 288 { 289 $matrix =& $this->attribute( 'matrix' ); 290 $columns =& $matrix['columns']['sequential']; 291 292 if ( $toSecondCol ) 293 $columns[$secondColIdx] = $columns[$firstColIdx]; 294 else 295 $columns[$firstColIdx] = $columns[$secondColIdx]; 296 } 297 298 /*! 299 */ 300 function copyCellsDataBetweenColumns ( $firstColIdx, $secondColIdx, $toSecondCol ) 301 { 302 $columnCount = $this->attribute( 'columnCount' ); 303 $rowCount = $this->attribute( 'rowCount' ); 304 $cells =& $this->attribute( 'cells' ); 305 $firstColPos = $firstColIdx; 306 $secondColIdx= $secondColIdx; 307 308 // walk through rows and add elements one by one. 309 while ( $rowCount > 0 ) 310 { 311 if ( $toSecondCol ) 312 { 313 $cells[$secondColIdx] = $cells[$firstColIdx]; 314 } 315 else 316 { 317 $cells[$firstColIdx] = $cells[$secondColIdx]; 318 } 319 320 $firstColIdx += $columnCount; 321 $secondColIdx += $columnCount; 322 --$rowCount; 323 } 324 } 325 326 /*! 327 Searches in matrix columns with identifiers that in \a $matrixColumnDefinition and 328 a) if column exists and \a $updateColumnsAttributesAllowed is true then modification of 329 column attributes is performed( index, name, etc.); 330 b) if column doesn't exists and \a $addNewColumnsAllowed then new column will be created. 331 */ 332 function updateColumns( &$matrixColumnDefinition, $addNewColumnsAllowed, $updateColumnsAttributesAllowed ) 333 { 334 $matrixWasModified = false; 335 336 if ( $matrixColumnDefinition && $matrixColumnDefinition !== false ) 337 { 338 $columns =& $matrixColumnDefinition->attribute( 'columns' ); 339 foreach ( $columns as $column ) 340 { 341 $originalColumn =& $this->getColumnDefinitionByID( $column['identifier'] ); 342 if ( $originalColumn !== false && $updateColumnsAttributesAllowed ) 343 { 344 $matrixWasModified |= $this->adjustColumnName( $originalColumn, $column['name'] ); 345 $matrixWasModified |= $this->adjustColumnIndex( $originalColumn, $column['index'] ); 346 } 347 else if ( $addNewColumnsAllowed ) 348 { 349 $matrixWasModified |= $this->addColumn( $column ); 350 } 351 } 352 } 353 return $matrixWasModified; 354 } 355 356 /*! 357 Removes columns that are in matrix but not in \a $matrixColumnDefinition 358 */ 359 function removeUselessColumns( &$matrixColumnDefinition ) 360 { 361 $matrixWasModified = false; 362 $columnsToRemove =& $this->getColumnsToRemove( $matrixColumnDefinition ); 363 364 if ( count( $columnsToRemove ) > 0 ) 365 { 366 // remove begins from last column (reverse order ) 367 $keys = array_keys( $columnsToRemove ); 368 $keys = array_reverse( $keys ); 369 370 foreach ( $keys as $key ) 371 { 372 $column =& $columnsToRemove[$key]; 373 $this->removeColumn( $column ); 374 } 375 376 $matrixWasModified = true; 377 } 378 379 return $matrixWasModified; 380 } 381 382 /*! 383 Checks if column \a $columnDefinition has name \a $newColumnName. If so does 384 nothing and returns false, otherwise changes column's name to 385 \a $newColumnName and returns true. 386 */ 387 function adjustColumnName( &$columnDefinition, $newColumnName ) 388 { 389 if ( $columnDefinition['name'] != $newColumnName ) 390 { 391 $this->setColumnName( $columnDefinition, $newColumnName ); 392 return true; 393 } 394 return false; 395 } 396 397 /*! 398 Sets column's name to \a $newColumnName. 399 */ 400 function setColumnName( &$columnDefinition, $newColumnName ) 401 { 402 $columnDefinition['name'] = $newColumnName; 403 } 404 405 /*! 406 Checks if column \a $columnDefinition has index \a $newColumnIndex. If so does 407 nothing and returns false, otherwise changes column's index to 408 \a $newColumnIndex and returns true. 409 */ 410 function adjustColumnIndex( &$columnDefinition, $newColumnIndex ) 411 { 412 $colIdx = $columnDefinition['index']; 413 414 if ( $columnDefinition['index'] != $newColumnIndex ) 415 { 416 $this->setColumnIndex( $columnDefinition, $newColumnIndex ); 417 return true; 418 } 419 return false; 420 } 421 422 /*! 423 Sets column's name to \a $newColumnIndex. 424 */ 425 function setColumnIndex( &$columnDefinition, $newColumnIndex ) 426 { 427 $columnDefinition['index'] = $newColumnIndex; 428 } 429 430 /*! 431 Searches column definition by indentifier. If column was found returns it, 432 otherwise returns false. 433 */ 434 function &getColumnDefinitionByID( &$id ) 435 { 436 $isColumnExists = false; 437 $matrix =& $this->attribute( 'matrix' ); 438 $columns =& $matrix['columns']['sequential']; 439 440 $keys = array_keys( $columns ); 441 foreach ( $keys as $key ) 442 { 443 $column =& $columns[$key]; 444 if ( $column['identifier'] == $id ) 445 { 446 return $column; 447 } 448 } 449 return $isColumnExists; 450 } 451 452 /*! 453 Searches columns that are in matrix but not in \a $matrixColumnDefinition. 454 */ 455 function &getColumnsToRemove( &$matrixColumnsDefinition ) 456 { 457 $columnsToRemove = array(); 458 $matrix =& $this->attribute( 'matrix' ); 459 $columns =& $matrix['columns']['sequential']; 460 461 foreach ( $columns as $column ) 462 { 463 if ( !eZMatrix::isColumnExists( $column, $matrixColumnsDefinition ) ) 464 { 465 $columnsToRemove[] = $column; 466 } 467 } 468 469 return $columnsToRemove; 470 } 471 472 /*! 473 \a static 474 Searches column \a $columnToFind in \a $matrixColumnDefinition. 475 Returns true if found, false - otherwise. 476 */ 477 function isColumnExists( &$columnToFind, &$matrixColumnsDefinition ) 478 { 479 $columns =& $matrixColumnsDefinition->attribute( 'columns' ); 480 481 foreach ( $columns as $column ) 482 { 483 if ( $column['identifier'] === $columnToFind['identifier'] ) 484 return true; 485 } 486 487 return false; 488 } 489 490 /*! 491 Adds column \a $columnDefinition to eZMatrix object. 492 */ 493 function addColumn( &$columnDefinition ) 494 { 495 $this->addColumnToMatrix( $columnDefinition ); 496 $this->addColumnToCells( $columnDefinition ); 497 return true; 498 } 499 500 /*! 501 Adds column \a $columnDefinition to 'matrix' member of eZMatrix. 502 */ 503 function addColumnToMatrix( &$columnDefinition ) 504 { 505 $matrix =& $this->attribute( 'matrix' ); 506 $columns =& $matrix['columns']['sequential']; 507 508 $newColumn = array( 'identifier' => $columnDefinition['identifier'], 509 'index' => $columnDefinition['index'], 510 'name' => $columnDefinition['name'] ); 511 512 array_splice( $columns, $columnDefinition['index'], 0, array( $newColumn ) ); 513 } 514 515 /*! 516 Adds column \a $columnDefinition to 'cells' member of eZMatrix. 517 */ 518 function addColumnToCells( &$columnDefinition ) 519 { 520 $cells =& $this->attribute( 'cells' ); 521 $columnCount = $this->attribute( 'columnCount' ); 522 $rowCount = $this->attribute( 'rowCount' ); 523 $pos = $columnDefinition['index']; 524 525 // walk through rows and add elements one by one. 526 while ( $rowCount > 0 ) 527 { 528 array_splice( $cells, $pos, 0, '' ); 529 $pos += $columnCount; 530 --$rowCount; 531 } 532 } 533 534 /*! 535 Removess column \a $columnDefinition from eZMatrix object. 536 */ 537 function removeColumn( &$columnDefinition ) 538 { 539 $this->removeColumnFromCells( $columnDefinition ); 540 $this->removeColumnFromMatrix( $columnDefinition ); 541 } 542 543 /*! 544 Removess column \a $columnDefinition from 'cells' member of eZMatrix. 545 */ 546 function removeColumnFromCells( &$columnDefinition ) 547 { 548 $cells =& $this->attribute( 'cells' ); 549 $rowCount = $this->attribute( 'rowCount' ); 550 $columnCount = $this->attribute( 'columnCount' ); 551 552 // last position(index) of element to remove in $cells. 553 $pos = ( $rowCount - 1 ) * $columnCount + $columnDefinition['index']; 554 555 // walk through rows and remove elements one by one. 556 while ( $rowCount > 0 ) 557 { 558 array_splice( $cells, $pos, 1 ); 559 $pos -= $columnCount; 560 --$rowCount; 561 } 562 } 563 564 /*! 565 Removess column \a $columnDefinition from 'matrix' member of eZMatrix. 566 */ 567 function removeColumnFromMatrix( &$columnDefinition ) 568 { 569 $matrix =& $this->attribute( 'matrix' ); 570 $columns =& $matrix['columns']['sequential']; 571 $pos = 0; 572 573 foreach ( $columns as $column ) 574 { 575 if ( $column['identifier'] == $columnDefinition['identifier'] ) 576 { 577 array_splice( $columns, $pos, 1 ); 578 return true; 579 } 580 ++$pos; 581 } 582 return false; 583 } 584 585 /*! 586 Sets the name of the matrix 587 */ 588 function setName( $name ) 589 { 590 $this->Name = $name; 591 } 592 593 /*! 594 Returns the name of the matrix. 595 */ 596 function &name() 597 { 598 return $this->Name; 599 } 600 601 function attributes() 602 { 603 return array( 'name' , 604 'rows', 605 'columns', 606 'matrix', 607 'cells', 608 'rowCount', 609 'columnCount' ); 610 } 611 612 function hasAttribute( $name ) 613 { 614 return in_array( $name, $this->attributes() ); 615 } 616 617 function &attribute( $name ) 618 { 619 switch ( $name ) 620 { 621 case "name" : 622 { 623 return $this->Name; 624 }break; 625 case "matrix" : 626 { 627 return $this->Matrix; 628 }break; 629 case "cells" : 630 { 631 return $this->Cells; 632 }break; 633 case "rows" : 634 { 635 return $this->Matrix['rows']; 636 }break; 637 case "columns" : 638 { 639 return $this->Matrix['columns']; 640 }break; 641 case "rowCount" : 642 { 643 $rowCount = count( $this->Matrix['rows']['sequential'] ); 644 return $rowCount; 645 }break; 646 case "columnCount" : 647 { 648 $columnCount = count( $this->Matrix['columns']['sequential'] ); 649 return $columnCount; 650 }break; 651 default: 652 { 653 eZDebug::writeError( "Attribute '$name' does not exist", 'eZMatrix::attribute' ); 654 $retValue = null; 655 return $retValue; 656 }break; 657 } 658 } 659 660 function addRow( $beforeIndex = false, $addCount = 1 ) 661 { 662 $addCount = min( $addCount, 40 ); 663 664 for ( $r = $addCount; $r > 0; $r-- ) 665 { 666 $newCells = array(); 667 $numColumns = $this->attribute( 'columnCount' ); 668 $numRows = $this->attribute( 'rowCount' ); 669 for ( $i = 0; $i < $numColumns; $i++ ) 670 { 671 $newCells[] = ''; 672 } 673 $newRow = array(); 674 $newRow['columns'] = $newCells; 675 $this->NumRows++; 676 if ( $beforeIndex === false ) 677 { 678 $this->Cells = array_merge( $this->Cells, $newCells ); 679 $newRow['identifier'] = 'row_' . ( $numRows + 1 ); 680 $newRow['name'] = 'Row_' . ( $numRows + 1 ); 681 $this->Matrix['rows']['sequential'][] = $newRow; 682 683 } 684 else 685 { 686 $insertIndex = ( $beforeIndex + 1 ) * $numColumns - $numColumns; 687 array_splice( $this->Cells, $insertIndex, 0, $newCells ); 688 $newRow['identifier'] = 'row_' . $beforeIndex; 689 $newRow['name'] = 'Row_' . ( $numRows + 1 ); 690 array_splice( $this->Matrix['rows']['sequential'], $beforeIndex, 0, array( $newRow ) ); 691 692 } 693 } 694 } 695 696 function removeRow( $rowNum ) 697 { 698 $numColumns = $this->attribute( 'columnCount' ); 699 $numRows = $this->attribute( 'rowCount' ); 700 701 array_splice( $this->Cells, $rowNum * $numColumns, $numColumns ); 702 array_splice( $this->Matrix['rows']['sequential'], $rowNum, 1 ); 703 $this->NumRows--; 704 } 705 706 /*! 707 Will decode an xml string and initialize the eZ matrix object 708 */ 709 function decodeXML( $xmlString ) 710 { 711 $xml = new eZXML(); 712 $dom = $xml->domTree( $xmlString ); 713 if ( $xmlString != "" ) 714 { 715 // set the name of the node 716 $nameArray = $dom->elementsByName( "name" ); 717 $this->setName( $nameArray[0]->textContent() ); 718 719 $columns = $dom->elementsByName( "columns" ); 720 $numColumns = $columns[0]->attributeValue( 'number'); 721 722 $rows = $dom->elementsByName( "rows" ); 723 $numRows = $rows[0]->attributeValue( 'number'); 724 725 $namedColumns = $dom->elementsByName( "column" ); 726 $namedColumnList = array(); 727 if ( count( $namedColumns ) > 0 ) 728 { 729 foreach ( $namedColumns as $namedColumn ) 730 { 731 $columnName = $namedColumn->textContent(); 732 $columnID = $namedColumn->attributeValue( 'id' ); 733 $columnNumber = $namedColumn->attributeValue( 'num' ); 734 $namedColumnList[$columnNumber] = array( 'name' => $columnName, 735 'column_number' => $columnNumber, 736 'column_id' => $columnID ); 737 } 738 } 739 $cellArray = $dom->elementsByName( "c" ); 740 $cellCount = count( $cellArray ); 741 $cellList = array(); 742 for ( $i = 0; $i < $cellCount; ++$i ) 743 { 744 $cellList[] = $cellArray[$i]->textContent(); 745 } 746 747 $rows = array( 'sequential' => array() ); 748 $sequentialRows =& $rows['sequential']; 749 750 for ( $i = 1; $i <= $numRows; $i++ ) 751 { 752 $row = array( 'identifier' => 'row_' . $i , 753 'name' => 'Row_' . $i ); 754 $rowColumns = array(); 755 for ( $j = 1; $j <= $numColumns; $j++ ) 756 { 757 $rowColumns[] = $cellList[ ($i-1) * $numColumns + $j-1]; 758 } 759 $row['columns'] = $rowColumns; 760 $sequentialRows[] = $row; 761 } 762 763 $columns = array( 'sequential' => array(), 764 'id' => array() ); 765 $sequentialColumns =& $columns['sequential']; 766 $idColumns =& $columns['id']; 767 768 for ( $i = 0; $i < $numColumns; $i++ ) 769 { 770 if ( isset( $column ) ) 771 unset( $column ); 772 $column = array(); 773 if ( isset( $namedColumnList[$i] ) && is_array( $namedColumnList[$i] ) ) 774 { 775 $column = array( 'identifier' => $namedColumnList[$i]['column_id'], 776 'index' => $i, 777 'name' => $namedColumnList[$i]['name'] ); 778 } 779 else 780 { 781 $column = array( 'identifier' => 'col_' . ($i + 1), 782 'index' => $i, 783 'name' => 'Col_' . ($i + 1) ); 784 785 } 786 787 $columnRows = array(); 788 for( $j = 0; $j < $numRows; $j++ ) 789 { 790 $columnRows[] =& $sequentialRows[$j]['columns'][$i]; 791 } 792 $column['rows'] =& $columnRows; 793 unset( $columnRows ); 794 $sequentialColumns[] =& $column; 795 $idColumns[$column['identifier']] =& $column; 796 797 } 798 $matrix = array( 'rows' => &$rows, 799 'columns' => &$columns, 800 'cells' => &$cellList ); 801 802 $this->Matrix =& $matrix; 803 $this->NumRows =& $numRows; 804 $this->NumColumns =& $numColumns; 805 $this->Cells =& $cellList; 806 } 807 else 808 { 809 $this->Cells = array(); 810 $this->Matrix = array(); 811 } 812 } 813 /*! 814 \static 815 \return the XML structure in \a $domDocument as text. 816 It will take of care of the necessary charset conversions 817 for content storage. 818 */ 819 function domString( &$domDocument ) 820 { 821 $ini =& eZINI::instance(); 822 $xmlCharset = $ini->variable( 'RegionalSettings', 'ContentXMLCharset' ); 823 if ( $xmlCharset == 'enabled' ) 824 { 825 include_once ( 'lib/ezi18n/classes/eztextcodec.php' ); 826 $charset = eZTextCodec::internalCharset(); 827 } 828 else if ( $xmlCharset == 'disabled' ) 829 $charset = true; 830 else 831 $charset = $xmlCharset; 832 if ( $charset !== true ) 833 { 834 include_once ( 'lib/ezi18n/classes/ezcharsetinfo.php' ); 835 $charset = eZCharsetInfo::realCharsetCode( $charset ); 836 } 837 $domString = $domDocument->toString( $charset ); 838 return $domString; 839 } 840 841 /*! 842 Will return the XML string for this matrix. 843 */ 844 function &xmlString( ) 845 { 846 $doc = new eZDOMDocument( "Matrix" ); 847 $root = $doc->createElementNode( "ezmatrix" ); 848 $doc->setRoot( $root ); 849 850 $name = $doc->createElementNode( "name" ); 851 $nameValue = $doc->createTextNode( $this->Name ); 852 $name->appendChild( $nameValue ); 853 854 $name->setContent( $this->Name() ); 855 $root->appendChild( $name ); 856 857 858 $columnsNode = $doc->createElementNode( "columns" ); 859 860 861 $sequentalColumns =& $this->Matrix['columns']['sequential']; 862 // $columnAmount = count( $sequentalColumns ); 863 $columnAmount = $this->NumColumns; 864 $columnsNode->appendAttribute( $doc->createAttributeNode( 'number', $columnAmount ) ); 865 $root->appendChild( $columnsNode ); 866 867 if ( $sequentalColumns != null ) 868 { 869 for( $i = 0; $i < $columnAmount; $i++ ) 870 { 871 $column =& $sequentalColumns[$i]; 872 if( $column != null && $column['identifier'] != 'col_'. $i+1 ) 873 { 874 unset( $columnNode ); 875 $columnNode = $doc->createElementNode( 'column' ); 876 $columnNode->appendAttribute( $doc->createAttributeNode( 'num', $i ) ); 877 $columnNode->appendAttribute( $doc->createAttributeNode( 'id', $column['identifier'] ) ); 878 879 unset( $columnValueNode ); 880 $columnValueNode = $doc->createTextNode( $column["name"] ); 881 882 $columnNode->appendChild( $columnValueNode ); 883 $columnsNode->appendChild( $columnNode ); 884 } 885 } 886 887 } 888 // $rows = & $dom->elementsByName( "rows" ); 889 890 $rowsNode = $doc->createElementNode( "rows" ); 891 // $rowAmount = count( $this->Matrix['rows'] ); 892 $rowAmount = $this->NumRows; 893 894 $rowsNode->appendAttribute( $doc->createAttributeNode( 'number', $rowAmount ) ); 895 896 $root->appendChild( $rowsNode ); 897 898 foreach ( $this->Cells as $cell ) 899 { 900 unset( $cellNode ); 901 $cellNode = $doc->createElementNode( 'c' ); 902 903 unset( $columnValueNode ); 904 $columnValueNode = $doc->createTextNode( $cell ); 905 906 $cellNode->appendChild( $columnValueNode ); 907 $root->appendChild( $cellNode ); 908 } 909 910 $xml = eZMatrix::domString( $doc ); 911 912 return $xml; 913 } 914 915 /// Contains the Matrix name 916 var $Name; 917 918 /// Contains the Matrix array 919 var $Matrix; 920 921 /// Contains the number of columns 922 var $NumColumns; 923 924 /// Contains the number of rows 925 926 var $NumRows; 927 var $Cells; 928 929 930 931 } 932 /* 933 $content = array( 'rows' => array( array( 'identifier' => 'some', 934 'name' => 'Some', 935 'columns' => array( 1, "test", 5 ) ), 936 array( 'identifier' => 'some2', 937 'name' => 'Some2', 938 'columns' => array( 2, "test2", 10 ) ) ), 939 'columns' => array( 'id' => array( 'c1' => &array( 'identifier' => 'c1', 940 'name' => 'C1', 941 'index' => 1, 942 'columns' => array( 1, 2 ) ) ), 943 'sequential' => array( array( 'identifier' => 'c1', 944 'name' => 'C1', 945 'columns' => array( 1, 2 ) ), 946 array( 'identifier' => 'c2', 947 'name' => 'C2', 948 'columns' => array( "test", "test2" ) ), 949 array( 'identifier' => 'c3', 950 'name' => 'C3', 951 'columns' => array( 5, 10 ) ) ) ); 952 953 '<input type="text" name="_c1_r1" '; 954 955 $matrix = array( array( 1, "test", 5 ), 956 array( 2, "test2", 10 ) ); 957 $matrix[1][1] = 42; 958 */ 959 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |