Monday, 25 March 2013

Moodle 2.4 Blocks Changes in Code

I was looking for a module block for Moodle  My client wanted a scrolling Testimonials block. Ideally they wanted to have a set of several testimonials that could easily be edited and would display in a random order and maybe scroll across the block. I had a look for such a thing, but couldn't find anything, so I decided to write one myself.
There was a good looking tutorial to get started so I did. The only problem was that it didn't work. If I took their code and put it up it just broke Moodle telling me that the block had errors in it.
I initially decided that it was me and making silly typos. Having got rid of my only mistake the thing still didn't work. so I went back to basics.
This is a very simple block just to display some text. It works with Moodle 2.4.

block_testimonials.php


<?php

// This file is part of Moodle - http://moodle.org/

/**
 * Form for editing banners block instances.
 *
 * @package   testimonials Philip M Russell Ltd
 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
 * @license   http://www.gnu.org/copyleft/gpl.banners GNU GPL v3 or later
 */

class block_testimonials extends block_base {

    public function init() {
        $this->title = get_string('pluginname', 'block_testimonials');        
    }
public function get_content() {
    if ($this->content !== null) {
      return $this->content;
    }

    $this->content         =  new stdClass;
    $this->content->text   = 'BRE Training is a great place to learn how to do things properly.';
    $this->content->footer = 'BRE Training';

    return $this->content;
  }
}   // Here's the closing bracket for the class definition


Version.php


<?php
// This file is part of Moodle - http://moodle.org/

/**
 * Version details
 *
 * @package    testimonials
 * @subpackage html
 * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined('MOODLE_INTERNAL') || die();

$plugin->version   = 2012112901;        // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires  = 2012062500;        // Requires this Moodle version
$plugin->component = 'block_testimonials';      // Full name of the plugin (used for diagnostics)
$plugin->cron      = 0;
$plugin->maturity  = MATURITY_BETA;
$plugin->release   = '2.3 (Build: 2012112900)'; 

db/access.php


<?php

// This file is part of Moodle - http://moodle.org/
/*
* @copyright 2013 Philip M Russell Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$capabilities = array(

'block/testimonials:myaddinstance' => array(
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
)

);

lang/en/block_testimonials.php


<?php

// This file is part of Moodle - http://moodle.org/
/**
 * @package   testimonials
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
 * @license   http://www.gnu.org/copyleft/gpl.banners GNU GPL v3 or later
 */


$string['pluginname'] = 'Testimonials block';
$string['testimonials'] = 'Simple HTML';
$string['testimonials:addinstance'] = 'Add a new simple HTML block';
$string['testimonials:myaddinstance'] = 'Add a new simple HTML block to the My Moodle page';

edit_form.php


<?php

class block_testimonials_edit_form extends block_edit_form {

    protected function specific_definition($mform) {

        // Section header title according to language file.
        $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));

        // A sample string variable with a default value.
        $mform->addElement('text', 'config_text', get_string('blockstring', 'block_testimonials'));
        $mform->setDefault('config_text', 'default value');
        $mform->setType('config_text', PARAM_MULTILANG);        

    }
}

Each of these php programs is saved into a directory called testimonials and was copped by into moodle/blocks.

On loading Moodle the block was detected and I was asked to update the Moodle database. If there are any errors then this shows up straight away. Then it is necessary to remove the block and recode.



Thursday, 14 March 2013

10 questions to ask about a new website

Many people have a web site because it seems the right thing to do. But often you need to ask some questions of yourself before you get started.


10 Questions to ask about why you need a website.


  1. Why do you want a website?
  2. Why do you need a website?
  3. What is the mission or purpose of the company / organisation?
  4. What are your short and long-term goals for your website?
  5. Who are the intended audiences for your website?
  6. Why will people come to your site the very first time?
  7. What will make them want to come back?
  8. What content will make up your website?
  9. What content do you have?
  10. Why shouldn't I build this myself?
Why do you want a website? 
This is often a killer question that many cannot answer. Web sites are not really for fun, they are there for business and primarily to make money. If a business is doing things just for fun then just how is it making money?

Why do you need a website?
This is the better question. You need a website to market. your company, as an alternative sales place, to get information about what you do to your customers, to add items to your company that cannot easily be obtained in any other way.

What is the mission or purpose of the company / organisation?
Once you have identified this, this can be accentuated in your web site. If your purpose is to make money then an eCommerce website rather than a bricks and mortar shop my be the solution. If is amazing what can be bought over the web. Many things that are often thought cannot be sold over the web are being successfully done by other - possible your rivals.

What are your short and long-term goals for your website?
Having a web site without a goal gives you no idea whether this a bottomless pit you have opened up or whether the site is in fact making money for you. Once the web site is going, set short term targets and see if you are achieving them. If not change the target or change the web site, or change your strategy.
Short term goals are only part of long term goals. Long term goals are about profit and success. Theses need to be carefully monitored and tested.

Who are the intended audiences for your website?
Website are bought by companies, but the users don't work for the company. Many sites are written by the company with little regard for the person who is actually going to use them. Some of my clients say that they want this or that. What they should be saying is that my clients want this or that to help them ......
Very few companies seem to have a really good idea who their audience is. For some it is obvious, but for others your perceived audience is often not your intended audience. If you know who your audience is then the website can be used to target them and increase your sales.

Why will people come to your site the very first time?
There are probably a hundred or so web sites like yours. Why should some one choose yours over anyone else's.  I am told by many of my customers that their product is better than others. But how to put this over. Products are one thing but websites are something else. Some people only go to the top website on the list in Google because it must be the best. Gimmicks work - have something on your website that someone wants. Sometimes you need some thing to attract the customer and perhaps something to make them come back. Some type of work is essential to get you to the top of the search engine list.

What will make them want to come back?
Getting the customer to your web site for the first time is hard enough, but now you need to keep them coming back. Some use a new calendar every month. Some have email lists and special offers every month or day. Some use gift tokens and money off. Change is a must. A website that stays the same gives on one a reason to come back. A site that changes or a dynamic site can make all the difference.

What content will make up your website?
Some of my clients really do say to me build me a website - I do such and such. They give me no content or details and expect me to know all about their company, what they do and how they do it. You know your business better than anyone else. You know what you do and how you do it and this is what sets you apart from the rest. 

What content do you have?
As a web developer I need pictures of work done, the property, the product, how its done and this is often very lacking. I usually have to do this myself or employ a professional photographer to get first class images of the business. I then need special graphical images made up to simplify and explain the processes. A company is about doing its thing. A website is about promoting and selling this idea or product. The two often don't go together.

Why shouldn't I build this myself?
I'm a Garage owner - why shouldn't I build a web site - surely there are lots of good tools out there. Probably because for the same reason that I can buy great spanners and a car manual, but it doesn't mean that I can fix the car properly. My mechanic charges me £50 for mending my car, £5 for hitting it and £45 for knowing where and how hard. The same is true for websites. Millions of new websites appear on the internet everyday. You want yours to be number one.

Wednesday, 13 March 2013

Ie8 emulator isn't the same as the real thing

I have been doing a fair bit of work recently for a company do Moodle design.. Many of their staff still use IE8 and XP. Gradually their staff are moving over to IE9 and 10 and Chrome. I have been creating Moodle sites for them and we need to look at the site in all the Browsers including IE8
Now the easiest way of doing this is to fire up a load of browsers on a PC and have a look at the web site on the different browsers. Because of the difficulty in having IE8 and IE9 on the same machine, I have been putting IE10 into emulator mode and running it as IE8. (press F12 to call up the  Code popup) Selecting the Browse Mode as IE8 and the Document Mode as IE8 is supposed to make this browser behave as IE8. Now for most pages this seems to work. Some of Moodle behaves as I would expect it to, but some doesn't. Therefore I have had to either use an old XP machine or to load up the Microsoft emulator and run a copy of XP with IE8. This is a pain, but at least it works.

So when is IE8 not IE8 when IE10 is pretending to be IE8