Rev 10819 | AutorÃa | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Controller;
use Laminas\Authentication\AuthenticationService;
use Laminas\Authentication\Result as AuthResult;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\Mvc\I18n\Translator;
use Laminas\Log\LoggerInterface;
use Laminas\View\Model\ViewModel;
use Laminas\View\Model\JsonModel;
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
use LeadersLinked\Mapper\MyTrainerQuestionsMapper;
use LeadersLinked\Form\MyTrainerQuestionForm;
use LeadersLinked\Model\MyTrainerQuestions;
use LeadersLinked\Mapper\MyTrainerAnswerMapper;
use LeadersLinked\Form\MyTrainerAnswerForm;
use LeadersLinked\Model\MyTrainerAnswer;
use LeadersLinked\Model\Feed;
use LeadersLinked\Form\CreateFeedForm;
use LeadersLinked\Form\TopicForm;
use LeadersLinked\Mapper\UserMapper;
class MyTrainerAnswerController extends AbstractActionController
{
/**
*
* @var AdapterInterface
*/
private $adapter;
/**
*
* @var AbstractAdapter
*/
private $cache;
/**
*
* @var LoggerInterface
*/
private $logger;
/**
*
* @var array
*/
private $config;
/**
*
* @param AdapterInterface $adapter
* @param AbstractAdapter $cache
* @param LoggerInterface $logger
* @param array $config
*/
public function __construct($adapter, $cache , $logger, $config)
{
$this->adapter = $adapter;
$this->cache = $cache;
$this->logger = $logger;
$this->config = $config;
}
public function IndexAction()
{
$currentUserPlugin = $this->plugin('currentUserPlugin');
$currentUser = $currentUserPlugin->getUser();
$currentCompany = $currentUserPlugin->getCompany();
$urgent = $this->params()->fromRoute('urgent');
$question = $this->params()->fromRoute('myt_id');
if(!isset($urgent)){
$urgent='';
}
if(!isset($topic_uuid)){
$topic_uuid='';
}
try{
$request = $this->getRequest();
if($request->isGet()) {
$headers = $request->getHeaders();
$isJson = false;
if($headers->has('Accept')) {
$accept = $headers->get('Accept');
$prioritized = $accept->getPrioritized();
foreach($prioritized as $key => $value) {
$raw = trim($value->getRaw());
if(!$isJson) {
$isJson = strpos($raw, 'json');
}
}
}
$questionsMapper = MyTrainerQuestionsMapper::getInstance($this->adapter);
$questions = $questionsMapper->fetchOneByUuid($question);
// return new JsonModel([
// 'success' => false,
// 'data' => $questions
// ]);
$rolAdmin=true;
$formFeed = new CreateFeedForm($this->adapter);
$formTopicNomal = new TopicForm();
$this->layout()->setTemplate('layout/layout-backend');
$viewModel = new ViewModel();
$viewModel->setTemplate('leaders-linked/my-trainer-answer/index.phtml');
$viewModel->setVariables([
'formFeed' => $formFeed,
'topic_uuid' => $topic_uuid,
'myt_id' => $questions->uuid,
'formTopicNormal' => $formTopicNomal,
'urgent'=>$urgent,
'question_title' => $questions->title,
'question_text' => $questions->text,
'rolAdmin'=>$rolAdmin,
]);
return $viewModel ;
} else {
return new JsonModel([
'success' => false,
'data' => 'ERROR_METHOD_NOT_ALLOWED'
]);
}
} catch (\Throwable $e) {
$e->getMessage();
return new JsonModel([
'success' => false,
'data' => $e
]);
}
}
}