EmailSender   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 3
c 4
b 1
f 1
lcom 1
cbo 3
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A send() 0 21 2
1
<?php
2
3
/**
4
 * This file is part of the Investform module for webcms2.
5
 * Copyright (c) @see LICENSE
6
 */
7
8
namespace WebCMS\InvestformModule\Common;
9
10
use Nette\Mail\Message;
11
12
13
/**
14
 * 
15
 */
16
class EmailSender
17
{
18
	private $settings;
19
20
	private $investment;
21
22
	private $type;
23
24
	public function __construct($settings, $investment, $type)
25
	{
26
		$this->settings = $settings;
27
		$this->investment = $investment;
28
		$this->type = $type;
29
	}
30
31
	public function send()
32
	{
33
		$pdfPrinter = new PdfPrinter($this->investment);
34
35
		$htmlBody = $this->settings->get(ucfirst($this->type).' Email body', 'InvestformModule', 'textarea')->getValue();
36
		if ($this->type == 'form') {
37
			$pdfPrinter->printPdfForm();
38
			$htmlBody = \WebCMS\Helpers\SystemHelper::replaceStatic($htmlBody, array('CONTRACT_PATH'), array(\WebCMS\Helpers\SystemHelper::$baseUrl . 'upload/contracts/' . $this->investment->getHash() . '.pdf'));
39
		} else {
40
			$pdfPrinter->printPdfContract(false, $this->investment->getInvestmentDate());
41
			$htmlBody = \WebCMS\Helpers\SystemHelper::replaceStatic($htmlBody, array('CONTRACT_PATH'), array(\WebCMS\Helpers\SystemHelper::$baseUrl . 'upload/contracts/' . $this->investment->getContractHash() . '.pdf'));
42
		}
43
44
		$mail = new Message;
45
		$mail->setFrom($this->settings->get('Info email', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue())
46
		    ->addTo($this->investment->getEmail())
47
		    ->setSubject($this->settings->get(ucfirst($this->type).' Subject', 'InvestformModule', 'text')->getValue())
48
		    ->setHTMLBody($htmlBody);
49
50
		$mail->send();
51
	}
52
}
53