Rev 10273 | 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\Form\CreateFeedForm;
use LeadersLinked\Library\Functions;
use LeadersLinked\Mapper\UserMapper;
use LeadersLinked\Mapper\CompanyMapper;
use LeadersLinked\Mapper\TopicMapper;
use LeadersLinked\Model\Feed;
use LeadersLinked\Mapper\FeedMapper;
use LeadersLinked\Mapper\MyTrainerQuestionsMapper;
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();
$id = $this->params()->fromRoute('id');
$request = $this->getRequest();
if(!$id) {
$data = [
'success' => false,
'data' => 'ERROR_INVALID_PARAMETER'
];
return new JsonModel($data);
}
$questionMapper = MyTrainerQuestionMapper::getInstance($this->adapter);
$question = $questionMapper->fetchOneByUuid($id);
if (!$question) {
$data = [
'success' => false,
'data' => 'ERROR_RECORD_NOT_FOUND'
];
return new JsonModel($data);
}
if($request->isGet()) {
$formAdd = new CreateFeedForm($this->adapter);
$this->layout()->setTemplate('layout/layout-backend');
$viewModel = new ViewModel();
$viewModel->setTemplate('leaders-linked/my-trainer-answer/index.phtml');
$viewModel->setVariables([
'formAdd' => $formAdd,
'id'=>$id,
'question_title'=>$question->title,
'question_description'=>$question->description,
]);
return $viewModel ;
} else {
return new JsonModel([
'success' => false,
'data' => 'ERROR_METHOD_NOT_ALLOWED'
]);;
}
}
}