Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6849 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
/**
3
 *
4
 * Controlador: Mis Perfiles
5
 *
6
 */
7
declare(strict_types=1);
8
 
9
namespace LeadersLinked\Controller;
10
 
11
use Laminas\Db\Adapter\AdapterInterface;
6849 efrain 12
 
1 www 13
use Laminas\Mvc\Controller\AbstractActionController;
14
use Laminas\Log\LoggerInterface;
15
use Laminas\View\Model\ViewModel;
16
 
17
 
18
use Laminas\View\Model\JsonModel;
19
use LeadersLinked\Form\Help\SendForm;
20
use LeadersLinked\Mapper\CompanyMapper;
21
use LeadersLinked\Mapper\CompanyUserMapper;
22
use LeadersLinked\Mapper\UserMapper;
23
use LeadersLinked\Model\Email;
24
use LeadersLinked\Mapper\EmailMapper;
25
 
26
 
27
class HelpController extends AbstractActionController
28
{
29
    /**
30
     *
6866 efrain 31
     * @var \Laminas\Db\Adapter\AdapterInterface
1 www 32
     */
33
    private $adapter;
34
 
35
    /**
36
     *
6866 efrain 37
     * @var \LeadersLinked\Cache\CacheInterface
1 www 38
     */
6866 efrain 39
    private $cache;
40
 
41
 
42
    /**
43
     *
44
     * @var \Laminas\Log\LoggerInterface
45
     */
1 www 46
    private $logger;
47
 
48
    /**
49
     *
50
     * @var array
51
     */
52
    private $config;
53
 
6866 efrain 54
 
1 www 55
    /**
56
     *
6866 efrain 57
     * @var \Laminas\Mvc\I18n\Translator
58
     */
59
    private $translator;
60
 
61
 
62
    /**
63
     *
64
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
65
     * @param \LeadersLinked\Cache\CacheInterface $cache
66
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
1 www 67
     * @param array $config
6866 efrain 68
     * @param \Laminas\Mvc\I18n\Translator $translator
1 www 69
     */
6866 efrain 70
    public function __construct($adapter, $cache, $logger, $config, $translator)
1 www 71
    {
72
        $this->adapter      = $adapter;
6866 efrain 73
        $this->cache        = $cache;
1 www 74
        $this->logger       = $logger;
75
        $this->config       = $config;
6866 efrain 76
        $this->translator   = $translator;
1 www 77
    }
78
 
79
    /**
80
     *
81
     * Generación del listado de perfiles
82
     * {@inheritDoc}
83
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
84
     */
85
    public function indexAction()
86
    {
87
 
88
        $this->layout()->setTemplate('layout/layout.phtml');
89
        $viewModel = new ViewModel();
90
        $viewModel->setTemplate('leaders-linked/help/index.phtml');
91
        return $viewModel ;
92
 
93
    }
94
 
95
 
96
 
97
    public function sendAction()
98
    {
99
        $request = $this->getRequest();
100
        if($request->isPost()) {
101
 
102
 
103
            $currentUserPlugin = $this->plugin('currentUserPlugin');
104
            $currentUser = $currentUserPlugin->getUser();
105
 
106
            $data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
107
 
108
            $form = new SendForm();
109
            $form->setData($data);
110
 
111
            if($form->isValid()) {
112
                $subject = $form->get('subject')->getValue();
113
                $message = $form->get('message')->getValue();
114
 
115
 
116
                $message = "<p>Nombre : {$currentUser->first_name} </p>" .
117
                "<p>Apellido : {$currentUser->last_name} </p>" .
118
                "<p>Email : {$currentUser->email} </p>" .
119
                $message;
120
 
121
                $email = new Email();
122
                $email->content = json_encode([
123
                    'to_address' => 'ayuda@leaderslinked.com',
124
                    'to_name' => 'Soporte del Sitio Web',
125
                    'cc' => [],
126
                    'bcc' => [],
127
                    'subject' => $subject,
128
                    'message' => $message,
129
                ]);
130
                $email->status = Email::STATUS_PENDING;
131
                $email->tried = 0;
132
 
133
                $emailMapper = EmailMapper::getInstance($this->adapter);
134
                $result = $emailMapper->insert($email);
135
 
136
                if($result) {
137
                    return new JsonModel([
138
                        'success'   => true,
139
                        'data'   =>  'LABEL_HELP_SENT_SUCCESSFULLY'
140
                    ]);
141
 
142
                } else {
143
                    return new JsonModel([
144
                        'success'   => false,
145
                        'data'   =>  'ERROR_UNKNOWN'
146
                    ]);
147
                }
148
 
149
 
150
 
151
 
152
 
153
 
154
            } else {
155
 
156
 
157
                $messages = [];
158
                $form_messages = (array) $form->getMessages();
159
                foreach($form_messages  as $fieldname => $field_messages)
160
                {
161
                    $messages[$fieldname] = array_values($field_messages);
162
                }
163
 
164
                return new JsonModel([
165
                    'success'   => false,
166
                    'data'   => $messages
167
                ]);
168
            }
169
 
170
 
171
 
172
        } else {
173
            return new JsonModel([
174
                'success' => false,
175
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
176
            ]);
177
        }
178
 
179
    }
180
 
181
}