Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
10273 eleazar 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Authentication\AuthenticationService;
7
use Laminas\Authentication\Result as AuthResult;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
10
use Laminas\Mvc\Controller\AbstractActionController;
11
use Laminas\Mvc\I18n\Translator;
12
use Laminas\Log\LoggerInterface;
13
use Laminas\View\Model\ViewModel;
14
use Laminas\View\Model\JsonModel;
15
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10759 eleazar 16
use LeadersLinked\Mapper\MyTrainerQuestionsMapper;
10953 eleazar 17
use LeadersLinked\Mapper\FeedMapper;
10759 eleazar 18
use LeadersLinked\Form\MyTrainerQuestionForm;
19
use LeadersLinked\Model\MyTrainerQuestions;
10601 eleazar 20
 
21
use LeadersLinked\Model\Feed;
10273 eleazar 22
use LeadersLinked\Form\CreateFeedForm;
10601 eleazar 23
use LeadersLinked\Form\TopicForm;
24
 
10273 eleazar 25
use LeadersLinked\Mapper\UserMapper;
26
 
27
class MyTrainerAnswerController extends AbstractActionController
28
{
29
    /**
30
     *
31
     * @var AdapterInterface
32
     */
33
    private $adapter;
34
 
35
 
36
    /**
37
     *
38
     * @var AbstractAdapter
39
     */
40
    private $cache;
41
 
42
    /**
43
     *
44
     * @var  LoggerInterface
45
     */
46
    private $logger;
47
 
48
    /**
49
     *
50
     * @var array
51
     */
52
    private $config;
53
 
54
 
55
 
56
    /**
57
     *
58
     * @param AdapterInterface $adapter
59
     * @param AbstractAdapter $cache
60
     * @param LoggerInterface $logger
61
     * @param array $config
62
     */
63
    public function __construct($adapter, $cache , $logger, $config)
64
    {
65
        $this->adapter      = $adapter;
66
        $this->cache        = $cache;
67
        $this->logger       = $logger;
68
        $this->config       = $config;
69
 
70
 
71
    }
10601 eleazar 72
 
73
    public function IndexAction()
10273 eleazar 74
    {
75
        $currentUserPlugin = $this->plugin('currentUserPlugin');
76
        $currentUser = $currentUserPlugin->getUser();
77
        $currentCompany = $currentUserPlugin->getCompany();
10832 eleazar 78
        $myt_id   = $this->params()->fromRoute('myt_id');
10766 eleazar 79
 
10848 eleazar 80
 
10612 eleazar 81
        try{
82
            $request = $this->getRequest();
83
            if($request->isGet()) {
84
                $headers  = $request->getHeaders();
10273 eleazar 85
 
10612 eleazar 86
                $isJson = false;
87
                if($headers->has('Accept')) {
88
                    $accept = $headers->get('Accept');
89
 
90
                    $prioritized = $accept->getPrioritized();
91
 
92
                    foreach($prioritized as $key => $value) {
93
                        $raw = trim($value->getRaw());
94
 
95
                        if(!$isJson) {
96
                            $isJson = strpos($raw, 'json');
97
                        }
98
 
10601 eleazar 99
                    }
100
                }
10953 eleazar 101
                $feedMapper = FeedMapper::getInstance($this->adapter);
102
                $feed = $feedMapper->fetchOneByUuid($myt_id);
10601 eleazar 103
 
10612 eleazar 104
                $rolAdmin=true;
10601 eleazar 105
 
10612 eleazar 106
                $formFeed = new CreateFeedForm($this->adapter);
107
                $formTopicNomal = new TopicForm();
108
                $this->layout()->setTemplate('layout/layout-backend');
109
                $viewModel = new ViewModel();
110
                $viewModel->setTemplate('leaders-linked/my-trainer-answer/index.phtml');
111
                $viewModel->setVariables([
112
                    'formFeed'    =>  $formFeed,
10832 eleazar 113
                    'myt_id' => $myt_id,
10612 eleazar 114
                    'formTopicNormal' => $formTopicNomal,
10953 eleazar 115
                    'question_title' => $feed->title,
10981 eleazar 116
                    'question_text' => $feed->description,
10612 eleazar 117
                    'rolAdmin'=>$rolAdmin,
118
                ]);
119
                return $viewModel ;
120
 
121
 
122
            } else {
123
                return new JsonModel([
124
                    'success' => false,
125
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
126
                ]);
127
            }
128
        } catch (\Throwable $e) {
129
            $e->getMessage();
10273 eleazar 130
            return new JsonModel([
131
                'success' => false,
10612 eleazar 132
                'data' => $e
10601 eleazar 133
            ]);
10273 eleazar 134
        }
10612 eleazar 135
 
10273 eleazar 136
    }
10601 eleazar 137
 
138
 
139
 
10273 eleazar 140
}