Saturday 31 January 2015

Easy clock with Javascript (jQuery)

Hello,

An easy and fast way to develope a clock that is updated every minute:

<div class="clock">
<i class="fa fa-clock-o"> </i><span>15:51</span><script type="text/javascript">
var intervalclock = 0;
function startClock() {
  setTimeout(function() {
    print_clock();
    intervalclock = 60;
    setInterval(function() {
      print_clock();
    }, intervalclock * 1000);
  }, intervalclock * 1000);
}
    
function print_clock() {
  var now = new Date();
  var hour = now.getHours();
  var minute = now.getMinutes();
  if (minute < 10) { minute = "0" + minute; };
  var timeString = hour + ':' + minute;
  $('.clock\ > span').text(timeString);
}
    
$(window).load(function() {
  var timeclock = new Date();
  intervalclock = 60 - timeclock.getSeconds();
  if(intervalclock == 60) {
    intervalclock = 0;
  }
  startClock();
});
</script>
</div>

Best regards!

Thursday 8 January 2015

Moodle: Number of courses in which a user is enrolled

Hello,

Moodle is a software designed to create online courses. You can add a lot of tailor-made plugins.

One of the most interesting info that would be interesting could be... The number of courses in which a user is enrolled. We can know it by (tested with version 2.6.2):

global $DB;
$sql_count = 'SELECT COUNT(c.id)
FROM mdl_course AS c
JOIN mdl_context AS ct ON c.id = ct.instanceid
JOIN mdl_role_assignments AS ra ON ra.contextid = ct.id
JOIN mdl_user AS u ON u.id = ra.userid
JOIN mdl_role AS r ON r.id = ra.roleid
WHERE u.id = ?';
$courses_count = $DB->count_records_sql($sql_count, array($idUser));


Regards!

Friday 2 January 2015

tt_news: Modify query to database

tt_news is an extension of TYPO3 designed to publish news in our website. It's a very popular extension and it allows publish and manage news about our company, association, etc. You can find extension manual here.

Suppose that we have our own extension with our own plugins and we want to indicate that in the news list we only want news with ID greater than 100... So we should use a hook that is prepared for the extension in order to modify the database query.

In this example we used TYPO3 4.4.4 and tt_news 3.0.1. Files to modify are:
ext_localconf.php

if (TYPO3_MODE == 'FE')  { require_once(t3lib_extMgm::extPath('user_t3_test').'user_t3_test_selectHook.php'); }
$TYPO3_CONF_VARS['EXTCONF']['tt_news']['selectConfHook'][] = 'user_t3_test_selectHook';


user_t3_test_selectHook.php

class user_t3_test_selectHook {
public function processSelectConfHook(&$parentObject, $selectConf) {
$selectConf['where'] .= ' AND uid > 100 ';
return $selectConf;
}


I hope you find it useful! Regards!

Thursday 1 January 2015

Overwrite title tag with TypoScript

TYPO3 is a powerful CMS that uses its own configuration language called TypoScript. This article does not explain what or how to configure TYPO3. In this case only show you how to override the title tag of a page using TypoScript. To develop this example we used a quite old version of TYPO3: 4.2.14 but this solution is also valid for newer versions. Suppose we want new title "Test", then the TypoScript of our template should be:
config.noPageTitle = 2
page = PAGE
page.headerData.10 = TEXT
page.headerData.10.wrap = <title>Test</title>
In the first line we say that we don't want to print the default title. More info here. In the other 3 lines we change the page header adding our title. I hope you find it useful! Regards!