| 1 | 
           www | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
              | 
        
        
            | 
            | 
           3 | 
           declare(strict_types=1);
  | 
        
        
            | 
            | 
           4 | 
              | 
        
        
            | 
            | 
           5 | 
           namespace LeadersLinked\Library;
  | 
        
        
            | 
            | 
           6 | 
              | 
        
        
            | 
            | 
           7 | 
              | 
        
        
            | 
            | 
           8 | 
           use Laminas\Db\Adapter\AdapterInterface;
  | 
        
        
           | 6749 | 
           efrain | 
           9 | 
           use LeadersLinked\Cache\CacheInterface;
  | 
        
        
           | 1 | 
           www | 
           10 | 
           use Laminas\View\Renderer\PhpRenderer;
  | 
        
        
            | 
            | 
           11 | 
           use Laminas\Log\LoggerInterface;
  | 
        
        
            | 
            | 
           12 | 
           use Laminas\Authentication\AuthenticationService;
  | 
        
        
            | 
            | 
           13 | 
           use LeadersLinked\Mapper\NotificationMapper;
  | 
        
        
            | 
            | 
           14 | 
           use LeadersLinked\Mapper\MessageMapper;
  | 
        
        
            | 
            | 
           15 | 
           use LeadersLinked\Mapper\ConnectionMapper;
  | 
        
        
            | 
            | 
           16 | 
           use LeadersLinked\Mapper\QueryMapper;
  | 
        
        
            | 
            | 
           17 | 
           use Laminas\Paginator\Adapter\DbSelect;
  | 
        
        
            | 
            | 
           18 | 
           use Laminas\Paginator\Paginator;
  | 
        
        
            | 
            | 
           19 | 
           use LeadersLinked\Mapper\UserMapper;
  | 
        
        
            | 
            | 
           20 | 
           use LeadersLinked\Mapper\FeedMapper;
  | 
        
        
            | 
            | 
           21 | 
           use LeadersLinked\Mapper\GroupMapper;
  | 
        
        
            | 
            | 
           22 | 
           use LeadersLinked\Mapper\JobMapper;
  | 
        
        
            | 
            | 
           23 | 
           use LeadersLinked\Mapper\CompanyMapper;
  | 
        
        
            | 
            | 
           24 | 
           use Laminas\View\Model\ViewModel;
  | 
        
        
            | 
            | 
           25 | 
           use LeadersLinked\Model\Message;
  | 
        
        
            | 
            | 
           26 | 
           use LeadersLinked\Model\Connection;
  | 
        
        
            | 
            | 
           27 | 
           use LeadersLinked\Model\Notification;
  | 
        
        
            | 
            | 
           28 | 
           use LeadersLinked\Mapper\UserExperienceMapper;
  | 
        
        
            | 
            | 
           29 | 
           use Laminas\Db\Sql\Select;
  | 
        
        
            | 
            | 
           30 | 
              | 
        
        
           | 6388 | 
           efrain | 
           31 | 
              | 
        
        
           | 1 | 
           www | 
           32 | 
           class UserNotification
  | 
        
        
            | 
            | 
           33 | 
           {
  | 
        
        
            | 
            | 
           34 | 
               const NOTIFICATION_TYPE_UNREAD = 'unread';
  | 
        
        
            | 
            | 
           35 | 
               const NOTIFICATION_TYPE_REGULAR = 'regular';
  | 
        
        
            | 
            | 
           36 | 
              | 
        
        
            | 
            | 
           37 | 
              | 
        
        
            | 
            | 
           38 | 
               /**
  | 
        
        
            | 
            | 
           39 | 
                *
  | 
        
        
            | 
            | 
           40 | 
                * @var AdapterInterface
  | 
        
        
            | 
            | 
           41 | 
                */
  | 
        
        
            | 
            | 
           42 | 
               private $adapter;
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
            | 
            | 
           44 | 
              | 
        
        
            | 
            | 
           45 | 
               /**
  | 
        
        
            | 
            | 
           46 | 
                *
  | 
        
        
           | 6749 | 
           efrain | 
           47 | 
                * @var CacheInterface
  | 
        
        
           | 1 | 
           www | 
           48 | 
                */
  | 
        
        
            | 
            | 
           49 | 
               private $cache;
  | 
        
        
            | 
            | 
           50 | 
              | 
        
        
            | 
            | 
           51 | 
               /**
  | 
        
        
            | 
            | 
           52 | 
                *
  | 
        
        
            | 
            | 
           53 | 
                * @var  LoggerInterface
  | 
        
        
            | 
            | 
           54 | 
                */
  | 
        
        
            | 
            | 
           55 | 
               private $logger;
  | 
        
        
            | 
            | 
           56 | 
              | 
        
        
            | 
            | 
           57 | 
              | 
        
        
            | 
            | 
           58 | 
               /**
  | 
        
        
            | 
            | 
           59 | 
                *
  | 
        
        
            | 
            | 
           60 | 
                * @var  PhpRenderer
  | 
        
        
            | 
            | 
           61 | 
                */
  | 
        
        
            | 
            | 
           62 | 
               private $phpRender;
  | 
        
        
            | 
            | 
           63 | 
              | 
        
        
            | 
            | 
           64 | 
               /**
  | 
        
        
            | 
            | 
           65 | 
                *
  | 
        
        
            | 
            | 
           66 | 
                * @var integer
  | 
        
        
            | 
            | 
           67 | 
                */
  | 
        
        
            | 
            | 
           68 | 
               private $session_user_id;
  | 
        
        
            | 
            | 
           69 | 
              | 
        
        
            | 
            | 
           70 | 
               /**
  | 
        
        
            | 
            | 
           71 | 
                *
  | 
        
        
            | 
            | 
           72 | 
                * @var integer
  | 
        
        
            | 
            | 
           73 | 
                */
  | 
        
        
            | 
            | 
           74 | 
               private $session_language_id;
  | 
        
        
            | 
            | 
           75 | 
              | 
        
        
            | 
            | 
           76 | 
               /**
  | 
        
        
            | 
            | 
           77 | 
                *
  | 
        
        
            | 
            | 
           78 | 
                * @param AdapterInterface $adapter
  | 
        
        
           | 6749 | 
           efrain | 
           79 | 
                * @param CacheInterface $cache
  | 
        
        
           | 1 | 
           www | 
           80 | 
                * @param LoggerInterface $logger
  | 
        
        
            | 
            | 
           81 | 
                */
  | 
        
        
           | 6749 | 
           efrain | 
           82 | 
               public function __construct(AdapterInterface $adapter, CacheInterface $cache , LoggerInterface $logger, PhpRenderer $phpRender)
  | 
        
        
           | 1 | 
           www | 
           83 | 
               {
  | 
        
        
            | 
            | 
           84 | 
                   $this->adapter          = $adapter;
  | 
        
        
            | 
            | 
           85 | 
                   $this->cache            = $cache;
  | 
        
        
            | 
            | 
           86 | 
                   $this->logger           = $logger;
  | 
        
        
            | 
            | 
           87 | 
                   $this->phpRender        = $phpRender;
  | 
        
        
            | 
            | 
           88 | 
              | 
        
        
            | 
            | 
           89 | 
                   $authService = new AuthenticationService();
  | 
        
        
            | 
            | 
           90 | 
                   if($authService->hasIdentity()) {
  | 
        
        
            | 
            | 
           91 | 
                       $identity = $authService->getIdentity();
  | 
        
        
            | 
            | 
           92 | 
                       $this->session_user_id = (int) $identity['user_id'];
  | 
        
        
            | 
            | 
           93 | 
                   } else {
  | 
        
        
            | 
            | 
           94 | 
                       $this->session_user_id = 0;
  | 
        
        
            | 
            | 
           95 | 
                   }
  | 
        
        
            | 
            | 
           96 | 
              | 
        
        
            | 
            | 
           97 | 
                   $this->session_language_id = 1;
  | 
        
        
            | 
            | 
           98 | 
               }
  | 
        
        
            | 
            | 
           99 | 
              | 
        
        
            | 
            | 
           100 | 
               /**
  | 
        
        
            | 
            | 
           101 | 
                *
  | 
        
        
            | 
            | 
           102 | 
                * @return int
  | 
        
        
            | 
            | 
           103 | 
                */
  | 
        
        
            | 
            | 
           104 | 
               public function getUnreadNotificationsCount()
  | 
        
        
            | 
            | 
           105 | 
               {
  | 
        
        
            | 
            | 
           106 | 
              | 
        
        
            | 
            | 
           107 | 
               }
  | 
        
        
            | 
            | 
           108 | 
               /**
  | 
        
        
            | 
            | 
           109 | 
                *
  | 
        
        
            | 
            | 
           110 | 
                * @return int
  | 
        
        
            | 
            | 
           111 | 
                */
  | 
        
        
            | 
            | 
           112 | 
               public function getUnreadMessagesCount()
  | 
        
        
            | 
            | 
           113 | 
               {
  | 
        
        
            | 
            | 
           114 | 
                   $messageMapper = MessageMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           115 | 
                   return $messageMapper->fetchUnreadMessagesCount($this->session_user_id);
  | 
        
        
            | 
            | 
           116 | 
               }
  | 
        
        
            | 
            | 
           117 | 
              | 
        
        
            | 
            | 
           118 | 
               /**
  | 
        
        
            | 
            | 
           119 | 
                *
  | 
        
        
            | 
            | 
           120 | 
                * @return int
  | 
        
        
            | 
            | 
           121 | 
                */
  | 
        
        
            | 
            | 
           122 | 
               public function getConnectionRequestCount()
  | 
        
        
            | 
            | 
           123 | 
               {
  | 
        
        
            | 
            | 
           124 | 
                   $connectionMapper = ConnectionMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           125 | 
                   return $connectionMapper->fetchConnectionRequestCount($this->session_user_id);
  | 
        
        
            | 
            | 
           126 | 
               }
  | 
        
        
            | 
            | 
           127 | 
              | 
        
        
            | 
            | 
           128 | 
               /**
  | 
        
        
            | 
            | 
           129 | 
                *
  | 
        
        
            | 
            | 
           130 | 
                * @return boolean
  | 
        
        
            | 
            | 
           131 | 
                */
  | 
        
        
            | 
            | 
           132 | 
               public function markNotificationsAsRead()
  | 
        
        
            | 
            | 
           133 | 
               {
  | 
        
        
            | 
            | 
           134 | 
                   $notificationMapper = NotificationMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           135 | 
                   return $notificationMapper->markNotificationsAsRead($this->session_user_id);
  | 
        
        
            | 
            | 
           136 | 
               }
  | 
        
        
            | 
            | 
           137 | 
              | 
        
        
            | 
            | 
           138 | 
               /**
  | 
        
        
            | 
            | 
           139 | 
                *
  | 
        
        
            | 
            | 
           140 | 
                * @param int $currentPage
  | 
        
        
            | 
            | 
           141 | 
                * @param string $notification_type
  | 
        
        
            | 
            | 
           142 | 
                * @return string
  | 
        
        
            | 
            | 
           143 | 
                */
  | 
        
        
            | 
            | 
           144 | 
               public function getNotifications($currentPage = 1, $notification_type = self::NOTIFICATION_TYPE_REGULAR)
  | 
        
        
            | 
            | 
           145 | 
               {
  | 
        
        
           | 3138 | 
           efrain | 
           146 | 
              | 
        
        
           | 6388 | 
           efrain | 
           147 | 
              | 
        
        
           | 3138 | 
           efrain | 
           148 | 
              | 
        
        
           | 6388 | 
           efrain | 
           149 | 
              | 
        
        
           | 1 | 
           www | 
           150 | 
                   $content = '';
  | 
        
        
            | 
            | 
           151 | 
              | 
        
        
            | 
            | 
           152 | 
                   $queryMapper = QueryMapper::getInstance($this->adapter);
  | 
        
        
           | 6388 | 
           efrain | 
           153 | 
                   $now = $queryMapper->getDatebaseNow();
  | 
        
        
            | 
            | 
           154 | 
              | 
        
        
           | 1 | 
           www | 
           155 | 
                   $select = $queryMapper->getSql()->select(NotificationMapper::_TABLE);
  | 
        
        
            | 
            | 
           156 | 
                   $select->where->equalTo('user_id', $this->session_user_id);
  | 
        
        
            | 
            | 
           157 | 
                   if ($notification_type ==  self::NOTIFICATION_TYPE_UNREAD) {
  | 
        
        
            | 
            | 
           158 | 
                       $select->where->and->equalTo('is_notified', UserNotification::IS_NOTIFIED_NO);
  | 
        
        
            | 
            | 
           159 | 
                   }
  | 
        
        
            | 
            | 
           160 | 
                   $select->order('id DESC');
  | 
        
        
            | 
            | 
           161 | 
              | 
        
        
            | 
            | 
           162 | 
                   $dbSelect = new DbSelect($select, $this->adapter);
  | 
        
        
            | 
            | 
           163 | 
                   $paginator = new Paginator($dbSelect);
  | 
        
        
            | 
            | 
           164 | 
                   $paginator->setCurrentPageNumber($currentPage);
  | 
        
        
            | 
            | 
           165 | 
                   $paginator->setItemCountPerPage(NO_OF_NOTIFICATIONS_PER_PAGE);
  | 
        
        
            | 
            | 
           166 | 
              | 
        
        
            | 
            | 
           167 | 
                   $notifications = [];
  | 
        
        
            | 
            | 
           168 | 
                   $items = $paginator->getCurrentItems();
  | 
        
        
            | 
            | 
           169 | 
              | 
        
        
            | 
            | 
           170 | 
              | 
        
        
            | 
            | 
           171 | 
                   if ($items) {
  | 
        
        
            | 
            | 
           172 | 
                       $notificationMapper = NotificationMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           173 | 
              | 
        
        
            | 
            | 
           174 | 
                       foreach ($items as $item)
  | 
        
        
            | 
            | 
           175 | 
                       {
  | 
        
        
            | 
            | 
           176 | 
              | 
        
        
           | 3138 | 
           efrain | 
           177 | 
                           $time_ago               = Functions::timeAgo($item['added_on'],  $now);
  | 
        
        
           | 1 | 
           www | 
           178 | 
                           $type                   = $item['type'];
  | 
        
        
            | 
            | 
           179 | 
                           $action_by_user_id      = (int) $item['action_by_user_id'];
  | 
        
        
            | 
            | 
           180 | 
                           $action_by_user_name    = '';
  | 
        
        
            | 
            | 
           181 | 
                           $action_by_user_picture = '';
  | 
        
        
            | 
            | 
           182 | 
                           $feed_id                = (int) $item['feed_id'];
  | 
        
        
            | 
            | 
           183 | 
                           $group_id               = (int) $item['group_id'];
  | 
        
        
            | 
            | 
           184 | 
                           $job_id                 = (int) $item['job_id'];
  | 
        
        
            | 
            | 
           185 | 
                           $company_id             = (int) $item['company_id'];
  | 
        
        
            | 
            | 
           186 | 
                           $post_title             = '';
  | 
        
        
            | 
            | 
           187 | 
                           $group_name             = '';
  | 
        
        
            | 
            | 
           188 | 
                           $job_title              = '';
  | 
        
        
            | 
            | 
           189 | 
                           $company_name           = '';
  | 
        
        
            | 
            | 
           190 | 
              | 
        
        
            | 
            | 
           191 | 
                           if ($action_by_user_id) {
  | 
        
        
            | 
            | 
           192 | 
                               $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           193 | 
                               $user = $userMapper->fetchOne($action_by_user_id);
  | 
        
        
            | 
            | 
           194 | 
                               $action_by_user_picture = $user->avatar;
  | 
        
        
            | 
            | 
           195 | 
                               $action_by_user_name = $user->first_name . ' '.  $user->last_name;
  | 
        
        
            | 
            | 
           196 | 
                           }
  | 
        
        
            | 
            | 
           197 | 
                           if ($feed_id) {
  | 
        
        
            | 
            | 
           198 | 
                               $feedMapper = FeedMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           199 | 
                               $feed = $feedMapper->fetchOne($feed_id);
  | 
        
        
            | 
            | 
           200 | 
                               $post_title = $feed->post_title;
  | 
        
        
            | 
            | 
           201 | 
                           }
  | 
        
        
            | 
            | 
           202 | 
                           if ($group_id) {
  | 
        
        
            | 
            | 
           203 | 
                               $groupMapper = GroupMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           204 | 
                               $group = $groupMapper->fetchOne($group_id);
  | 
        
        
            | 
            | 
           205 | 
                               $group_name = $group->group_name;
  | 
        
        
            | 
            | 
           206 | 
                           }
  | 
        
        
            | 
            | 
           207 | 
                           if ($job_id) {
  | 
        
        
            | 
            | 
           208 | 
                               $jobMapper = JobMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           209 | 
                               $job = $jobMapper->fetchOne($job_id);
  | 
        
        
            | 
            | 
           210 | 
                               $job_title = $job->job_title;
  | 
        
        
            | 
            | 
           211 | 
                           }
  | 
        
        
            | 
            | 
           212 | 
                           if ($company_id) {
  | 
        
        
            | 
            | 
           213 | 
                               $companyMapper = CompanyMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           214 | 
                               $company = $companyMapper->fetchOne($company_id);
  | 
        
        
            | 
            | 
           215 | 
              | 
        
        
            | 
            | 
           216 | 
              | 
        
        
            | 
            | 
           217 | 
                               $company_name = $company->company_name;
  | 
        
        
            | 
            | 
           218 | 
                           }
  | 
        
        
            | 
            | 
           219 | 
              | 
        
        
            | 
            | 
           220 | 
                           if($action_by_user_picture) {
  | 
        
        
            | 
            | 
           221 | 
                               $user_img = $this->url('storage', ['type' => 'user', 'filename' => 'th2_' . $action_by_user_picture, 'code' => Functions::encryptIt($action_by_user_id)]);
  | 
        
        
            | 
            | 
           222 | 
              | 
        
        
            | 
            | 
           223 | 
                           } else {
  | 
        
        
            | 
            | 
           224 | 
                               $user_img = URL_USER_DEFAULT_AVATAR;
  | 
        
        
            | 
            | 
           225 | 
                           }
  | 
        
        
            | 
            | 
           226 | 
              | 
        
        
            | 
            | 
           227 | 
                           switch ($type) {
  | 
        
        
            | 
            | 
           228 | 
                               case Notification::TYPE_CONNECTION_REQUEST_ACCEPTED :
  | 
        
        
            | 
            | 
           229 | 
                                   $notification_text  = LABEL_COM_DET_YOUR_CONNECTION_REQUEST_ACCEPTED .' '. $action_by_user_name;
  | 
        
        
            | 
            | 
           230 | 
                                   $notification_url   = $this->url('user', ['user_id' =>  Functions::encryptIt($action_by_user_id)]);
  | 
        
        
            | 
            | 
           231 | 
                                   $notification_title = LABEL_CONNECTION_REQUEST_ACCEPTED;
  | 
        
        
            | 
            | 
           232 | 
                                   break;
  | 
        
        
            | 
            | 
           233 | 
              | 
        
        
            | 
            | 
           234 | 
              | 
        
        
            | 
            | 
           235 | 
                               case Notification::TYPE_LIKE :
  | 
        
        
            | 
            | 
           236 | 
                                   $notification_text  = $action_by_user_name .' '. LABEL_LIKED_YOUR_POST . $post_title;
  | 
        
        
            | 
            | 
           237 | 
                                   $notification_url   = $this->url('feed', ['feed_id' =>  Functions::encryptIt($feed_id)]);
  | 
        
        
            | 
            | 
           238 | 
                                   $notification_title = $action_by_user_name .' '. LABEL_LIKED_YOUR_POST. $post_title;
  | 
        
        
            | 
            | 
           239 | 
                                   break;
  | 
        
        
            | 
            | 
           240 | 
              | 
        
        
            | 
            | 
           241 | 
                               case Notification::TYPE_COMMENT :
  | 
        
        
            | 
            | 
           242 | 
                                   $notification_text  = $action_by_user_name.' ' . LABEL_COMMENTED_ON_YOUR_POST.' ' . $post_title;
  | 
        
        
            | 
            | 
           243 | 
                                   $notification_url   = $this->url('feed', ['feed_id' =>  Functions::encryptIt($feed_id)]);
  | 
        
        
            | 
            | 
           244 | 
                                   $notification_title = $action_by_user_name.' ' . LABEL_COMMENTED_ON_YOUR_POST.' ' . $post_title;
  | 
        
        
            | 
            | 
           245 | 
                                   break;
  | 
        
        
            | 
            | 
           246 | 
              | 
        
        
            | 
            | 
           247 | 
                               case Notification::TYPE_SHARE :
  | 
        
        
            | 
            | 
           248 | 
                                   $notification_text  = $action_by_user_name.' ' . LABEL_SHARED_YOUR_POST.' ' . $post_title;
  | 
        
        
            | 
            | 
           249 | 
                                   $notification_url   = $this->url('feed', ['feed_id' =>  Functions::encryptIt($feed_id)]);
  | 
        
        
            | 
            | 
           250 | 
                                   $notification_title = $action_by_user_name.' ' . LABEL_SHARED_YOUR_POST.' ' . $post_title;
  | 
        
        
            | 
            | 
           251 | 
                                   break;
  | 
        
        
            | 
            | 
           252 | 
              | 
        
        
            | 
            | 
           253 | 
                               case Notification::TYPE_RECEIVED_GROUP_JOINING_INVITATION :
  | 
        
        
            | 
            | 
           254 | 
                                   $notification_text  = $action_by_user_name.' ' .  LABEL_SENT_INVITATION.' ' . $group_name;
  | 
        
        
            | 
            | 
           255 | 
                                   $notification_url   = $this->url('group', ['group_id' =>  Functions::encryptIt($group_id)]);
  | 
        
        
            | 
            | 
           256 | 
                                   $notification_title = LABEL_GROUP_JOINING_INVITATION;
  | 
        
        
            | 
            | 
           257 | 
                                   break;
  | 
        
        
            | 
            | 
           258 | 
              | 
        
        
            | 
            | 
           259 | 
                               case Notification::TYPE_RECEIVED_GROUP_JOINING_REQUEST :
  | 
        
        
            | 
            | 
           260 | 
                                   $notification_text  = $action_by_user_name.' ' . LABEL_SENT_INVITATION.' ' . $group_name;
  | 
        
        
            | 
            | 
           261 | 
                                   $notification_url   = $this->url('group-received-invitation', ['group_id' =>  Functions::encryptIt($group_id)]); //get_group_detail_url($group_id).'?received-invitation';
  | 
        
        
            | 
            | 
           262 | 
                                   $notification_title = LABEL_GROUP_JOINING_INVITATION;
  | 
        
        
            | 
            | 
           263 | 
                                   break;
  | 
        
        
            | 
            | 
           264 | 
              | 
        
        
            | 
            | 
           265 | 
                               case Notification::TYPE_GROUP_JOINING_REQUEST_ACCEPTED :
  | 
        
        
            | 
            | 
           266 | 
                                   $notification_text  = $action_by_user_name.' ' .  LABEL_ACCEPTED_YOUR_REQUEST_FOR_JOINING_GROUP.' '  . $group_name;
  | 
        
        
            | 
            | 
           267 | 
                                   $notification_url   = $this->url('group', ['group_id' =>  Functions::encryptIt($group_id)]);
  | 
        
        
            | 
            | 
           268 | 
                                   $notification_title = LABEL_GROUP_JOINING_REQUEST_ACCEPTED;
  | 
        
        
            | 
            | 
           269 | 
                                   break;
  | 
        
        
            | 
            | 
           270 | 
              | 
        
        
            | 
            | 
           271 | 
                               case Notification::TYPE_APPLIED_ON_JOB :
  | 
        
        
            | 
            | 
           272 | 
                                   $notification_text  = $action_by_user_name.' ' .  LABEL_APPLIED_ON_JOB.' ' . $job_title;
  | 
        
        
            | 
            | 
           273 | 
                                   $notification_url   = $this->url('job-applicants', ['job_id' =>  Functions::encryptIt($job_id)]);
  | 
        
        
            | 
            | 
           274 | 
                                   $notification_title = LABEL_APPLIED_ON_JOB_CAPITAL;
  | 
        
        
            | 
            | 
           275 | 
                                   break;
  | 
        
        
            | 
            | 
           276 | 
              | 
        
        
            | 
            | 
           277 | 
                               case Notification::TYPE_FOLLOW_COMPANY :
  | 
        
        
            | 
            | 
           278 | 
                                   $notification_text  = $action_by_user_name.' ' . LABEL_FOLLOWED_COMPANY.' ' . $company_name;
  | 
        
        
            | 
            | 
           279 | 
                                   $notification_url   = $this->url('company-followers', ['company_id' =>  Functions::encryptIt($company_id)]); //get_company_detail_url($company_id).'?company-followers';
  | 
        
        
            | 
            | 
           280 | 
                                   $notification_title = LABEL_FOLLOW_COMPANY;
  | 
        
        
            | 
            | 
           281 | 
                                   break;
  | 
        
        
            | 
            | 
           282 | 
              | 
        
        
            | 
            | 
           283 | 
                               case Notification::TYPE_NEW_FEED_POSTED_IN_GROUP :
  | 
        
        
            | 
            | 
           284 | 
                                   $notification_text  = $action_by_user_name.' ' . LABEL_POSTED_GROUP.' ' . $group_name;
  | 
        
        
            | 
            | 
           285 | 
                                   $notification_url   = $this->url('group-feed', ['group_id' =>  Functions::encryptIt($group_id), 'feed-id' => Functions::encryptIt($feed_id)]); //get_group_detail_url($group_id).'?id='.encryptIt($feed_id).'#'.encryptIt($feed_id);
  | 
        
        
            | 
            | 
           286 | 
                                   $notification_title = LABEL_NEW_POST;
  | 
        
        
            | 
            | 
           287 | 
                                   break;
  | 
        
        
            | 
            | 
           288 | 
              | 
        
        
            | 
            | 
           289 | 
                               case Notification::TYPE_ADD_MEMBER_IN_PRIVATE_GROUP :
  | 
        
        
            | 
            | 
           290 | 
                                   $notification_text  = $action_by_user_name.' ' .LABEL_ADDED_IN_GROUP.' '. $group_name;
  | 
        
        
            | 
            | 
           291 | 
                                   $notification_url   = $this->url('group', ['group_id' =>  Functions::encryptIt($group_id)]);
  | 
        
        
            | 
            | 
           292 | 
                                   $notification_title = LABEL_ADDED_MEMBER;
  | 
        
        
            | 
            | 
           293 | 
                                   break;
  | 
        
        
            | 
            | 
           294 | 
              | 
        
        
            | 
            | 
           295 | 
                           }
  | 
        
        
            | 
            | 
           296 | 
              | 
        
        
            | 
            | 
           297 | 
                           array_push($notifications, [
  | 
        
        
            | 
            | 
           298 | 
                               'text'  => $notification_text,
  | 
        
        
            | 
            | 
           299 | 
                               'url'   => $notification_url,
  | 
        
        
            | 
            | 
           300 | 
                               'title' => $notification_title,
  | 
        
        
            | 
            | 
           301 | 
                               'time'  => $time_ago,
  | 
        
        
            | 
            | 
           302 | 
                               'image' => $user_img
  | 
        
        
            | 
            | 
           303 | 
                           ]);
  | 
        
        
            | 
            | 
           304 | 
              | 
        
        
            | 
            | 
           305 | 
                           $notificationMapper->markNotificationsAsNotified((int) $item['id'], $this->session_user_id);
  | 
        
        
            | 
            | 
           306 | 
                       }
  | 
        
        
            | 
            | 
           307 | 
              | 
        
        
            | 
            | 
           308 | 
                       $viewModel = new ViewModel();
  | 
        
        
            | 
            | 
           309 | 
                       $viewModel->setTerminal(true);
  | 
        
        
            | 
            | 
           310 | 
                       $viewModel->setTemplate('leaders-linked/notifications/single-notification-header.phtml');
  | 
        
        
            | 
            | 
           311 | 
                       $viewModel->setVariables([
  | 
        
        
            | 
            | 
           312 | 
                          'notifications' => $notifications
  | 
        
        
            | 
            | 
           313 | 
                       ]);
  | 
        
        
            | 
            | 
           314 | 
              | 
        
        
            | 
            | 
           315 | 
                       $content = $this->phpRender->render($viewModel);
  | 
        
        
            | 
            | 
           316 | 
              | 
        
        
            | 
            | 
           317 | 
                       if($paginator->count() > 1) {
  | 
        
        
            | 
            | 
           318 | 
                           $viewModel = new ViewModel();
  | 
        
        
            | 
            | 
           319 | 
                           $viewModel->setTerminal(true);
  | 
        
        
            | 
            | 
           320 | 
                           $viewModel->setTemplate('leaders-linked/notifications/view-all-notification.phtml');
  | 
        
        
            | 
            | 
           321 | 
                           $viewModel->setVariables([
  | 
        
        
            | 
            | 
           322 | 
                               'view_all_notification_url' => $this->url('view-all-notification')
  | 
        
        
            | 
            | 
           323 | 
                           ]);
  | 
        
        
            | 
            | 
           324 | 
              | 
        
        
            | 
            | 
           325 | 
                           $content .= $this->phpRender->render($viewModel);
  | 
        
        
            | 
            | 
           326 | 
                       }
  | 
        
        
            | 
            | 
           327 | 
              | 
        
        
            | 
            | 
           328 | 
                   } else {
  | 
        
        
            | 
            | 
           329 | 
                       $viewModel = new ViewModel();
  | 
        
        
            | 
            | 
           330 | 
                       $viewModel->setTerminal(true);
  | 
        
        
            | 
            | 
           331 | 
                       $viewModel->setTemplate('leaders-linked/notifications/no-result-found.phtml');
  | 
        
        
            | 
            | 
           332 | 
              | 
        
        
            | 
            | 
           333 | 
                       $content = $this->phpRender->render($viewModel);
  | 
        
        
            | 
            | 
           334 | 
                   }
  | 
        
        
            | 
            | 
           335 | 
                   return $content;
  | 
        
        
            | 
            | 
           336 | 
               }
  | 
        
        
            | 
            | 
           337 | 
              | 
        
        
            | 
            | 
           338 | 
               /**
  | 
        
        
            | 
            | 
           339 | 
                *
  | 
        
        
            | 
            | 
           340 | 
                * @param int $currentPage
  | 
        
        
            | 
            | 
           341 | 
                * @return array
  | 
        
        
            | 
            | 
           342 | 
                */
  | 
        
        
            | 
            | 
           343 | 
               public function getMessages(int $currentPage = 1)
  | 
        
        
            | 
            | 
           344 | 
               {
  | 
        
        
           | 6388 | 
           efrain | 
           345 | 
              | 
        
        
           | 1 | 
           www | 
           346 | 
              | 
        
        
           | 6388 | 
           efrain | 
           347 | 
              | 
        
        
           | 1 | 
           www | 
           348 | 
                   $queryMapper = QueryMapper::getInstance($this->adapter);
  | 
        
        
           | 6388 | 
           efrain | 
           349 | 
                   $now = $queryMapper->getDatebaseNow();
  | 
        
        
            | 
            | 
           350 | 
              | 
        
        
           | 1 | 
           www | 
           351 | 
                   $select = $queryMapper->getSql()->select(MessageMapper::_TABLE);
  | 
        
        
            | 
            | 
           352 | 
                   $select->where->equalTo('user_id', $this->session_user_id)->and->equalTo('receiver_status', Message::STATUS_NORMAL);
  | 
        
        
            | 
            | 
           353 | 
                   $select->group('conversation_id');
  | 
        
        
            | 
            | 
           354 | 
                   $select->order('id DESC');
  | 
        
        
            | 
            | 
           355 | 
              | 
        
        
            | 
            | 
           356 | 
                   $dbSelect = new DbSelect($select, $this->adapter);
  | 
        
        
            | 
            | 
           357 | 
                   $paginator = new Paginator($dbSelect);
  | 
        
        
            | 
            | 
           358 | 
                   $paginator->setCurrentPageNumber($currentPage);
  | 
        
        
            | 
            | 
           359 | 
                   $paginator->setItemCountPerPage(NO_OF_NOTIFICATIONS_PER_PAGE);
  | 
        
        
            | 
            | 
           360 | 
              | 
        
        
            | 
            | 
           361 | 
                   $content = '';
  | 
        
        
            | 
            | 
           362 | 
                   $items = $paginator->getCurrentItems();
  | 
        
        
            | 
            | 
           363 | 
                   if ($items) {
  | 
        
        
            | 
            | 
           364 | 
              | 
        
        
            | 
            | 
           365 | 
                       $messages = [];
  | 
        
        
            | 
            | 
           366 | 
                       foreach($items as $item)
  | 
        
        
            | 
            | 
           367 | 
                       {
  | 
        
        
            | 
            | 
           368 | 
                           $action_by_user_id      = (int) $item['sender_id'];
  | 
        
        
            | 
            | 
           369 | 
                           $action_by_user_name    = '';
  | 
        
        
            | 
            | 
           370 | 
                           $user_img               = '';
  | 
        
        
            | 
            | 
           371 | 
                           if ($action_by_user_id) {
  | 
        
        
            | 
            | 
           372 | 
                               $userMapper = UserMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           373 | 
                               $user = $userMapper->fetchOne($action_by_user_id);
  | 
        
        
            | 
            | 
           374 | 
              | 
        
        
            | 
            | 
           375 | 
                               if($user->avatar) {
  | 
        
        
            | 
            | 
           376 | 
                                   $user_img = $this->url('storage', ['type' => 'user', 'filename' => 'th2_' . $user->avatar,  'code' => Functions::encryptIt($user->id)]);
  | 
        
        
            | 
            | 
           377 | 
                               } else {
  | 
        
        
            | 
            | 
           378 | 
                                   $user_img = URL_USER_DEFAULT_AVATAR;
  | 
        
        
            | 
            | 
           379 | 
                               }
  | 
        
        
            | 
            | 
           380 | 
                               $action_by_user_name = $user->first_name . ' ' . $user->last_name;
  | 
        
        
            | 
            | 
           381 | 
                           }
  | 
        
        
            | 
            | 
           382 | 
              | 
        
        
            | 
            | 
           383 | 
                           array_push($messages, [
  | 
        
        
            | 
            | 
           384 | 
                               'title'         => $action_by_user_name,
  | 
        
        
            | 
            | 
           385 | 
                               'text'          => $item['message'],
  | 
        
        
            | 
            | 
           386 | 
                               'url'           => $this->url('messaging/thread', ['conversation_id' => Functions::encryptIt($item['conversation_id'])] ).'/#message',
  | 
        
        
           | 3138 | 
           efrain | 
           387 | 
                               'time'          => Functions::timeAgo($item['sent_on'], $now),
  | 
        
        
           | 1 | 
           www | 
           388 | 
                               'image'         => $user_img,
  | 
        
        
           | 630 | 
           efrain | 
           389 | 
                               'active_class'  => $item['is_read'] == Message::YES ? 'active' : ''
  | 
        
        
           | 1 | 
           www | 
           390 | 
                           ]);
  | 
        
        
            | 
            | 
           391 | 
              | 
        
        
            | 
            | 
           392 | 
                       }
  | 
        
        
            | 
            | 
           393 | 
              | 
        
        
            | 
            | 
           394 | 
              | 
        
        
            | 
            | 
           395 | 
                       $viewModel = new ViewModel();
  | 
        
        
            | 
            | 
           396 | 
                       $viewModel->setTerminal(true);
  | 
        
        
            | 
            | 
           397 | 
                       $viewModel->setTemplate('leaders-linked/notification/single-message-header.phtml');
  | 
        
        
            | 
            | 
           398 | 
                       $viewModel->setVariables([
  | 
        
        
            | 
            | 
           399 | 
                           'messages' => $messages
  | 
        
        
            | 
            | 
           400 | 
                       ]);
  | 
        
        
            | 
            | 
           401 | 
              | 
        
        
            | 
            | 
           402 | 
                       $content = $this->phpRender->render($viewModel);
  | 
        
        
            | 
            | 
           403 | 
              | 
        
        
            | 
            | 
           404 | 
                       if ($paginator->count() > 1) {
  | 
        
        
            | 
            | 
           405 | 
                           $viewModel = new ViewModel();
  | 
        
        
            | 
            | 
           406 | 
                           $viewModel->setTerminal(true);
  | 
        
        
            | 
            | 
           407 | 
                           $viewModel->setTemplate('leaders-linked/common/load-more-li.phtml');
  | 
        
        
            | 
            | 
           408 | 
                           $viewModel->setVariables([
  | 
        
        
            | 
            | 
           409 | 
                               'load_more_link' => $this->url('load-more-messages/page', ['page' => $paginator->getCurrentPageNumber() + 1 ])
  | 
        
        
            | 
            | 
           410 | 
                           ]);
  | 
        
        
            | 
            | 
           411 | 
              | 
        
        
            | 
            | 
           412 | 
                           $content .= $this->phpRender->render($viewModel);
  | 
        
        
            | 
            | 
           413 | 
                       }
  | 
        
        
            | 
            | 
           414 | 
                       $consersationFound = true;
  | 
        
        
            | 
            | 
           415 | 
                   } else {
  | 
        
        
            | 
            | 
           416 | 
                       $consersationFound = false;
  | 
        
        
            | 
            | 
           417 | 
              | 
        
        
            | 
            | 
           418 | 
                       $viewModel = new ViewModel();
  | 
        
        
            | 
            | 
           419 | 
                       $viewModel->setTerminal(true);
  | 
        
        
            | 
            | 
           420 | 
                       $viewModel->setTemplate('leaders-linked/common/no-result-found.phtml');
  | 
        
        
            | 
            | 
           421 | 
              | 
        
        
            | 
            | 
           422 | 
                       $content = $this->phpRender->render($viewModel);
  | 
        
        
            | 
            | 
           423 | 
              | 
        
        
            | 
            | 
           424 | 
                   }
  | 
        
        
            | 
            | 
           425 | 
              | 
        
        
            | 
            | 
           426 | 
                   $viewModel = new ViewModel();
  | 
        
        
            | 
            | 
           427 | 
                   $viewModel->setTerminal(true);
  | 
        
        
            | 
            | 
           428 | 
                   $viewModel->setTemplate('leaders-linked/common/view-all-notification.phtml');
  | 
        
        
            | 
            | 
           429 | 
                   $viewModel->setVariables([
  | 
        
        
            | 
            | 
           430 | 
                       'view_all_notification_url' => $this->url('messaging')
  | 
        
        
            | 
            | 
           431 | 
                   ]);
  | 
        
        
            | 
            | 
           432 | 
              | 
        
        
            | 
            | 
           433 | 
              | 
        
        
            | 
            | 
           434 | 
                   $view_all_messages = $this->phpRender->render($viewModel);
  | 
        
        
            | 
            | 
           435 | 
                   $response = [
  | 
        
        
            | 
            | 
           436 | 
                       'consersationFound' => $consersationFound ? true : false,
  | 
        
        
            | 
            | 
           437 | 
                       'content'           => $content,
  | 
        
        
            | 
            | 
           438 | 
                       'view_all_messages' => $view_all_messages
  | 
        
        
            | 
            | 
           439 | 
                   ];
  | 
        
        
            | 
            | 
           440 | 
                   return $response;
  | 
        
        
            | 
            | 
           441 | 
               }
  | 
        
        
            | 
            | 
           442 | 
              | 
        
        
            | 
            | 
           443 | 
               /**
  | 
        
        
            | 
            | 
           444 | 
                *
  | 
        
        
            | 
            | 
           445 | 
                * @param int $currentPage
  | 
        
        
            | 
            | 
           446 | 
                * @param bool $invitation_pagination
  | 
        
        
            | 
            | 
           447 | 
                * @return string
  | 
        
        
            | 
            | 
           448 | 
                */
  | 
        
        
            | 
            | 
           449 | 
               public function getConnectionRequest(int $currentPage = 1, bool $invitation_pagination = true)
  | 
        
        
            | 
            | 
           450 | 
               {
  | 
        
        
            | 
            | 
           451 | 
                   $queryMapper = QueryMapper::getInstance($this->adapter);
  | 
        
        
            | 
            | 
           452 | 
                   $select = $queryMapper->getSql()->select();
  | 
        
        
            | 
            | 
           453 | 
                   $select->columns(['id', 'request_from', 'request_to']);
  | 
        
        
            | 
            | 
           454 | 
                   $select->from(['c' => ConnectionMapper::_TABLE]);
  | 
        
        
            | 
            | 
           455 | 
                   $select->join(['au' => UserMapper::_TABLE], 'u.id = c.request_from', ['first_name','last_name', 'avatar']);
  | 
        
        
            | 
            | 
           456 | 
                   $select->join(['ue' => UserExperienceMapper::_TABLE], 'ue.company_id = com.id', ['job_title'], Select::JOIN_LEFT);
  | 
        
        
            | 
            | 
           457 | 
                   $select->join(['com' => CompanyMapper::_TABLE], 'ue.company_id = com.id', ['company_name'], Select::JOIN_LEFT);
  | 
        
        
            | 
            | 
           458 | 
                   $select->where->equalTo('c.request_to', $this->session_user_id)->and->equalTo('status', Connection::STATUS_SENT);
  | 
        
        
            | 
            | 
           459 | 
                   $select->group(' c.id');
  | 
        
        
            | 
            | 
           460 | 
                   $select->order('id DESC');
  | 
        
        
            | 
            | 
           461 | 
              | 
        
        
            | 
            | 
           462 | 
                   $dbSelect = new DbSelect($select, $this->adapter);
  | 
        
        
            | 
            | 
           463 | 
                   $paginator = new Paginator($dbSelect);
  | 
        
        
            | 
            | 
           464 | 
                   $paginator->setCurrentPageNumber($currentPage);
  | 
        
        
            | 
            | 
           465 | 
                   $paginator->setItemCountPerPage(NO_OF_NOTIFICATIONS_PER_PAGE);
  | 
        
        
            | 
            | 
           466 | 
              | 
        
        
            | 
            | 
           467 | 
              | 
        
        
            | 
            | 
           468 | 
                   $items = $paginator->getCurrentItems();
  | 
        
        
            | 
            | 
           469 | 
              | 
        
        
            | 
            | 
           470 | 
                   if ($items) {
  | 
        
        
            | 
            | 
           471 | 
              | 
        
        
            | 
            | 
           472 | 
                       $connections = [];
  | 
        
        
            | 
            | 
           473 | 
              | 
        
        
            | 
            | 
           474 | 
                       foreach($items as $item)
  | 
        
        
            | 
            | 
           475 | 
                       {
  | 
        
        
            | 
            | 
           476 | 
                           $action_by_user_id      = $item['request_from'];
  | 
        
        
            | 
            | 
           477 | 
                           $action_by_user_name    = $item['first_name'] . ' ' . $item['last_name'];
  | 
        
        
            | 
            | 
           478 | 
                           $message_text           = $action_by_user_name .' '. LABEL_SENT_CONNECTION_REQUEST;
  | 
        
        
            | 
            | 
           479 | 
                           $message_title          = $action_by_user_name;
  | 
        
        
            | 
            | 
           480 | 
                           if($item['avatar']) {
  | 
        
        
            | 
            | 
           481 | 
                               $user_img = $this->url('storage', ['type' => 'user', 'filename' => $item['avatar'], 'code' => Functions::encryptIt($action_by_user_id)]);
  | 
        
        
            | 
            | 
           482 | 
                           } else {
  | 
        
        
            | 
            | 
           483 | 
                               $user_img = URL_USER_DEFAULT_AVATAR;
  | 
        
        
            | 
            | 
           484 | 
                           }
  | 
        
        
            | 
            | 
           485 | 
              | 
        
        
            | 
            | 
           486 | 
              | 
        
        
            | 
            | 
           487 | 
                           array_push($connections, [
  | 
        
        
            | 
            | 
           488 | 
                               'user_img' => $user_img,
  | 
        
        
            | 
            | 
           489 | 
                               'message_title' => $message_title,
  | 
        
        
            | 
            | 
           490 | 
                               'message_text' => $message_text,
  | 
        
        
            | 
            | 
           491 | 
                               'encrypted_user_id' => Functions::encryptIt($action_by_user_id)
  | 
        
        
            | 
            | 
           492 | 
                           ]);
  | 
        
        
            | 
            | 
           493 | 
              | 
        
        
            | 
            | 
           494 | 
              | 
        
        
            | 
            | 
           495 | 
                       }
  | 
        
        
            | 
            | 
           496 | 
              | 
        
        
            | 
            | 
           497 | 
                       $viewModel = new ViewModel();
  | 
        
        
            | 
            | 
           498 | 
                       $viewModel->setTerminal(true);
  | 
        
        
            | 
            | 
           499 | 
                       $viewModel->setTemplate('leaders-linked/common/single-connection-header.phtml');
  | 
        
        
            | 
            | 
           500 | 
                       $viewModel->setVariables([
  | 
        
        
            | 
            | 
           501 | 
                           'connections' => $connections
  | 
        
        
            | 
            | 
           502 | 
                       ]);
  | 
        
        
            | 
            | 
           503 | 
              | 
        
        
            | 
            | 
           504 | 
                       $content = $this->phpRender->render($viewModel);;
  | 
        
        
            | 
            | 
           505 | 
              | 
        
        
            | 
            | 
           506 | 
                   } else {
  | 
        
        
            | 
            | 
           507 | 
                       $viewModel = new ViewModel();
  | 
        
        
            | 
            | 
           508 | 
                       $viewModel->setTerminal(true);
  | 
        
        
            | 
            | 
           509 | 
                       $viewModel->setTemplate('leaders-linked/common/no-connection-requests.phtml');
  | 
        
        
            | 
            | 
           510 | 
                       $content = $this->phpRender->render($viewModel);;
  | 
        
        
            | 
            | 
           511 | 
                   }
  | 
        
        
            | 
            | 
           512 | 
              | 
        
        
            | 
            | 
           513 | 
                   return $content;
  | 
        
        
            | 
            | 
           514 | 
               }
  | 
        
        
            | 
            | 
           515 | 
              | 
        
        
            | 
            | 
           516 | 
               /**
  | 
        
        
            | 
            | 
           517 | 
                *
  | 
        
        
            | 
            | 
           518 | 
                * @return string[]
  | 
        
        
            | 
            | 
           519 | 
                */
  | 
        
        
            | 
            | 
           520 | 
               public function getAllNotifications()
  | 
        
        
            | 
            | 
           521 | 
               {
  | 
        
        
            | 
            | 
           522 | 
                   $response = [];
  | 
        
        
            | 
            | 
           523 | 
                   $response['general_notifications']      = $this->getNotifications();
  | 
        
        
            | 
            | 
           524 | 
                   $response['job_notifications']          = '';
  | 
        
        
            | 
            | 
           525 | 
                   $response['company_notifications']      = '';
  | 
        
        
            | 
            | 
           526 | 
                   $response['group_notifications']        = '';
  | 
        
        
            | 
            | 
           527 | 
              | 
        
        
            | 
            | 
           528 | 
                   $messages                               = $this->getMessages();
  | 
        
        
            | 
            | 
           529 | 
                   $response['consersationFound']          = $messages['consersationFound'];
  | 
        
        
            | 
            | 
           530 | 
                   $response['messages']                   = $messages['content'];
  | 
        
        
            | 
            | 
           531 | 
                   $response['view_all_messages']          = $messages['view_all_messages'];
  | 
        
        
            | 
            | 
           532 | 
              | 
        
        
            | 
            | 
           533 | 
                   $response['connection_request']         = $this->getConnectionRequest();
  | 
        
        
            | 
            | 
           534 | 
                   $response['notifications_count']        = $this->getUnreadNotificationsCount();
  | 
        
        
            | 
            | 
           535 | 
                   $response['messages_count']             = $this->getUnreadMessagesCount();
  | 
        
        
            | 
            | 
           536 | 
                   $response['connection_request_count']   = $this->getConnectionRequestCount();
  | 
        
        
            | 
            | 
           537 | 
                   return $response;
  | 
        
        
            | 
            | 
           538 | 
               }
  | 
        
        
            | 
            | 
           539 | 
           }
  |