Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Email Contract to Student Button #333

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions class/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

use \Intern\InternSettings;

// Setup autoloader for Composer to load SwiftMail via autoload
require_once PHPWS_SOURCE_DIR . 'mod/intern/vendor/autoload.php';

/**
* Abstract class for representing an email to be sent. Provides a
* central implementaion of message sending/delivery via SwiftMail
Expand Down Expand Up @@ -96,7 +93,7 @@ protected function buildMessageBody($templateFileName)
* @param Array $bcc
* @return \Swift_Message if successful.
*/
protected static function buildSwiftMessage($to, $fromAddress, $fromName, $subject, $content, $cc = NULL, $bcc = NULL){
protected function buildSwiftMessage($to, $fromAddress, $fromName, $subject, $content, $cc = NULL, $bcc = NULL){

// Sanity checking
if(!isset($to) || $to === null){
Expand Down
58 changes: 58 additions & 0 deletions class/Email/StudentContractEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace Intern\Email;

use \Intern\Internship;
use \Intern\InternSettings;
use \Intern\InternshipContractPdfView;

class StudentContractEmail extends Email {

private $internship;
private $pdfView;

/**
* Sends an email to the student with their contract attached.
*
* @param InternSettings $emailSettings
* @param Internship $internship
*/
public function __construct(InternSettings $emailSettings, Internship $internship, InternshipContractPdfView $pdfView)
{
parent::__construct($emailSettings);

$this->internship = $internship;
$this->pdfView = $pdfView;
}

protected function getTemplateFileName() {
return 'email/StudentContract.tpl';
}

protected function buildMessage()
{
$term = Term::rawToRead($this->internship->getTerm());

$this->to = $this->internship->getEmail() . $this->emailSettings->getEmailDomain();
$this->subject = "Internship Contract for $term";

$this->tpl['TERM'] = $term;
$this->tpl['AGENCY'] = $this->internship->getAgency()->getName();
}

/**
* Override parent function of same name so that we can handle attaching the Contract
*/
protected function buildSwiftMessage($to, $fromAddress, $fromName, $subject, $content, $cc = NULL, $bcc = NULL){
$message = parent::buildSwiftMessage($to, $fromAddress, $fromName, $subject, $content, $cc, $bcc);

$pdfFile = $this->pdfView->getPdf()->output('internship-contract.pdf', 'S');

$attachment = \Swift_Attachment::newInstance($pdfFile, $this->internship->getFullName() . ' Internship Contract.pdf');

$message->attach($attachment);

return $message;
}


}
2 changes: 0 additions & 2 deletions class/InternshipContractPdfView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Intern;

require_once PHPWS_SOURCE_DIR . 'mod/intern/vendor/autoload.php';

/**
* InternshipContractPdfView
*
Expand Down
13 changes: 13 additions & 0 deletions class/InternshipInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ public function handleRequest()
$pdf = $pdfView->getPdf();
$pdf->output();
exit;
case 'emailPdf' :
$i = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
$emgContacts = EmergencyContactFactory::getContactsForInternship($i);
$pdfView = new InternshipContractPdfView($i, $emgContacts);

$meailSettings = $emailSettings = \Intern\InternSettings::getInstance();
$email = new email\StudentContractEmail($emailSettings, $i, $pdfView);
$email->send();

\NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, 'Contract emailed to student.');
\NQ::close();
\PHPWS_Core::reroute("index.php?module=intern&action=ShowInternship&internship_id=" . $i->getId());
exit;
case 'upload_document_form':
$docManager = new DocumentManager();
echo $docManager->edit();
Expand Down
Loading