Rev 343 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Controller;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\JsonModel;
use LeadersLinked\Model\Page;
use LeadersLinked\Mapper\NotificationMapper;
use LeadersLinked\Mapper\PageMapper;
use LeadersLinked\Mapper\UserMapper;
use LeadersLinked\Mapper\ConnectionMapper;
use LeadersLinked\Mapper\PostMapper;
use LeadersLinked\Model\Post;
use LeadersLinked\Mapper\FeedMapper;
use LeadersLinked\Model\Feed;
use LeadersLinked\Model\User;
use LeadersLinked\Model\Connection;
use LeadersLinked\Mapper\NetworkMapper;
use LeadersLinked\Library\Functions;
use LeadersLinked\Model\Network;
use LeadersLinked\Library\ExternalCredentials;
use Nullix\CryptoJsAes\CryptoJsAes;
use LeadersLinked\Library\Storage;
class HomeController extends AbstractActionController
{
/**
*
* @var \Laminas\Db\Adapter\AdapterInterface
*/
private $adapter;
/**
*
* @var \LeadersLinked\Cache\CacheInterface
*/
private $cache;
/**
*
* @var \Laminas\Log\LoggerInterface
*/
private $logger;
/**
*
* @var array
*/
private $config;
/**
*
* @var \Laminas\Mvc\I18n\Translator
*/
private $translator;
/**
*
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
* @param \LeadersLinked\Cache\CacheInterface $cache
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
* @param array $config
* @param \Laminas\Mvc\I18n\Translator $translator
*/
public function __construct($adapter, $cache, $logger, $config, $translator)
{
$this->adapter = $adapter;
$this->cache = $cache;
$this->logger = $logger;
$this->config = $config;
$this->translator = $translator;
}
public function cryptoAction()
{
header('Content-type: text/plain');
$email = '{"ct":"eZd1aD5p3miv+UsN/7CfAst+8U/Tu4de/n5Rmaf/VsicEYlJG3DH4JvRoxCUwcSA","iv":"8abe13978c33e8701857c6377f09864c","s":"cb61b5d25010408b"}';
$password = '{"ct":"v5maMXocpQT5Jr02vBzXhw==","iv":"a2f8244c89dd690c60ded5f49092d552","s":"522aeee2356f0677"}';
$aes = 'HP8Rc6vBnr2CJyVG';
echo "Email = $email \r\n";
echo "Password = $password \r\n";
echo "AES = $aes \r\n\r\n";
$emailDecrypt = CryptoJsAes::decrypt($email, $aes);
$passwordDecrypt = CryptoJsAes::decrypt($password, $aes);
echo "EmailDecrypt = $emailDecrypt \r\n";
echo "PasswordDecrypt = $passwordDecrypt \r\n";
exit;
}
public function storageAction()
{
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
$currentNetwork = $currentNetworkPlugin->getNetwork();
$request = $this->getRequest();
if ($request->isGet()) {
$code = $this->params()->fromRoute('code');
if(empty($code)) {
$data = [
'success' => false,
'data' => 'ERROR_STORAGE_CODE_INVALID'
];
return new JsonModel($data);
}
$storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
$storageFile = $storageFileMapper->fetchOneByCode($code);
if($storageFile) {
if(file_exists($storageFile->path)) {
// Try to open file
if (!is_readable($storageFile->path)) {
return $this->getResponse()->setStatusCode(500);
}
// Get file size in bytes.
$fileSize = filesize($storageFile->path);
// Get MIME type of the file.
$mimeType = mime_content_type($storageFile->path);
if($mimeType===false) {
$mimeType = 'application/octet-stream';
}
$fileContent = file_get_contents($storageFile->path);
$response = $this->getResponse();
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-type: ' . $mimeType);
$headers->addHeaderLine('Content-length: ' . $fileSize);
if($fileContent!==false) {
$response->setContent($fileContent);
return $response;
} else {
$this->getResponse()->setStatusCode(500);
return;
}
} else {
return $this->getResponse()->setStatusCode(404);
}
} else {
return $this->getResponse()->setStatusCode(404);
}
} else {
$data = [
'success' => false,
'data' => 'ERROR_METHOD_NOT_ALLOWED'
];
return new JsonModel($data);
}
}
public function indexAction()
{
/*
if(!empty($this->config['leaderslinked.runmode.autologin'])) {
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
$currentNetwork = $currentNetworkPlugin->getNetwork();
$authService = new AuthenticationService();
if(!$authService->hasIdentity()) {
$adapter = new AuthEmailAdapter($this->adapter);
$adapter->setData('santiago.olivera@leaderslinked.com', $currentNetwork->id);
$authService->authenticate($adapter);
}
}
/*
$currentUserPlugin = $this->plugin('currentUserPlugin');
if ($currentUserPlugin->hasIdentity()) {
return $this->redirect()->toRoute('dashboard');
} else {
return $this->redirect()->toRoute('signin');
}*/
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
$currentNetwork = $currentNetworkPlugin->getNetwork();
$request = $this->getRequest();
if ($request->isGet()) {
$currentUserPlugin = $this->plugin('currentUserPlugin');
if (empty($_SESSION['aes'])) {
$_SESSION['aes'] = Functions::generatePassword(16);
}
if ($this->config['leaderslinked.runmode.sandbox']) {
$site_key = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
} else {
$site_key = $this->config['leaderslinked.google_captcha.production_site_key'];
}
$access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
$sandbox = $this->config['leaderslinked.runmode.sandbox'];
if ($sandbox) {
$google_map_key = $this->config['leaderslinked.google_map.sandbox_api_key'];
} else {
$google_map_key = $this->config['leaderslinked.google_map.production_api_key'];
}
$data = [
'site_key' => $site_key,
'google_map_key' => $google_map_key,
'aes' => $_SESSION['aes'],
'defaultNetwork' => $currentNetwork->default,
'is_logged_in' => $currentUserPlugin->hasIdentity() ? true : false,
'access_usign_social_networks' => $access_usign_social_networks && $currentNetwork && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
];
if($currentNetwork->default == Network::DEFAULT_YES) {
$currentUserPlugin = $this->plugin('currentUserPlugin');
if ($currentUserPlugin->hasIdentity()) {
$externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
$externalCredentials->getUserBy($currentUserPlugin->getUserId());
if($currentNetwork->xmpp_active) {
$data['xmpp_domain'] = $currentNetwork->xmpp_domain;
$data['xmpp_hostname'] = $currentNetwork->xmpp_hostname;
$data['xmpp_port'] = $currentNetwork->xmpp_port;
$data['xmpp_username'] = $externalCredentials->getUsernameXmpp();
$data['xmpp_password'] = $externalCredentials->getPasswordXmpp();
$data['inmail_username'] = $externalCredentials->getUsernameInmail();
$data['inmail_password'] = $externalCredentials->getPasswordInmail();
}
}
}
return new JsonModel($data);
} else {
$data = [
'success' => false,
'data' => 'ERROR_METHOD_NOT_ALLOWED'
];
return new JsonModel($data);
}
}
public function privacyPolicyAction()
{
$pageCode = Page::PAGE_CODE_PRIVACY_POLICY;
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
$currentNetwork = $currentNetworkPlugin->getNetwork();
$currentUserPlugin = $this->plugin('currentUserPlugin');
$pageMapper = PageMapper::getInstance($this->adapter);
$page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
if (!$page) {
$networkMapper = NetworkMapper::getInstance($this->adapter);
$network = $networkMapper->fetchOneByDefault();
$pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
if ($pageDefault) {
$page = new Page();
$page->network_id = $currentNetwork->id;
$page->code = $pageDefault->code;
$page->content = $pageDefault->content;
$page->fixed = $pageDefault->fixed;
$page->page_default_id = $pageDefault->id;
$page->title = $pageDefault->title;
$page->status = $pageDefault->status;
$page->type = $pageDefault->type;
$page->url = $pageDefault->url;
$pageMapper->insert($page);
}
}
return new JsonModel([
'success' => true,
'data' => [
'title' => $page->title,
'content' => $page->content
]
]);
}
public function cookiesAction()
{
$pageCode = Page::PAGE_CODE_COOKIES;
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
$currentNetwork = $currentNetworkPlugin->getNetwork();
$currentUserPlugin = $this->plugin('currentUserPlugin');
$pageMapper = PageMapper::getInstance($this->adapter);
$page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
if (!$page) {
$networkMapper = NetworkMapper::getInstance($this->adapter);
$network = $networkMapper->fetchOneByDefault();
$pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
if ($pageDefault) {
$page = new Page();
$page->network_id = $currentNetwork->id;
$page->code = $pageDefault->code;
$page->content = $pageDefault->content;
$page->fixed = $pageDefault->fixed;
$page->page_default_id = $pageDefault->id;
$page->title = $pageDefault->title;
$page->status = $pageDefault->status;
$page->type = $pageDefault->type;
$page->url = $pageDefault->url;
$pageMapper->insert($page);
}
}
return new JsonModel([
'success' => true,
'data' => [
'title' => $page->title,
'content' => $page->content
]
]);
}
public function professionalismPolicyAction()
{
$pageCode = Page::PAGE_CODE_PROFESSIONALISM_POLICY;
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
$currentNetwork = $currentNetworkPlugin->getNetwork();
$currentUserPlugin = $this->plugin('currentUserPlugin');
$pageMapper = PageMapper::getInstance($this->adapter);
$page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
if (!$page) {
$networkMapper = NetworkMapper::getInstance($this->adapter);
$network = $networkMapper->fetchOneByDefault();
$pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
if ($pageDefault) {
$page = new Page();
$page->network_id = $currentNetwork->id;
$page->code = $pageDefault->code;
$page->content = $pageDefault->content;
$page->fixed = $pageDefault->fixed;
$page->page_default_id = $pageDefault->id;
$page->title = $pageDefault->title;
$page->status = $pageDefault->status;
$page->type = $pageDefault->type;
$page->url = $pageDefault->url;
$pageMapper->insert($page);
}
}
return new JsonModel([
'success' => true,
'data' => [
'title' => $page->title,
'content' => $page->content
]
]);
}
public function termsAndConditionsAction()
{
$pageCode = Page::PAGE_CODE_TERMS_AND_CONDITIONS;
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
$currentNetwork = $currentNetworkPlugin->getNetwork();
$currentUserPlugin = $this->plugin('currentUserPlugin');
$pageMapper = PageMapper::getInstance($this->adapter);
$page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
if (!$page) {
$networkMapper = NetworkMapper::getInstance($this->adapter);
$network = $networkMapper->fetchOneByDefault();
$pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
if ($pageDefault) {
$page = new Page();
$page->network_id = $currentNetwork->id;
$page->code = $pageDefault->code;
$page->content = $pageDefault->content;
$page->fixed = $pageDefault->fixed;
$page->page_default_id = $pageDefault->id;
$page->title = $pageDefault->title;
$page->status = $pageDefault->status;
$page->type = $pageDefault->type;
$page->url = $pageDefault->url;
$pageMapper->insert($page);
}
}
return new JsonModel([
'success' => true,
'data' => [
'title' => $page->title,
'content' => $page->content
]
]);
}
public function checkSessionAction()
{
$request = $this->getRequest();
if ($request->isGet()) {
$currentUserPlugin = $this->plugin('currentUserPlugin');
if (!$currentUserPlugin->hasIdentity()) {
//$flashMessenger = $this->plugin('FlashMessenger');
//$flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
$response = [
'success' => false,
'data' => [
'message' => '', //ERROR_SESSION_NOT_FOUND',
'url' => $this->url()->fromRoute('signout')
]
];
return new JsonModel($response);
}
$currentUser = $currentUserPlugin->getUser();
if ($currentUser->last_activity_on) {
$last_activity_on = strtotime($currentUser->last_activity_on);
} else {
$last_activity_on = strtotime('-1 day');
}
$expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
if (time() > $expiry_time) {
//$flashMessenger = $this->plugin('FlashMessenger');
//$flashMessenger->addErrorMessage('ERROR_SESSION_EXPIRED');
$response = [
'success' => false,
'data' => [
'message' => 'ERROR_SESSION_EXPIRED',
'url' => $this->url()->fromRoute('signout')
]
];
} else {
$notificationMapper = NotificationMapper::getInstance($this->adapter);
$total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
/*
$messageMapper = MessageMapper::getInstance($this->adapter);
$total_messages = $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);*/
$total_messages = 0;
$response = [
'success' => true,
'data' => [
'total_notifications' => $total_notifications,
'total_messages' => $total_messages
]
];
}
} else {
$response = [
'success' => false,
'data' => 'ERROR_METHOD_NOT_ALLOWED'
];
}
return new JsonModel($response);
}
public function incTotalExternalSharedAction()
{
$request = $this->getRequest();
if ($request->isPost()) {
$currentUserPlugin = $this->plugin('currentUserPlugin');
$currentUser = $currentUserPlugin->getUser();
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
$currentNetwork = $currentNetworkPlugin->getNetwork();
$code = $this->params()->fromRoute('code');
$type = $this->params()->fromRoute('type');
$user = $this->params()->fromRoute('user');
$timestamp = intval($this->params()->fromRoute('timestamp'), 10);
$rand = intval($this->params()->fromRoute('rand'), 10);
$password = $this->params()->fromRoute('password');
$checkpassword = '';
$userCheck = '';
if ($user && $timestamp > 0 && $rand > 0 && $password) {
$userMapper = UserMapper::getInstance($this->adapter);
$userCheck = $userMapper->fetchOneByUuid($user);
if ($userCheck) {
$checkpassword = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
}
}
if (empty($password) || $password != $checkpassword) {
$data = [
'success' => false,
'data' => 'ERROR_UNAUTHORIZED'
];
return new JsonModel($data);
}
if ($type == 'feed' && $code) {
$feedMapper = FeedMapper::getInstance($this->adapter);
$feed = $feedMapper->fetchOneByUuidAnyStatus($code);
if ($feed) {
if ($feed->network_id != $currentNetwork->id) {
$data = [
'success' => false,
'data' => 'ERROR_UNAUTHORIZED'
];
return new JsonModel($data);
}
if ($feedMapper->incTotalExternalShared($feed->id)) {
$total = $feedMapper->fetchTotalExternalShared($feed->id);
$this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el feed : ' . $feed->title);
$data = [
'success' => true,
'data' => $total,
];
return new JsonModel($data);
} else {
$data = [
'success' => false,
'data' => $feedMapper->getError()
];
return new JsonModel($data);
}
} else {
$data = [
'success' => false,
'data' => 'ERROR_FEED_NOT_FOUND',
];
return new JsonModel($data);
}
} else if ($type == 'post' && $code) {
$postMapper = PostMapper::getInstance($this->adapter);
$post = $postMapper->fetchOneByUuid($code);
if ($post && $post->status == Post::STATUS_ACTIVE) {
if ($post->network_id != $currentNetwork->id) {
$data = [
'success' => false,
'data' => 'ERROR_UNAUTHORIZED'
];
return new JsonModel($data);
}
if ($postMapper->incTotalExternalShared($post->id)) {
$total = $postMapper->fetchTotalExternalShared($post->id);
$this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el post : ' . $post->title);
$data = [
'success' => true,
'data' => $total,
];
return new JsonModel($data);
} else {
$data = [
'success' => false,
'data' => $postMapper->getError()
];
return new JsonModel($data);
}
} else {
$data = [
'success' => false,
'data' => 'ERROR_POST_NOT_FOUND'
];
return new JsonModel($data);
}
}
} else {
$response = [
'success' => false,
'data' => 'ERROR_METHOD_NOT_ALLOWED'
];
return new JsonModel($response);
}
}
public function languageAction()
{
$request = $this->getRequest();
if ($request->isGet()) {
$pathname = dirname(__DIR__);
$filename = $pathname . DIRECTORY_SEPARATOR . 'i18n' . DIRECTORY_SEPARATOR . 'spanish.php';
if(file_exists($filename)) {
$arr = include $filename;
$arr = array_filter($arr, function($a) {
return strpos($a, 'LABEL_') !== false;
}, ARRAY_FILTER_USE_KEY);
$data = [];
foreach($arr as $key => $value)
{
$key = str_replace('LABEL_', 'LANG_', $key);
$data[ $key ] = $value;
}
$response = [
'success' => true,
'data' => $data
];
return new JsonModel($response);
} else {
$response = [
'success' => false,
'data' => 'ERROR_METHOD_NOT_ALLOWED'
];
return new JsonModel($response);
}
} else {
$response = [
'success' => false,
'data' => 'ERROR_METHOD_NOT_ALLOWED'
];
return new JsonModel($response);
}
}
public function shareAction()
{
$request = $this->getRequest();
if ($request->isGet()) {
$currentUserPlugin = $this->plugin('currentUserPlugin');
$currentUser = $currentUserPlugin->getUser();
$code = $this->params()->fromRoute('code');
$type = $this->params()->fromRoute('type');
$user = $this->params()->fromRoute('user');
$timestamp = intval($this->params()->fromRoute('timestamp'), 10);
$rand = intval($this->params()->fromRoute('rand'), 10);
$password = $this->params()->fromRoute('password');
$checkpassword = '';
$userCheck = '';
if ($user && $timestamp > 0 && $rand > 0 && $password) {
$userMapper = UserMapper::getInstance($this->adapter);
$userCheck = $userMapper->fetchOneByUuid($user);
if ($userCheck) {
$checkpassword = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
}
}
if (empty($password) || $password != $checkpassword) {
$data = [
'success' => false,
'data' => 'ERROR_UNAUTHORIZED'
];
return new JsonModel($data);
}
/*
$share_params = [
'type' => $type,
'code' => $code,
'user' => $currentUser->uuid,
'timestamp' => $timestamp,
'rand' => $rand,
'password' => $password,
];
$share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params , ['force_canonical' => true]);
*/
$hostname = empty($_SERVER['HTTP_HOST']) ? '' : $_SERVER['HTTP_HOST'];
$networkMapper = NetworkMapper::getInstance($this->adapter);
$network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
if(!$network) {
$network = $networkMapper->fetchOneByDefault();
}
$hostname = trim($network->main_hostname);
$base_share = 'https://' . $hostname;
$share_url = $base_share . $_SERVER['REQUEST_URI'];
$share_image = $base_share . '/images/ll-logo.png';
$share_title = '';
$share_description = '';
if ($type == 'feed' && $code) {
$feedMapper = FeedMapper::getInstance($this->adapter);
$feed = $feedMapper->fetchOneByUuidAnyStatus($code);
// if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
if ($feed) {
$share_title = $feed->title ? $feed->title : '';
if ($feed->posted_or_shared == Feed::SHARED) {
$feed = $feedMapper->fetchOneAnyStatus($feed->shared_feed_id);
if ($feed->title) {
$share_title = $share_title . ' - ' . $feed->title;
}
}
$share_description = $feed->description;
$image_name = '';
if ($feed->file_type == Storage::FILE_TYPE_IMAGE) {
$image_name = $feed->file_name;
} else if ($feed->file_image_preview) {
$image_name = $feed->file_image_preview;
}
if ($image_name) {
$source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
$target_path = $this->config['leaderslinked.frontend.frontend']. DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
//$target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
if (!file_exists($target_path)) {
mkdir($target_path, 0755, true);
}
$target = $target_path . DIRECTORY_SEPARATOR . $image_name;
if (!file_exists($target)) {
copy($source, $target);
$share_image = $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
} else {
$share_image = $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
}
}
} else {
return new JsonModel([
'success' => false,
'data' => 'ERROR_FEED_OR_POST_SHARED'
]);
}
} else if ($type == 'post' && $code) {
$postMapper = PostMapper::getInstance($this->adapter);
$post = $postMapper->fetchOneByUuid($code);
if ($post && $post->status == Post::STATUS_ACTIVE) {
$share_title = $post->title;
$share_description = $post->description;
if ($post->image) {
$source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
// $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
$target_path = $this->config['leaderslinked.frontend.frontend'] . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
if (!file_exists($target_path)) {
mkdir($target_path, 0755, true);
}
$target = $target_path . DIRECTORY_SEPARATOR . $post->image;
if (!file_exists($target)) {
copy($source, $target);
$share_image = $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
} else {
$share_image = $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
}
}
} else {
return new JsonModel([
'success' => false,
'data' => 'ERROR_FEED_OR_POST_SHARED'
]);
}
}
if ($currentUserPlugin->hasIdentity()) {
$currentUser = $currentUserPlugin->getUser();
if ($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id) {
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
$connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
if ($connection) {
if ($connection->status != Connection::STATUS_ACCEPTED) {
$connectionMapper->approve($connection);
}
} else {
$connection = new Connection();
$connection->request_from = $currentUser->id;
$connection->request_to = $userCheck->id;
$connection->status = Connection::STATUS_ACCEPTED;
$connectionMapper->insert($connection);
}
}
} else {
$this->cache->setItem('user_share_invitation', [
'code' => $code,
'type' => $type,
'user' => $user
]);
}
return new JsonModel([
'success' => true,
'data' => [
'image' => $share_image,
'url' => $share_url,
'title' => strip_tags($share_title),
'description' => strip_tags($share_description),
]
]);
} else {
$response = [
'success' => false,
'data' => 'ERROR_METHOD_NOT_ALLOWED'
];
return new JsonModel($response);
}
}
}