compteur de visite group (ref #151)

This commit is contained in:
afornerot 2020-06-09 11:24:07 +02:00
parent e18790790b
commit e85f74cda5
5 changed files with 104 additions and 12 deletions

View File

@ -349,7 +349,7 @@ class GroupController extends Controller
// Avatar // Avatar
$avatar="<img onClick='seeUser(".$data->getId().")' src='/".$this->container->getParameter('alias')."/uploads/avatar/".$data->getAvatar()."' style='width:30px;background-color:#337ab7;margin:auto;display:block;cursor:pointer;'>"; $avatar="<img onClick='seeUser(".$data->getId().")' src='/".$this->container->getParameter('alias')."/uploads/avatar/".$data->getAvatar()."' style='width:30px;background-color:#337ab7;margin:auto;display:block;cursor:pointer;'>";
array_push($output["data"],array("DT_RowId"=>"user".$data->getId(),$action,$avatar,$data->getUsername(),$data->getEmail(),$fgmanager)); array_push($output["data"],array("DT_RowId"=>"user".$data->getId(),$action,$avatar,$data->getUsername(),$data->getEmail(),"",$fgmanager));
} }
// Retour // Retour
@ -492,8 +492,13 @@ class GroupController extends Controller
} }
// Visite
$visite="";
if($usergroup->getVisitedate()) {
$visite=$usergroup->getVisitedate()->format("d/m/Y H:i")."<br>nb = ".$usergroup->getVisitecpt();
}
array_push($output["data"],array("DT_RowId"=>"user".$data->getId(),$action,$avatar,$data->getUsername(),$data->getEmail(),$fgmanager)); array_push($output["data"],array("DT_RowId"=>"user".$data->getId(),$action,$avatar,$data->getUsername(),$data->getEmail(),$visite,$fgmanager));
} }
// Retour // Retour
@ -974,8 +979,8 @@ class GroupController extends Controller
public function usergroupexportAction($id,Request $request, $access="config") public function usergroupexportAction($id,Request $request, $access="config")
{ {
// Récupération de l'enregistrement courant // Récupération de l'enregistrement courant
$data=$this->getData($id); $group=$this->getData($id);
$this->canManager($data,$access); $this->canManager($group,$access);
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$dir = $this->get('kernel')->getRootDir() . '/../uploads/export/'; $dir = $this->get('kernel')->getRootDir() . '/../uploads/export/';
@ -989,7 +994,7 @@ class GroupController extends Controller
$e = '"'; // this is the default but i like to be explicit $e = '"'; // this is the default but i like to be explicit
// Entête de colonne // Entête de colonne
$data=["id","Login","Nom","Prénom","Email","Téléphone",$this->getParameter("labelniveau01"),$this->getParameter("labelniveau02"),"Métier","Fonction","Nom Usage","Autres Prénom","Sexe","Adresse","Date Naissance","Pays Naissance","Ville Naissance"]; $data=["id","Login","Nom","Prénom","Email","Téléphone",$this->getParameter("labelniveau01"),$this->getParameter("labelniveau02"),"Métier","Fonction","Nom Usage","Autres Prénom","Sexe","Adresse","Date Naissance","Pays Naissance","Ville Naissance","Date Visite","Nb Visites"];
fputcsv($csvh, $data, $d, $e); fputcsv($csvh, $data, $d, $e);
// Liste des utilisateurs en fonction du role de l'utilisateur en cours // Liste des utilisateurs en fonction du role de l'utilisateur en cours
@ -1040,9 +1045,18 @@ class GroupController extends Controller
"birthdate"=>($user->getBirthdate()?$user->getBirthdate()->format("d/m/Y"):""), "birthdate"=>($user->getBirthdate()?$user->getBirthdate()->format("d/m/Y"):""),
"birthcountry"=>($user->getBirthcountry()?$user->getBirthcountry()->getLabel():""), "birthcountry"=>($user->getBirthcountry()?$user->getBirthcountry()->getLabel():""),
"birthplace"=>($user->getBirthplace()?$user->getBirthplace()->getLabel():""), "birthplace"=>($user->getBirthplace()?$user->getBirthplace()->getLabel():""),
"visitedate"=>"",
"visitecpt"=>"",
]; ];
$usergroup=$em->getRepository("CadolesCoreBundle:UserGroup")->findOneBy(["user"=>$user,"group"=>$group]);
if($usergroup) {
if($usergroup->getVisitedate()) {
$data["visitedate"]=$usergroup->getVisitedate()->format("d/m/Y H:i");
$data["visitecpt"]=$usergroup->getVisitecpt();
}
}
fputcsv($csvh, $data, $d, $e); fputcsv($csvh, $data, $d, $e);
} }
fclose($csvh); fclose($csvh);

View File

@ -45,6 +45,16 @@ class UserGroup
*/ */
private $keyvalue; private $keyvalue;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $visitedate;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $visitecpt;
/** /**
* Get id * Get id
* *
@ -150,4 +160,52 @@ class UserGroup
{ {
return $this->keyvalue; return $this->keyvalue;
} }
/**
* Set visitedate
*
* @param \DateTime $visitedate
*
* @return UserGroup
*/
public function setVisitedate($visitedate)
{
$this->visitedate = $visitedate;
return $this;
}
/**
* Get visitedate
*
* @return \DateTime
*/
public function getVisitedate()
{
return $this->visitedate;
}
/**
* Set visitecpt
*
* @param integer $visitecpt
*
* @return UserGroup
*/
public function setVisitecpt($visitecpt)
{
$this->visitecpt = $visitecpt;
return $this;
}
/**
* Get visitecpt
*
* @return integer
*/
public function getVisitecpt()
{
return $this->visitecpt;
}
} }

View File

@ -287,7 +287,7 @@
if($curentuser!="anon.") { if($curentuser!="anon.") {
$visitedate=$curentuser->getVisitedate(); $visitedate=$curentuser->getVisitedate();
$visitedate->add(new \DateInterval("PT1H")); if($visitedate) $visitedate->add(new \DateInterval("PT1H"));
$now=new \DateTime(); $now=new \DateTime();
if($visitedate<$now) { if($visitedate<$now) {
$curentuser->setVisitedate($now); $curentuser->setVisitedate($now);

View File

@ -30,6 +30,7 @@
<th width="70px" class="no-sort">Avatar</th> <th width="70px" class="no-sort">Avatar</th>
<th width="200px">Login</th> <th width="200px">Login</th>
<th>Email</th> <th>Email</th>
<th class="no-sort">Visite</th>
{% if group.fgcanshare %} {% if group.fgcanshare %}
<th class="no-sort">Manager</th> <th class="no-sort">Manager</th>
{% endif %} {% endif %}
@ -56,6 +57,7 @@
<th width="70px" class="no-sort">Avatar</th> <th width="70px" class="no-sort">Avatar</th>
<th width="200px">Login</th> <th width="200px">Login</th>
<th>Email</th> <th>Email</th>
<th class="no-sort">Visite</th>
{% if group.fgcanshare %} {% if group.fgcanshare %}
<th class="no-sort">Manager</th> <th class="no-sort">Manager</th>
{% endif %} {% endif %}

View File

@ -515,6 +515,24 @@ class PageController extends Controller
} }
*/ */
// Compteur de visite
if($this->getUser()) {
$group=$em->getRepository("CadolesCoreBundle:Group")->find($groupid);
if($group && $group->getFgcanshare()) {
$usergroup=$em->getRepository("CadolesCoreBundle:UserGroup")->findoneby(["group"=>$group,"user"=>$this->getUser()]);
if($usergroup) {
$visitedate=$usergroup->getVisitedate();
if($visitedate) $visitedate->add(new \DateInterval("PT1H"));
$now=new \DateTime();
if($visitedate<$now) {
$usergroup->setVisitedate($now);
$usergroup->setVisitecpt($usergroup->getVisitecpt()+1);
$em->persist($usergroup);
$em->flush();
}
}
}
}
// Type Calendrier // Type Calendrier
if($entity->getPageCategory()->getId()==-100) { if($entity->getPageCategory()->getId()==-100) {