Monday, 17 November 2014

Datatables in a bootstrap 3 modal window

Datatables is an important javascript plugin for jQuery to improve behaviour of our website tables.

Recently I saw that using tables (datatables tables) in a bootstrap modal window, after init the table, part of table was shown outside of the window.

I'm using version 1.9.3 of datatables, version 1.10.2 of jQuery and versio 3.0.1 of bootstrap.

My solution was use "fnDrawCallback" function in order to change the window's size after "drawing" the table:

tableObject = $('#idTable').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "ajaxSource",
"fnDrawCallback": function( oSettings ) {
$('#idTable').find('.modal-dialog').css(
{
width:'auto',
height:'auto',
'max-height':'100%'
});
},
'aaSorting': [[ 0, "asc" ]]
});


Kind regards!

Sunday, 9 November 2014

Moodle: get top category from course data

Hello!

If we have course data and we want to get top category from that, we can do this:

$category = $DB->get_record('course_categories', array('id' => $courseObj->category));
$arrCats = explode("/", ($category->path));
$topCategory = $DB->get_record('course_categories', array('id' => intval($arrCats[1])));


Best regards!

Sunday, 26 October 2014

Moodle: purge all caches by console

Hello,

If we have a moodle installed, a very interesting method to delete all caches is to use system console. To do that, we have to go to our moodle route and execute:

php admin/cli/purge_caches.php

Best regards!

Saturday, 18 October 2014

Backup with rsync

Hello,

Today I set up a bash script in order to create backups with rsync. I created it in a OS 10.7.x (Lion) environment. Steps I did are:
Best regards!

Wednesday, 10 September 2014

PHP: Clean uploaded filenames

Hello,

When a file is uploaded to a server, you could have filenames with characters that can cause problems. To clear the filename you can use:

$filename = time().'_'.$_FILES["file"]["name"]; // File name.
$filename = preg_replace('/[[:^print:]]/', '', $filename); // Replace illegal chars


Regards!

Wednesday, 9 July 2014

Laravel 4: Create multi language page with session

Laravel is a strong PHP framework that is widely used. Recently, I was developing with that framework and I needed to create a website with content in 2 languages: catalan and spanish.

To solve this problem you can use some options... like url with language or save language in session. I decided to use the last one.

I created this code:

filters.php

App::before(function($request) {
// We use the locale of the session
if ( Session::has('locale') ) { App::setLocale(Session::get('locale')); }
});

BaseController.php

class BaseController extends Controller {

public function switchLocale($lang) {
// We change the locale lang in the session and redirect back (see filter language in filters.php).
if ( in_array($lang, Config::get('app.available_language')) ) {
Session::put('locale', $lang);
}
return Redirect::back();
}
}

app.php

'locale' => 'es',
'fallback_locale' => 'ca',
'available_language' => array('es', 'ca'),

Finally,  in our view we use this code in the links used to change the language:

Catalan -> URL::action('BaseController@switchLocale', array('ca'))
Spanish -> URL::action('BaseController@switchLocale', array('es'))

Wednesday, 4 June 2014

felogin: actions to do after login

Sometimes inside a TYPO3 website after install and config felogin, we would like to do some actions everytime that user would acces to website. To do that, we can use an extension hook. In this example we use TYPO3 4.5.32 and 1.3.1 felogin.

Inside ext_localconf.php of our extension:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['login_confirmed'][] = 'EXT:test_extension/hooks/class.feloginhook.php:test_extension_hooksHandler->onLogin';

Inside class.feloginhook.php:

class test_extension_hooksHandler { public function onLogin() { // Actions to do here... Insert in a database, in a log... redirections... } }

Regards!