
Originally Posted by
gwmbox
That is why I was trying to 'not' mention it was Joomla or any other specific CMS, as we need to take that out of the equation when we look at trying to resolve what I am doing. What I mean here is imagine I never mentioned it was CMS related, or in particular Joomla related.
Well, yes and no; I came up with my suggested refactoring based on the assumption that it was "plain PHP" - and the idea turned out to be unusable because it's inside Joomla. So, you didn't get "shut out" right away, but you did manage to waste some time
.
If you "never mentioned" it was Joomla, we'd still be milling around, wondering why you "can't use" this solution, that solution, etc. - it would be frustrating.
- - - - - - - - - - - - - - - - - - - - - - - - -
Here's the basics of the new plan:
PHP Code:
<?php
// still recommending putting classnames in an array.
// $classnames[ row_sum ] = array( col_number=>classname ,col_number=>classname , . . . )
// these values taken from your earlier examples.
// double-check (some seem to be missing; row sum=2, for example).
$classnames[10] = array( 1=>'col3' ,2=>'col3' ,3=>'col3' ,4=>'col3' );
$classnames[6] = array( 1=>'col4' ,2=>'col4' ,3=>'col4' ,4=>'' );
$classnames[4] = array( 1=>'col6' ,2=>'' ,3=>'col6' ,4=>'' );
$classnames[1] = array( 1=>'col12',2=>'' ,3=>'' ,4=>'' );
$classnames[9] = array( 1=>'col6' ,2=>'' ,3=>'col3' ,4=>'col3' );
$classnames[8] = array( 1=>'col3' ,2=>'' ,3=>'col6' ,4=>'col3' );
$classnames[7] = array( 1=>'col3' ,2=>'col3' ,3=>'' ,4=>'col6' );
$classnames[3] = array( 1=>'col3' ,2=>'col9' ,3=>'' ,4=>'' );
$classnames[5] = array( 1=>'col9' ,2=>'' ,3=>'' ,4=>'col3' );
// loop through 12 rows
for( $row=1; $row<=12; $row++ ){
// this will hold the sum of all the values tallied
$row_sum = 0;
// loop through 4 columns
for( $col=1; $col<=4; $col++ ){
// "row-c" variable
$rc = "row{$row}c{$col}";
// if the column has content
if( $this->countModules( "pos-$rc" ) ){
// add the col number (1 ... 4) to the row total
$row_sum += $col;
}
}
// assign classname set for this row
$class[$row] = $classnames[$row_sum];
}
IIUC, this should be compatible with the Joomla methods you're using. When you're done, $class will be a map of classnames to apply to each row and column - for example,
PHP Code:
<table>
<tr id=row1>
<td id=row1c1 class=<?= $class[1][1] ?>>whatever goes in col1</td>
<td id=row1c2 class=<?= $class[1][2] ?>>whatever goes in col2</td>
<td id=row1c3 class=<?= $class[1][3] ?>>whatever goes in col3</td>
<td id=row1c4 class=<?= $class[1][4] ?>>whatever goes in col4</td>
</tr>
<!-- etc. . . . -->
</table>
Bookmarks