Blame view

src/lib/MyMailer/OnlineEvent.php 1.8 KB
ef60cd4d   Administrator   first commit
1
2
3
4
  <?php
  namespace MyMailer;
  
  class OnlineEvent extends Event{
2dfdc329   Administrator   change request to...
5
  
ef60cd4d   Administrator   first commit
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
      private $props = array();
      private static $instance;
  
      public static function getInstance(){
          if(empty(self::$instance)){
              self::$instance = new  OnlineEvent();
          }
          return self::$instance;
      }
  
      public function replaceData($target, $replacement, $str)
      {
          $text = str_replace($target, $replacement, $str);
          return $text;
      }
  
      public function itemSet($template, $data){
          $num = count($data);
  
          for($i=0; $i<$num; $i++){
              foreach($data[$i] as $k => $v){
  
                  $target = '{{item_'.$i.'_'.$k.'}}';
                  $replacement = $v;
                  $template['text'] = $this->replaceData($target, $replacement, $template['text']);
  
              }
          }
  
          return $template['text'];
  
      }
  
      public function dataSet($text, $data){
  
          foreach($data as $k => $v){
  
              $target = '{{'.$k.'}}';
              $replacement = $v;
              $text = $this->replaceData($target, $replacement, $text);
  
          }
  
  
          return $text;
  
      }
  
      public function itemDynamicSet($template, $data){
  
          $num = count($data);
          $contentText = '';
          for($i=0; $i<$num; $i++){
              $contentTextOneBlock = $template['dynamic_content'];
              foreach($data[$i] as $k => $v){
  
                  $target = '{{item_'.$k.'}}';
                  print "target = '{{item_'.$k.'}}'" ;
                  $replacement = $v;
                  print "replacement = $v" ;
                  $contentTextOneBlock = $this->replaceData($target, $replacement, $contentTextOneBlock);
  
              }
              $contentText .= $contentTextOneBlock;
          }
  
          $template = $template['header']. $contentText .$template['footer'];
  
  
          return $template;
  
      }
  
  
  }