[SOLVED] Form Email Plugin : date format in echo + Solution

Status
Not open for further replies.

marcq

Member
Hi,

It is not a Fabrikar issue, but I'm stuck since two days with this issue.

I have created a query which is running in my email template.

The outpout of 2 dates is wrong :
2016-04-29 22:00:00

Should be :
Vendredi 24 avril 2016

I'm trying to implement the "strftime" function into my echos, but I couldn't find a way to do it properly.

My script :

Code:
$candidateid = JRequest::getVar('gprh_fabrik_user_enrollment___id');
$db = JFactory::getDbo();
   $query = $db->getQuery(true);
   $query
      ->select (array('gprh_fabrik_user_enrollment.id', 'gprh_fabrik_user_training_124_repeat.nom_formation', 'gprh_fabrik_user_training_124_repeat.intitule_session', 'gprh_fabrik_user_training_124_repeat.session_au', 'gprh_fabrik_user_training_124_repeat.session_au'))   
      ->from('gprh_fabrik_user_enrollment')
      ->leftJoin('gprh_fabrik_user_enrollment_repeat_choix_formation ON gprh_fabrik_user_enrollment.id = gprh_fabrik_user_enrollment_repeat_choix_formation.parent_id')
      ->leftJoin('gprh_fabrik_user_training_124_repeat ON gprh_fabrik_user_enrollment_repeat_choix_formation.choix_formation = gprh_fabrik_user_training_124_repeat.id')
      ->leftJoin('gprh_fabrik_user_training ON gprh_fabrik_user_training_124_repeat.parent_id = gprh_fabrik_user_training.id')
      ->having('gprh_fabrik_user_enrollment.id = ' . $db->quote($candidateid))
     ->group('gprh_fabrik_user_enrollment.id, gprh_fabrik_user_training_124_repeat.nom_formation, gprh_fabrik_user_training_124_repeat.intitule_session, gprh_fabrik_user_training_124_repeat.session_du, gprh_fabrik_user_training_124_repeat.session_au');
   $db->setQuery($query);
   $row = $db->loadObjectList();
   echo "<div style='font-family: arial, helvetica, sans-serif; font-size: 11pt;'><OL>";
   foreach ($row as $item)
   {
      echo "<LI> $item->nom_formation | ";
      echo "$item->intitule_session | ";
      echo "du : $item->session_du | ";
      echo "au : $item->session_au<br /><br />";
      echo "</LI>";
   }
   echo "</OL></div>";

I wan't to implement the "strftime" function into the two following echos :

Code:
      echo "du : $item->session_du | ";
      echo "au : $item->session_au<br /><br />";

Last try who failed was :

Code:
      echo "du: strftime('%A %d %B %Y', strtotime($item->session_du)) | ";
      echo "au: strftime('%A %d %B %Y', strtotime($item->session_du))<br /><br />";

I would appreciate some help.

Thanks in advance,

Marc
 
Last edited:
I'm struggling since three days with this issue which is honestly to complicated for my SQL/PHP knowledge.
I have created numerous posts in different PHP, SQL, Joomla forums but without success.
I'm stuck, so if someone knows how I could manage to solve this issue, I would appreciate.
Marc
 
Well, that's why you have a Pro sub. :)

Let me know which form (or list) this email template is in, and I'll take a look at it for you.

I'm puzzled as to why the code you quoted above doesn't work. I hadn't noticed in my initial response that you are correctly feeding your date through strtotime(), which should work. I just tested your line of code here, and it does work (although in English, not French).

But on the whole it is better to get used to using the DateTime class, which provides a lot of useful date handling features.

-- hugh
 
Can you give me some instructions on how best to test it? how the form needs to be filled out, or do you have a test row I can work on?

-- hugh
 
Email output should look like that (see attached PDF file), dates which needs to be changed are in red
 

Attachments

  • Fwd_ Confirmation d'inscription.pdf
    130.8 KB · Views: 192
S'OK, I just needed to know if I had to do anything specific to get that query that selects the dates to find anything.


Sent from my Nexus 7 using Tapatalk
 
OK, I finally figured out I have to select some of those checkboxes, to get the query to select some rows with dates in. That's what i asking about with "needed to know if I had to do anything specific to get that query that selects the dates to find anything", and you didn't mention that.

Should be working now.

-- hugh
 
Hi Hugh,

Thanks a lot, it is working ! My Apologies concerning the checkboxes, It was a misunderstanding from my side. Cheers, Marc

Solution from Hugh to whom it might interest :

Code:
$candidateid = JRequest::getVar('gprh_fabrik_user_enrollment___id');
$db = JFactory::getDbo();
   $query = $db->getQuery(true);
   $query
      ->select (array('gprh_fabrik_user_enrollment.id', 'gprh_fabrik_user_training_124_repeat.nom_formation', 'gprh_fabrik_user_training_124_repeat.intitule_session', 'gprh_fabrik_user_training_124_repeat.session_du', 'gprh_fabrik_user_training_124_repeat.session_au'))   
      ->from('gprh_fabrik_user_enrollment')
      ->leftJoin('gprh_fabrik_user_enrollment_repeat_choix_formation ON gprh_fabrik_user_enrollment.id = gprh_fabrik_user_enrollment_repeat_choix_formation.parent_id')
      ->leftJoin('gprh_fabrik_user_training_124_repeat ON gprh_fabrik_user_enrollment_repeat_choix_formation.choix_formation = gprh_fabrik_user_training_124_repeat.id')
      ->leftJoin('gprh_fabrik_user_training ON gprh_fabrik_user_training_124_repeat.parent_id = gprh_fabrik_user_training.id')
      ->having('gprh_fabrik_user_enrollment.id = ' . $db->quote($candidateid))
     ->group('gprh_fabrik_user_enrollment.id, gprh_fabrik_user_training_124_repeat.nom_formation, gprh_fabrik_user_training_124_repeat.intitule_session, gprh_fabrik_user_training_124_repeat.session_du, gprh_fabrik_user_training_124_repeat.session_au');
   $db->setQuery($query);
   $row = $db->loadObjectList();
   echo "<div style='font-family: arial, helvetica, sans-serif; font-size: 11pt;'><UL>";
   foreach ($row as $item)
   {
           $du_date = new DateTime($item->session_du, new DateTimeZone('Europe/Zurich'));
           $du_date_formatted = $du_date->format('d/m/Y');
           $au_date = new DateTime($item->session_au, new DateTimeZone('Europe/Zurich'));
           $au_date_formatted = $au_date->format('d/m/Y');

      echo "<LI> $item->nom_formation | ";
      echo "$item->intitule_session | ";
      echo "du : $du_date_formatted  | ";
      echo "au : $au_date_formatted <br /><br />";
      echo "</LI>";
   }
   echo "</UL></div>";
 
Or you could use JDate() instead of DateTime(). The Joomla JDate() class extends PHP's DateTime, and (iirc) will automatically apply the TZ.

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top