private function loadTemplate($message, $code, $formId, $publisherId) { // Add configuration helper file require_once JPATH_COMPONENT . '/helpers/configuration.php'; // Check that code is valid if (!ConfigurationHelper::isValidParameterName($code)) { JFactory::getApplication()->enqueueMessage(JText::_('COM_ISSNREGISTRY_ERROR_MESSAGE_INVALID_CODE_PARAMETER'), 'error'); return false; } // Get component parameters $params = JComponentHelper::getParams('com_issnregistry'); // Check if this is a form handled message $isFormHandled = ConfigurationHelper::isFormHandled($code); // Check if this is a publisher summary message $isPublisherSummary = ConfigurationHelper::isPublisherSummary($code); // Init variables $form = null; // Get message type id for the given code $messageTypeId = $params->get($code, 0); // Check that the value has been defined if ($messageTypeId == 0) { JFactory::getApplication()->enqueueMessage(JText::_('COM_ISSNREGISTRY_ERROR_MESSAGE_NO_DEFAULT_MESSAGE_TYPE_FOUND'), 'warning'); return false; } // Set message type id $message->message_type_id = $messageTypeId; // Load publisher model $publisherModel = JModelLegacy::getInstance('publisher', 'IssnregistryModel'); // Variable that tell if publisher email address should be used $usePublisherEmail = false; if ($isFormHandled) { // Load form model $formModel = JModelLegacy::getInstance('form', 'IssnregistryModel'); // Load form $form = $formModel->getItem($formId); // Check that we found a form if (!$form) { JFactory::getApplication()->enqueueMessage(JText::_('COM_ISSNREGISTRY_ERROR_MESSAGE_NO_FORM_FOUND'), 'warning'); return false; } // Set form id $message->form_id = $form->id; // Set publisher id $publisherId = $form->publisher_id; // Set language code $message->lang_code = $form->lang_code; // Update recipient $message->recipient = $form->email; // If email is empty, use publisher email if (empty($message->recipient)) { $usePublisherEmail = true; } } // Load publisher $publisher = $publisherModel->getPublisherById($publisherId); // Check the result if (!$publisher) { JFactory::getApplication()->enqueueMessage(JText::_('COM_ISSNREGISTRY_ERROR_MESSAGE_NO_PUBLISHER_FOUND'), 'warning'); return false; } if ($isPublisherSummary || $usePublisherEmail) { // Set language code $message->lang_code = $publisher->lang_code; // Update recipient $message->recipient = $this->getEmail($publisher); } // Set publisher id $message->publisher_id = $publisherId; // Load message template model $messageTemplateModel = JModelLegacy::getInstance('messagetemplate', 'IssnregistryModel'); // Load template $template = $messageTemplateModel->getMessageTemplateByTypeAndLanguage($messageTypeId, $message->lang_code); // Check that we found a template if (!$template) { JFactory::getApplication()->enqueueMessage(JText::_('COM_ISSNREGISTRY_ERROR_MESSAGE_NO_TEMPLATE_FOUND'), 'warning'); return false; } // Update template id $message->message_template_id = $template->id; // Set subject $message->subject = $template->subject; // Set message $message->message = $template->message; // Load language file - translations are used // in "filterPublications" function later JFactory::getLanguage()->load('com_issnregistry_email', JPATH_ADMINISTRATOR, $message->lang_code, true); // Init publications array $publications = array(); // If so, load publications if ($isFormHandled || $isPublisherSummary) { // Load publication model $publicationModel = JModelLegacy::getInstance('publication', 'IssnregistryModel'); // Load publications if ($isFormHandled) { $publications = $publicationModel->getPublicationsByFormId($formId); } else { $publications = $publicationModel->getPublicationsByPublisherId($publisherId); } // Check the result if (!$publications) { JFactory::getApplication()->enqueueMessage(JText::_('COM_ISSNREGISTRY_ERROR_MESSAGE_NO_PUBLICATIONS_FOUND'), 'warning'); } // Add publications info $message->message = $this->filterPublications($message->message, $publications); // Add publication title $message->message = $this->filterPublicationTitle($message->message, $publications); // Add publication title to subject $message->subject = $this->filterPublicationTitle($message->subject, $publications); } // Filter message $message->message = $this->filterMessage($message->message, $form, $publisher); // Operation was successfull return true; }