Sunday 7 December 2014

Moodle: custom CSS in Essential theme

When you want to custom a moodle instance, you could need to modify Essential theme, for example, I don't want to see headers in SCORM content. The best option is use customcss property.

We go to admin/settings.php?section=theme_essential_generic in our site and we search for customcss textarea. To avoid seeing headers in SCORM, we add:

#page-mod-scorm-player div[role=main] h2 {display: none;}
#page-mod-scorm-player header[role=banner] {display: none;}


Best regards!

Tuesday 2 December 2014

Install MAMP + Laravel 4

Hello,

Today I installed in Mac OS X (10.7.5) server MAMP (3.0.4) + Laravel 4. I did these steps:
  • First, I downloaded and installed MAMP from http://www.mamp.info. I modified default conf changin ports to 80 and 3306.
  • Next, I modified file bash_profile (vim ~/.bash_profile): export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH alias composer="php /usr/bin/composer.phar" alias laravel="~/.composer/vendor/bin/laravel"
  • Then, I reset terminal and downloaded composer: curl -sS getcomposer.org/installer | php.
  • Next step, move composer.phar: sudo mv composer.phar /usr/bin/
  • I donwloaded Laravel 4 installer: composer global require "laravel/installer=~1.1"
  • I went to /Applications/MAMP/htdocs and I created a new Laravel project: laravel new ibancardonasubiela.tk
  • Then, I created a new virtual host in my MAMP. To do that, I edited file Applications/MAMP/conf/apache/httpd.conf and I uncommented "Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf". Then I edited file Applications/MAMP/conf/apache/extra/httpd-vhosts.conf and I added: <VirtualHost *:80>                     DocumentRoot /Applications/MAMP/htdocs/ibancardonasubiela.tk/public                                   ServerName wwww.ibancardonasubiela.local </VirtualHost>
  • I restarted MAMP service.
  • I edited file  /etc/hosts (sudo vim /etc/hosts) adding: 127.0.0.1 www.ibancardonasubiela.local
  • And, finally, Laravel installed in http://www.ibancardonasubiela.local/

Moodle: Delete one file in moodle filesystem

Hola,

After seeing how to add files and how to list them. Today we will see how to delete them:

$fs = get_file_storage();

// Prepare file record object
$fileinfo = array(
'component' => 'backup',
'filearea' => 'course',
'itemid' => 0,
'contextid' => 0,
'filepath' => '/',
'filename' => 'filename.xlsx'
); 


// Get file
$file = $fs->get_file($fileinfo['contextid'], $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'], $fileinfo['filepath'],
$fileinfo['filename']);

// Delete it if it exists
if ($file) {
if ($file->delete()) {
return true;
} else {
return false;
}
}


Best regards!

Monday 1 December 2014

Moodle: list files in moodle filesystem

Hello,

Last day we saw how to create an excel file in modle: http://icsbcn.blogspot.com/2014/11/moodle-create-and-save-excel-file-in.html

If we want to list that files, we can do this:

// List excel files
$table = new html_table();
$table->head = array('filename', 'filedate', 'filesize', '');
$table->align = array('left', 'left', 'left','left');


// Get files
$fs = get_file_storage();
$files = $fs->get_area_files(0,  'backup', 'course', 0, 'timemodified DESC', false);
foreach ($files as $file) {
$filename = $file->get_filename();


$row = array();
$row[] = $filename; // filename
$row[] = date('d/m/Y H:i:s', $file->get_timecreated()); // creation date
$row[] = $this->formatSizeUnits($file->get_filesize()); // file size as human view


// Download link
$url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $filename);
$row[] = html_writer::link($url, get_string('downloadfile', 'moodle'));


$table->data[] = $row;
}
// End get files


$content .= html_writer::start_tag('div', array('id' => 'list_files'));
$content .= html_writer::table($table);
$content .= html_writer::end_tag('div');
// End list excel files

Best regards!