Archive for 2006

Drawers made from old floorboards

Just put a page up with photos from my latest woodwork project – a small chest of drawers made from some old floorboards given to me. Here’s a picture of it finished…

MSG on Google Maps

Have just done my first version of overlaying geolocation info for MSG users onto Google Maps. At the moment it’s pretty rough and ready (only on my dev server), but seems to do the basics, eg changes the ‘pin’ when a users state changes. Quick screenshot here with users having different presence states:

Another problem for me to work on is how to ‘cluster’ users, as things stand with my map, users will only be clustered if they have exactly the same latitude and longitude – which fairly quickly starts to break down – on the image above there are several pins around Milton Keynes and it’s not really obvious exactly how many users are there – or whether there are more pins hidden behind the pins you can already see.

So I’m going to look to see how we can do the clustering more sensibly (perhaps at different resolutions of Google maps), this was solved quite well in BuddySpace, so I’m going to have a look at the algorithm used there (see the tech report on it) and see if I could apply the same algorithm, or if other algorithms have been developed in the last few years.

PHP arrays & recordsets to Javascript Objects (JSON)

Whilst writing the code for our MSG-Moodle integration, I needed to write a couple of helper functions to turn PHP arrays and ADOdb recordsets into JSON objects, and thought other might find them useful, so here they are:

This one takes an associative array of objects to turn into JSON object:

/**
* @param $objects object to turn into JSON
* @param $name overall name of the JSON object
* @param $callback name of the callback function
* @return string of the JSON object
*/
function phpToJSON($objects,$name,$callback=''){
$str = '';
if ($callback != ''){
$str .= $callback.'(';
}
if ($objects){
$str .= '{"'.$name.'":[';
$okeys = array_keys($objects);
for ($i=0; $i< sizeof($okeys); $i++){
$myobj = $objects[$okeys[$i]];
$attr = get_object_vars($myobj);
$str .= '{';
$keys = array_keys($attr);
for($j=0;$j< sizeof($keys); $j++){
$str .= '"'. $keys[$j] .'":"'. $attr[$keys[$j]] .'"';
if ($j != (sizeof($keys)-1)){
$str .= ',';
}
}
$str .= '}';
if ($i != (sizeof($objects)-1)){
$str .= ',';
}
}
$str .= ']}';
}
if ($callback != ''){
$str .= ');';
}
return $str;
}

and this one takes an ADOdb recordset and turns it into JSON object:

/**
* @param $objects object to turn into JSON
* @param $name overall name of the JSON object
* @param $callback name of the callback function
* @return string of the JSON object
*/
function phpRSToJSON($rs,$name,$callback=''){
$str = '';
if ($callback != ''){
$str .= $callback.'(';
}
if ($rs){

$str .= '{"'.$name.'":[';

$i=0;
while(!$rs->EOF) {
$i++;
$str .= '{';
$keys = array_keys($rs->fields);
for($j=0;$jfields[$keys[$j]] .'"';
if ($j != (sizeof($keys)-1)){
$str .= ',';
}
}
$str .= '}';
if ($i != $rs->RecordCount()){
$str .= ',';
}
$rs->MoveNext();
}

$str .= ']}';
}
if ($callback != ''){
$str .= ');';
}
return $str;
}

Hope you find these useful, and if you spot anything wrong (or that could be done better!) – please feel free to let me know 🙂

Article on JoinIn

New article on the JISC e-Learning Focus site about the JoinIn project I was involved just before I moved over to the OpenLearn project: JoinIn project: Sharing Groups between LAMS and Moodle

left click and right click – spot the difference??

Had fun this morning figuring out how to get the context menu for MSG Alert to display the same context menu when you right or left click on it. You’d think that ought to be very easy to do (and it is when you know how) but it was totally non obvious to me – the NotifyIcon class only has click, doubleclick, mouseclick etc methods, there aren’t any methods which deal solely with left or right clicks.

I tried a variety of approaches (from the number of messages in forums etc this isn’t a new problem!!), most of which used the NotifyIcon.ContextMenu.Show() method. However when I tried this, although the menu appeared fine, a blank item appeared in the taskbar, which looked really horrible!!! In the ended I opted for the method described here. This seemed to be the only reliable way of doing it.

Whilst doing this I also ‘upgraded’ my menu from ContextMenu to a ContextMenuStrip to take advantage of being able to add icons etc etc.

MSGAlert rewritten in Visual C#

Just about finished rewriting MSGAlert in visual c# and we’re now just testing it all out. Has been fairly painless – well, once we decided to go with c# instead of c++. So now users will see a balloon tool tip in the taskbar notification area when a new message is received and should stop some of the problems/comments we had where users didn’t find the notification of a new message to be obvious enough!

Hopefully we’ll not find very many bugs or issues and I can get on with the Google maps that I was playing with before 😉

Visual C++ to Visual C#

So, after a couple of weeks messing around (and to be honest – not getting very far!!!) with Visual C++ finally decided that it was probably best to go with Visual C# .NET instead. C# is much more ‘understandable’ to me, having done Java before, and hope that should make the code much easier to develop and maintain. In fact I’ve got further in couple of days with C# than I had with 2 weeks of C++, and with each I was starting at the same level, I’d not used either before.

Have even got as far (in the recoded MSG Alert program) as connecting up to the server, sending and receiving responses, so I think the ‘hard’ bits are all done, and I just need to spend some time putting it all together 🙂

MSG updated

Have now pretty much finished off moving the MSG block to use JSON style services instead on XmlHttRequest and Chris has made quite a few updates to the BuddyXML service and MSG Client so we don;t get the odd little problems I previously mentioned. One big change is the ability to hook onto existing sessions, so for example if you log in with the MSG web client and then log in with MSG alert, they’ll use the same session, whereas previously you would actually be running two separate instances.

We’ve still got a fair bit more testing to do I think, but so far all seems good 🙂

Now I’m back on the Visual C++ stuff for updating MSG Alert, which is moving (very slowly!) forward, I’ve still got plenty to learn there I think 🙂

Moving MSG-Moodle to use JSON

Spent the last few days updating the MSG-Moodle block so that is uses the JSON method rather than XmlHttpRequest and all seems to be going quite well. It will certainly make the application much more responsive as it makes the MSG-Moodle block a ‘proper’ client rather than having all the communication going via Moodle using a global user. It also means we can flag up when a user receives messages and they are always logged in to MSG if they have logged in to Moodle.

We still have a few problems to overcome, for example the fact that you could have multiple ‘clients’ running – eg the standard MSG Client and MSG-Moodle which causes a few problems for one grabbing presence and message notifications before the other has also obtained the data – this is because the data sits in a queue which is cleared when it;s returned to the client, so if it’s obtained for one client then the queue is clear when the other client requests the info. Hopefully we can get a neat solution to that one.

in the end I think we’ll have ended up almost re-writing the MSG block, but I think it;s definitely worth it if we can get it running ok – especially as it’ll remove all the ‘mess’ of caching presences etc within the Moodle database.

Moodle Roles & Permissions

Also having ‘fun’ trying to implement the new roles and permissions stuff in Moodle, really can’t seem to get it to work how I want, and very few examples of how to use the roles and permissions with blocks seem to exist, the only one is in the RSS block – and I have a suspicion that this isn’t working correctly anyway (not 100% sure)