Ever need to load in a Sugar bean but can’t remember if the directory name is the same as the bean name is the same as the php file containing the bean? Don’t worry you’re not alone. This was a design flaw that has propogated even into the latest versions of sugar. But there’s an easier way. Rather than requiring_once the full path of the php file housing the bean, use the following snippet:
$beanname = ‘Contact’;
require_once($GLOBALS['beanFiles'][$beanname]);
$focus = new $beanname;
Substitude beanname for whatever you want and bingo. This will also help ensure that with future versions of sugar when they add the ability to sublcass and extend in beans you’re loading the correct version.
Software, SugarCRM
Need a json object to output json encoded data? Use the following code sample, the json object is automiatcally included in when the application is started so no requires are needed:
$json = getJSONobj();
$out = $json->encode($ret, true);
@ob_end_clean();
ob_start();
echo $out;
ob_end_flush();
Software, SugarCRM
Some sugar related date functions:
Get the current date time stamp in a database agnostic fashion:
gmdate($GLOBALS['timedate']->get_db_date_time_format());
You’ll notice we use the gmdate function since all dates within sugar are stored in the gmt timezone. The conversions to the user format and timezone are applied when the SugarBean retrieve function is executed.
To convert from db to display format use:
$display_now = $GLOBALS['timedate']->to_display_date_time($now);
Where $now is the db version of gmdate.
Software, SugarCRM
In the process of learning the ropes regarding customizing Joomla. What I’ve found so far has been promising but also disappointing. Working on the 1.5 code base, there is currently no way to safetly overide any language pack entries. Meaning any changes you make will be affected when you upgrade the system. Supposidely 1.6 will address this issue. I’ll keep posting little tidbits of info with regards to what I find…. Perhaps one day I’ll createa cohesive tutorial but I doubt that.
What I really wanted with Joomla was a CMS system that I could hack to hell and that I could use to easily automate the setup, data propogation, and deployment. Why you ask? Well, I’m trying to take advantage of affiliate commissions and am trying to mash some things together. In the process I found that I needed to modify how sections, categories, and components are displayed. Here’s what I’ve found so far. If you need to modify how a component is displayed you can simply copy the default views provided by the system into the theme that you are using. Then you can customize this file to your needs. The benefits to this approach is that you can then simply zip up and deploy your themes with your customizations which makes things slighly easier at least in my opinion. You could modify the core file but why worry about upgradability in the future. For my needs I simply copied in the default.php file from the components/views/section/tmp directory into my theme.
Joomla
Sugar has a Relate type field which can be added on the EditView layout. This field works great for selecting related records from a seperate module. There are really two ways to make a selection, the user can start typing and an auto-fill functionality will kick in. Or, they can use the select button which opens a seperate window. Well, what if we want to apply a callback function afterwards to perform some processing. How do we do that? Well, here’s the easiest way, just copy and paste. Since it’s a Firday night, I’ll update the explanation later:
sqs_objects['account_name']['post_onblur_function'] = ’set_after_sqs’;
/**
* Call back function after auto-fill. Cannot pass in an anonymous function do to bad coding on sugars part.
*/
function set_after_sqs()
{
handleCalculations();
}
/**
* Since we can’t pass in another call back function to the popup window we are appending to the
* exisiting functionality.
*/
var tmpSetReturnFunc = set_return;
set_return = function(popup_reply_data)
{
tmpSetReturnFunc(popup_reply_data);
handleCalculations();
}
Ext.onReady(init);
Software, javascript
SugarCRM uses a notion of metadata files to provide two purposes:
- Define relationships between beans
- Create the necessary table structures used to manage this relationships.
All of the metadata files for the oob modules are stored in the root/metadata folder. The files are ‘registered’ in the TableDictionary.php which is located in the modules directory. If you need to add custom meta data files you can create them and add them to the custom/metadata directory. You will probably need to create this directory yourself. In order to register these new dictionary entries you can simply create a file and add them in here:
‘custom/application/Ext/TableDictionary/tabledictionary.ext.php’
This will ensure that your entries are all upgrade safe.
Software, SugarCRM
On ocassion it becomes necessary to query the database for whatever particular reason. If you are extending a bean object then you already have a db object availabile to you from the instance variable $db. So you could access the database object by referncing it like this:
$this->db->query(”Select * from something”);
If however you are extending other files and need access a database object the recommended approach is to make the following call:
$db = DBManagerFactory::getInstance();
This is a bit safer than just using the global db variable as the getInstance implements the singleton pattern and will always return a valid db object. Unless of course your configuration file does not point to a valid database.
Software, SugarCRM
When customizing Sugar you may on ocassion want to create a function that will be available in multiple locations. Typically a good place to put this function would be in the following location:
include/utils.php
However, if you were to upgrade Sugar at a later time your customizations would be overriden. Instead, create a file in the following location:
custom/include/custom_utils.php
This will ensure that your cutomizations are upgrade safe and because the file is loaded from the utils.php file which is loaded in the entryPoint.php file you’ll have access to all of the functions in any piece of sugar code.
Software, SugarCRM
With the 5.x code base of Sugar sometimes it is still necessary to extend base fields or create new ones rather than using Studio to create custom fields. Studio has come a long way and is absolutely fantastic and powerful. But in the case you want to create new vardef entries, to ensure that they are upgrade safe create them in the following directory (starting from your sugar install root):
custom/Extension/modules/<module name>/Ext/Vardefs/vardefs.ext.php
When you use the quick repair and rebuild a new file will be created in the following location:
custom/modules/<module name>/Ext/Vardefs/vardefs.ext.php
Do not edit the second file that is created. Any edits to this file will be overriden when you run the repair and rebuild so be certain to make edits to the first file listed.
The same holds true for language files. If you need to insert new langauge strings do so by creating and or editing the following file:
custom/Extension/modules/<module name>/Ext/Language/en_us.lang.php
Of course if you are using a different language pack then you will need to replace the ‘en_us’ string. After running the repair and rebuild you will then find a newly created language file in the following location:
custom/modules/<module name>/Ext/Language/en_us.lang.ext.php
Software, SugarCRM
I’m in the process of switching from a windows based laptop to a MacBook obviously running Mac OS. So far the transition has been fairly smooth until now. I’ve been looking for something to replace tortoise svn and WinMerge but have come up short. Every program I’ve tried so far requires a license unlike the window combination I had which I find somewhat ironic. I’ve tried the following svn programs:
- Versions
- Synco svn
- Zig Version
- And two others that have already been deleted….
Most of them work ok, they have the basic features anybody would expect but I could easily execute them on the command line so if you don’t have a GUI that gives you added functionality then what’s the point? Specifically I’d like to have the ability to select two different revisions from the same repository, generate a list of files, and then have the ability to export those files into a zip. This way I can incrementally apply updates to the sites I’m managing. Also, most of the utilities won’t let me select/de-select which files I want to check in if I indicate that I want to check the root of the repository in. There’s tons of other examples of how they are all lacking but I’m still pretty unhappy about it so I don’t want to pontificate. The bottom line I guess is that tortoise svn rocks. Before I could do all the advanced stuff through it’s simple but effective GUI. Now I’m stuck generating diffs and patching directories which is ok but not great. I may but something together which will use the svn log and svn export utlities together once I have some time. I would like to put some Mac tools together after March so perhaps that will be my next side project. Creating a half way decent svn client….
One final note, the merge utilities available for the Mac fall into the same boat as the svn utilities. Nothing really comparable to WinMerge and you still need to shell out some clams. Araxis merge is probably the best that I’ve found so far….
Uncategorized