Commit d1e8ed28 authored by Nigel McNie's avatar Nigel McNie
Browse files

Add new get_layout() method to Views and use it everywhere we were hardcoding view_layout stuff.



This is _actually_ a long-winded way of doing a theming fix. IE6 needs to have
a couple of percentage points of width shaved off the View column widths,
otherwise you can end up with columns wrapping to a new line, which is not cool
at all. So if we detect IE6, we now do this.
Signed-off-by: default avatarNigel McNie <nigel@catalyst.net.nz>
parent d7b595ab
......@@ -219,17 +219,7 @@ class PluginExportLeap extends PluginExport {
$this->smarty->assign('contenttype', 'html');
$this->smarty->assign('content', $view->build_columns());
$this->smarty->assign('viewdata', $config['columns']);
if (isset($layouts[$config['layout']])) {
$layout = $config['layout'];
}
else {
// This line ruthlessly stolen from lib/upgrade.php - the only
// place where view layouts are canonically specified
$layout = ($config['numcolumns'] == 2 ? 1 : ($config['numcolumns'] == 3 ? 4 : 7));
}
if (isset($layouts[$layout])) {
$this->smarty->assign('layout', $layouts[$layout]->widths);
}
$this->smarty->assign('layout', $view->get_layout()->widths);
$ownerformat = ($config['ownerformat']) ? $config['ownerformat'] : FORMAT_NAME_DISPLAYNAME;
$this->smarty->assign('ownerformat', $ownerformat);
$this->smarty->assign('leaptype', 'selection');
......
......@@ -1232,6 +1232,20 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2009102100) {
// Now the view_layout table has to have records for all column widths
$record = (object)array(
'columns' => 1,
'widths' => '100',
);
insert_record('view_layout', $record);
$record = (object)array(
'columns' => 5,
'widths' => '20,20,20,20,20',
);
insert_record('view_layout', $record);
}
return $status;
}
......
......@@ -973,25 +973,10 @@ function install_blocktype_extras() {
*/
function install_view_column_widths() {
db_begin();
$layouts = array(
2 => array(
'50,50',
'67,33',
'33,67',
),
3 => array(
'33,33,33',
'25,50,25',
'15,70,15',
),
4 => array(
'25,25,25,25',
'20,30,30,20',
),
);
require_once('view.php');
$layout = new StdClass;
foreach ($layouts as $column => $widths) {
foreach (View::$layouts as $column => $widths) {
foreach ($widths as $width) {
$layout->columns = $column;
$layout->widths = $width;
......
......@@ -63,6 +63,49 @@ class View {
private $copynewgroups;
private $type;
/**
* Valid view layouts. These are read at install time and inserted into
* view_layout, but not updated afterwards, so if you're changing one
* you'll need to do that manually. Actually, you'd better talk to the
* Mahara dev team about what else needs changing if you do touch this.
*
* A hash of columns => list of view widths
*/
public static $layouts = array(
1 => array(
'100',
),
2 => array(
'50,50',
'67,33',
'33,67',
),
3 => array(
'33,33,33',
'25,50,25',
'15,70,15',
),
4 => array(
'25,25,25,25',
'20,30,30,20',
),
5 => array(
'20,20,20,20,20',
),
);
/**
* Which view layout is considered the "default" for views with the given
* number of columns. Must be present in $layouts of course.
*/
public static $defaultlayouts = array(
1 => '100',
2 => '50,50',
3 => '33,33,33',
4 => '25,25,25,25',
5 => '20,20,20,20,20',
);
public function __construct($id=0, $data=null) {
if (!empty($id)) {
$tempdata = get_record('view','id',$id);
......@@ -983,16 +1026,16 @@ class View {
}
// Set column widths
if ($this->get('numcolumns') > 1) {
$layout = $this->get('layout');
if ($layout) {
$i = 0;
// The get_field also verifies the layout is correct for the
// number of columns in the view
foreach (explode(',', get_field('view_layout', 'widths', 'id', $layout, 'columns', $this->get('numcolumns'))) as $width) {
$this->columns[++$i]['width'] = $width;
}
$layout = $this->get_layout();
$i = 0;
$is_ie6 = (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.0'));
foreach (explode(',', $layout->widths) as $width) {
// IE6 has interesting padding issues that mean we have to tell
// porkies so all the columns stay beside each other
if ($is_ie6) {
$width -= 2;
}
$this->columns[++$i]['width'] = $width;
}
foreach ($data as $block) {
......@@ -1506,6 +1549,43 @@ class View {
return null;
}
/**
* Returns a record from the view_layout table matching the layout for this
* View.
*
* If the layout for the view is null, then this method returns the record
* for the default layout for the number of columns the View has.
*
* Check the view_layout table for what fields you'll get back, but the
* most interesting one is 'widths', which is a comma-separated list of %
* widths for the columns in the View.
*
* @return array A record from the view_layout table.
*/
public function get_layout() {
static $viewlayouts = null;
if ($viewlayouts === null) {
$viewlayouts = get_records_assoc('view_layout');
}
$layout = $this->get('layout');
$numcolumns = $this->get('numcolumns');
if (!$layout) {
foreach ($viewlayouts as $layout) {
if ($layout->widths == self::$defaultlayouts[$numcolumns]) {
return $layout;
}
}
}
if (isset($viewlayouts[$layout])) {
return $viewlayouts[$layout];
}
throw new SystemException("Unknown view layout (id=$layout)");
}
/**
* Exports the view configuration as a data structure. This does not
* include access rules or ownership information - only the information
......
......@@ -109,24 +109,6 @@ html>body #column-container {
cursor: default;
}
/* each column div will have a class matching one of these, the number is the
number of columns in total, so widths can be made equal */
.columns1 {
width: 99%;
}
.columns2 {
width: 49%;
}
.columns3 {
width: 32%;
}
.columns4 {
width: 24%;
}
.columns5 {
width: 19%;
}
.column {
vertical-align: top;
float: left;
......@@ -134,16 +116,6 @@ html>body #column-container {
padding: 0 0.9%;
position: relative;
}
* html .columns1 {
width: 96%;
}
* html .columns2 {
width: 46%;
}
* html .columns3 {
width: 30%;
}
* html .column {
overflow: hidden;
}
......
......@@ -51,7 +51,7 @@ if (!$USER->can_edit_view($view)) {
// if not set, use equal width layout for that number of columns
if (!$currentlayout) {
$currentlayout = ($numcolumns == 2 ? 1 : ($numcolumns == 3 ? 4 : 7));
$currentlayout = $view->get_layout()->id;
}
if ($numcolumns > 1 && $numcolumns < 5) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment