Categories
SugarCRM: really shared calendar
06th February 2009
SugarCRM is a decent piece of software. At least, it doesn’t look bad and source code is not as scary as it could be. However, it could have better documentation (I realized that when I was adding some custom fields to built-in entities). But this is another topic.
And today I am going to tell you about its Calendar feature. My colleagues were wishing it could be easier to share a meeting with others. Yes, sharing is theoretically (and practically) possible. All you have to do is to add selected individuals to your event and they will see it on their calendars in “Shared” section. This sounds like sensible behavior for large companies. However, for a small company like us it is more desirable to have zero-friction sharing. It will bring some informational noise (meetings that don’t really relate to certain individuals), but since we are small company, we can live with it. So, I started looking into the sources and here are my findings. SugarCRM stores association between users and meetings (and other entities, like calls) in join tables, usually named like “meetings_users”. And it uses these tables, when showing calendar. The easiest solution for our problem (zero friction sharing) would be to take that join table out of queries and show ALL meetings. And we will do just that.
Go into <sugarcrm_path>/include/utils/activity_utils.php. In the beginning of the file there will be a function build_related_list_by_user_id. It is used by all calendar routines to extract related events. Find strings:
$select = "SELECT {$bean->table_name}.* from {$bean->rel_users_table},{$bean->table_name} ";
$auto_where .= " {$bean->rel_users_table}.{$bean_id_name}={$bean->table_name}.id AND {$bean->rel_users_table}.user_id='{$user_id}' AND {$bean->table_name}.deleted=0 AND {$bean->rel_users_table}.deleted=0";
And replace them with something like this:
$select = '';
$auto_where = ' WHERE ';
if(!empty($where)) {
$auto_where .= $where. ' AND ';
}
// Use a simpler query in case of meetings.
if($bean->table_name == "meetings") {
$select = "SELECT {$bean->table_name}.* from {$bean->table_name} ";
$auto_where .= " {$bean->table_name}.deleted=0 ";
}
else {
$select = "SELECT {$bean->table_name}.* from {$bean->rel_users_table},{$bean->table_name} ";
$auto_where .= " {$bean->rel_users_table}.{$bean_id_name}={$bean->table_name}.id AND {$bean->rel_users_table}.user_id='{$user_id}' AND {$bean->table_name}.deleted=0 AND {$bean->rel_users_table}.deleted=0";
}
Voila! Thas was easy, wasn’t it? And here is unified diff file for your convenience.
3 Comments »
RSS feed for comments on this post. TrackBack URL
[...] I was implementing previous issue, my manager asked me: “Can we also mark meetings with colors, corresponding to users?”. [...]
Pingback by SugarCRM: More colors! | Thoughts on Software and Computers — February 6, 2009 @ 3:24 PM
Hello,
your patch was what I needed, I had to change it for SugarCRM 5.5.
row 9 becomes:
$select = “SELECT {$bean->table_name}.* from {$bean->table_name}, {$bean->rel_users_table} “;
Thank you,
Andrea
(p.s.: the registration process is painful for just leaving a comment..
)
Comment by andrea — January 11, 2010 @ 6:21 AM
Yeah, maybe you’re right. I’ll disable this pain for a while and let’s see if will get flooded with spam or not
I am glad my post was useful to you
Comment by admin — January 11, 2010 @ 6:51 AM