<?php

use Doctrine\ORM\EntityRepository;

class ViewedNotiByStRepository extends EntityRepository
{

    public function addViewNotiBySt($noti_id,$by_username)
    {
        $entityManager = $this->getEntityManager();
        $time_stamp = date('d-m-Y H:i:s');

        $nv = new ViewedNotiBySt;
        $nv->setNotiId($noti_id);
        $nv->setByUsername($by_username);
        $nv->setViewedAt($time_stamp);
        $entityManager->persist($nv);
        $entityManager->flush();
    }

   public function getViewedNotiBySt($by_username){
        $dql = "SELECT COUNT(r.id) as nos FROM ViewedNotiBySt r WHERE r.by_username=:u";
        $query = $this->getEntityManager()->createQuery($dql)->setParameter('u',$by_username);
        $r = $query->getResult();
        if(sizeof($r) > 0)
        return $r[0]['nos'];
        else return 0;
    }
}