I have been working on this class for days with no luck or results.
I'm trying to insert variable in the email body that contains a function that iterates through an array. The variable that has problems is the $yearFunction
that calls cleaningArrays()
method.
I have tested by inserting an exit()
right after calling the cleaningArrays()
and I could the data through the array is correct, but it won't just get passed down to the body section.
When an email is sent it just comes as blank no data from the $yearFunction
variable.
// No direct access.
defined('_JEXEC') or die;
// Include dependancy of the main controller form class
jimport('joomla.application.component.controllerform');
JForm::addFormPath(JPATH_COMPONENT_ADMINISTRATOR . '/models/forms');
class VifBadgesControllerBadges extends JControllerForm
{
protected $yearBadgeArray;
protected $moduleBadgeArray;
protected $otherBadgeArray;
protected $yearBadges;
protected $moduleBadges;
protected $otherBadges;
protected $recipientName;
protected $recipientEmail;
protected $message;
protected $badgeEarner;
protected $yearFunction;
public function cleaningArrays($list)
{
for ($k=0; $k < count($list); $k++)
{
echo $list[$k];
}
return ;
}
public function submit()
{
// Check for request forgeries.
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialize variables.
$app = JFactory::getApplication();
$mail = &JFactory::getMailer();
$user = JFactory::getUser();
$redirectUrl = JRoute::_('index.php/', false);
$postData = $app->input->post;
$this->recipientEmail = $postData->get('email', '', 'STRING');
$this->recipientName = $postData->get('name', '', 'STRING');
$this->message = $postData->get('message', '', 'STRING');
$this->badgeEarner = $postData->get('badgeEarner', '', '');
$yearBadgeArray = $postData->get('yearBadgeData', '', '');
$moduleBadgeArray = $postData->get('moduleBadgeData', '', '');
$otherBadgeArray = $postData->get('otherBadgeData', '', '');
$this->yearBadgeArray= unserialize(base64_decode($yearBadgeArray));
$this->moduleBadgeArray= unserialize(base64_decode($moduleBadgeArray));
$this->otherBadgeArray= unserialize(base64_decode($otherBadgeArray));
$yearFunction = function()
{
$badge = [];
foreach ($this->yearBadgeArray as $yearBadge)
{
$badge[] = $yearBadge[2][1];
}
$this->cleaningArrays($badge);
};
$body = "<div style='font-family:arial,helvetica,sans-serif;font-size:12px;'>
<p>Hi ".$this->recipientName.",</p>
<p>".$this->badgeEarner." has earned digital badges for completing a PD modules in VIF's Learning Center and wants to share the details with you!</p>
<p><strong>Message from ".$this->badgeEarner."</strong> " .$this->message."</p>
<p><strong>Year Badges:</strong></p>
<p>".$yearFunction()."</p>
<hr style='border:0px;color:rgb(237,237,235);min-height:1px;width:525px;background-color:rgb(237,237,235)' />
<div style='font-family:arial,helvetica,sans-serif;text-align:center;font-size:10px;color:rgb(102,102,102)'>
<p>This email was sent to Andrew from Community.</p><p>2015</p></div>";
$senderEmail = $user->email;
$senderName = $user->name;
$sender = array($senderEmail, $senderName);
$mail->ClearAddresses();
$mail->setSender($sender);
$mail->addRecipient($this->recipientEmail);
$mail->Encoding = 'base64';
$mail->setSubject(JText::_($this->badgeEarner.' Shared a Digital Badge'));
$mail->IsHTML(true);
$mail->setBody($body);
$send = $mail->Send();
}
}
JRequest
as it's deprecateddevelopment
on your Global Configuration? Also, have you tried returning the result of your anonymous function like so:return $this->cleaningArrays($badge);
?