Blame view

src/lib/MyMailer/EventAdder.php 4.26 KB
f7818cdf   Administrator   change request to...
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
  <?php
  namespace MyMailer;
  
  class EventAdder{
  
      public $post;
      public $host;
  
      public function __construct( $post){
  
          $project_model = new \projects();
  
          $this->host = $_SERVER['HTTP_ORIGIN'];
  
          $this->post = $post;
  
          $project = $project_model->getProjectId($this->host);
  
          $this->post['project_id'] = $project->id;
  
          $this->post['project_name'] = $project->name;
  
          if(!$this->post['project_id']){
              throw new \Exception("Project {$this->host} not found");
          } else {
              print_r($this->post);
          }
  
      }
  
      public function callEventFactory(){
  
          if(isset($this->post['event_type'])){
              switch ($this->post['event_type']) {
                  case 'add_subscribe':
  
  
                      $event = new EventOnlineSubscribe();
  
  
  
                      $customer = $event->subscribeNewCustomer($this->post);
  
                      $event->addLatterListToNewCustomer($this->post,$customer);
  
                      $templateManager = new EventTemplateManager();
  
                      $data = $templateManager->insertEventData($this->post['event'],$this->host,$this->post['project_id'],'event_online');
  
                      $item_data = $templateManager->insertItemData($this->post);
  
                      $template = $templateManager->prepareTemplate($data);
  
                      $template = $templateManager->prepareEventData($item_data, $template, $this->post);
  
                      $MyMailer = new EventMailer();
  
                      $MyMailer->setFromName($this->post['project_name']);
  
                      $event->sendEventDelivery($this->post, $data, $template);
  
                      break;
                  case 'online_event':
  
                      $templateManager = new EventTemplateManager();
  
                      $data = $templateManager->insertEventData($this->post['event'],$this->host,$this->post['project_id'],'event_online');
  
                      $item_data = $templateManager->insertItemData($this->post);
  
                      $template = $templateManager->prepareTemplate($item_data,$data);
  
                      $template = $templateManager->prepareEventData([], $template, $this->post);
  
                      $event = new EventOnline();
  
                      $event->sendEventDelivery( $this->post, $data, $template);
  
                      break;
  
                  case 'spy_event':
  
                      $spyEvent = new EventSpy();
  
                      $customer = $spyEvent->getCustomer($this->post);
  
  
                      switch ($this->post['action']) {
                          case 'order_add':
  
                              $spyID =  $spyEvent->saveSpyData($this->post,$customer);
                              $spyEvent->saveSpyOrder($spyID, 'added',$this->post);
  
                              break;
  
                          case 'order_delete':
                              $spyID =  $spyEvent->getSpyData($this->post,$customer);
                              $spyEvent->saveSpyOrder($spyID, 'deleted',$this->post);
  
                              break;
                          case 'order_finish':
  
  
                              $model = new \spyEvent();
  
                              $item_data = $model->spyTimeAfter($this->post['project_id'], $customer->id)->toArray();
  
                              $templateManager = new EventTemplateManager();
  
                              $data = $templateManager->insertEventData($this->post['event'],$this->host,$this->post['project_id'],'event_online');
  
                              $template = $templateManager->prepareTemplate($data);
  
                              $template = $templateManager->prepareEventData($item_data, $template, $this->post);
  
                              $spyEvent->sendEventDelivery( $this->post, $data, $template);
  
                              $spyID =  $spyEvent->saveSpyData($this->post,$customer);
                              $spyEvent->finishSpyOrder($this->post,$customer);
  
                              break;
  
                          default:
                              throw new \Exception("Unknown event action {$this->post['action']}");
                      }
  
                      break;
                  default:
                      throw new \Exception("Unknown event type");
              }
          } else {
              throw new \Exception("Unknown event type");
          }
      }
  }