Skip to main content

Posts

Showing posts from 2014

How to retrieve data from another table while retrieving data from a table in loadFormData function in Joomla 2.5

I have to show data from two different tables. Therefore I had to change 'loadFormData' function to satisfy that. Current implementation was as follows. /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormData()  { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_speakee.edit.batchofcard.data', array()); if (empty($data))  { $data = $this->getItem();                         }                          return $data; } Then I changed it to get data from another table called 'Discount' by calling table of 'Discount' and got table properties by primary key.  /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormDat

Convert date from one timezone to another timezone PHP

This example is from phone call history  //set default time zone date_default_timezone_set('America/New_York'); //Set call date and time $call_date = new DateTime(date("d-m-Y H:i:s", strtotime($call['calldate']." ".$call['calltime']))); //Create new time zone object $la_time = new DateTimeZone('Europe/London'); //Set time zone to date $call_date->setTimezone($la_time); //show new date and time echo $call_date->format('d-m-Y'); echo $call_date->format("H:i:s"); Chamath Gunasekara

Replace empty names with concatenated text in MySQL

There was a drop down which had a huge list of employees. But some of them hadn't name. It was empty. But not NULL in database.  Initial query was as follows.  SELECT emp_id, name from employees order by name asc But it shows empty options in select list first. Then I tried to replace name which was NULL using IFNULL function.  SELECT aemp_id, IFNULL(name, concat('Employee - ', emp_id)) as name from employees  where name="" order by name asc But it was failed due to empty values for name field. Then I checked for empty value for name field.              NULLIF(name, "") It will return NULL value if it is empty. Then I used  COALESCE function.It returns first NULL or NULL if there no-null values in the list. Complete query as follows. SELECT emp_id, COALESCE(NULLIF(name, ""), concat('Employee - ', emp_id)) as name from employees where name="" order by name asc enjoy. Chamath Gunasekara

How to add Google fonts to select in TinyMCE editor in Joomla backend

There was a requirement from one of our customers to select Google fonts which we were using in front end pages in Tiny mice editors in Joomla 2.5 back end. I couldn't find a plug-in which provides this functionality from the back end. There are few plug-ins which can be used to enable Google fonts or font.com fonts by selectors (like class or ids).   Then I went through the source code of tiny mice editor plug-in found a way add new fonts. It was a bad thing when we think about joomla updates. But with client perspective it was a good solution I think. You are welcome to discuss with regards pros and cons.  Add new fonts here Edit editor_template.js file in  media\editors\ tinymce\ jscripts\ tiny_mce\ themes\ advanced\ editor_template.js Search for 'theme_advanced_fonts' or 'Arial' or 'georgia'. There are few places of 'theme_advanced_fonts'. You need to find correct place.  theme_advanced_fonts:"Andale Mono=andale mono,times;Arial=aria