Dynamic logo display in courses

Dynamic logo display in courses

by Ray Lawrence -
Number of replies: 40
Hi,

I'd like to set up a course so that a course specific logo is displayed in the header. The behaviour I'd like is essentially the same as the standard logo theme but specific to individual courses.

Can anyone give me any pointers?

Average of ratings: -
In reply to Ray Lawrence

Re: Dynamic logo display in courses

by Sam Hemelryk -
Hi Ray,

The first thing to springs to mind is to include the logo through CSS as a background image in which case you will be able to very easily swap the logo based on the CSS classes that get added to the body tag.
When viewing a course a CSS class such as course-{courseid} e.g. course-1, course-2, course-3 gets added to the body tag. This happens in both Moodle 1.X and Moodle 2.0.

If you would rather include a standard image tag then perhaps you could let us know which version of Moodle you using?

Cheers
Sam
In reply to Sam Hemelryk

Re: Dynamic logo display in courses

by Ray Lawrence -
Hi Sam,

Indeed, but access to the server to update images isn't an option here. 1.9.x btw
In reply to Ray Lawrence

Re: Dynamic logo display in courses

by Mary Evans -
Ray do you have Admin rights for your VLE site? If so then you can up load images to Site Files, and link to them via CSS.

Did you see my last comment on this thread? About the discussion about this very subject of alternative header images in courses?

Mary
In reply to Mary Evans

Re: Dynamic logo display in courses

by Ray Lawrence -
Hi Mary,

Yes I did. If I read it correctly this requires changes to references in CSS which requires server access. The latter is not an option for the site in question.
In reply to Ray Lawrence

Re: Dynamic logo display in courses

by Mary Evans -
Well how do you expect any of it to work if you don't have access to the server? Even if we could come up with a css file and a php file with the necessary code to do what you want, you would still need to upload the files...one way or another. How do think Moodle works? By magic!

In reply to Mary Evans

Re: Dynamic logo display in courses

by Ray Lawrence -
Indeed. smile

The challenge is to come up with the code that will reference an image file in a location where the end users can upload without access to the server. Although we take server access for granted there are many users, such as the ones who need this solution, who are never permitted server access.

Thanks to everyone for their suggestions so far... I'm sure there must be a way.
In reply to Mary Evans

Re: Dynamic logo display in courses

by Steven A -
Mary,

The admin, who has access to the server, sets up an environment in which teachers, who don't have access to the server, can upload content though the Moodle UI during course creation/editing. It's magic! wink
In reply to Steven A

Re: Dynamic logo display in courses

by Mary Evans -
Steven,

We have to assume NO access to the server. User Interface will NOT be an option as this will not be included in Moodle 2.1.x although it is included as Legacy Files in Moodle 2.0 for the present.

The alternative, and there are numerous to follow here, is that everything would have to be done using the Evans Server Protocol (ESP where imagination is KEY - think it and it happens).

rofl.gif

Mary ROFL






In reply to Mary Evans

Re: Dynamic logo display in courses

by Steven A -
I understood "without access to the server" to mean "no admin access" or "no access to the Control Panel of the hosting service".

And by "Moodle UI" I meant the "front end of Moodle".

I believe Ray is looking for a way to upload a dynamic course logo in much the same way that you uploaded the ROFL icon: via an upload field placed neatly in the Moodle UI. wink
In reply to Steven A

Re: Dynamic Logo - Server Access

by Mary Evans -
It's not an uploaded image, it's hot linked.

Server access, is server access you either have it or you don't.

If a teacher/course creator can up load files/images via the Moodle UI then that is, technically speaking, having access to the server, a limited access I grant you, but access non the less, but let's not quibble about it...life's too short.
In reply to Mary Evans

Re: Dynamic Logo - Server Access

by Steven A -
Mary,

Please go back and read Ray's post above. He says, "the end users can upload without access to the server". (LINK)

You ask us to not quibble - and I apologize if you interpret my tone as quibbling; I'm not intending it to be so - but the semantics are important here because they are causing an important misunderstanding.

I believe Ray is looking for a way to empower his end users to upload dynamic logos to their courses without direct access to his servers. My suggestions have been based on this understanding.
In reply to Steven A

Re: Dynamic Logo - Server Access

by Ray Lawrence -
Hi,

My apologies my terminology seems to have confused the issue. To clarify:

Server access: Direct access to the server using FTP, SFTP etc. Required to upload images or alter CSS files directly on the server.

The target users are able to upload files using the Moodle GUI. They may be admins but mainly users assigned to the Teacher role in courses.

"I believe Ray is looking for a way to empower his end users to upload dynamic logos to their courses without direct access to his servers." Exactly! smile
In reply to Ray Lawrence

Re: Dynamic Logo - Server Access

by Mary Evans -
Ray,

My original misunderstanding came from this post I made earlier in the discussion, where I suggested uploading to the Site Files your answer stated no access to the server was possible, or words to that effect.

In the light of recent discussion I have added some more thoughts on the challenge HERE just below your comment to Frank.

Mary


In reply to Mary Evans

Re: Dynamic Logo - Server Access

by Ray Lawrence -
Ah, I see.

I was referring to the requirement to have server access to the CSS files.

I have access to site files but teachers don't.

Ray
In reply to Ray Lawrence

Re: Dynamic Logo - Server Access

by Mary Evans -
Ray,

My point was that you can STILL have access to a CSS file which has been uploaded to Site Files by a Teacher. I've used this option my self on occasion for a similar purpose, and for the same reason, because, updating the main CSS in the theme folder was not accessible without a lot of messing about. The use of this CSS file was more to style a page, not the header, although there is nothing to stop you trying this method out. It just needs a little bit of HTML and CSS know how, easy enough to learn for a teacher I would have thought!

Mary
In reply to Ray Lawrence

Re: Dynamic logo display in courses

by Steven A -
Have you thought of using the course summary to accomplish a dynamic logo?

Start by putting an image into the course summary (Administration>Settings). Then put the following code somewhere in your theme's header, or wherever you want the dynamic course logo to appear:

<?PHP
if (!empty($COURSE->summary)) {
echo $COURSE->summary;
}
?>

In reply to Steven A

Re: Dynamic logo display in courses

by Ray Lawrence -
Thanks Steven,

Unfortunately images in the course summary will be displayed when viewing courses in a category and this isn't desirable for us.

Could this approach be modified for an image located in course files
In reply to Ray Lawrence

Re: Dynamic logo display in courses

by Steven A -
Ray,

I'm sure it could, but unfortunately I don't know how to implement it. And I bet it would require significant changes to the core code.

How about the low-tech approach of just putting the dynamic logo in topic 0?
In reply to Steven A

Re: Dynamic logo display in courses

by Frank Ralf -
Hi Ray,

I've created a screenshot how I have understood the suggestions so far. I don't quite understand the problem with putting the image in topic 0.

Perhaps you could post a screenshot what you want to achieve.

tia
Frank
Attachment Topic_0_summary_with_image.png
In reply to Frank Ralf

Re: Dynamic logo display in courses

by Frank Ralf -
And here's another one:

Inserting an external image into a specific course's header by using external CSS via Firefox add-on Stylish.

This is only meant as a proof of concept. The modifications only apply on your own computer where Stylish is installed.

hth
Frank
Attachment External_course_image_with_Stylish.png
In reply to Frank Ralf

Re: Dynamic logo display in courses

by Ray Lawrence -
Yes that's the broad effect. However, in the example shown the teacher would need to be able to adapt the path in the CSS or only one header image could be used.
In reply to Frank Ralf

Re: Dynamic logo display in courses

by Ray Lawrence -
Hi Ralf,

I understood Steven to mean the "summary" area in course settings rather than topic 0.
In reply to Ray Lawrence

Re: Dynamic logo display in courses

by Steven A -
Yes, I meant the course summary area, editable via the course settings as in the screenshot below. In this example, the teacher uploads the dynamic logo to the course summary, which is controlled by the HTML editor. The logo then appears anywhere you want it to depending on where you add the PHP code I mentioned in an earlier reply. In the screenshot, you can see I've added it just below <div id="page"> in header.html of the standard theme.

Ray, I believe this is what you have been trying to achieve, just in an area that is not the course summary. If so, you might want to think about creating (1) another instance of the HTML editor on the "Edit course settings" page, and (2) another snippet of PHP that will call the logo based on course ID.

The CSS solution seems unworkable because it requires teachers to have access to CSS files. If you want the logo to be editable via the front end, then I think you will need to create a new upload field for your teachers on the "Edit course settings" page (requires modifying the core code) and then placing some snippet of PHP in your theme that will call your dynamic logo based on course ID.

If I can ask, why is using Topic O not an option?
Attachment dynamicLogo.png
Average of ratings:Useful (1)
In reply to Steven A

Re: Dynamic logo display in courses

by Frank Ralf -
Hi Steven,

That's cool! Now I understand: You (miss-) use the course summary as a container for the uploaded image and output the image via PHP anywhere in the theme you want.

But for injecting the PHP into theme you will have to have write access to the theme files on the server, which isn't the case with Ray, if I understand correctly.
In reply to Frank Ralf

Re: Dynamic logo display in courses

by Ray Lawrence -
Hi Frank,

Not quite. The theme can include whatever PHP as the server admin will upload this (once).

It must be able to be used with a course specific image that the Teacher can upload in the Moodle gui. Therefore it must be capable of dealing with a variable course ID number.
In reply to Frank Ralf

Re: Dynamic logo display in courses

by Mary Evans -
In that case would it be feasable to have a set of themes based on the parent theme but incorporating the dynamics of the "Standard Logo" theme, where each seperate theme's logo has a unique filename, where this filename is embedded in the header code for the theme as is found in Standard Logo's header.html?

For Example in the theme for Course 1 the php in the header would be as follows:

if (file_exists($CFG->dirroot.'/logo-course1.jpg')) {
$standardlogo = $CFG->httpswwwroot.'/logo-course1.jpg';
} else if (file_exists($CFG->dirroot.'/logo-course1.gif')) {
$standardlogo = $CFG->httpswwwroot.'/logo-course1.gif';
} else if (file_exists($CFG->dataroot.'/1/logo-course1.jpg')) {
require_once($CFG->libdir.'/filelib.php');
$standardlogo = get_file_url('1/logo-course1.jpg', null, 'httpscoursefile');
} else if (file_exists($CFG->dataroot.'/1/logo-course1.gif')) {
require_once($CFG->libdir.'/filelib.php');
$standardlogo = get_file_url('1/logo-course1.gif', null, 'httpscoursefile');
}

This then would allow the Course Creator/Editing Teacher to upload course specific logos, each with their unique filename, to the Server Files via Moodle UI

And when the Course Creator/Editing Teacher creates a course which needs a course specific logo in the header, all they need do is select the desired theme pertaining to that specific logo in order to achive the desired outcome.

Would you say this method is within the remit for the 'challenge' Ray?

Mary
In reply to Frank Ralf

Re: Dynamic logo display in courses

by Steven A -
Hi Frank,

Cool, eh? Yes, this is my "misuse" of the course summary. wink

Injecting the PHP into the theme does require access to the core files (the theme), but once the PHP has been injected once, that's it. Then the PHP calls the course ID dynamically for each course. No more maintenance is necessary.
In reply to Steven A

Re: Dynamic logo display in courses

by Ray Lawrence -
Yes, another location that can e called dynamically is needed. Changes to core aren't possible either.

Topic 0: The differentiation needs to be in the header as part of the theme to save valuable space in the remainder of the visible area of the course page.
In reply to Ray Lawrence

Re: Dynamic logo display in courses

by Steven A -
Hi Ray,

Thanks for explaining. Yes, I agree with you about valuable screen real estate. That's why I explored and eventually discovered the course summary trick.

For your situation, without being able to modify the core code, you'll need some function that is already in Moodle that you are not currently using, and that you can commandeer for this dynamic logo. For me, that function is the PHP I mentioned above. For your situation, I unfortunately don't know what to recommend.
In reply to Ray Lawrence

Re: Dynamic logo display in courses

by Ray Lawrence -
Oops, sorry Frank. I called you Ralf in an earlier reply. That happens to me too.
In reply to Ray Lawrence

Re: Dynamic logo display in courses

by Frank Ralf -
No probs. You're not the first and won't be the last wink
In reply to Frank Ralf

Re: Dynamic logo display in courses

by Mary Evans -
That's too easy Frank, Operator D would be more of a challenge!
In reply to Ray Lawrence

Re: Dynamic logo display in courses

by Steven A -
Ray,

I believe I have found a solution that you might like. It requires a one-time modification of your theme's header.html to inject the following code:

<div id="dynamic-logo">
<?PHP
echo '<img src="'.$CFG->wwwroot.'/file.php/'.$COURSE->id.'/logo/dynamic-logo.jpg" />';
?>
</div>


It is simply a formula that will construct a link which points to a file called "dynamic-logo.jpg" in a folder called "logo" in a given course (generated dynamically with $COURSE->id) on your domain (also generated dynamically with $CFG->wwwroot). I've also surrounded the dynamic logo with a div called "dynamic-logo" so that it may be styled to your liking in CSS. Feel free to change the names of the file, folder, and div. My example is only for example. wink

The dynamic logos are stored within the course, so your teachers will be able to upload a file through the Moodle UI. One caveat: instruct your teachers that the logo must be a named "dynamic-logo.jpg" and it must reside in the "logo" folder within the course (or whatever nomenclature you choose).

If the PHP finds a logo, it displays it. If it finds nothing, it displays nothing.

I've tested it locally (see screenshot). Let me know what you think.

Attachment dynamicLogo2.png
Average of ratings:Useful (2)
In reply to Steven A

Re: Dynamic logo display in courses

by Frank Ralf -
Hi Steven,

That's really cool!

Where did you get that $CFG->wwwroot.'/file.php/' part from? I tried $CFG->dataroot .'/'. $COURSE->id but couldn't get it to work properly.

Cheers,
Frank
In reply to Frank Ralf

Re: Dynamic logo display in courses

by Mary Evans -
Frank,

The file.php part is given in the URL for standard logo image. If you look at the image in a standard logo theme the URL looks like this for my website...
.

What I did not realise, was that by adding the $Course->id inplace of the 1 in the above URL using the same heading code in the Standard Logo theme you can assign a number of logos for different courses. This puts a whole new dimension in Moodle theme design, which I am sure Ray will no doubt be talking about in his next How to Moodle book.

Cool!

Mary
In reply to Mary Evans

Re: Dynamic logo display in courses

by Frank Ralf -
Well, actually I got that idea from your remark above that a theme could use a CSS file from a course's file section... wink
In reply to Frank Ralf

Re: Dynamic logo display in courses

by Steven A -
Hi Frank,

Thanks! Cool, eh?

I got the $CFG->wwwroot part from the config.php file. The file.php part is a part of the absolute URL of *any* file uploaded to course files. wink

So you tried $CFG->dataroot? That is the location of the "moodledata" directory (we also know this from config.php) and would insert "moodledata" into the URL. But if you look at the absolute URL of any file uploaded to course files, they all have the same basic structure: www.domain.com/moodle/file.php/...

So the domain name I got from $CFG->wwwroot, the file.php bit I threw in because it's always there, the course ID is of course $COURSE-id, the directory structure and filename thereafter I just decided arbitrarily (logo/dynamic-logo.jpg), and then I just concatenated the bits and pieces together, oh and also crossed my fingers. wink