| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           declare(strict_types=1);
  | 
        
        
            | 
            | 
           3 | 
              | 
        
        
            | 
            | 
           4 | 
           namespace LeadersLinked\Controller;
  | 
        
        
            | 
            | 
           5 | 
              | 
        
        
            | 
            | 
           6 | 
           use Laminas\Db\Adapter\AdapterInterface;
  | 
        
        
            | 
            | 
           7 | 
           use Laminas\Mvc\Controller\AbstractActionController;
  | 
        
        
            | 
            | 
           8 | 
           use LeadersLinked\Hydrator\ObjectPropertyHydrator;
  | 
        
        
            | 
            | 
           9 | 
           use Laminas\Log\LoggerInterface;
  | 
        
        
            | 
            | 
           10 | 
           use Laminas\View\Model\ViewModel;
  | 
        
        
            | 
            | 
           11 | 
           use Laminas\View\Model\JsonModel;
  | 
        
        
            | 
            | 
           12 | 
           use LeadersLinked\Mapper\UserMapper;
  | 
        
        
            | 
            | 
           13 | 
           use LeadersLinked\Library\Functions;
  | 
        
        
            | 
            | 
           14 | 
           use LeadersLinked\Mapper\UserPasswordMapper;
  | 
        
        
            | 
            | 
           15 | 
           use LeadersLinked\Form\AccountSetting\NotificationSettingForm;
  | 
        
        
            | 
            | 
           16 | 
           use LeadersLinked\Mapper\UserNotificationSettingMapper;
  | 
        
        
            | 
            | 
           17 | 
           use LeadersLinked\Form\AccountSetting\ChangePasswordForm;
  | 
        
        
            | 
            | 
           18 | 
           use LeadersLinked\Form\AccountSetting\ChangeImageForm;
  | 
        
        
            | 
            | 
           19 | 
           use LeadersLinked\Library\Image;
  | 
        
        
            | 
            | 
           20 | 
           use LeadersLinked\Form\AccountSetting\LocationForm;
  | 
        
        
            | 
            | 
           21 | 
           use LeadersLinked\Model\Location;
  | 
        
        
            | 
            | 
           22 | 
           use LeadersLinked\Mapper\LocationMapper;
  | 
        
        
            | 
            | 
           23 | 
           use LeadersLinked\Form\AccountSetting\PrivacySettingForm;
  | 
        
        
            | 
            | 
           24 | 
           use LeadersLinked\Mapper\UserProfileMapper;
  | 
        
        
            | 
            | 
           25 | 
           use LeadersLinked\Form\AccountSetting\BasicForm;
  | 
        
        
            | 
            | 
           26 | 
           use LeadersLinked\Form\Transaction\FundsAddForm;
  | 
        
        
            | 
            | 
           27 | 
           use LeadersLinked\Mapper\UserBrowserMapper;
  | 
        
        
            | 
            | 
           28 | 
           use LeadersLinked\Mapper\QueryMapper;
  | 
        
        
            | 
            | 
           29 | 
           use LeadersLinked\Mapper\DeviceHistoryMapper;
  | 
        
        
            | 
            | 
           30 | 
           use LeadersLinked\Mapper\DeviceMapper;
  | 
        
        
            | 
            | 
           31 | 
           use Laminas\Hydrator\ArraySerializableHydrator;
  | 
        
        
            | 
            | 
           32 | 
           use Laminas\Db\ResultSet\HydratingResultSet;
  | 
        
        
            | 
            | 
           33 | 
           use Laminas\Paginator\Adapter\DbSelect;
  | 
        
        
            | 
            | 
           34 | 
           use Laminas\Paginator\Paginator;
  | 
        
        
            | 
            | 
           35 | 
           use LeadersLinked\Mapper\UserIpMapper;
  | 
        
        
            | 
            | 
           36 | 
           use LeadersLinked\Model\Transaction;
  | 
        
        
            | 
            | 
           37 | 
           use LeadersLinked\Model\Provider;
  | 
        
        
            | 
            | 
           38 | 
           use LeadersLinked\Mapper\TransactionMapper;
  | 
        
        
            | 
            | 
           39 | 
           use LeadersLinked\Mapper\UserProviderMapper;
  | 
        
        
            | 
            | 
           40 | 
           use LeadersLinked\Model\UserProvider;
  | 
        
        
            | 
            | 
           41 | 
           use LeadersLinked\Model\UserPassword;
  | 
        
        
            | 
            | 
           42 | 
           use LeadersLinked\Model\UserDeleted;
  | 
        
        
            | 
            | 
           43 | 
           use LeadersLinked\Mapper\UserDeletedMapper;
  | 
        
        
            | 
            | 
           44 | 
           use LeadersLinked\Model\UserType;
  | 
        
        
            | 
            | 
           45 | 
           use LeadersLinked\Model\User;
  | 
        
        
            | 
            | 
           46 | 
           use LeadersLinked\Library\QueueEmail;
  | 
        
        
            | 
            | 
           47 | 
           use LeadersLinked\Mapper\EmailTemplateMapper;
  | 
        
        
            | 
            | 
           48 | 
           use LeadersLinked\Model\EmailTemplate;
  | 
        
        
            | 
            | 
           49 | 
           use LeadersLinked\Cache\CacheInterface;
  | 
        
        
            | 
            | 
           50 | 
           use PayPalHttp\HttpException;
  | 
        
        
            | 
            | 
           51 | 
           use PayPalCheckoutSdk\Core\SandboxEnvironment;
  | 
        
        
            | 
            | 
           52 | 
           use PayPalCheckoutSdk\Core\ProductionEnvironment;
  | 
        
        
            | 
            | 
           53 | 
           use PayPalCheckoutSdk\Core\PayPalHttpClient;
  | 
        
        
            | 
            | 
           54 | 
           use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
  | 
        
        
            | 
            | 
           55 | 
           use Laminas\Mvc\I18n\Translator;
  | 
        
        
           | 283 | 
           www | 
           56 | 
           use LeadersLinked\Library\Storage;
  | 
        
        
           | 1 | 
           efrain | 
           57 | 
              | 
        
        
            | 
            | 
           58 | 
              | 
        
        
            | 
            | 
           59 | 
           class AccountSettingController extends AbstractActionController
  | 
        
        
            | 
            | 
           60 | 
           {
  | 
        
        
            | 
            | 
           61 | 
               /**
  | 
        
        
            | 
            | 
           62 | 
                *
  | 
        
        
            | 
            | 
           63 | 
                * @var \Laminas\Db\Adapter\AdapterInterface
  | 
        
        
            | 
            | 
           64 | 
                */
  | 
        
        
            | 
            | 
           65 | 
               private $adapter;
  | 
        
        
            | 
            | 
           66 | 
              | 
        
        
            | 
            | 
           67 | 
               /**
  | 
        
        
            | 
            | 
           68 | 
                *
  | 
        
        
            | 
            | 
           69 | 
                * @var \LeadersLinked\Cache\CacheInterface
  | 
        
        
            | 
            | 
           70 | 
                */
  | 
        
        
            | 
            | 
           71 | 
               private $cache;
  | 
        
        
            | 
            | 
           72 | 
              | 
        
        
            | 
            | 
           73 | 
              | 
        
        
            | 
            | 
           74 | 
               /**
  | 
        
        
            | 
            | 
           75 | 
                *
  | 
        
        
            | 
            | 
           76 | 
                * @var \Laminas\Log\LoggerInterface
  | 
        
        
            | 
            | 
           77 | 
                */
  | 
        
        
            | 
            | 
           78 | 
               private $logger;
  | 
        
        
            | 
            | 
           79 | 
              | 
        
        
            | 
            | 
           80 | 
               /**
  | 
        
        
            | 
            | 
           81 | 
                *
  | 
        
        
            | 
            | 
           82 | 
                * @var array
  | 
        
        
            | 
            | 
           83 | 
                */
  | 
        
        
            | 
            | 
           84 | 
               private $config;
  | 
        
        
            | 
            | 
           85 | 
              | 
        
        
            | 
            | 
           86 | 
              | 
        
        
            | 
            | 
           87 | 
               /**
  | 
        
        
            | 
            | 
           88 | 
                *
  | 
        
        
            | 
            | 
           89 | 
                * @var \Laminas\Mvc\I18n\Translator
  | 
        
        
            | 
            | 
           90 | 
                */
  | 
        
        
            | 
            | 
           91 | 
               private $translator;
  | 
        
        
            | 
            | 
           92 | 
              | 
        
        
            | 
            | 
           93 | 
              | 
        
        
            | 
            | 
           94 | 
               /**
  | 
        
        
            | 
            | 
           95 | 
                *
  | 
        
        
            | 
            | 
           96 | 
                * @param \Laminas\Db\Adapter\AdapterInterface $adapter
  | 
        
        
            | 
            | 
           97 | 
                * @param \LeadersLinked\Cache\CacheInterface $cache
  | 
        
        
            | 
            | 
           98 | 
                * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
  | 
        
        
            | 
            | 
           99 | 
                * @param array $config
  | 
        
        
            | 
            | 
           100 | 
                * @param \Laminas\Mvc\I18n\Translator $translator
  | 
        
        
            | 
            | 
           101 | 
                */
  | 
        
        
            | 
            | 
           102 | 
               public function __construct($adapter, $cache, $logger, $config, $translator)
  | 
        
        
            | 
            | 
           103 | 
               {
  | 
        
        
            | 
            | 
           104 | 
                   $this->adapter      = $adapter;
  | 
        
        
            | 
            | 
           105 | 
                   $this->cache        = $cache;
  | 
        
        
            | 
            | 
           106 | 
                   $this->logger       = $logger;
  | 
        
        
            | 
            | 
           107 | 
                   $this->config       = $config;
  | 
        
        
            | 
            | 
           108 | 
                   $this->translator   = $translator;
  | 
        
        
            | 
            | 
           109 | 
               }
  | 
        
        
            | 
            | 
           110 | 
              | 
        
        
            | 
            | 
           111 | 
               public function indexAction()
  | 
        
        
            | 
            | 
           112 | 
               {
  | 
        
        
            | 
            | 
           113 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           114 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           115 | 
              | 
        
        
            | 
            | 
           116 | 
                       $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
  | 
        
        
            | 
            | 
           117 | 
                       $currentNetwork = $currentNetworkPlugin->getNetwork();
  | 
        
        
            | 
            | 
           118 | 
              | 
        
        
            | 
            | 
           119 | 
              | 
        
        
            | 
            | 
           120 | 
                       $tab =  Functions::sanitizeFilterString($this->params()->fromQuery('tab'));
  | 
        
        
            | 
            | 
           121 | 
                       if(!in_array($tab, ['nav-basic', 'nav-notification', 'nav-password', 'nav-image', 'nav-location', 'nav-privacy', 'nav-ips', 'nav-browsers', 'nav-transactions', 'nav-social-networks'])) {
  | 
        
        
            | 
            | 
           122 | 
                           $tab = 'nav-basic';
  | 
        
        
            | 
            | 
           123 | 
                       }
  | 
        
        
            | 
            | 
           124 | 
              | 
        
        
            | 
            | 
           125 | 
                       $sandbox = $this->config['leaderslinked.runmode.sandbox'];
  | 
        
        
            | 
            | 
           126 | 
                       if($sandbox) {
  | 
        
        
            | 
            | 
           127 | 
                           $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
  | 
        
        
            | 
            | 
           128 | 
                       } else {
  | 
        
        
            | 
            | 
           129 | 
                           $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
  | 
        
        
            | 
            | 
           130 | 
                       }
  | 
        
        
            | 
            | 
           131 | 
              | 
        
        
            | 
            | 
           132 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           133 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           134 | 
              | 
        
        
            | 
            | 
           135 | 
                       $userUserNotificationSettingMapper = UserNotificationSettingMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           136 | 
                       $userUserNotificationSetting = $userUserNotificationSettingMapper->fetchOne($currentUser->id);
  | 
        
        
            | 
            | 
           137 | 
              | 
        
        
            | 
            | 
           138 | 
              | 
        
        
            | 
            | 
           139 | 
              | 
        
        
            | 
            | 
           140 | 
                       if($currentUser->location_id) {
  | 
        
        
            | 
            | 
           141 | 
              | 
        
        
            | 
            | 
           142 | 
                           $locationMapper = LocationMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           143 | 
                           $location = $locationMapper->fetchOne($currentUser->location_id);
  | 
        
        
            | 
            | 
           144 | 
                           if($location) {
  | 
        
        
            | 
            | 
           145 | 
                               $location_formatted_address = $location->formatted_address;
  | 
        
        
           | 141 | 
           efrain | 
           146 | 
              | 
        
        
            | 
            | 
           147 | 
                               $formLocation = new LocationForm();
  | 
        
        
           | 1 | 
           efrain | 
           148 | 
                               $formLocation->setData((array) $location);
  | 
        
        
            | 
            | 
           149 | 
                           }
  | 
        
        
            | 
            | 
           150 | 
                       } else {
  | 
        
        
            | 
            | 
           151 | 
                           $location_formatted_address = '';
  | 
        
        
            | 
            | 
           152 | 
                       }
  | 
        
        
            | 
            | 
           153 | 
              | 
        
        
            | 
            | 
           154 | 
                       $facebook    = 0;
  | 
        
        
            | 
            | 
           155 | 
                       $twitter     = 0;
  | 
        
        
            | 
            | 
           156 | 
                       $google      = 0;
  | 
        
        
            | 
            | 
           157 | 
              | 
        
        
            | 
            | 
           158 | 
              | 
        
        
            | 
            | 
           159 | 
                       $userProviderMapper = UserProviderMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           160 | 
                       $userProviders = $userProviderMapper->fetchAllByUserId($currentUser->id);
  | 
        
        
            | 
            | 
           161 | 
                       foreach($userProviders as $userProvider)
  | 
        
        
            | 
            | 
           162 | 
                       {
  | 
        
        
            | 
            | 
           163 | 
                           switch($userProvider->provider)
  | 
        
        
            | 
            | 
           164 | 
                           {
  | 
        
        
            | 
            | 
           165 | 
                               case  UserProvider::PROVIDER_FACEBOOK :
  | 
        
        
            | 
            | 
           166 | 
                                   $facebook  = 1;
  | 
        
        
            | 
            | 
           167 | 
                                   break;
  | 
        
        
            | 
            | 
           168 | 
              | 
        
        
            | 
            | 
           169 | 
                               case  UserProvider::PROVIDER_TWITTER :
  | 
        
        
            | 
            | 
           170 | 
                                   $twitter = 1;
  | 
        
        
            | 
            | 
           171 | 
                                   break;
  | 
        
        
            | 
            | 
           172 | 
              | 
        
        
            | 
            | 
           173 | 
                               case  UserProvider::PROVIDER_GOOGLE :
  | 
        
        
            | 
            | 
           174 | 
                                   $google  = 1;
  | 
        
        
            | 
            | 
           175 | 
                                   break;
  | 
        
        
            | 
            | 
           176 | 
              | 
        
        
            | 
            | 
           177 | 
                           }
  | 
        
        
            | 
            | 
           178 | 
                       }
  | 
        
        
            | 
            | 
           179 | 
              | 
        
        
           | 333 | 
           www | 
           180 | 
                       $storage = Storage::getInstance($this->config, $this->adapter);
  | 
        
        
           | 283 | 
           www | 
           181 | 
                       $image =  $storage->getUserImage($currentUser);
  | 
        
        
            | 
            | 
           182 | 
              | 
        
        
           | 1 | 
           efrain | 
           183 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           184 | 
                           'tab' => $tab,
  | 
        
        
            | 
            | 
           185 | 
                           'balance' => number_format(floatval($currentUser->balance), 2),
  | 
        
        
            | 
            | 
           186 | 
                           'amounts' => [
  | 
        
        
            | 
            | 
           187 | 
                               '5' => '5 LABEL_USD',
  | 
        
        
            | 
            | 
           188 | 
                               '10' => '10 LABEL_USD',
  | 
        
        
            | 
            | 
           189 | 
                               '15' => '15 LABEL_USD',
  | 
        
        
            | 
            | 
           190 | 
                               '20' => '20 LABEL_USD',
  | 
        
        
            | 
            | 
           191 | 
                               '25' => '25 LABEL_USD',
  | 
        
        
            | 
            | 
           192 | 
                               '50' => '50 LABEL_USD',
  | 
        
        
            | 
            | 
           193 | 
                               '75' => '75 LABEL_USD',
  | 
        
        
            | 
            | 
           194 | 
                               '100' => '100 LABEL_USD',
  | 
        
        
            | 
            | 
           195 | 
                           ],
  | 
        
        
            | 
            | 
           196 | 
                           'usertype_id' => $currentUser->usertype_id,
  | 
        
        
           | 283 | 
           www | 
           197 | 
                           'image' => $image,
  | 
        
        
           | 142 | 
           efrain | 
           198 | 
                           //'config' => $this->config,
  | 
        
        
           | 1 | 
           efrain | 
           199 | 
                           'google_map_key' => $google_map_key,
  | 
        
        
            | 
            | 
           200 | 
                           'location_formatted_address' => $location_formatted_address,
  | 
        
        
            | 
            | 
           201 | 
                           'google' => $google,
  | 
        
        
            | 
            | 
           202 | 
                           'facebook' => $facebook,
  | 
        
        
            | 
            | 
           203 | 
                           'twitter' => $twitter,
  | 
        
        
            | 
            | 
           204 | 
                           'defaultNetwork' => $currentNetwork->default,
  | 
        
        
            | 
            | 
           205 | 
                           'show_in_search' => $currentUser->show_in_search,
  | 
        
        
            | 
            | 
           206 | 
                           'user_notifications' => [
  | 
        
        
            | 
            | 
           207 | 
                               'receive_connection_request' => $userUserNotificationSetting->receive_connection_request,
  | 
        
        
            | 
            | 
           208 | 
                               'accept_my_request_connection' => $userUserNotificationSetting->accept_my_request_connection,
  | 
        
        
            | 
            | 
           209 | 
                               'receive_invitation_group' => $userUserNotificationSetting->receive_invitation_group,
  | 
        
        
            | 
            | 
           210 | 
                               'accept_my_request_join_group' => $userUserNotificationSetting->accept_my_request_join_group,
  | 
        
        
            | 
            | 
           211 | 
                               'receive_request_join_my_group' => $userUserNotificationSetting->receive_request_join_my_group,
  | 
        
        
            | 
            | 
           212 | 
                               'receive_invitation_company' => $userUserNotificationSetting->receive_invitation_company,
  | 
        
        
            | 
            | 
           213 | 
                               'like_my_feed' => $userUserNotificationSetting->like_my_feed,
  | 
        
        
            | 
            | 
           214 | 
                               'comment_my_feed' => $userUserNotificationSetting->comment_my_feed,
  | 
        
        
            | 
            | 
           215 | 
                               'share_my_feed' => $userUserNotificationSetting->share_my_feed,
  | 
        
        
            | 
            | 
           216 | 
                               'receive_inmail' => $userUserNotificationSetting->receive_inmail,
  | 
        
        
            | 
            | 
           217 | 
                               'receive_invitation_meeting' => $userUserNotificationSetting->receive_invitation_meeting,
  | 
        
        
            | 
            | 
           218 | 
                               'receive_reminder_meeting' => $userUserNotificationSetting->receive_reminder_meeting,
  | 
        
        
            | 
            | 
           219 | 
                               'receive_records_available_meeting' => $userUserNotificationSetting->receive_records_available_meeting,
  | 
        
        
            | 
            | 
           220 | 
                           ]
  | 
        
        
            | 
            | 
           221 | 
              | 
        
        
            | 
            | 
           222 | 
                       ]);
  | 
        
        
            | 
            | 
           223 | 
              | 
        
        
            | 
            | 
           224 | 
              | 
        
        
            | 
            | 
           225 | 
                   } else {
  | 
        
        
            | 
            | 
           226 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           227 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           228 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           229 | 
                       ]);
  | 
        
        
            | 
            | 
           230 | 
                   }
  | 
        
        
            | 
            | 
           231 | 
               }
  | 
        
        
            | 
            | 
           232 | 
              | 
        
        
            | 
            | 
           233 | 
               public function notificationAction()
  | 
        
        
            | 
            | 
           234 | 
               {
  | 
        
        
            | 
            | 
           235 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           236 | 
              | 
        
        
            | 
            | 
           237 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           238 | 
                       $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           239 | 
              | 
        
        
            | 
            | 
           240 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           241 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           242 | 
              | 
        
        
            | 
            | 
           243 | 
                       $userUserNotificationSettingMapper = UserNotificationSettingMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           244 | 
                       $userUserNotificationSetting = $userUserNotificationSettingMapper->fetchOne($currentUser->id);
  | 
        
        
            | 
            | 
           245 | 
              | 
        
        
            | 
            | 
           246 | 
              | 
        
        
            | 
            | 
           247 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           248 | 
                          'success' => true,
  | 
        
        
            | 
            | 
           249 | 
                          'data' => [
  | 
        
        
            | 
            | 
           250 | 
                              'receive_connection_request' => $userUserNotificationSetting->receive_connection_request ? 1 : 0,
  | 
        
        
            | 
            | 
           251 | 
                              'accept_my_request_connection' => $userUserNotificationSetting->accept_my_request_connection ? 1 : 0,
  | 
        
        
            | 
            | 
           252 | 
              | 
        
        
            | 
            | 
           253 | 
                              'receive_invitation_group' => $userUserNotificationSetting->receive_invitation_group ? 1 : 0,
  | 
        
        
            | 
            | 
           254 | 
                              'accept_my_request_join_group' => $userUserNotificationSetting->accept_my_request_join_group ? 1 : 0,
  | 
        
        
            | 
            | 
           255 | 
                              'receive_request_join_my_group' => $userUserNotificationSetting->receive_request_join_my_group ? 1 : 0,
  | 
        
        
            | 
            | 
           256 | 
              | 
        
        
            | 
            | 
           257 | 
              | 
        
        
            | 
            | 
           258 | 
                              'receive_invitation_company' => $userUserNotificationSetting->receive_invitation_company ? 1 : 0,
  | 
        
        
            | 
            | 
           259 | 
              | 
        
        
            | 
            | 
           260 | 
                              'like_my_feed' => $userUserNotificationSetting->like_my_feed ? 1 : 0,
  | 
        
        
            | 
            | 
           261 | 
                              'comment_my_feed' => $userUserNotificationSetting->comment_my_feed ? 1 : 0,
  | 
        
        
            | 
            | 
           262 | 
                              'share_my_feed' => $userUserNotificationSetting->share_my_feed ? 1 : 0,
  | 
        
        
            | 
            | 
           263 | 
                              'receive_inmail' => $userUserNotificationSetting->receive_inmail ? 1 : 0,
  | 
        
        
            | 
            | 
           264 | 
              | 
        
        
            | 
            | 
           265 | 
                              'receive_invitation_meeting' => $userUserNotificationSetting->receive_invitation_meeting ? 1 : 0,
  | 
        
        
            | 
            | 
           266 | 
                              'receive_reminder_meeting' => $userUserNotificationSetting->receive_reminder_meeting ? 1 : 0,
  | 
        
        
            | 
            | 
           267 | 
                              'receive_records_available_meeting' => $userUserNotificationSetting->receive_records_available_meeting ? 1 : 0,
  | 
        
        
            | 
            | 
           268 | 
              | 
        
        
            | 
            | 
           269 | 
                          ]
  | 
        
        
            | 
            | 
           270 | 
                       ]);
  | 
        
        
            | 
            | 
           271 | 
              | 
        
        
            | 
            | 
           272 | 
              | 
        
        
            | 
            | 
           273 | 
                   } else  if($request->isPost()) {
  | 
        
        
            | 
            | 
           274 | 
              | 
        
        
            | 
            | 
           275 | 
                       $dataPost = $request->getPost()->toArray();
  | 
        
        
            | 
            | 
           276 | 
                       $form = new NotificationSettingForm();
  | 
        
        
            | 
            | 
           277 | 
                       $form->setData($dataPost);
  | 
        
        
            | 
            | 
           278 | 
              | 
        
        
            | 
            | 
           279 | 
                       if($form->isValid()) {
  | 
        
        
            | 
            | 
           280 | 
                           $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           281 | 
                           $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           282 | 
              | 
        
        
            | 
            | 
           283 | 
                           $dataPost = (array) $form->getData();
  | 
        
        
            | 
            | 
           284 | 
                           $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           285 | 
              | 
        
        
            | 
            | 
           286 | 
                           $userUserNotificationSettingMapper = UserNotificationSettingMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           287 | 
                           $userUserNotificationSetting = $userUserNotificationSettingMapper->fetchOne($currentUser->id);
  | 
        
        
            | 
            | 
           288 | 
                           $hydrator->hydrate($dataPost, $userUserNotificationSetting);
  | 
        
        
            | 
            | 
           289 | 
              | 
        
        
            | 
            | 
           290 | 
                           if($userUserNotificationSettingMapper->update($userUserNotificationSetting)) {
  | 
        
        
            | 
            | 
           291 | 
                               $this->logger->info('Se guardo las preferencias de notificación', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
            | 
            | 
           292 | 
                               $data = [
  | 
        
        
            | 
            | 
           293 | 
                                   'success'   => true,
  | 
        
        
            | 
            | 
           294 | 
                                   'data'      => 'LABEL_NOTIFICATION_SETTINGS_UPDATE'
  | 
        
        
            | 
            | 
           295 | 
                               ];
  | 
        
        
            | 
            | 
           296 | 
                           } else {
  | 
        
        
            | 
            | 
           297 | 
                               $data = [
  | 
        
        
            | 
            | 
           298 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           299 | 
                                   'data'   => 'ERROR_UNKNOWN'
  | 
        
        
            | 
            | 
           300 | 
                               ];
  | 
        
        
            | 
            | 
           301 | 
                           }
  | 
        
        
            | 
            | 
           302 | 
              | 
        
        
            | 
            | 
           303 | 
                           return new JsonModel($data);
  | 
        
        
            | 
            | 
           304 | 
              | 
        
        
            | 
            | 
           305 | 
                       } else {
  | 
        
        
            | 
            | 
           306 | 
                           $messages = [];
  | 
        
        
            | 
            | 
           307 | 
              | 
        
        
            | 
            | 
           308 | 
              | 
        
        
            | 
            | 
           309 | 
              | 
        
        
            | 
            | 
           310 | 
                           $form_messages = (array) $form->getMessages();
  | 
        
        
            | 
            | 
           311 | 
                           foreach($form_messages  as $fieldname => $field_messages)
  | 
        
        
            | 
            | 
           312 | 
                           {
  | 
        
        
            | 
            | 
           313 | 
              | 
        
        
            | 
            | 
           314 | 
                               $messages[$fieldname] = array_values($field_messages);
  | 
        
        
            | 
            | 
           315 | 
                           }
  | 
        
        
            | 
            | 
           316 | 
              | 
        
        
            | 
            | 
           317 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           318 | 
                               'success'   => false,
  | 
        
        
            | 
            | 
           319 | 
                               'data'   => $messages
  | 
        
        
            | 
            | 
           320 | 
                           ]);
  | 
        
        
            | 
            | 
           321 | 
                       }
  | 
        
        
            | 
            | 
           322 | 
                   }  else {
  | 
        
        
            | 
            | 
           323 | 
                       $data = [
  | 
        
        
            | 
            | 
           324 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           325 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           326 | 
                       ];
  | 
        
        
            | 
            | 
           327 | 
              | 
        
        
            | 
            | 
           328 | 
                       return new JsonModel($data);
  | 
        
        
            | 
            | 
           329 | 
                   }
  | 
        
        
            | 
            | 
           330 | 
              | 
        
        
            | 
            | 
           331 | 
                   return new JsonModel($data);
  | 
        
        
            | 
            | 
           332 | 
              | 
        
        
            | 
            | 
           333 | 
               }
  | 
        
        
            | 
            | 
           334 | 
              | 
        
        
            | 
            | 
           335 | 
              | 
        
        
            | 
            | 
           336 | 
              | 
        
        
            | 
            | 
           337 | 
              | 
        
        
            | 
            | 
           338 | 
              | 
        
        
            | 
            | 
           339 | 
               public function passwordAction()
  | 
        
        
            | 
            | 
           340 | 
               {
  | 
        
        
            | 
            | 
           341 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           342 | 
                   if($request->isPost()) {
  | 
        
        
            | 
            | 
           343 | 
                       $dataPost = $request->getPost()->toArray();
  | 
        
        
            | 
            | 
           344 | 
                       $form = new ChangePasswordForm();
  | 
        
        
            | 
            | 
           345 | 
                       $form->setData($dataPost);
  | 
        
        
            | 
            | 
           346 | 
              | 
        
        
            | 
            | 
           347 | 
                       if($form->isValid()) {
  | 
        
        
            | 
            | 
           348 | 
                           $data = (array) $form->getData();
  | 
        
        
            | 
            | 
           349 | 
                           $password = $data['password'];
  | 
        
        
            | 
            | 
           350 | 
              | 
        
        
            | 
            | 
           351 | 
                           $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           352 | 
                           $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           353 | 
              | 
        
        
            | 
            | 
           354 | 
              | 
        
        
            | 
            | 
           355 | 
                           $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           356 | 
                           $userPasswords = $userPasswordMapper->fetchAllByUserId($currentUser->id);
  | 
        
        
            | 
            | 
           357 | 
              | 
        
        
            | 
            | 
           358 | 
                           $oldPassword = false;
  | 
        
        
            | 
            | 
           359 | 
                           foreach($userPasswords as $userPassword)
  | 
        
        
            | 
            | 
           360 | 
                           {
  | 
        
        
            | 
            | 
           361 | 
                               if(password_verify($password, $userPassword->password) || (md5($password) == $userPassword->password))
  | 
        
        
            | 
            | 
           362 | 
                               {
  | 
        
        
            | 
            | 
           363 | 
                                   $oldPassword = true;
  | 
        
        
            | 
            | 
           364 | 
                                   break;
  | 
        
        
            | 
            | 
           365 | 
                               }
  | 
        
        
            | 
            | 
           366 | 
                           }
  | 
        
        
            | 
            | 
           367 | 
              | 
        
        
            | 
            | 
           368 | 
                           if($oldPassword) {
  | 
        
        
            | 
            | 
           369 | 
                               $this->logger->err('Cambio de contraseña del usuario - error contraseña ya utilizada anteriormente', ['user_id' =>  $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
            | 
            | 
           370 | 
              | 
        
        
            | 
            | 
           371 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           372 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           373 | 
                                   'data'      => 'ERROR_PASSWORD_HAS_ALREADY_BEEN_USED'
  | 
        
        
            | 
            | 
           374 | 
              | 
        
        
            | 
            | 
           375 | 
                               ]);
  | 
        
        
            | 
            | 
           376 | 
                           } else {
  | 
        
        
            | 
            | 
           377 | 
                               $password_hash = password_hash($password, PASSWORD_DEFAULT);
  | 
        
        
            | 
            | 
           378 | 
              | 
        
        
            | 
            | 
           379 | 
                               $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           380 | 
                               $result = $userMapper->updatePassword($currentUser, $password_hash);
  | 
        
        
            | 
            | 
           381 | 
                               if($result) {
  | 
        
        
            | 
            | 
           382 | 
              | 
        
        
            | 
            | 
           383 | 
                                   $userPassword = new UserPassword();
  | 
        
        
            | 
            | 
           384 | 
                                   $userPassword->user_id = $currentUser->id;
  | 
        
        
            | 
            | 
           385 | 
                                   $userPassword->password = $password_hash;
  | 
        
        
            | 
            | 
           386 | 
                                   $userPasswordMapper->insert($userPassword);
  | 
        
        
            | 
            | 
           387 | 
              | 
        
        
            | 
            | 
           388 | 
                                   $this->logger->info('Cambio de contraseña del usuario realizado', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
            | 
            | 
           389 | 
              | 
        
        
            | 
            | 
           390 | 
              | 
        
        
            | 
            | 
           391 | 
                                   return new JsonModel([
  | 
        
        
            | 
            | 
           392 | 
                                       'success'   => true,
  | 
        
        
            | 
            | 
           393 | 
                                       'data'      => 'LABEL_YOUR_PASSWORD_HAS_BEEN_UPDATED'
  | 
        
        
            | 
            | 
           394 | 
              | 
        
        
            | 
            | 
           395 | 
                                   ]);
  | 
        
        
            | 
            | 
           396 | 
                               } else {
  | 
        
        
            | 
            | 
           397 | 
                                   $this->logger->err('Cambio de contraseña del usuario - error desconocido', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
            | 
            | 
           398 | 
              | 
        
        
            | 
            | 
           399 | 
                                   return new JsonModel([
  | 
        
        
            | 
            | 
           400 | 
                                       'success'   => true,
  | 
        
        
            | 
            | 
           401 | 
                                       'data'      => 'ERROR_THERE_WAS_AN_ERROR'
  | 
        
        
            | 
            | 
           402 | 
              | 
        
        
            | 
            | 
           403 | 
                                   ]);
  | 
        
        
            | 
            | 
           404 | 
                               }
  | 
        
        
            | 
            | 
           405 | 
                           }
  | 
        
        
            | 
            | 
           406 | 
              | 
        
        
            | 
            | 
           407 | 
                       } else {
  | 
        
        
            | 
            | 
           408 | 
                           $messages = [];
  | 
        
        
            | 
            | 
           409 | 
              | 
        
        
            | 
            | 
           410 | 
                           $form_messages = (array) $form->getMessages();
  | 
        
        
            | 
            | 
           411 | 
                           foreach($form_messages  as $fieldname => $field_messages)
  | 
        
        
            | 
            | 
           412 | 
                           {
  | 
        
        
            | 
            | 
           413 | 
                               $messages[$fieldname] = array_values($field_messages);
  | 
        
        
            | 
            | 
           414 | 
                           }
  | 
        
        
            | 
            | 
           415 | 
              | 
        
        
            | 
            | 
           416 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           417 | 
                               'success'   => false,
  | 
        
        
            | 
            | 
           418 | 
                               'data'   => $messages
  | 
        
        
            | 
            | 
           419 | 
                           ]);
  | 
        
        
            | 
            | 
           420 | 
                       }
  | 
        
        
            | 
            | 
           421 | 
              | 
        
        
            | 
            | 
           422 | 
                   }
  | 
        
        
            | 
            | 
           423 | 
              | 
        
        
            | 
            | 
           424 | 
              | 
        
        
            | 
            | 
           425 | 
              | 
        
        
            | 
            | 
           426 | 
                   return new JsonModel([
  | 
        
        
            | 
            | 
           427 | 
                       'success' => false,
  | 
        
        
            | 
            | 
           428 | 
                       'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           429 | 
                   ]);
  | 
        
        
            | 
            | 
           430 | 
               }
  | 
        
        
            | 
            | 
           431 | 
              | 
        
        
            | 
            | 
           432 | 
               public function imageAction()
  | 
        
        
            | 
            | 
           433 | 
               {
  | 
        
        
           | 788 | 
           stevensc | 
           434 | 
                   // Obtener el usuario actual
  | 
        
        
           | 1 | 
           efrain | 
           435 | 
                   $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           436 | 
                   $currentUser = $currentUserPlugin->getUser();
  | 
        
        
           | 788 | 
           stevensc | 
           437 | 
              | 
        
        
            | 
            | 
           438 | 
                   // Obtener el operation
  | 
        
        
           | 1 | 
           efrain | 
           439 | 
                   $operation = $this->params()->fromRoute('operation');
  | 
        
        
            | 
            | 
           440 | 
              | 
        
        
           | 788 | 
           stevensc | 
           441 | 
                   $request = $this->getRequest();
  | 
        
        
           | 1 | 
           efrain | 
           442 | 
              | 
        
        
           | 789 | 
           stevensc | 
           443 | 
                   if(!$request->isPost() && !$request->isGet()) {
  | 
        
        
           | 788 | 
           stevensc | 
           444 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           445 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           446 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           447 | 
                       ]);
  | 
        
        
            | 
            | 
           448 | 
                   }
  | 
        
        
            | 
            | 
           449 | 
              | 
        
        
            | 
            | 
           450 | 
                   $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           451 | 
                   $storage = Storage::getInstance($this->config, $this->adapter);
  | 
        
        
            | 
            | 
           452 | 
                   $target_path = $storage->getPathUser();
  | 
        
        
           | 1 | 
           efrain | 
           453 | 
              | 
        
        
            | 
            | 
           454 | 
                   if($request->isGet()) {
  | 
        
        
           | 283 | 
           www | 
           455 | 
                       $image = $storage->getUserImage($currentUser);
  | 
        
        
           | 1 | 
           efrain | 
           456 | 
              | 
        
        
            | 
            | 
           457 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           458 | 
                           'success' => true,
  | 
        
        
           | 283 | 
           www | 
           459 | 
                           'data' => $image,
  | 
        
        
           | 1 | 
           efrain | 
           460 | 
                       ]);
  | 
        
        
           | 788 | 
           stevensc | 
           461 | 
                   }
  | 
        
        
            | 
            | 
           462 | 
              | 
        
        
            | 
            | 
           463 | 
                   if($request->isPost()) {
  | 
        
        
           | 1 | 
           efrain | 
           464 | 
                       if($operation == 'delete') {
  | 
        
        
           | 788 | 
           stevensc | 
           465 | 
                           // Si el usuario no tiene image
  | 
        
        
            | 
            | 
           466 | 
                           if(!$currentUser->image) {
  | 
        
        
            | 
            | 
           467 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           468 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           469 | 
                                   'data'   =>  'ERROR_RECORD_NOT_FOUND'
  | 
        
        
            | 
            | 
           470 | 
                               ]);
  | 
        
        
           | 1 | 
           efrain | 
           471 | 
                           }
  | 
        
        
           | 788 | 
           stevensc | 
           472 | 
              | 
        
        
            | 
            | 
           473 | 
                           // Si no se puede borrar el archivo
  | 
        
        
            | 
            | 
           474 | 
                           if(!$storage->deleteFile($target_path ,$currentUser->uuid, $currentUser->image)) {
  | 
        
        
            | 
            | 
           475 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           476 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           477 | 
                                   'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
  | 
        
        
            | 
            | 
           478 | 
                               ]);
  | 
        
        
            | 
            | 
           479 | 
                           }
  | 
        
        
           | 1 | 
           efrain | 
           480 | 
              | 
        
        
           | 788 | 
           stevensc | 
           481 | 
                           // Actualizar el usuario
  | 
        
        
           | 1 | 
           efrain | 
           482 | 
                           $currentUser->image = '';
  | 
        
        
            | 
            | 
           483 | 
                           if(!$userMapper->update($currentUser)) {
  | 
        
        
            | 
            | 
           484 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           485 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           486 | 
                                   'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
  | 
        
        
            | 
            | 
           487 | 
                               ]);
  | 
        
        
            | 
            | 
           488 | 
                           }
  | 
        
        
           | 788 | 
           stevensc | 
           489 | 
              | 
        
        
            | 
            | 
           490 | 
                           $this->logger->info('Se borro el image  del usuario ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
            | 
            | 
           491 | 
                       }
  | 
        
        
            | 
            | 
           492 | 
              | 
        
        
            | 
            | 
           493 | 
                       if($operation == 'upload') {
  | 
        
        
           | 1 | 
           efrain | 
           494 | 
                           $form = new ChangeImageForm($this->config);
  | 
        
        
            | 
            | 
           495 | 
                           $data 	= array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
  | 
        
        
            | 
            | 
           496 | 
              | 
        
        
            | 
            | 
           497 | 
                           $form->setData($data);
  | 
        
        
            | 
            | 
           498 | 
              | 
        
        
           | 788 | 
           stevensc | 
           499 | 
                           if(!$form->isValid()) {
  | 
        
        
            | 
            | 
           500 | 
                               $messages = [];
  | 
        
        
            | 
            | 
           501 | 
                               $form_messages = (array) $form->getMessages();
  | 
        
        
           | 283 | 
           www | 
           502 | 
              | 
        
        
           | 788 | 
           stevensc | 
           503 | 
                               foreach($form_messages  as $fieldname => $field_messages)
  | 
        
        
            | 
            | 
           504 | 
                               {
  | 
        
        
            | 
            | 
           505 | 
                                   $messages[$fieldname] = array_values($field_messages);
  | 
        
        
           | 1 | 
           efrain | 
           506 | 
                               }
  | 
        
        
            | 
            | 
           507 | 
              | 
        
        
           | 788 | 
           stevensc | 
           508 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           509 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           510 | 
                                   'data'   => $messages
  | 
        
        
            | 
            | 
           511 | 
                               ]);
  | 
        
        
            | 
            | 
           512 | 
                           }
  | 
        
        
           | 283 | 
           www | 
           513 | 
              | 
        
        
           | 788 | 
           stevensc | 
           514 | 
                           $storage->setFiles($request->getFiles()->toArray());
  | 
        
        
            | 
            | 
           515 | 
                           if(!$storage->setCurrentFilename('image')) {
  | 
        
        
            | 
            | 
           516 | 
                               $this->logger->err('Error al subir la imagen del usuario', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
            | 
            | 
           517 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           518 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           519 | 
                                   'data'   =>  'ERROR_UPLOAD_FILE'
  | 
        
        
            | 
            | 
           520 | 
                               ]);
  | 
        
        
            | 
            | 
           521 | 
                           }
  | 
        
        
            | 
            | 
           522 | 
              | 
        
        
            | 
            | 
           523 | 
                           // Si el usuario tiene image se borra
  | 
        
        
            | 
            | 
           524 | 
                           if($currentUser->image) {
  | 
        
        
            | 
            | 
           525 | 
                               // Si el usuario tiene image, se borra
  | 
        
        
            | 
            | 
           526 | 
                               if(!$storage->deleteFile($target_path, $currentUser->uuid, $currentUser->image)) {
  | 
        
        
            | 
            | 
           527 | 
                                   $this->logger->err('Error al borrar la imagen del usuario', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
           | 1 | 
           efrain | 
           528 | 
                                   return new JsonModel([
  | 
        
        
            | 
            | 
           529 | 
                                       'success'   => false,
  | 
        
        
            | 
            | 
           530 | 
                                       'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
  | 
        
        
            | 
            | 
           531 | 
                                   ]);
  | 
        
        
            | 
            | 
           532 | 
                               }
  | 
        
        
           | 788 | 
           stevensc | 
           533 | 
                           }
  | 
        
        
            | 
            | 
           534 | 
              | 
        
        
            | 
            | 
           535 | 
                           // Obtener el tamaño de la imagen
  | 
        
        
            | 
            | 
           536 | 
                           list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
  | 
        
        
            | 
            | 
           537 | 
              | 
        
        
            | 
            | 
           538 | 
                           // Obtener el archivo temporal
  | 
        
        
           | 793 | 
           stevensc | 
           539 | 
                           $source_filename    = $storage->getTmpFilename();
  | 
        
        
            | 
            | 
           540 | 
                           $filename           = $storage->getFilename();
  | 
        
        
            | 
            | 
           541 | 
                           $target_filename    = $storage->composePathToFilename(Storage::TYPE_USER, $currentUser->uuid, $filename);
  | 
        
        
           | 788 | 
           stevensc | 
           542 | 
              | 
        
        
           | 792 | 
           stevensc | 
           543 | 
              | 
        
        
            | 
            | 
           544 | 
                           $this->logger->err('source_filename: ' . $source_filename . ' target_filename: ' . $target_filename);
  | 
        
        
            | 
            | 
           545 | 
              | 
        
        
           | 788 | 
           stevensc | 
           546 | 
                           if(!$storage->uploadImageResize($source_filename, $target_filename, $target_width, $target_height)) {
  | 
        
        
            | 
            | 
           547 | 
                               $this->logger->err('Error al subir la imagen del usuario', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
           | 1 | 
           efrain | 
           548 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           549 | 
                                   'success'   => false,
  | 
        
        
           | 788 | 
           stevensc | 
           550 | 
                                   'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
  | 
        
        
           | 1 | 
           efrain | 
           551 | 
                               ]);
  | 
        
        
            | 
            | 
           552 | 
                           }
  | 
        
        
           | 788 | 
           stevensc | 
           553 | 
              | 
        
        
            | 
            | 
           554 | 
              | 
        
        
           | 791 | 
           stevensc | 
           555 | 
                           $currentUser->image = $filename;
  | 
        
        
           | 788 | 
           stevensc | 
           556 | 
                           if(!$userMapper->updateImage($currentUser)) {
  | 
        
        
            | 
            | 
           557 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           558 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           559 | 
                                   'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
  | 
        
        
            | 
            | 
           560 | 
                               ]);
  | 
        
        
            | 
            | 
           561 | 
                           }
  | 
        
        
            | 
            | 
           562 | 
              | 
        
        
            | 
            | 
           563 | 
                           $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           564 | 
                           $userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
  | 
        
        
           | 791 | 
           stevensc | 
           565 | 
              | 
        
        
           | 788 | 
           stevensc | 
           566 | 
                           if($userProfile) {
  | 
        
        
           | 791 | 
           stevensc | 
           567 | 
                               $userProfile->image = $filename;
  | 
        
        
           | 788 | 
           stevensc | 
           568 | 
                               $userProfileMapper->updateImage($userProfile);
  | 
        
        
            | 
            | 
           569 | 
                           }
  | 
        
        
            | 
            | 
           570 | 
              | 
        
        
            | 
            | 
           571 | 
                           $this->logger->info('Se actualizo el image del usuario', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
           | 1 | 
           efrain | 
           572 | 
                       }
  | 
        
        
           | 283 | 
           www | 
           573 | 
              | 
        
        
            | 
            | 
           574 | 
              | 
        
        
           | 1 | 
           efrain | 
           575 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           576 | 
                           'success'   => true,
  | 
        
        
           | 788 | 
           stevensc | 
           577 | 
                           'data' =>  $storage->getUserImage($currentUser)
  | 
        
        
           | 1 | 
           efrain | 
           578 | 
                       ]);
  | 
        
        
            | 
            | 
           579 | 
                   }
  | 
        
        
            | 
            | 
           580 | 
               }
  | 
        
        
            | 
            | 
           581 | 
              | 
        
        
            | 
            | 
           582 | 
              | 
        
        
            | 
            | 
           583 | 
              | 
        
        
            | 
            | 
           584 | 
               /**
  | 
        
        
            | 
            | 
           585 | 
                * Actualización de la ubucación
  | 
        
        
            | 
            | 
           586 | 
                * @return \Laminas\View\Model\JsonModel
  | 
        
        
            | 
            | 
           587 | 
                */
  | 
        
        
            | 
            | 
           588 | 
               public function locationAction()
  | 
        
        
            | 
            | 
           589 | 
               {
  | 
        
        
            | 
            | 
           590 | 
                   $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           591 | 
                   $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           592 | 
              | 
        
        
            | 
            | 
           593 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           594 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           595 | 
                       $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           596 | 
              | 
        
        
            | 
            | 
           597 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           598 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           599 | 
              | 
        
        
            | 
            | 
           600 | 
                       $locationMapper = LocationMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           601 | 
                       $location = $locationMapper->fetchOne($currentUser->location_id);
  | 
        
        
            | 
            | 
           602 | 
              | 
        
        
            | 
            | 
           603 | 
              | 
        
        
            | 
            | 
           604 | 
                       $data = [
  | 
        
        
            | 
            | 
           605 | 
                           'formatted_address' => $location ? $location->formatted_address : '',
  | 
        
        
            | 
            | 
           606 | 
                           'address1' => $location ? $location->address1 : '',
  | 
        
        
            | 
            | 
           607 | 
                           'address2' => $location ? $location->address2 : '',
  | 
        
        
            | 
            | 
           608 | 
                           'country' => $location ? $location->country : '',
  | 
        
        
            | 
            | 
           609 | 
                           'state' => $location ? $location->state : '',
  | 
        
        
            | 
            | 
           610 | 
                           'city1' => $location ? $location->city1 : '',
  | 
        
        
            | 
            | 
           611 | 
                           'city2' => $location ? $location->city2 : '',
  | 
        
        
            | 
            | 
           612 | 
                           'postal_code' => $location ? $location->postal_code : '',
  | 
        
        
            | 
            | 
           613 | 
                           'latitude' => $location ? $location->latitude : '',
  | 
        
        
            | 
            | 
           614 | 
                           'longitude' => $location ? $location->longitude : '',
  | 
        
        
            | 
            | 
           615 | 
                       ];
  | 
        
        
            | 
            | 
           616 | 
              | 
        
        
            | 
            | 
           617 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           618 | 
                           'success' => true,
  | 
        
        
            | 
            | 
           619 | 
                           'data' => $data
  | 
        
        
            | 
            | 
           620 | 
                       ]);
  | 
        
        
            | 
            | 
           621 | 
              | 
        
        
            | 
            | 
           622 | 
              | 
        
        
            | 
            | 
           623 | 
                   } else  if($request->isPost()) {
  | 
        
        
            | 
            | 
           624 | 
              | 
        
        
            | 
            | 
           625 | 
                       $form = new LocationForm();
  | 
        
        
            | 
            | 
           626 | 
                       $dataPost = $request->getPost()->toArray();
  | 
        
        
            | 
            | 
           627 | 
              | 
        
        
            | 
            | 
           628 | 
                       $form->setData($dataPost);
  | 
        
        
            | 
            | 
           629 | 
              | 
        
        
            | 
            | 
           630 | 
                       if($form->isValid()) {
  | 
        
        
            | 
            | 
           631 | 
              | 
        
        
            | 
            | 
           632 | 
              | 
        
        
            | 
            | 
           633 | 
                           $dataPost = (array) $form->getData();
  | 
        
        
            | 
            | 
           634 | 
              | 
        
        
            | 
            | 
           635 | 
                           $location = new Location();
  | 
        
        
            | 
            | 
           636 | 
                           $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           637 | 
                           $hydrator->hydrate($dataPost, $location);
  | 
        
        
            | 
            | 
           638 | 
              | 
        
        
            | 
            | 
           639 | 
                           $location->id = $currentUser->location_id;
  | 
        
        
            | 
            | 
           640 | 
              | 
        
        
            | 
            | 
           641 | 
                           $locationMapper = LocationMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           642 | 
                           if($currentUser->location_id) {
  | 
        
        
            | 
            | 
           643 | 
                               $result = $locationMapper->update($location);
  | 
        
        
            | 
            | 
           644 | 
                           } else {
  | 
        
        
            | 
            | 
           645 | 
                               $result = $locationMapper->insert($location);
  | 
        
        
            | 
            | 
           646 | 
              | 
        
        
            | 
            | 
           647 | 
                               if($result) {
  | 
        
        
            | 
            | 
           648 | 
                                   $currentUser->location_id = $location->id;
  | 
        
        
            | 
            | 
           649 | 
              | 
        
        
            | 
            | 
           650 | 
              | 
        
        
            | 
            | 
           651 | 
                                   $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           652 | 
                                   $userMapper->updateLocation($currentUser);
  | 
        
        
            | 
            | 
           653 | 
                               }
  | 
        
        
            | 
            | 
           654 | 
                           }
  | 
        
        
            | 
            | 
           655 | 
              | 
        
        
            | 
            | 
           656 | 
                           if($result) {
  | 
        
        
            | 
            | 
           657 | 
                               $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           658 | 
                               $userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
  | 
        
        
            | 
            | 
           659 | 
                               if($userProfile) {
  | 
        
        
            | 
            | 
           660 | 
                                   $userProfile->location_id = $location->id;
  | 
        
        
            | 
            | 
           661 | 
                                   $userProfileMapper->updateLocation($userProfile);
  | 
        
        
            | 
            | 
           662 | 
                               }
  | 
        
        
            | 
            | 
           663 | 
                           }
  | 
        
        
            | 
            | 
           664 | 
              | 
        
        
            | 
            | 
           665 | 
                           if($result) {
  | 
        
        
            | 
            | 
           666 | 
                               $this->logger->info('Se actualizo la ubicación del usuario ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
            | 
            | 
           667 | 
              | 
        
        
            | 
            | 
           668 | 
                               $response = [
  | 
        
        
            | 
            | 
           669 | 
                                   'success'   => true,
  | 
        
        
            | 
            | 
           670 | 
                                   'data' => [
  | 
        
        
            | 
            | 
           671 | 
                                       'formatted_address' => $location->formatted_address,
  | 
        
        
            | 
            | 
           672 | 
                                       'message' =>  'LABEL_LOCATION_UPDATED' ,
  | 
        
        
            | 
            | 
           673 | 
              | 
        
        
            | 
            | 
           674 | 
                                   ]
  | 
        
        
            | 
            | 
           675 | 
                               ];
  | 
        
        
            | 
            | 
           676 | 
                           } else {
  | 
        
        
            | 
            | 
           677 | 
                               $response = [
  | 
        
        
            | 
            | 
           678 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           679 | 
                                   'data' => 'ERROR_THERE_WAS_AN_ERROR'
  | 
        
        
            | 
            | 
           680 | 
                               ];
  | 
        
        
            | 
            | 
           681 | 
                           }
  | 
        
        
            | 
            | 
           682 | 
              | 
        
        
            | 
            | 
           683 | 
              | 
        
        
            | 
            | 
           684 | 
              | 
        
        
            | 
            | 
           685 | 
                           return new JsonModel($response);
  | 
        
        
            | 
            | 
           686 | 
              | 
        
        
            | 
            | 
           687 | 
                       } else {
  | 
        
        
            | 
            | 
           688 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           689 | 
                               'success'   => false,
  | 
        
        
            | 
            | 
           690 | 
                               'data'   =>   'ERROR_PLACED_AUTOCOMPLETE_DOES_NOT_CONTAIN_GEOMETRY'
  | 
        
        
            | 
            | 
           691 | 
                           ]);
  | 
        
        
            | 
            | 
           692 | 
                       }
  | 
        
        
            | 
            | 
           693 | 
                   }
  | 
        
        
            | 
            | 
           694 | 
              | 
        
        
            | 
            | 
           695 | 
              | 
        
        
            | 
            | 
           696 | 
                   $data = [
  | 
        
        
            | 
            | 
           697 | 
                       'success' => false,
  | 
        
        
            | 
            | 
           698 | 
                       'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           699 | 
                   ];
  | 
        
        
            | 
            | 
           700 | 
              | 
        
        
            | 
            | 
           701 | 
              | 
        
        
            | 
            | 
           702 | 
                   return new JsonModel($data);
  | 
        
        
            | 
            | 
           703 | 
               }
  | 
        
        
            | 
            | 
           704 | 
              | 
        
        
            | 
            | 
           705 | 
               public function privacyAction()
  | 
        
        
            | 
            | 
           706 | 
               {
  | 
        
        
            | 
            | 
           707 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           708 | 
              | 
        
        
            | 
            | 
           709 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           710 | 
              | 
        
        
            | 
            | 
           711 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           712 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           713 | 
              | 
        
        
            | 
            | 
           714 | 
                       $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           715 | 
                       $user = $userMapper->fetchOne($currentUser->id);
  | 
        
        
            | 
            | 
           716 | 
              | 
        
        
            | 
            | 
           717 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           718 | 
                           'success' => true,
  | 
        
        
            | 
            | 
           719 | 
                           'data' => [
  | 
        
        
            | 
            | 
           720 | 
                               'show_in_search' => $user->show_in_search ? 1  : 0
  | 
        
        
            | 
            | 
           721 | 
                           ]
  | 
        
        
            | 
            | 
           722 | 
                       ]);
  | 
        
        
            | 
            | 
           723 | 
              | 
        
        
            | 
            | 
           724 | 
              | 
        
        
            | 
            | 
           725 | 
                   } else if($request->isPost()) {
  | 
        
        
            | 
            | 
           726 | 
              | 
        
        
            | 
            | 
           727 | 
                       $dataPost = $request->getPost()->toArray();
  | 
        
        
            | 
            | 
           728 | 
                       $form = new PrivacySettingForm();
  | 
        
        
            | 
            | 
           729 | 
                       $form->setData($dataPost);
  | 
        
        
            | 
            | 
           730 | 
              | 
        
        
            | 
            | 
           731 | 
                       if($form->isValid()) {
  | 
        
        
            | 
            | 
           732 | 
                           $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           733 | 
                           $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           734 | 
              | 
        
        
            | 
            | 
           735 | 
                           $dataPost = (array) $form->getData();
  | 
        
        
            | 
            | 
           736 | 
                           $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           737 | 
              | 
        
        
            | 
            | 
           738 | 
              | 
        
        
            | 
            | 
           739 | 
                           $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           740 | 
                           $hydrator->hydrate($dataPost, $currentUser);
  | 
        
        
            | 
            | 
           741 | 
              | 
        
        
            | 
            | 
           742 | 
                           if($userMapper->updatePrivacy($currentUser)) {
  | 
        
        
            | 
            | 
           743 | 
                               $this->logger->info('Se guardo las preferencias de privacidad', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
            | 
            | 
           744 | 
                               $data = [
  | 
        
        
            | 
            | 
           745 | 
                                   'success'   => true,
  | 
        
        
            | 
            | 
           746 | 
                                   'data'      => 'LABEL_PRIVACY_UPDATE'
  | 
        
        
            | 
            | 
           747 | 
                               ];
  | 
        
        
            | 
            | 
           748 | 
                           } else {
  | 
        
        
            | 
            | 
           749 | 
                               $data = [
  | 
        
        
            | 
            | 
           750 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           751 | 
                                   'data'   => 'ERROR_UNKNOWN'
  | 
        
        
            | 
            | 
           752 | 
                               ];
  | 
        
        
            | 
            | 
           753 | 
                           }
  | 
        
        
            | 
            | 
           754 | 
              | 
        
        
            | 
            | 
           755 | 
                           return new JsonModel($data);
  | 
        
        
            | 
            | 
           756 | 
              | 
        
        
            | 
            | 
           757 | 
                       } else {
  | 
        
        
            | 
            | 
           758 | 
                           $messages = [];
  | 
        
        
            | 
            | 
           759 | 
              | 
        
        
            | 
            | 
           760 | 
              | 
        
        
            | 
            | 
           761 | 
              | 
        
        
            | 
            | 
           762 | 
                           $form_messages = (array) $form->getMessages();
  | 
        
        
            | 
            | 
           763 | 
                           foreach($form_messages  as $fieldname => $field_messages)
  | 
        
        
            | 
            | 
           764 | 
                           {
  | 
        
        
            | 
            | 
           765 | 
              | 
        
        
            | 
            | 
           766 | 
                               $messages[$fieldname] = array_values($field_messages);
  | 
        
        
            | 
            | 
           767 | 
                           }
  | 
        
        
            | 
            | 
           768 | 
              | 
        
        
            | 
            | 
           769 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           770 | 
                               'success'   => false,
  | 
        
        
            | 
            | 
           771 | 
                               'data'   => $messages
  | 
        
        
            | 
            | 
           772 | 
                           ]);
  | 
        
        
            | 
            | 
           773 | 
                       }
  | 
        
        
            | 
            | 
           774 | 
                   }  else {
  | 
        
        
            | 
            | 
           775 | 
                       $data = [
  | 
        
        
            | 
            | 
           776 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           777 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           778 | 
                       ];
  | 
        
        
            | 
            | 
           779 | 
              | 
        
        
            | 
            | 
           780 | 
                       return new JsonModel($data);
  | 
        
        
            | 
            | 
           781 | 
                   }
  | 
        
        
            | 
            | 
           782 | 
              | 
        
        
            | 
            | 
           783 | 
                   return new JsonModel($data);
  | 
        
        
            | 
            | 
           784 | 
              | 
        
        
            | 
            | 
           785 | 
               }
  | 
        
        
            | 
            | 
           786 | 
              | 
        
        
            | 
            | 
           787 | 
               public function basicAction()
  | 
        
        
            | 
            | 
           788 | 
               {
  | 
        
        
            | 
            | 
           789 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           790 | 
              | 
        
        
            | 
            | 
           791 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           792 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           793 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           794 | 
              | 
        
        
            | 
            | 
           795 | 
                       $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           796 | 
                       $user = $userMapper->fetchOne($currentUser->id);
  | 
        
        
            | 
            | 
           797 | 
              | 
        
        
            | 
            | 
           798 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           799 | 
                           'success' => true,
  | 
        
        
            | 
            | 
           800 | 
                           'data' => [
  | 
        
        
            | 
            | 
           801 | 
                               'first_name' => $user->first_name,
  | 
        
        
            | 
            | 
           802 | 
                               'last_name' => $user->last_name,
  | 
        
        
            | 
            | 
           803 | 
                               'gender' => $user->gender ? $user->gender : '',
  | 
        
        
            | 
            | 
           804 | 
                               'phone' => $user->phone ? $user->phone : '',
  | 
        
        
            | 
            | 
           805 | 
                               'email' => $user->email,
  | 
        
        
            | 
            | 
           806 | 
                               'is_adult' => $user->is_adult,
  | 
        
        
            | 
            | 
           807 | 
                               'timezone' => $user->timezone,
  | 
        
        
            | 
            | 
           808 | 
                           ]
  | 
        
        
            | 
            | 
           809 | 
                       ]);
  | 
        
        
            | 
            | 
           810 | 
              | 
        
        
            | 
            | 
           811 | 
              | 
        
        
            | 
            | 
           812 | 
                   } else if($request->isPost()) {
  | 
        
        
            | 
            | 
           813 | 
              | 
        
        
            | 
            | 
           814 | 
                       $dataPost = $request->getPost()->toArray();
  | 
        
        
            | 
            | 
           815 | 
              | 
        
        
            | 
            | 
           816 | 
              | 
        
        
            | 
            | 
           817 | 
                       if(empty($dataPost['is_adult'])) {
  | 
        
        
            | 
            | 
           818 | 
                           $dataPost['is_adult'] = User::IS_ADULT_NO;
  | 
        
        
            | 
            | 
           819 | 
                       } else {
  | 
        
        
            | 
            | 
           820 | 
                           $dataPost['is_adult'] = $dataPost['is_adult'] == User::IS_ADULT_YES ? User::IS_ADULT_YES : User::IS_ADULT_NO;
  | 
        
        
            | 
            | 
           821 | 
                       }
  | 
        
        
            | 
            | 
           822 | 
              | 
        
        
            | 
            | 
           823 | 
              | 
        
        
            | 
            | 
           824 | 
              | 
        
        
            | 
            | 
           825 | 
                       $form = new  BasicForm();
  | 
        
        
            | 
            | 
           826 | 
                       $form->setData($dataPost);
  | 
        
        
            | 
            | 
           827 | 
              | 
        
        
            | 
            | 
           828 | 
                       if($form->isValid()) {
  | 
        
        
            | 
            | 
           829 | 
                           $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           830 | 
                           $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           831 | 
              | 
        
        
            | 
            | 
           832 | 
                           $dataPost = (array) $form->getData();
  | 
        
        
            | 
            | 
           833 | 
                           $hydrator = new ObjectPropertyHydrator();
  | 
        
        
            | 
            | 
           834 | 
              | 
        
        
            | 
            | 
           835 | 
              | 
        
        
            | 
            | 
           836 | 
                           $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           837 | 
                           $user = $userMapper->fetchOne($currentUser->id);
  | 
        
        
            | 
            | 
           838 | 
              | 
        
        
            | 
            | 
           839 | 
                           $hydrator->hydrate($dataPost, $user);
  | 
        
        
            | 
            | 
           840 | 
              | 
        
        
            | 
            | 
           841 | 
              | 
        
        
            | 
            | 
           842 | 
              | 
        
        
            | 
            | 
           843 | 
                           if($userMapper->updateBasic($user)) {
  | 
        
        
            | 
            | 
           844 | 
                               $this->logger->info('Se guardaron los datos básicos ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
  | 
        
        
            | 
            | 
           845 | 
                               $data = [
  | 
        
        
            | 
            | 
           846 | 
                                   'success'   => true,
  | 
        
        
            | 
            | 
           847 | 
                                   'data'      => 'LABEL_BASIC_UPDATE'
  | 
        
        
            | 
            | 
           848 | 
                               ];
  | 
        
        
            | 
            | 
           849 | 
                           } else {
  | 
        
        
            | 
            | 
           850 | 
                               $data = [
  | 
        
        
            | 
            | 
           851 | 
                                   'success'   => false,
  | 
        
        
            | 
            | 
           852 | 
                                   'data'   => 'ERROR_UNKNOWN'
  | 
        
        
            | 
            | 
           853 | 
                               ];
  | 
        
        
            | 
            | 
           854 | 
                           }
  | 
        
        
            | 
            | 
           855 | 
              | 
        
        
            | 
            | 
           856 | 
                           return new JsonModel($data);
  | 
        
        
            | 
            | 
           857 | 
              | 
        
        
            | 
            | 
           858 | 
                       } else {
  | 
        
        
            | 
            | 
           859 | 
                           $messages = [];
  | 
        
        
            | 
            | 
           860 | 
              | 
        
        
            | 
            | 
           861 | 
              | 
        
        
            | 
            | 
           862 | 
              | 
        
        
            | 
            | 
           863 | 
                           $form_messages = (array) $form->getMessages();
  | 
        
        
            | 
            | 
           864 | 
                           foreach($form_messages  as $fieldname => $field_messages)
  | 
        
        
            | 
            | 
           865 | 
                           {
  | 
        
        
            | 
            | 
           866 | 
              | 
        
        
            | 
            | 
           867 | 
                               $messages[$fieldname] = array_values($field_messages);
  | 
        
        
            | 
            | 
           868 | 
                           }
  | 
        
        
            | 
            | 
           869 | 
              | 
        
        
            | 
            | 
           870 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           871 | 
                               'success'   => false,
  | 
        
        
            | 
            | 
           872 | 
                               'data'   => $messages
  | 
        
        
            | 
            | 
           873 | 
                           ]);
  | 
        
        
            | 
            | 
           874 | 
                       }
  | 
        
        
            | 
            | 
           875 | 
                   }  else {
  | 
        
        
            | 
            | 
           876 | 
                       $data = [
  | 
        
        
            | 
            | 
           877 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           878 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           879 | 
                       ];
  | 
        
        
            | 
            | 
           880 | 
              | 
        
        
            | 
            | 
           881 | 
                       return new JsonModel($data);
  | 
        
        
            | 
            | 
           882 | 
                   }
  | 
        
        
            | 
            | 
           883 | 
              | 
        
        
            | 
            | 
           884 | 
                   return new JsonModel($data);
  | 
        
        
            | 
            | 
           885 | 
              | 
        
        
            | 
            | 
           886 | 
               }
  | 
        
        
            | 
            | 
           887 | 
              | 
        
        
            | 
            | 
           888 | 
               public function browsersAction()
  | 
        
        
            | 
            | 
           889 | 
               {
  | 
        
        
            | 
            | 
           890 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           891 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           892 | 
              | 
        
        
            | 
            | 
           893 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           894 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           895 | 
              | 
        
        
            | 
            | 
           896 | 
                       $search = '';
  | 
        
        
            | 
            | 
           897 | 
                       $page               = intval($this->params()->fromQuery('start', 1), 10);
  | 
        
        
            | 
            | 
           898 | 
                       $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
  | 
        
        
            | 
            | 
           899 | 
                       $order_field        = 'updated_on';
  | 
        
        
            | 
            | 
           900 | 
                       $order_direction = 'DESC';
  | 
        
        
            | 
            | 
           901 | 
              | 
        
        
            | 
            | 
           902 | 
              | 
        
        
            | 
            | 
           903 | 
              | 
        
        
            | 
            | 
           904 | 
                       $userBrowserMapper = UserBrowserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           905 | 
                       $paginator = $userBrowserMapper->fetchAllDataTable($currentUser->id, $search, $page, $records_x_page, $order_field, $order_direction);
  | 
        
        
            | 
            | 
           906 | 
              | 
        
        
            | 
            | 
           907 | 
                       $items = [];
  | 
        
        
            | 
            | 
           908 | 
                       $records = $paginator->getCurrentItems();
  | 
        
        
            | 
            | 
           909 | 
                       foreach($records as $record)
  | 
        
        
            | 
            | 
           910 | 
                       {
  | 
        
        
            | 
            | 
           911 | 
                           $item = [
  | 
        
        
            | 
            | 
           912 | 
                               'id' => $record->id,
  | 
        
        
            | 
            | 
           913 | 
                               'platform' => $record->platform,
  | 
        
        
            | 
            | 
           914 | 
                               'browser' => $record->browser,
  | 
        
        
            | 
            | 
           915 | 
                               'device_type' => $record->device_type,
  | 
        
        
            | 
            | 
           916 | 
                               'version' => $record->version,
  | 
        
        
            | 
            | 
           917 | 
                               'updated_on' => $record->updated_on,
  | 
        
        
            | 
            | 
           918 | 
                           ];
  | 
        
        
            | 
            | 
           919 | 
              | 
        
        
            | 
            | 
           920 | 
                           array_push($items, $item);
  | 
        
        
            | 
            | 
           921 | 
                       }
  | 
        
        
            | 
            | 
           922 | 
              | 
        
        
            | 
            | 
           923 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           924 | 
                           'success' => true,
  | 
        
        
            | 
            | 
           925 | 
                           'data' => [
  | 
        
        
            | 
            | 
           926 | 
                               'items' => $items,
  | 
        
        
            | 
            | 
           927 | 
                               'total' => $paginator->getTotalItemCount(),
  | 
        
        
            | 
            | 
           928 | 
                           ]
  | 
        
        
            | 
            | 
           929 | 
                       ]);
  | 
        
        
            | 
            | 
           930 | 
              | 
        
        
            | 
            | 
           931 | 
                   } else {
  | 
        
        
            | 
            | 
           932 | 
                       return new JsonModel(['success' => false, 'data' => 'ERROR_METHOD_NOT_ALLOWED' ]);
  | 
        
        
            | 
            | 
           933 | 
                   }
  | 
        
        
            | 
            | 
           934 | 
               }
  | 
        
        
            | 
            | 
           935 | 
               public function devicesAction()
  | 
        
        
            | 
            | 
           936 | 
               {
  | 
        
        
            | 
            | 
           937 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           938 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           939 | 
              | 
        
        
            | 
            | 
           940 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           941 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           942 | 
              | 
        
        
            | 
            | 
           943 | 
                       $page               = intval($this->params()->fromPost('start', 1), 10);
  | 
        
        
            | 
            | 
           944 | 
                       $records_x_page     = intval($this->params()->fromPost('length', 10), 10);
  | 
        
        
            | 
            | 
           945 | 
              | 
        
        
            | 
            | 
           946 | 
              | 
        
        
            | 
            | 
           947 | 
                       /*
  | 
        
        
            | 
            | 
           948 | 
                        select d.platform, d.brand, d.manufacturer, d.model, d.version,
  | 
        
        
            | 
            | 
           949 | 
                        dh.ip, dh.updated_on  from tbl_device_history as dh
  | 
        
        
            | 
            | 
           950 | 
                        inner join tbl_devices as d on d.id  = dh.device_id
  | 
        
        
            | 
            | 
           951 | 
                        where dh.user_id = 4 order by dh.updated_on  desc
  | 
        
        
            | 
            | 
           952 | 
                        */
  | 
        
        
            | 
            | 
           953 | 
              | 
        
        
            | 
            | 
           954 | 
                       $queryMapper = QueryMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           955 | 
                       $select = $queryMapper->getSql()->select();
  | 
        
        
            | 
            | 
           956 | 
                       $select->columns(['ip', 'updated_on']);
  | 
        
        
            | 
            | 
           957 | 
                       $select->from(['dh' => DeviceHistoryMapper::_TABLE]);
  | 
        
        
            | 
            | 
           958 | 
                       $select->join(['d' => DeviceMapper::_TABLE], 'd.id  = dh.device_id', ['id', 'platform','brand','manufacturer','model','version']);
  | 
        
        
            | 
            | 
           959 | 
                       $select->where->equalTo('dh.user_id', $currentUser->id);
  | 
        
        
            | 
            | 
           960 | 
                       $select->order('updated_on desc ');
  | 
        
        
            | 
            | 
           961 | 
              | 
        
        
            | 
            | 
           962 | 
              | 
        
        
            | 
            | 
           963 | 
              | 
        
        
            | 
            | 
           964 | 
                       $hydrator   = new ArraySerializableHydrator();
  | 
        
        
            | 
            | 
           965 | 
                       $resultset  = new HydratingResultSet($hydrator);
  | 
        
        
            | 
            | 
           966 | 
              | 
        
        
            | 
            | 
           967 | 
                       $adapter = new DbSelect($select, $queryMapper->getSql(), $resultset);
  | 
        
        
            | 
            | 
           968 | 
                       $paginator = new Paginator($adapter);
  | 
        
        
            | 
            | 
           969 | 
                       $paginator->setItemCountPerPage($records_x_page);
  | 
        
        
            | 
            | 
           970 | 
                       $paginator->setCurrentPageNumber($page);
  | 
        
        
            | 
            | 
           971 | 
              | 
        
        
            | 
            | 
           972 | 
                       $items = [];
  | 
        
        
            | 
            | 
           973 | 
                       $records = $paginator->getCurrentItems();
  | 
        
        
            | 
            | 
           974 | 
                       foreach($records as $record)
  | 
        
        
            | 
            | 
           975 | 
                       {
  | 
        
        
            | 
            | 
           976 | 
                           $item = [
  | 
        
        
            | 
            | 
           977 | 
                               'id' => $record['id'],
  | 
        
        
            | 
            | 
           978 | 
                               'platform' => $record['platform'],
  | 
        
        
            | 
            | 
           979 | 
                               'brand' => $record['brand'],
  | 
        
        
            | 
            | 
           980 | 
                               'manufacturer' => $record['manufacturer'],
  | 
        
        
            | 
            | 
           981 | 
                               'version' => $record['version'],
  | 
        
        
            | 
            | 
           982 | 
                               'model' => $record['model'],
  | 
        
        
            | 
            | 
           983 | 
                               'version' => $record['version'],
  | 
        
        
            | 
            | 
           984 | 
                               'ip' => $record['ip'],
  | 
        
        
            | 
            | 
           985 | 
                               'updated_on' => $record['updated_on'],
  | 
        
        
            | 
            | 
           986 | 
                           ];
  | 
        
        
            | 
            | 
           987 | 
              | 
        
        
            | 
            | 
           988 | 
                           array_push($items, $item);
  | 
        
        
            | 
            | 
           989 | 
                       }
  | 
        
        
            | 
            | 
           990 | 
              | 
        
        
            | 
            | 
           991 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           992 | 
                           'success' => true,
  | 
        
        
            | 
            | 
           993 | 
                           'data' => [
  | 
        
        
            | 
            | 
           994 | 
                               'items' => $items,
  | 
        
        
            | 
            | 
           995 | 
                               'total' => $paginator->getTotalItemCount(),
  | 
        
        
            | 
            | 
           996 | 
                           ]
  | 
        
        
            | 
            | 
           997 | 
                       ]);
  | 
        
        
            | 
            | 
           998 | 
              | 
        
        
            | 
            | 
           999 | 
                   } else {
  | 
        
        
            | 
            | 
           1000 | 
                       return new JsonModel(['success' => false, 'data' => 'ERROR_METHOD_NOT_ALLOWED' ]);
  | 
        
        
            | 
            | 
           1001 | 
                   }
  | 
        
        
            | 
            | 
           1002 | 
               }
  | 
        
        
            | 
            | 
           1003 | 
              | 
        
        
            | 
            | 
           1004 | 
              | 
        
        
            | 
            | 
           1005 | 
               public function ipsAction()
  | 
        
        
            | 
            | 
           1006 | 
               {
  | 
        
        
            | 
            | 
           1007 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           1008 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           1009 | 
              | 
        
        
            | 
            | 
           1010 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           1011 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           1012 | 
              | 
        
        
            | 
            | 
           1013 | 
                       $search = '';
  | 
        
        
            | 
            | 
           1014 | 
                       $page               = intval($this->params()->fromPost('start', 1), 10);
  | 
        
        
            | 
            | 
           1015 | 
                       $records_x_page     = intval($this->params()->fromPost('length', 10), 10);
  | 
        
        
            | 
            | 
           1016 | 
                       $order_field        = 'updated_on';
  | 
        
        
            | 
            | 
           1017 | 
                       $order_direction = 'DESC';
  | 
        
        
            | 
            | 
           1018 | 
              | 
        
        
            | 
            | 
           1019 | 
              | 
        
        
            | 
            | 
           1020 | 
              | 
        
        
            | 
            | 
           1021 | 
                       $userBrowserMapper = UserIpMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           1022 | 
                       $paginator = $userBrowserMapper->fetchAllDataTable($currentUser->id, $search, $page, $records_x_page, $order_field, $order_direction);
  | 
        
        
            | 
            | 
           1023 | 
              | 
        
        
            | 
            | 
           1024 | 
                       $items = [];
  | 
        
        
            | 
            | 
           1025 | 
                       $records = $paginator->getCurrentItems();
  | 
        
        
            | 
            | 
           1026 | 
                       foreach($records as $record)
  | 
        
        
            | 
            | 
           1027 | 
                       {
  | 
        
        
            | 
            | 
           1028 | 
                           $item = [
  | 
        
        
            | 
            | 
           1029 | 
                               'id' => $record->id,
  | 
        
        
            | 
            | 
           1030 | 
                               'ip' => $record->ip,
  | 
        
        
            | 
            | 
           1031 | 
                               'country_name' => $record->country_name,
  | 
        
        
            | 
            | 
           1032 | 
                               'state_name' => $record->state_name,
  | 
        
        
            | 
            | 
           1033 | 
                               'city' => $record->city,
  | 
        
        
            | 
            | 
           1034 | 
                               'postal_code' => $record->postal_code,
  | 
        
        
            | 
            | 
           1035 | 
                               'updated_on' => $record->updated_on,
  | 
        
        
            | 
            | 
           1036 | 
                           ];
  | 
        
        
            | 
            | 
           1037 | 
              | 
        
        
            | 
            | 
           1038 | 
                           array_push($items, $item);
  | 
        
        
            | 
            | 
           1039 | 
                       }
  | 
        
        
            | 
            | 
           1040 | 
              | 
        
        
            | 
            | 
           1041 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           1042 | 
                           'success' => true,
  | 
        
        
            | 
            | 
           1043 | 
                           'data' => [
  | 
        
        
            | 
            | 
           1044 | 
                               'items' => $items,
  | 
        
        
            | 
            | 
           1045 | 
                               'total' => $paginator->getTotalItemCount(),
  | 
        
        
            | 
            | 
           1046 | 
                           ]
  | 
        
        
            | 
            | 
           1047 | 
                       ]);
  | 
        
        
            | 
            | 
           1048 | 
              | 
        
        
            | 
            | 
           1049 | 
                   } else {
  | 
        
        
            | 
            | 
           1050 | 
                       return new JsonModel(['success' => false, 'data' => 'ERROR_METHOD_NOT_ALLOWED' ]);
  | 
        
        
            | 
            | 
           1051 | 
                   }
  | 
        
        
            | 
            | 
           1052 | 
               }
  | 
        
        
            | 
            | 
           1053 | 
              | 
        
        
            | 
            | 
           1054 | 
               public function transactionsAction()
  | 
        
        
            | 
            | 
           1055 | 
               {
  | 
        
        
            | 
            | 
           1056 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           1057 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           1058 | 
              | 
        
        
            | 
            | 
           1059 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           1060 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           1061 | 
              | 
        
        
            | 
            | 
           1062 | 
                       $search = '';
  | 
        
        
            | 
            | 
           1063 | 
                       $page               = intval($this->params()->fromPost('start', 1), 10);
  | 
        
        
            | 
            | 
           1064 | 
                       $records_x_page     = intval($this->params()->fromPost('length', 10), 10);
  | 
        
        
            | 
            | 
           1065 | 
                       $order_field        = 'updated_on';
  | 
        
        
            | 
            | 
           1066 | 
                       $order_direction = 'DESC';
  | 
        
        
            | 
            | 
           1067 | 
              | 
        
        
            | 
            | 
           1068 | 
                       $status = [
  | 
        
        
            | 
            | 
           1069 | 
                           Transaction::STATUS_CANCELLED => 'LABEL_CANCELLED',
  | 
        
        
            | 
            | 
           1070 | 
                           Transaction::STATUS_PENDING => 'LABEL_PENDING',
  | 
        
        
            | 
            | 
           1071 | 
                           Transaction::STATUS_PROCESSING => 'LABEL_PROCESSING',
  | 
        
        
            | 
            | 
           1072 | 
                           Transaction::STATUS_REJECTED => 'LABEL_REJECTED',
  | 
        
        
            | 
            | 
           1073 | 
                           Transaction::STATUS_COMPLETED => 'LABEL_COMPLETED',
  | 
        
        
            | 
            | 
           1074 | 
                           Transaction::STATUS_CANCELLED => 'LABEL_CANCELLED',
  | 
        
        
            | 
            | 
           1075 | 
                       ];
  | 
        
        
            | 
            | 
           1076 | 
              | 
        
        
            | 
            | 
           1077 | 
                       $types = [
  | 
        
        
            | 
            | 
           1078 | 
                           Transaction::TYPE_COUPON => 'LABEL_COUPON',
  | 
        
        
            | 
            | 
           1079 | 
                           Transaction::TYPE_PAYMENT => 'LABEL_PAYMENT',
  | 
        
        
            | 
            | 
           1080 | 
                           Transaction::TYPE_REVERSE => 'LABEL_REVERSE',
  | 
        
        
            | 
            | 
           1081 | 
                           Transaction::TYPE_TRANSFER => 'LABEL_TRANSFER',
  | 
        
        
            | 
            | 
           1082 | 
                       ];
  | 
        
        
            | 
            | 
           1083 | 
              | 
        
        
            | 
            | 
           1084 | 
                       $providers = [
  | 
        
        
            | 
            | 
           1085 | 
                           Provider::PAYPAL => 'LABEL_PAYPAL',
  | 
        
        
            | 
            | 
           1086 | 
                       ];
  | 
        
        
            | 
            | 
           1087 | 
              | 
        
        
            | 
            | 
           1088 | 
                       $transactionMapper = TransactionMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           1089 | 
                       $paginator = $transactionMapper->fetchAllDataTable($currentUser->id, $search, $page, $records_x_page, $order_field, $order_direction);
  | 
        
        
            | 
            | 
           1090 | 
              | 
        
        
            | 
            | 
           1091 | 
                       $items = [];
  | 
        
        
            | 
            | 
           1092 | 
                       $records = $paginator->getCurrentItems();
  | 
        
        
            | 
            | 
           1093 | 
                       foreach($records as $record)
  | 
        
        
            | 
            | 
           1094 | 
                       {
  | 
        
        
            | 
            | 
           1095 | 
                           $item = [
  | 
        
        
            | 
            | 
           1096 | 
                               'id' => $record->id,
  | 
        
        
            | 
            | 
           1097 | 
                               'description' => $record->description,
  | 
        
        
            | 
            | 
           1098 | 
                               'provider' => $providers[$record->provider],
  | 
        
        
            | 
            | 
           1099 | 
                               'type' => $types[$record->type],
  | 
        
        
            | 
            | 
           1100 | 
                               'status' => $status[$record->status],
  | 
        
        
            | 
            | 
           1101 | 
                               'previous' => $record->previous,
  | 
        
        
            | 
            | 
           1102 | 
                               'amount' => $record->amount,
  | 
        
        
            | 
            | 
           1103 | 
                               'current' => $record->current,
  | 
        
        
            | 
            | 
           1104 | 
                               'updated_on' => $record->updated_on,
  | 
        
        
            | 
            | 
           1105 | 
                           ];
  | 
        
        
            | 
            | 
           1106 | 
              | 
        
        
            | 
            | 
           1107 | 
                           array_push($items, $item);
  | 
        
        
            | 
            | 
           1108 | 
                       }
  | 
        
        
            | 
            | 
           1109 | 
              | 
        
        
            | 
            | 
           1110 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           1111 | 
                           'success' => true,
  | 
        
        
            | 
            | 
           1112 | 
                           'data' => [
  | 
        
        
            | 
            | 
           1113 | 
                               'items' => $items,
  | 
        
        
            | 
            | 
           1114 | 
                               'total' => $paginator->getTotalItemCount(),
  | 
        
        
            | 
            | 
           1115 | 
                           ]
  | 
        
        
            | 
            | 
           1116 | 
                       ]);
  | 
        
        
            | 
            | 
           1117 | 
              | 
        
        
            | 
            | 
           1118 | 
                   } else {
  | 
        
        
            | 
            | 
           1119 | 
                       return new JsonModel(['success' => false, 'data' => 'ERROR_METHOD_NOT_ALLOWED' ]);
  | 
        
        
            | 
            | 
           1120 | 
                   }
  | 
        
        
            | 
            | 
           1121 | 
               }
  | 
        
        
            | 
            | 
           1122 | 
              | 
        
        
            | 
            | 
           1123 | 
              | 
        
        
            | 
            | 
           1124 | 
              | 
        
        
            | 
            | 
           1125 | 
               public function addFundAction()
  | 
        
        
            | 
            | 
           1126 | 
               {
  | 
        
        
            | 
            | 
           1127 | 
              | 
        
        
            | 
            | 
           1128 | 
                   $request = $this->request;
  | 
        
        
            | 
            | 
           1129 | 
                   if($request->isPost()) {
  | 
        
        
            | 
            | 
           1130 | 
              | 
        
        
            | 
            | 
           1131 | 
                       $form = new FundsAddForm();
  | 
        
        
            | 
            | 
           1132 | 
                       $form->setData($request->getPost()->toArray());
  | 
        
        
            | 
            | 
           1133 | 
                       if($form->isValid()) {
  | 
        
        
            | 
            | 
           1134 | 
              | 
        
        
            | 
            | 
           1135 | 
                           $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           1136 | 
                           $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           1137 | 
              | 
        
        
            | 
            | 
           1138 | 
              | 
        
        
            | 
            | 
           1139 | 
              | 
        
        
            | 
            | 
           1140 | 
              | 
        
        
            | 
            | 
           1141 | 
                           $dataPost = (array) $form->getData();
  | 
        
        
            | 
            | 
           1142 | 
              | 
        
        
            | 
            | 
           1143 | 
                           $description    = $dataPost['description'];
  | 
        
        
            | 
            | 
           1144 | 
                           $amount         = $dataPost['amount'];
  | 
        
        
            | 
            | 
           1145 | 
              | 
        
        
            | 
            | 
           1146 | 
              | 
        
        
            | 
            | 
           1147 | 
              | 
        
        
            | 
            | 
           1148 | 
                           $sandbox = $this->config['leaderslinked.runmode.sandbox_paypal'];
  | 
        
        
            | 
            | 
           1149 | 
                           if($sandbox) {
  | 
        
        
            | 
            | 
           1150 | 
                               //$account_id     = $this->config['leaderslinked.paypal.sandbox_account_id'];
  | 
        
        
            | 
            | 
           1151 | 
                               $client_id      = $this->config['leaderslinked.paypal.sandobx_client_id'];
  | 
        
        
            | 
            | 
           1152 | 
                               $client_secret  = $this->config['leaderslinked.paypal.sandbox_client_secret'];
  | 
        
        
            | 
            | 
           1153 | 
              | 
        
        
            | 
            | 
           1154 | 
              | 
        
        
            | 
            | 
           1155 | 
                               $environment = new SandboxEnvironment($client_id, $client_secret);
  | 
        
        
            | 
            | 
           1156 | 
              | 
        
        
            | 
            | 
           1157 | 
                           } else {
  | 
        
        
            | 
            | 
           1158 | 
                               // $account_id     = $this->config['leaderslinked.paypal.production_account_id'];
  | 
        
        
            | 
            | 
           1159 | 
                               $client_id      = $this->config['leaderslinked.paypal.production_client_id'];
  | 
        
        
            | 
            | 
           1160 | 
                               $client_secret  = $this->config['leaderslinked.paypal.production_client_secret'];
  | 
        
        
            | 
            | 
           1161 | 
              | 
        
        
            | 
            | 
           1162 | 
                               $environment = new ProductionEnvironment($client_id, $client_secret);
  | 
        
        
            | 
            | 
           1163 | 
                           }
  | 
        
        
            | 
            | 
           1164 | 
              | 
        
        
            | 
            | 
           1165 | 
                           $internal_id = uniqid(Provider::PAYPAL, true);
  | 
        
        
            | 
            | 
           1166 | 
                           $client = new PayPalHttpClient($environment);
  | 
        
        
            | 
            | 
           1167 | 
                           $request = new OrdersCreateRequest();
  | 
        
        
            | 
            | 
           1168 | 
              | 
        
        
            | 
            | 
           1169 | 
              | 
        
        
            | 
            | 
           1170 | 
                           //$request->prefer('return=representation');
  | 
        
        
            | 
            | 
           1171 | 
                           $request->body = [
  | 
        
        
            | 
            | 
           1172 | 
                               'intent' => 'CAPTURE',
  | 
        
        
            | 
            | 
           1173 | 
                               'purchase_units' => [[
  | 
        
        
            | 
            | 
           1174 | 
                                   'reference_id' => $internal_id,
  | 
        
        
            | 
            | 
           1175 | 
                                   'description' => $description,
  | 
        
        
            | 
            | 
           1176 | 
                                   'amount' => [
  | 
        
        
            | 
            | 
           1177 | 
                                       'value' => number_format($amount, 2),
  | 
        
        
            | 
            | 
           1178 | 
                                       'currency_code' => 'USD'
  | 
        
        
            | 
            | 
           1179 | 
                                   ]
  | 
        
        
            | 
            | 
           1180 | 
                               ]],
  | 
        
        
            | 
            | 
           1181 | 
                               'application_context' => [
  | 
        
        
            | 
            | 
           1182 | 
                                   'brand_name' => 'Leaders Linked',
  | 
        
        
            | 
            | 
           1183 | 
                                   'locale' => 'es-UY',
  | 
        
        
            | 
            | 
           1184 | 
                                   'cancel_url' => $this->url()->fromRoute('paypal/cancel', [] , ['force_canonical' => true]),
  | 
        
        
            | 
            | 
           1185 | 
                                   'return_url' => $this->url()->fromRoute('paypal/success', [] , ['force_canonical' => true]),
  | 
        
        
            | 
            | 
           1186 | 
                               ]
  | 
        
        
            | 
            | 
           1187 | 
                           ];
  | 
        
        
            | 
            | 
           1188 | 
              | 
        
        
            | 
            | 
           1189 | 
                           try {
  | 
        
        
            | 
            | 
           1190 | 
                               // Call API with your client and get a response for your call
  | 
        
        
            | 
            | 
           1191 | 
                               $response = $client->execute($request);
  | 
        
        
            | 
            | 
           1192 | 
              | 
        
        
            | 
            | 
           1193 | 
              | 
        
        
            | 
            | 
           1194 | 
                               $external_id = $response->result->id;
  | 
        
        
            | 
            | 
           1195 | 
                               $approve_url = '';
  | 
        
        
            | 
            | 
           1196 | 
                               if($response->result->status == 'CREATED') {
  | 
        
        
            | 
            | 
           1197 | 
              | 
        
        
            | 
            | 
           1198 | 
                                   $response->result->id;
  | 
        
        
            | 
            | 
           1199 | 
                                   foreach($response->result->links as $link)
  | 
        
        
            | 
            | 
           1200 | 
                                   {
  | 
        
        
            | 
            | 
           1201 | 
                                       if($link->rel == 'approve') {
  | 
        
        
            | 
            | 
           1202 | 
                                           $approve_url = $link->href;
  | 
        
        
            | 
            | 
           1203 | 
                                       }
  | 
        
        
            | 
            | 
           1204 | 
                                       //print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
  | 
        
        
            | 
            | 
           1205 | 
                                   }
  | 
        
        
            | 
            | 
           1206 | 
              | 
        
        
            | 
            | 
           1207 | 
              | 
        
        
            | 
            | 
           1208 | 
                               }
  | 
        
        
            | 
            | 
           1209 | 
              | 
        
        
            | 
            | 
           1210 | 
              | 
        
        
            | 
            | 
           1211 | 
                               //echo json_encode($resp, JSON_PRETTY_PRINT), "\n";
  | 
        
        
            | 
            | 
           1212 | 
              | 
        
        
            | 
            | 
           1213 | 
              | 
        
        
            | 
            | 
           1214 | 
              | 
        
        
            | 
            | 
           1215 | 
              | 
        
        
            | 
            | 
           1216 | 
              | 
        
        
            | 
            | 
           1217 | 
                               // To toggle printing the whole response body comment/uncomment below line
  | 
        
        
            | 
            | 
           1218 | 
                               // echo json_encode($resp->result, JSON_PRETTY_PRINT), "\n";
  | 
        
        
            | 
            | 
           1219 | 
                               if($external_id && $approve_url) {
  | 
        
        
            | 
            | 
           1220 | 
              | 
        
        
            | 
            | 
           1221 | 
                                   $transaction = new Transaction();
  | 
        
        
            | 
            | 
           1222 | 
                                   $transaction->internal_id = $internal_id;
  | 
        
        
            | 
            | 
           1223 | 
                                   $transaction->external_id = $external_id;
  | 
        
        
            | 
            | 
           1224 | 
                                   $transaction->provider = Provider::PAYPAL;
  | 
        
        
            | 
            | 
           1225 | 
                                   $transaction->user_id = $currentUser->id;
  | 
        
        
            | 
            | 
           1226 | 
                                   $transaction->previous = 0;
  | 
        
        
            | 
            | 
           1227 | 
                                   $transaction->amount = $amount;
  | 
        
        
            | 
            | 
           1228 | 
                                   $transaction->current = 0;
  | 
        
        
            | 
            | 
           1229 | 
                                   $transaction->status = Transaction::STATUS_PENDING;
  | 
        
        
            | 
            | 
           1230 | 
                                   $transaction->type = Transaction::TYPE_PAYMENT;
  | 
        
        
            | 
            | 
           1231 | 
                                   $transaction->description = $description;
  | 
        
        
            | 
            | 
           1232 | 
                                   $transaction->request = json_encode($response, JSON_PRETTY_PRINT);
  | 
        
        
            | 
            | 
           1233 | 
              | 
        
        
            | 
            | 
           1234 | 
                                   $requestId = Provider::PAYPAL . '-' . $external_id;
  | 
        
        
            | 
            | 
           1235 | 
              | 
        
        
            | 
            | 
           1236 | 
                                   $this->cache->setItem($requestId, serialize($transaction));
  | 
        
        
            | 
            | 
           1237 | 
              | 
        
        
            | 
            | 
           1238 | 
              | 
        
        
            | 
            | 
           1239 | 
              | 
        
        
            | 
            | 
           1240 | 
              | 
        
        
            | 
            | 
           1241 | 
                                   return new JsonModel(['success' => true, 'data' => $approve_url]);
  | 
        
        
            | 
            | 
           1242 | 
                               } else {
  | 
        
        
            | 
            | 
           1243 | 
                                   return new JsonModel(['success' => false, 'data' => 'ERROR_TRANSACTION_NOT_SAVED']);
  | 
        
        
            | 
            | 
           1244 | 
                               }
  | 
        
        
            | 
            | 
           1245 | 
              | 
        
        
            | 
            | 
           1246 | 
              | 
        
        
            | 
            | 
           1247 | 
              | 
        
        
            | 
            | 
           1248 | 
                           } catch (HttpException $ex) {
  | 
        
        
            | 
            | 
           1249 | 
              | 
        
        
            | 
            | 
           1250 | 
              | 
        
        
            | 
            | 
           1251 | 
                               return new JsonModel(['success' => false, 'data' => $ex->getMessage()]);
  | 
        
        
            | 
            | 
           1252 | 
                           }
  | 
        
        
            | 
            | 
           1253 | 
              | 
        
        
            | 
            | 
           1254 | 
                       } else {
  | 
        
        
            | 
            | 
           1255 | 
              | 
        
        
            | 
            | 
           1256 | 
                           $message = '';;
  | 
        
        
            | 
            | 
           1257 | 
                           $form_messages = (array) $form->getMessages();
  | 
        
        
            | 
            | 
           1258 | 
                           foreach($form_messages  as $fieldname => $field_messages)
  | 
        
        
            | 
            | 
           1259 | 
                           {
  | 
        
        
            | 
            | 
           1260 | 
                               foreach( $field_messages as $key => $value)
  | 
        
        
            | 
            | 
           1261 | 
                               {
  | 
        
        
            | 
            | 
           1262 | 
                                   $message = $value;
  | 
        
        
            | 
            | 
           1263 | 
                               }
  | 
        
        
            | 
            | 
           1264 | 
                           }
  | 
        
        
            | 
            | 
           1265 | 
              | 
        
        
            | 
            | 
           1266 | 
                           $response = [
  | 
        
        
            | 
            | 
           1267 | 
                               'success'   => false,
  | 
        
        
            | 
            | 
           1268 | 
                               'data'   => $message
  | 
        
        
            | 
            | 
           1269 | 
                           ];
  | 
        
        
            | 
            | 
           1270 | 
              | 
        
        
            | 
            | 
           1271 | 
                           return new JsonModel($response);
  | 
        
        
            | 
            | 
           1272 | 
              | 
        
        
            | 
            | 
           1273 | 
                       }
  | 
        
        
            | 
            | 
           1274 | 
              | 
        
        
            | 
            | 
           1275 | 
                   } else {
  | 
        
        
            | 
            | 
           1276 | 
                       return new JsonModel(['success' => false, 'data' => 'ERROR_METHOD_NOT_ALLOWED' ]);
  | 
        
        
            | 
            | 
           1277 | 
                   }
  | 
        
        
            | 
            | 
           1278 | 
               }
  | 
        
        
            | 
            | 
           1279 | 
              | 
        
        
            | 
            | 
           1280 | 
               public function removeFacebookAction()
  | 
        
        
            | 
            | 
           1281 | 
               {
  | 
        
        
            | 
            | 
           1282 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           1283 | 
                   if($request->isPost()) {
  | 
        
        
            | 
            | 
           1284 | 
              | 
        
        
            | 
            | 
           1285 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           1286 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           1287 | 
              | 
        
        
            | 
            | 
           1288 | 
              | 
        
        
            | 
            | 
           1289 | 
                       $userProviderMapper = UserProviderMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           1290 | 
                       $userProvider = $userProviderMapper->fetchOneByUserIdAndProvider($currentUser->id, UserProvider::PROVIDER_FACEBOOK);
  | 
        
        
            | 
            | 
           1291 | 
              | 
        
        
            | 
            | 
           1292 | 
                       if($userProvider) {
  | 
        
        
            | 
            | 
           1293 | 
              | 
        
        
            | 
            | 
           1294 | 
                           if($userProviderMapper->deleteByUserIdAndProvider($currentUser->id, UserProvider::PROVIDER_FACEBOOK)) {
  | 
        
        
            | 
            | 
           1295 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           1296 | 
                                   'success' => true,
  | 
        
        
            | 
            | 
           1297 | 
                                   'data' => 'LABEL_USER_PROVIDER_FACEBOOK_REMOVED'
  | 
        
        
            | 
            | 
           1298 | 
                               ]);
  | 
        
        
            | 
            | 
           1299 | 
              | 
        
        
            | 
            | 
           1300 | 
                           } else {
  | 
        
        
            | 
            | 
           1301 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           1302 | 
                                   'success' => false,
  | 
        
        
            | 
            | 
           1303 | 
                                   'data' => $userProviderMapper->getError()
  | 
        
        
            | 
            | 
           1304 | 
                               ]);
  | 
        
        
            | 
            | 
           1305 | 
                           }
  | 
        
        
            | 
            | 
           1306 | 
              | 
        
        
            | 
            | 
           1307 | 
              | 
        
        
            | 
            | 
           1308 | 
                       } else {
  | 
        
        
            | 
            | 
           1309 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1310 | 
                               'success' => false,
  | 
        
        
            | 
            | 
           1311 | 
                               'data' => 'ERROR_USER_PROVIDER_FACEBOOK_NOT_FOUND'
  | 
        
        
            | 
            | 
           1312 | 
                           ]);
  | 
        
        
            | 
            | 
           1313 | 
                       }
  | 
        
        
            | 
            | 
           1314 | 
              | 
        
        
            | 
            | 
           1315 | 
              | 
        
        
            | 
            | 
           1316 | 
                   } else {
  | 
        
        
            | 
            | 
           1317 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           1318 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           1319 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           1320 | 
                       ]);
  | 
        
        
            | 
            | 
           1321 | 
                   }
  | 
        
        
            | 
            | 
           1322 | 
               }
  | 
        
        
            | 
            | 
           1323 | 
              | 
        
        
            | 
            | 
           1324 | 
               public function addFacebookAction()
  | 
        
        
            | 
            | 
           1325 | 
               {
  | 
        
        
            | 
            | 
           1326 | 
                   /*
  | 
        
        
            | 
            | 
           1327 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           1328 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           1329 | 
              | 
        
        
            | 
            | 
           1330 | 
                       try {
  | 
        
        
            | 
            | 
           1331 | 
                           $app_id = $this->config['leaderslinked.facebook.app_id'];
  | 
        
        
            | 
            | 
           1332 | 
                           $app_password = $this->config['leaderslinked.facebook.app_password'];
  | 
        
        
            | 
            | 
           1333 | 
                           $app_graph_version = $this->config['leaderslinked.facebook.app_graph_version'];
  | 
        
        
            | 
            | 
           1334 | 
                           //$app_url_auth = $this->config['leaderslinked.facebook.app_url_auth'];
  | 
        
        
            | 
            | 
           1335 | 
                           //$redirect_url = $this->config['leaderslinked.facebook.app_redirect_url'];
  | 
        
        
            | 
            | 
           1336 | 
              | 
        
        
            | 
            | 
           1337 | 
              | 
        
        
            | 
            | 
           1338 | 
              | 
        
        
            | 
            | 
           1339 | 
                           $fb = new \Facebook\Facebook([
  | 
        
        
            | 
            | 
           1340 | 
                               'app_id' => $app_id,
  | 
        
        
            | 
            | 
           1341 | 
                               'app_secret' => $app_password,
  | 
        
        
            | 
            | 
           1342 | 
                               'default_graph_version' => $app_graph_version,
  | 
        
        
            | 
            | 
           1343 | 
                           ]);
  | 
        
        
            | 
            | 
           1344 | 
              | 
        
        
            | 
            | 
           1345 | 
                           $app_url_auth =  $this->url()->fromRoute('oauth/facebook', [], ['force_canonical' => true]);
  | 
        
        
            | 
            | 
           1346 | 
                           $helper = $fb->getRedirectLoginHelper();
  | 
        
        
            | 
            | 
           1347 | 
                           $permissions = ['email', 'public_profile']; // Optional permissions
  | 
        
        
            | 
            | 
           1348 | 
                           $facebookUrl = $helper->getLoginUrl($app_url_auth, $permissions);
  | 
        
        
            | 
            | 
           1349 | 
              | 
        
        
            | 
            | 
           1350 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1351 | 
                               'success' => true,
  | 
        
        
            | 
            | 
           1352 | 
                               'data' => $facebookUrl
  | 
        
        
            | 
            | 
           1353 | 
                           ]);
  | 
        
        
            | 
            | 
           1354 | 
                       } catch (\Throwable $e) {
  | 
        
        
            | 
            | 
           1355 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1356 | 
                               'success' => false,
  | 
        
        
            | 
            | 
           1357 | 
                               'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_FACEBOOK'
  | 
        
        
            | 
            | 
           1358 | 
                           ]);
  | 
        
        
            | 
            | 
           1359 | 
                       }
  | 
        
        
            | 
            | 
           1360 | 
              | 
        
        
            | 
            | 
           1361 | 
                   } else {
  | 
        
        
            | 
            | 
           1362 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           1363 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           1364 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           1365 | 
                       ]);
  | 
        
        
            | 
            | 
           1366 | 
                   }*/
  | 
        
        
            | 
            | 
           1367 | 
               }
  | 
        
        
            | 
            | 
           1368 | 
              | 
        
        
            | 
            | 
           1369 | 
               public function removeTwitterAction()
  | 
        
        
            | 
            | 
           1370 | 
               {
  | 
        
        
            | 
            | 
           1371 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           1372 | 
                   if($request->isPost()) {
  | 
        
        
            | 
            | 
           1373 | 
              | 
        
        
            | 
            | 
           1374 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           1375 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           1376 | 
              | 
        
        
            | 
            | 
           1377 | 
              | 
        
        
            | 
            | 
           1378 | 
                       $userProviderMapper = UserProviderMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           1379 | 
                       $userProvider = $userProviderMapper->fetchOneByUserIdAndProvider($currentUser->id, UserProvider::PROVIDER_TWITTER);
  | 
        
        
            | 
            | 
           1380 | 
              | 
        
        
            | 
            | 
           1381 | 
                       if($userProvider) {
  | 
        
        
            | 
            | 
           1382 | 
              | 
        
        
            | 
            | 
           1383 | 
                           if($userProviderMapper->deleteByUserIdAndProvider($currentUser->id, UserProvider::PROVIDER_TWITTER)) {
  | 
        
        
            | 
            | 
           1384 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           1385 | 
                                   'success' => true,
  | 
        
        
            | 
            | 
           1386 | 
                                   'data' => 'LABEL_USER_PROVIDER_TWITTER_REMOVED'
  | 
        
        
            | 
            | 
           1387 | 
                               ]);
  | 
        
        
            | 
            | 
           1388 | 
              | 
        
        
            | 
            | 
           1389 | 
                           } else {
  | 
        
        
            | 
            | 
           1390 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           1391 | 
                                   'success' => false,
  | 
        
        
            | 
            | 
           1392 | 
                                   'data' => $userProviderMapper->getError()
  | 
        
        
            | 
            | 
           1393 | 
                               ]);
  | 
        
        
            | 
            | 
           1394 | 
                           }
  | 
        
        
            | 
            | 
           1395 | 
              | 
        
        
            | 
            | 
           1396 | 
              | 
        
        
            | 
            | 
           1397 | 
                       } else {
  | 
        
        
            | 
            | 
           1398 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1399 | 
                               'success' => false,
  | 
        
        
            | 
            | 
           1400 | 
                               'data' => 'ERROR_USER_PROVIDER_TWITTER_NOT_FOUND'
  | 
        
        
            | 
            | 
           1401 | 
                           ]);
  | 
        
        
            | 
            | 
           1402 | 
                       }
  | 
        
        
            | 
            | 
           1403 | 
              | 
        
        
            | 
            | 
           1404 | 
              | 
        
        
            | 
            | 
           1405 | 
                   } else {
  | 
        
        
            | 
            | 
           1406 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           1407 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           1408 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           1409 | 
                       ]);
  | 
        
        
            | 
            | 
           1410 | 
                   }
  | 
        
        
            | 
            | 
           1411 | 
               }
  | 
        
        
            | 
            | 
           1412 | 
              | 
        
        
            | 
            | 
           1413 | 
               public function addTwitterAction()
  | 
        
        
            | 
            | 
           1414 | 
               {
  | 
        
        
            | 
            | 
           1415 | 
              | 
        
        
            | 
            | 
           1416 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           1417 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           1418 | 
              | 
        
        
            | 
            | 
           1419 | 
                       try {
  | 
        
        
            | 
            | 
           1420 | 
                           if($this->config['leaderslinked.runmode.sandbox']) {
  | 
        
        
            | 
            | 
           1421 | 
              | 
        
        
            | 
            | 
           1422 | 
                               $twitter_api_key = $this->config['leaderslinked.twitter.sandbox_api_key'];
  | 
        
        
            | 
            | 
           1423 | 
                               $twitter_api_secret = $this->config['leaderslinked.twitter.sandbox_api_secret'];
  | 
        
        
            | 
            | 
           1424 | 
              | 
        
        
            | 
            | 
           1425 | 
                           } else {
  | 
        
        
            | 
            | 
           1426 | 
                               $twitter_api_key = $this->config['leaderslinked.twitter.production_api_key'];
  | 
        
        
            | 
            | 
           1427 | 
                               $twitter_api_secret = $this->config['leaderslinked.twitter.production_api_secret'];
  | 
        
        
            | 
            | 
           1428 | 
                           }
  | 
        
        
            | 
            | 
           1429 | 
              | 
        
        
            | 
            | 
           1430 | 
              | 
        
        
            | 
            | 
           1431 | 
              | 
        
        
            | 
            | 
           1432 | 
                           //Twitter
  | 
        
        
            | 
            | 
           1433 | 
                           //$redirect_url =  $this->url()->fromRoute('oauth/twitter', [], ['force_canonical' => true]);
  | 
        
        
            | 
            | 
           1434 | 
                           $redirect_url = $this->config['leaderslinked.twitter.app_redirect_url'];
  | 
        
        
            | 
            | 
           1435 | 
                           $twitter = new \Abraham\TwitterOAuth\TwitterOAuth($twitter_api_key, $twitter_api_secret);
  | 
        
        
            | 
            | 
           1436 | 
                           $request_token =  $twitter->oauth('oauth/request_token', ['oauth_callback' => $redirect_url ]);
  | 
        
        
            | 
            | 
           1437 | 
                           $twitterUrl = $twitter->url('oauth/authorize', [ 'oauth_token' => $request_token['oauth_token'] ]);
  | 
        
        
            | 
            | 
           1438 | 
              | 
        
        
            | 
            | 
           1439 | 
                           $twitterSession = new \Laminas\Session\Container('twitter');
  | 
        
        
            | 
            | 
           1440 | 
                           $twitterSession->oauth_token = $request_token['oauth_token'];
  | 
        
        
            | 
            | 
           1441 | 
                           $twitterSession->oauth_token_secret = $request_token['oauth_token_secret'];
  | 
        
        
            | 
            | 
           1442 | 
              | 
        
        
            | 
            | 
           1443 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1444 | 
                               'success' => true,
  | 
        
        
            | 
            | 
           1445 | 
                               'data' =>  $twitterUrl
  | 
        
        
            | 
            | 
           1446 | 
                           ]);
  | 
        
        
            | 
            | 
           1447 | 
                       } catch (\Throwable $e) {
  | 
        
        
            | 
            | 
           1448 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1449 | 
                               'success' => false,
  | 
        
        
            | 
            | 
           1450 | 
                               'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_TWITTER'
  | 
        
        
            | 
            | 
           1451 | 
                           ]);
  | 
        
        
            | 
            | 
           1452 | 
                       }
  | 
        
        
            | 
            | 
           1453 | 
              | 
        
        
            | 
            | 
           1454 | 
                   } else {
  | 
        
        
            | 
            | 
           1455 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           1456 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           1457 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           1458 | 
                       ]);
  | 
        
        
            | 
            | 
           1459 | 
                   }
  | 
        
        
            | 
            | 
           1460 | 
              | 
        
        
            | 
            | 
           1461 | 
              | 
        
        
            | 
            | 
           1462 | 
               }
  | 
        
        
            | 
            | 
           1463 | 
              | 
        
        
            | 
            | 
           1464 | 
               public function removeGoogleAction()
  | 
        
        
            | 
            | 
           1465 | 
               {
  | 
        
        
            | 
            | 
           1466 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           1467 | 
                   if($request->isPost()) {
  | 
        
        
            | 
            | 
           1468 | 
              | 
        
        
            | 
            | 
           1469 | 
                       $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           1470 | 
                       $currentUser = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           1471 | 
              | 
        
        
            | 
            | 
           1472 | 
              | 
        
        
            | 
            | 
           1473 | 
                       $userProviderMapper = UserProviderMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           1474 | 
                       $userProvider = $userProviderMapper->fetchOneByUserIdAndProvider($currentUser->id, UserProvider::PROVIDER_GOOGLE);
  | 
        
        
            | 
            | 
           1475 | 
              | 
        
        
            | 
            | 
           1476 | 
                       if($userProvider) {
  | 
        
        
            | 
            | 
           1477 | 
              | 
        
        
            | 
            | 
           1478 | 
                           if($userProviderMapper->deleteByUserIdAndProvider($currentUser->id, UserProvider::PROVIDER_GOOGLE)) {
  | 
        
        
            | 
            | 
           1479 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           1480 | 
                                   'success' => true,
  | 
        
        
            | 
            | 
           1481 | 
                                   'data' => 'LABEL_USER_PROVIDER_GOOGLE_REMOVED'
  | 
        
        
            | 
            | 
           1482 | 
                               ]);
  | 
        
        
            | 
            | 
           1483 | 
              | 
        
        
            | 
            | 
           1484 | 
                           } else {
  | 
        
        
            | 
            | 
           1485 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           1486 | 
                                   'success' => false,
  | 
        
        
            | 
            | 
           1487 | 
                                   'data' => $userProviderMapper->getError()
  | 
        
        
            | 
            | 
           1488 | 
                               ]);
  | 
        
        
            | 
            | 
           1489 | 
                           }
  | 
        
        
            | 
            | 
           1490 | 
              | 
        
        
            | 
            | 
           1491 | 
              | 
        
        
            | 
            | 
           1492 | 
                       } else {
  | 
        
        
            | 
            | 
           1493 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1494 | 
                               'success' => false,
  | 
        
        
            | 
            | 
           1495 | 
                               'data' => 'ERROR_USER_PROVIDER_GOOGLE_NOT_FOUND'
  | 
        
        
            | 
            | 
           1496 | 
                           ]);
  | 
        
        
            | 
            | 
           1497 | 
                       }
  | 
        
        
            | 
            | 
           1498 | 
              | 
        
        
            | 
            | 
           1499 | 
              | 
        
        
            | 
            | 
           1500 | 
                   } else {
  | 
        
        
            | 
            | 
           1501 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           1502 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           1503 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           1504 | 
                       ]);
  | 
        
        
            | 
            | 
           1505 | 
                   }
  | 
        
        
            | 
            | 
           1506 | 
               }
  | 
        
        
            | 
            | 
           1507 | 
              | 
        
        
            | 
            | 
           1508 | 
               public function addGoogleAction()
  | 
        
        
            | 
            | 
           1509 | 
               {
  | 
        
        
            | 
            | 
           1510 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           1511 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           1512 | 
              | 
        
        
            | 
            | 
           1513 | 
                       try {
  | 
        
        
            | 
            | 
           1514 | 
              | 
        
        
            | 
            | 
           1515 | 
              | 
        
        
            | 
            | 
           1516 | 
                           //Google
  | 
        
        
            | 
            | 
           1517 | 
                           $google = new \Google_Client();
  | 
        
        
            | 
            | 
           1518 | 
                           $google->setAuthConfig('data/google/auth-leaderslinked/apps.google.com_secreto_cliente.json');
  | 
        
        
            | 
            | 
           1519 | 
                           $google->setAccessType("offline");        // offline access
  | 
        
        
            | 
            | 
           1520 | 
              | 
        
        
            | 
            | 
           1521 | 
                           $google->setIncludeGrantedScopes(true);   // incremental auth
  | 
        
        
            | 
            | 
           1522 | 
              | 
        
        
            | 
            | 
           1523 | 
                           $google->addScope('profile');
  | 
        
        
            | 
            | 
           1524 | 
                           $google->addScope('email');
  | 
        
        
            | 
            | 
           1525 | 
              | 
        
        
            | 
            | 
           1526 | 
                           // $redirect_url =  $this->url()->fromRoute('oauth/google', [], ['force_canonical' => true]);
  | 
        
        
            | 
            | 
           1527 | 
                           $redirect_url = $this->config['leaderslinked.google_auth.app_redirect_url'];
  | 
        
        
            | 
            | 
           1528 | 
              | 
        
        
            | 
            | 
           1529 | 
                           $google->setRedirectUri($redirect_url);
  | 
        
        
            | 
            | 
           1530 | 
                           $googleUrl = $google->createAuthUrl();
  | 
        
        
            | 
            | 
           1531 | 
              | 
        
        
            | 
            | 
           1532 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1533 | 
                               'success' => true,
  | 
        
        
            | 
            | 
           1534 | 
                               'data' =>  $googleUrl
  | 
        
        
            | 
            | 
           1535 | 
                           ]);
  | 
        
        
            | 
            | 
           1536 | 
                       } catch (\Throwable $e) {
  | 
        
        
            | 
            | 
           1537 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1538 | 
                               'success' => false,
  | 
        
        
            | 
            | 
           1539 | 
                               'data' =>  'ERROR_WE_COULD_NOT_CONNECT_TO_GOOGLE'
  | 
        
        
            | 
            | 
           1540 | 
                           ]);
  | 
        
        
            | 
            | 
           1541 | 
                       }
  | 
        
        
            | 
            | 
           1542 | 
              | 
        
        
            | 
            | 
           1543 | 
                   } else {
  | 
        
        
            | 
            | 
           1544 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           1545 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           1546 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           1547 | 
                       ]);
  | 
        
        
            | 
            | 
           1548 | 
                   }
  | 
        
        
            | 
            | 
           1549 | 
               }
  | 
        
        
            | 
            | 
           1550 | 
              | 
        
        
            | 
            | 
           1551 | 
               public function deleteAccountAction()
  | 
        
        
            | 
            | 
           1552 | 
               {
  | 
        
        
            | 
            | 
           1553 | 
              | 
        
        
            | 
            | 
           1554 | 
              | 
        
        
            | 
            | 
           1555 | 
                   $currentUserPlugin = $this->plugin('currentUserPlugin');
  | 
        
        
            | 
            | 
           1556 | 
                   $user = $currentUserPlugin->getUser();
  | 
        
        
            | 
            | 
           1557 | 
              | 
        
        
            | 
            | 
           1558 | 
              | 
        
        
            | 
            | 
           1559 | 
              | 
        
        
            | 
            | 
           1560 | 
                   $request = $this->getRequest();
  | 
        
        
            | 
            | 
           1561 | 
              | 
        
        
            | 
            | 
           1562 | 
                   if($request->isGet()) {
  | 
        
        
            | 
            | 
           1563 | 
              | 
        
        
            | 
            | 
           1564 | 
                       $this->sendEmailDeleteAccountKey($user);
  | 
        
        
            | 
            | 
           1565 | 
              | 
        
        
            | 
            | 
           1566 | 
              | 
        
        
            | 
            | 
           1567 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           1568 | 
                           'success' => true,
  | 
        
        
           | 190 | 
           efrain | 
           1569 | 
                           'data' =>  'LABEL_DELETE_ACCOUNT_WE_HAVE_SENT_A_CONFIRMATION_CODE'
  | 
        
        
            | 
            | 
           1570 | 
              | 
        
        
           | 1 | 
           efrain | 
           1571 | 
                       ]);
  | 
        
        
            | 
            | 
           1572 | 
              | 
        
        
            | 
            | 
           1573 | 
                   } else  if($request->isPost()) {
  | 
        
        
            | 
            | 
           1574 | 
              | 
        
        
            | 
            | 
           1575 | 
                       $code = $this->params()->fromPost('code');
  | 
        
        
            | 
            | 
           1576 | 
                       if(empty($code) || $code != $user->delete_account_key) {
  | 
        
        
            | 
            | 
           1577 | 
              | 
        
        
            | 
            | 
           1578 | 
                           $this->sendEmailDeleteAccountKey($user);
  | 
        
        
            | 
            | 
           1579 | 
              | 
        
        
            | 
            | 
           1580 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1581 | 
                               'success' => false,
  | 
        
        
           | 190 | 
           efrain | 
           1582 | 
                               'data' => 'ERROR_DELETE_ACCOUNT_CONFIRMATION_CODE_IS_WRONG'
  | 
        
        
           | 1 | 
           efrain | 
           1583 | 
                           ]);
  | 
        
        
            | 
            | 
           1584 | 
                       }
  | 
        
        
            | 
            | 
           1585 | 
              | 
        
        
            | 
            | 
           1586 | 
                       $delete_account_generated_on = strtotime($user->delete_account_generated_on);
  | 
        
        
            | 
            | 
           1587 | 
                       $expiry_time = $delete_account_generated_on + $this->config['leaderslinked.security.delete_account_expired'];
  | 
        
        
            | 
            | 
           1588 | 
              | 
        
        
            | 
            | 
           1589 | 
              | 
        
        
            | 
            | 
           1590 | 
                       if (time() > $expiry_time) {
  | 
        
        
            | 
            | 
           1591 | 
              | 
        
        
            | 
            | 
           1592 | 
                           $this->sendEmailDeleteAccountKey($user) ;
  | 
        
        
            | 
            | 
           1593 | 
              | 
        
        
            | 
            | 
           1594 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1595 | 
                               'success' => false,
  | 
        
        
           | 190 | 
           efrain | 
           1596 | 
                               'data' => 'ERROR_DELETE_ACCOUNT_CONFIRMATION_CODE_EXPIRED'
  | 
        
        
           | 1 | 
           efrain | 
           1597 | 
                           ]);
  | 
        
        
            | 
            | 
           1598 | 
              | 
        
        
            | 
            | 
           1599 | 
              | 
        
        
            | 
            | 
           1600 | 
                       }
  | 
        
        
            | 
            | 
           1601 | 
              | 
        
        
            | 
            | 
           1602 | 
                       $userDeleted  = new UserDeleted();
  | 
        
        
            | 
            | 
           1603 | 
                       $userDeleted->user_id = $user->id;
  | 
        
        
            | 
            | 
           1604 | 
                       $userDeleted->first_name = $user->first_name;
  | 
        
        
            | 
            | 
           1605 | 
                       $userDeleted->last_name = $user->last_name;
  | 
        
        
            | 
            | 
           1606 | 
                       $userDeleted->email = $user->email;
  | 
        
        
            | 
            | 
           1607 | 
                       $userDeleted->image = $user->image;
  | 
        
        
            | 
            | 
           1608 | 
                       $userDeleted->phone = $user->phone;
  | 
        
        
            | 
            | 
           1609 | 
                       $userDeleted->pending = UserDeleted::PENDING_YES;
  | 
        
        
            | 
            | 
           1610 | 
              | 
        
        
            | 
            | 
           1611 | 
              | 
        
        
            | 
            | 
           1612 | 
                       $userDeletedMapper = UserDeletedMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           1613 | 
                       if ($userDeletedMapper->insert($userDeleted)) {
  | 
        
        
            | 
            | 
           1614 | 
              | 
        
        
            | 
            | 
           1615 | 
                           $this->sendEmailDeleteAccountCompleted($user);
  | 
        
        
            | 
            | 
           1616 | 
              | 
        
        
            | 
            | 
           1617 | 
                           $user->first_name = 'LABEL_DELETE_ACCOUNT_FIRST_NAME';
  | 
        
        
            | 
            | 
           1618 | 
                           $user->last_name = 'LABEL_DELETE_ACCOUNT_LAST_NAME';
  | 
        
        
            | 
            | 
           1619 | 
                           $user->email = 'user-deleted-' . uniqid() . '@leaderslinked.com';
  | 
        
        
            | 
            | 
           1620 | 
                           $user->image = '';
  | 
        
        
            | 
            | 
           1621 | 
                           $user->usertype_id = UserType::USER_DELETED;
  | 
        
        
            | 
            | 
           1622 | 
                           $user->status = User::STATUS_DELETED;
  | 
        
        
            | 
            | 
           1623 | 
                           $user->delete_account_key = '';
  | 
        
        
            | 
            | 
           1624 | 
                           $user->delete_account_generated_on = '';
  | 
        
        
            | 
            | 
           1625 | 
              | 
        
        
            | 
            | 
           1626 | 
                           $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           1627 | 
                           if($userMapper->update($user)) {
  | 
        
        
            | 
            | 
           1628 | 
              | 
        
        
            | 
            | 
           1629 | 
              | 
        
        
            | 
            | 
           1630 | 
              | 
        
        
            | 
            | 
           1631 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           1632 | 
                                   'success' => true,
  | 
        
        
           | 190 | 
           efrain | 
           1633 | 
                                   'data' => 'LABEL_DELETE_ACCOUNT_WE_HAVE_STARTED_DELETING_YOUR_DATA',
  | 
        
        
           | 1 | 
           efrain | 
           1634 | 
                               ]);
  | 
        
        
            | 
            | 
           1635 | 
              | 
        
        
            | 
            | 
           1636 | 
              | 
        
        
            | 
            | 
           1637 | 
                           } else {
  | 
        
        
            | 
            | 
           1638 | 
                               return new JsonModel([
  | 
        
        
            | 
            | 
           1639 | 
                                   'success' => false,
  | 
        
        
           | 190 | 
           efrain | 
           1640 | 
                                   'data' => $userDeletedMapper->getError()
  | 
        
        
           | 1 | 
           efrain | 
           1641 | 
                               ]);
  | 
        
        
            | 
            | 
           1642 | 
                           }
  | 
        
        
            | 
            | 
           1643 | 
              | 
        
        
            | 
            | 
           1644 | 
              | 
        
        
            | 
            | 
           1645 | 
              | 
        
        
            | 
            | 
           1646 | 
                       } else {
  | 
        
        
            | 
            | 
           1647 | 
                           return new JsonModel([
  | 
        
        
            | 
            | 
           1648 | 
                               'success' => false,
  | 
        
        
           | 190 | 
           efrain | 
           1649 | 
                               'data' =>  $userDeletedMapper->getError()
  | 
        
        
            | 
            | 
           1650 | 
              | 
        
        
           | 1 | 
           efrain | 
           1651 | 
                           ]);
  | 
        
        
            | 
            | 
           1652 | 
                       }
  | 
        
        
            | 
            | 
           1653 | 
              | 
        
        
            | 
            | 
           1654 | 
              | 
        
        
            | 
            | 
           1655 | 
              | 
        
        
            | 
            | 
           1656 | 
              | 
        
        
            | 
            | 
           1657 | 
              | 
        
        
            | 
            | 
           1658 | 
                   }
  | 
        
        
            | 
            | 
           1659 | 
              | 
        
        
            | 
            | 
           1660 | 
              | 
        
        
            | 
            | 
           1661 | 
                       return new JsonModel([
  | 
        
        
            | 
            | 
           1662 | 
                           'success' => false,
  | 
        
        
            | 
            | 
           1663 | 
                           'data' => 'ERROR_METHOD_NOT_ALLOWED'
  | 
        
        
            | 
            | 
           1664 | 
                       ]);
  | 
        
        
            | 
            | 
           1665 | 
               }
  | 
        
        
            | 
            | 
           1666 | 
              | 
        
        
            | 
            | 
           1667 | 
              | 
        
        
            | 
            | 
           1668 | 
              | 
        
        
            | 
            | 
           1669 | 
              | 
        
        
            | 
            | 
           1670 | 
               private function sendEmailDeleteAccountKey($user)
  | 
        
        
            | 
            | 
           1671 | 
               {
  | 
        
        
            | 
            | 
           1672 | 
                   $delete_account_key = Functions::generatePassword(8);
  | 
        
        
            | 
            | 
           1673 | 
              | 
        
        
            | 
            | 
           1674 | 
                   $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           1675 | 
                   $userMapper->updateDeleteAccountKey($user->id, $delete_account_key);
  | 
        
        
            | 
            | 
           1676 | 
              | 
        
        
            | 
            | 
           1677 | 
                   $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           1678 | 
                   $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_DELETE_ACCOUNT_CODE, $user->network_id);
  | 
        
        
            | 
            | 
           1679 | 
                   if($emailTemplate) {
  | 
        
        
            | 
            | 
           1680 | 
                       $arrayCont = [
  | 
        
        
            | 
            | 
           1681 | 
                           'firstname' => $user->first_name,
  | 
        
        
            | 
            | 
           1682 | 
                           'lastname'  => $user->last_name,
  | 
        
        
            | 
            | 
           1683 | 
                           'code'      => $delete_account_key,
  | 
        
        
            | 
            | 
           1684 | 
                           'link'      => ''
  | 
        
        
            | 
            | 
           1685 | 
                       ];
  | 
        
        
            | 
            | 
           1686 | 
              | 
        
        
            | 
            | 
           1687 | 
                       $email = new QueueEmail($this->adapter);
  | 
        
        
            | 
            | 
           1688 | 
                       $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
  | 
        
        
            | 
            | 
           1689 | 
                   }
  | 
        
        
            | 
            | 
           1690 | 
               }
  | 
        
        
            | 
            | 
           1691 | 
              | 
        
        
            | 
            | 
           1692 | 
              | 
        
        
            | 
            | 
           1693 | 
               private function sendEmailDeleteAccountCompleted($user)
  | 
        
        
            | 
            | 
           1694 | 
               {
  | 
        
        
            | 
            | 
           1695 | 
              | 
        
        
            | 
            | 
           1696 | 
                   $emailTemplateMapper = EmailTemplateMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           1697 | 
                   $emailTemplate = $emailTemplateMapper->fetchOneByCodeAndNetworkId(EmailTemplate::CODE_DELETE_ACCOUNT_COMPLETED, $user->network_id);
  | 
        
        
            | 
            | 
           1698 | 
                   if($emailTemplate) {
  | 
        
        
            | 
            | 
           1699 | 
                       $arrayCont = [
  | 
        
        
            | 
            | 
           1700 | 
                           'firstname' => $user->first_name,
  | 
        
        
            | 
            | 
           1701 | 
                           'lastname'  => $user->last_name,
  | 
        
        
            | 
            | 
           1702 | 
                           'code'      => '',
  | 
        
        
            | 
            | 
           1703 | 
                           'link'      => ''
  | 
        
        
            | 
            | 
           1704 | 
                       ];
  | 
        
        
            | 
            | 
           1705 | 
              | 
        
        
            | 
            | 
           1706 | 
                       $email = new QueueEmail($this->adapter);
  | 
        
        
            | 
            | 
           1707 | 
                       $email->processEmailTemplate($emailTemplate, $arrayCont, $user->email, trim($user->first_name . ' ' . $user->last_name));
  | 
        
        
            | 
            | 
           1708 | 
                   }
  | 
        
        
            | 
            | 
           1709 | 
               }
  | 
        
        
            | 
            | 
           1710 | 
              | 
        
        
            | 
            | 
           1711 | 
           }
  |