Friday, November 7, 2008

Fedora 9 and mouse clicking problems

After a recent yum update around early November 2008, my mouse clicking started to have problems. Clicking on icons in the panel would not launch xterm, and clicking on the title bar of windows would maximize them. I also clicked on the Application menu in the panel and they would instantly close.

This was odd mouse behavior.

What I finally discovered is that although I was single clicking, linux was registering them as double clicks.

Changing nautilus or gnome settings didn't affect anything.

After reading this post

http://groups.google.com/group/linux.debian.bugs.dist/browse_thread/thread/36589b112565db28

they suggested that x was registering clicks on multiple mouse devices. For me it was /dev/input/mice an /dev/input/mouse0. This caused a single mouse click to be repeated.

in my xorg.conf i had the line
Option "Device" "/dev/input/mice"

I changed it to

Option "Device" "/dev/input/mouse0"

and it solved the problem.

/dev

Sunday, October 5, 2008

Formatting the result returned from a custom query in cakephp.

When you do custom queries with cakephp, the data is returned in mysql's format

For example

$this->User->query('Select * from cars as Car');

array(
[0] => array('Car' => array('name' => 'ford',
        'colour' => 'yellow')),
[1] => array('Car' => array('name' => 'toyota',
        'colour' => 'green')),
[2] => array('Car' => array('name' => 'nissan',
        'colour' => 'pink')))

What we want though is a more cakephp result set that looks like what we would get from a ->find('all') query:
eg.
array(
array('Car' => array(0 => array('name' => 'ford',
        'colour' => 'yellow'),
1 => array('name' => 'toyota',
        'colour' => 'green'),
2 => array('name' => 'nissan',
        'colour' => 'pink')) );


Solution:
Use the set extract function and assign it to a string

array('Car' => Set::extract($this->User->query($sql), '{n}.Car'))

Friday, September 26, 2008

VMware Server 2.0 Problems with mouse tracking in linux fedora 9

After installing the vmware 2.0 server I thought I'd check if there was a change with the vmware-toolbox.

You can install it by going to:
Installation -> Fedora 9 -> right hand menu called Status

Click on Upgrade/Install VMware Tools

This will bring up the vmware tools rpm, install it and run /usr/bin/vmware-config-tools.pl

Select all the default settings (if you mess up I think you can select -c and it will try to compile it for your kernel).

***

After all of that I found my mouse wasn't clicking where the cursor was. It was off by an inch depending on which side I entered the linux window. If I dragged and selected, the selection box was on another part of the screen.

Solution:
Look at /etc/X11/xorg.conf There are a bunch of new vmware settings that weren't in the previous versions. I don't have time to take apart the settings, but it looks like something is up with the vmware mouse drivers.

I copied an old xorg.conf.old.1 (probably auto backed up by vmware-config) into xorg.conf and it cleared up the problem.

Downside is if you don't use the vmware settings in xorg.conf, your system will automatically boot with vmware-toolbox and take up a spot on your toolbar. Using the vmware settings in xorg.conf seems makes everything automatic.

Thursday, August 28, 2008

HABTM cakephp and pagination with fields in the join table

Paginating HABTM: Brief version.

What I needed to do was to figure out how to paginate based on data within a join table. Most join tables contain two foreign keys referencing the two parent tables. I had a third field called type_id that I used to state what kind of role each user played.

We have three tables

CREATE TABLE `users` (
`id` int(11) NOT NULL default '0',
`name` varchar(50) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE `groups` (
`id` int(11) NOT NULL default '0',
`name` varchar(50) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;

Which has a has and belong join table called:

CREATE TABLE `users_groups` (
`user_id` int(11) default NULL,
`group_id` int(11) default NULL,
`type_id` int(10) unsigned NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`)
) ENGINE=InnoDB;

At this point we have the typical model files for groups and users. Which is enough to do queries between the two tables. Cakephp will automatically query the join table when doing pagination.

A problem arises now if we want to query the type_id as one of our conditions.

eg.
we have Bob
User - Bob who's in Group 'Car Group' and is an 'advisor type'. ie his type_id is 3.
User - Bob is also in Group 'Truck Group' and is a 'guest type' and type_id = 4

Some solutions have been:
1) change the users_groups join table and add an 'id'. This allows you to treat it as a model and paginate it. You also create a file in ./models/users_groups.php.
2) Instead of adding an 'id' and preserving the 'join' tableness of users_groups, you write a custom paginate() and paginateCount() query.

eg.
function paginate ($condition, ...) { $sql = 'Select....'; return $this->query($sql)}

My Solution:
create a file ./models/users_groups.php
class UsersGroup extends AppModel {

var $name = 'UsersGroup';

var $belongsTo = array('User', 'Group');
public $actsAs = array('Containable');
}

In your controller

function index() {
$this->paginate = array('UsersGroup' => array( 'contain' => 'Group', 'fields' => array('Group.*')) );

pr($this->paginate($this->User->UsersGroup, array('UsersGroup.user_id' => 1, 'UsersGroup.type_id' => 3)));
}

Conclusion:

That's it. Now you be able to find what groups bob is an advisor in.