/** * Function that allows child controller access to model data after the data has been saved. * * @param JModelLegacy $model The data model object. * @param array $validData The validated data. * * @return void * * @since 3.1 */ protected function postSaveHook(JModelLegacy $model, $validData = array()) { require_once JPATH_COMPONENT . '/helpers/sibdiet.php'; $db = $model->getDbo(); // Construct the query $query = $db->getQuery(true)->select('s.room1, s.room2, s.room3, s.room4, s.room5, p.id, p.fname, p.lname, p.mobile, u.email, u.username')->from('#__sibdiet_setdiets s')->join('INNER', '#__sibdiet_profiles p ON (s.profiles_id = p.id)')->join('INNER', '#__users u ON (p.users_id = u.id)')->where('s.id = ' . $validData['id']); // Setup the query $db->setQuery($query); // Return the result $result = $db->loadObject(); if ($result->email && !strpos($result->email, 'sibdiet') && $result->room1 && $result->room2 && $result->room3 && $result->room4 && $result->room5) { $siteLink = JUri::root(); $subject = JText::_('COM_SIBDIET_DIET_READY_EMAIL_SUBJECT'); $password = $result->username == $result->id + 200000 ? $result->mobile : JText::_('COM_SIBDIET_YOU_SET_PASSWORD'); // Prepare email body $body = JText::sprintf('COM_SIBDIET_DIET_READY_EMAIL_BODY', $result->fname . ' ' . $result->lname, $siteLink, $result->username, $password); if (SibdietHelper::sendEmail($result->email, $subject, $body)) { // Create an object for the record we are going to update. $object = new stdClass(); // Must be a valid primary key value. $object->id = $validData['id']; $object->room6 = JFactory::getUser()->id; // Update their details in the users table using id as the primary key. $result = JFactory::getDbo()->updateObject('#__sibdiet_setdiets', $object, 'id'); } } $app = JFactory::getApplication(); $filter = $app->getUserState('com_sibdiet.setdiets.filter'); $filter->profiles_id = ''; $app->setUserState('com_sibdiet.setdiets.filter', $filter); }