-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageHelper.php
executable file
·105 lines (83 loc) · 2.76 KB
/
MessageHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Messages;
class MessageHelper {
private $message;
private $typeParam=array();
private $listParam=array();
private $param;
public function __construct($message, $param = null){
$this->message = $message;
$this->param = $param;
$this->checkParam();
}
public function hasParam(){
//$check = false;
$this->listParam = explode($this->getParamPattern(), $this->message);
return count($this->listParam) > 0;
}
public function checkParam(){
if(!$this->hasParam()) return $this->typeParam=array();
for($i = 0; $i < count($this->listParam); $i++){
if($i%2 == 1)
$this->typeParam [] = $this->getParamPattern().$this->listParam[$i].$this->getParamPattern();
}
}
public function getMessagePersonnalized($contact){
$replace = array();
foreach($this->typeParam as $key => $value){
if($value === $this->getParamPattern().$this->getParamNom().$this->getParamPattern())
$replace[] = $contact->getNom();
if($value === $this->getParamPattern().$this->getParamPrenom().$this->getParamPattern())
$replace[] = $contact->getPrenom();
if($value === $this->getParamPattern().$this->getParamMail().$this->getParamPattern())
$replace[] = $contact->getEmail();
}
return str_replace($this->typeParam, $replace, $this->message);
}
/**
* Get the value of typeParam
*/
public function getTypeParam()
{
return $this->typeParam;
}
/**
* Set the value of typeParam
*
* @return self
*/
public function setTypeParam($typeParam)
{
$this->typeParam = $typeParam;
return $this;
}
/**
* Get the value of listParam
*/
public function getListParam()
{
return $this->listParam;
}
/**
* Set the value of listParam
*
* @return self
*/
public function setListParam($listParam)
{
$this->listParam = $listParam;
return $this;
}
public function getParamPattern(){
return !is_null($this->param)? $this->param->getParamPattern() : MessageHelperConstant::PATTERN;
}
public function getParamNom(){
return !is_null($this->param)? $this->param->getParamNom() : MessageHelperConstant::TYPE_PARAM_NOM;
}
public function getParamPrenom(){
return !is_null($this->param)? $this->param->getParamPrenom() : MessageHelperConstant::TYPE_PARAM_PRENOM;
}
public function getParamMail(){
return !is_null($this->param)? $this->param->getParamMail() : MessageHelperConstant::TYPE_PARAM_MAIL;
}
}