Skip to main content

Posts

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

How to create tar by excluding directories in centos Linux

I had a problem to compress files in my webserver. Because my images and backup folders were too large. Then I thought to exclude those directories and create a tar file. I have used --exclude option which matches patterns. First I have used following command to exclude images and backup folder. tar -cvf "new_tar_cha_2013-11-26.tar.gz" .  --exclude "path/to/backup/backup/*" --exclude "images/*" > error_tar_cha.log It excluded backup folder correctly. But It excluded all the images folders inside my directory. Because it matches the pattern . My solution was, I renamed to root images folder to different name - "images-cha1" and excluded it. It fixed my problem. tar -cvf "new_tar_cha_2013-11-26.tar.gz" .  --exclude "path/to/backup/backup/*" --exclude "images-cha1/*" > error_tar_cha.log I think this will be helpful for others also. Thanks

PHP :: How to request Webservice using PHP CURL

I had a problem when requesting webservice. My solution as follows.         $url = " https://path_to_service.asp " ; //setting the curl parameters.   $headers = array ( "Content-type: text/xml;charset=\"utf-8\"" ,     "Accept: text/xml" , "Cache-Control: no-cache" ,   "Pragma: no-cache" ,   "SOAPAction: \"run\""   );   try { $ch = curl_init ();   curl_setopt ( $ch , CURLOPT_URL , $url ); curl_setopt ( $ch , CURLOPT_POST , 1 );     // send xml request to a server   curl_setopt ( $ch , CURLOPT_SSL_VERIFYHOST , 0 );   curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER , 0 ); curl_setopt ( $ch , CURLOPT_POSTFIELDS , $xmlRequest );   curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ); c