Adding some intelligence to layout files

Adding some intelligence to layout files

by Rolley Tickner -
Number of replies: 8

Hey everyone : )

I'm working on a new theme for Moodle 2 at the moment; and I was wondering if anyone can please point me in the right direction regarding an enhancement I want one of my layouts to have?

Background/reason for enhancement:

We have a lot of academics at our institution who like to have a banner image in their course site.. it causes some huge consistency problems, they take up way too much screen space, and most of them repeat the course name and course code!

To save space, and reduce information redundancy I want to allow them to upload a picture in their course topic, which the course layout file then incorporates IN to the moodle banner.

What I've done:

I'm not exactly sure about the best approach, and I'm by no means an experienced OO programmer or even that experienced with PHP and the moodle back-end.. but, this is what I have so far.. it's half hard-coded, but it does work.  The digit 71 must be the row number of the file in the DB right?  I'm not sure how on earth I can go about parameterising this part, or even if I'm close or on the right track.. I'm out of my depth when it comes to having to query the DB to find the corresponding ID...

<?php  			
	global $CFG;
	$context = get_system_context();
	$file = $CFG->wwwroot . '/pluginfile.php/71/mod_resource/content/' . $context->id . '/banner.png';
	echo "<div id='customBanner' style='opacity: 0;'><img src='http://moodle.org/'" . $file . "' alt='Course banner' /></div>" ;
?>

btw, the opacity style is to do with some YUI3 effects I have; I'm also fading the image in after fading out the institution's logo.

Is the pluginfile.php even the right direction? Or is there a MUCH better way to do what I want?

I'll attach a screeny too. In the screenshot you can see what I mean, I've uploaded the banner.png file in the course topic area; the code above has then just rendered it in to the actual moodle banner smile

Any advice at all will be appreciated sooooo much.

Thanks smile

Rolley

Attachment newtheme-lowres.png
Average of ratings: -
In reply to Rolley Tickner

Re: Adding some intelligence to layout files

by Sam Hemelryk -
Hi Rolley,

The short answer is that it isn't quite that simple.
To me it looks like the 71 in the URL relates to the module context (The resources context). You'd need to come up with some smart way of getting the correct module context id when a user is browsing a course or something within a course and then hope that a file called banner.jpg has been uploaded there.

Personally I'd stick away from doing that being that it could be shaky ground and would probably add a fair bit to your workflow.

I seem to recall others look to do that same thing as well although I can't recall what solutions people came up with.
But then there are people who are WAY more active in this forum than me so hopefully someone will.

Having had a little bit of a think about it I would think that it would be cool to achieve this with a local plugin.
You could get it to give teachers or people with a specific capability the ability to upload a image which you could then use in the theme or where ever I suppose.
That way you could serve through the file API properly and wire into the navigation and such.
If I find myself a bit of spare time I might give it a shot, otherwise if you're feeling daring you could give it a go yourself.

Cheers
Sam
In reply to Sam Hemelryk

Re: Adding some intelligence to layout files

by Mary Evans -

Hi Sam,

I think this is the forum discussion you are meaning...

Dynamic logo display in courses (started by Ray Lawrance)

http://moodle.org/mod/forum/discuss.php?d=158491

Although some of the options mentioned in that thread might not work in Moodle 2.

Mary

In reply to Mary Evans

Re: Adding some intelligence to layout files

by Sam Hemelryk -
Thanks Mary, I was hoping you would remember it smile
In reply to Sam Hemelryk

Introducing the courselogo plugin... use at your own risk!

by Sam Hemelryk -
Ok so I found a bit of free time and knocked up a local plugin that allows a admin/manager/teacher to upload an image for a course to use.
The plugin then has a couple of functions that you can call within your theme to make use of the uploaded image for a course and even falls back to a default image if there isn't one.
It's integrated with the navigation so once you install it anyone with the correct capability should see it within a courses navigation.

The attached image shows it on the navigation.

I've only just written this plugin and I don't intend to use it myself so expect a bug or two. I've put as much information as I can into the readme file for the plugin including installation and how to integrate it with your themes, if you have any questions ask in here.

To check it out head to:
https://github.com/samhemelryk/moodle-local-courselogo

There you'll be able to see the readme, the course files and a download link smile
If people find it works and like it I'll put into Moodle's contrib.
If you have any questions ask somewhere in this forum or PM me and I'll help out or tell you to ask in a specific forum.

Cheers
Sam
Attachment courselogo.screenshot.jpg
In reply to Sam Hemelryk

Re: Introducing the courselogo plugin... use at your own risk!

by Rolley Tickner -

Good on ya Sam! I'll download it and have a look!

:D

In reply to Rolley Tickner

Re: Adding some intelligence to layout files

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Rolley

We have a lot of academics at our institution who like to have a banner image in their course site.

How sad.sad Good luck with trying to persuade them that "banners should be banned". I wonder where those academics get their design ideas from?

Joseph

In reply to Rolley Tickner

Re: Adding some intelligence to layout files

by Rolley Tickner -

Thanks everyone for your replies!

@Joseph: Yep, people are resistant to change in large organisations, the whole 'banner' thing is something they don't want to let go of. As a designer I fully support the negatives of banners, but hopefully what I'm doing here will help.

@Sam, @Mary & @Frank: Interesting, I'll definitely suss out those links ay. Thanks for that!

@Sam: A plugin eh? Didn't think of that, I wonder. I've never looked at making plugins before so I might do that : ) .... or .. I could wait and see if you do one!! HAHAHA :D ;)

For the moment though, I've found a way to do it, and that'll keep me going as a demo to the IT area here.  What I've done is taken advantage of the legacy course files option!  I know, lazy hey.  But it works beautifully, as soon as you upload the banner.jpg image into a course's legacy files area, the site uses the image in the header area.  Being a legacy set up, all I had to do was use the course id, and file.php:

$file = $CFG->wwwroot . '/file.php/' . $COURSE->id . '/banner.jpg';
echo (a div with the $file in it).

There's a couple of little things I need to sort out. Logic conditions.. such as finding out if I can test if the banner.jpg actually exists first. Even though I should really concentrate on setting it all up properly with the moodle 2 file format I think I'm going to have to live with using the legacy files for the moment.