vendor/theatre/core/src/Repository/StatsRepository.php line 74

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use TheatreCore\Entity\Stats;
  6. use TheatreCore\Traits\TheatreTrait;
  7. use App\Service\IdCookie;
  8. /**
  9.  * StatsRepository
  10.  *
  11.  * This class was generated by the Doctrine ORM. Add your own custom
  12.  * repository methods below.
  13.  */
  14. class StatsRepository extends ServiceEntityRepository
  15. {
  16.     use TheatreTrait;
  17.     private $em;
  18.     public $__table;
  19.     public $__table_object;
  20.     public $__idtable;
  21.     public function __construct(ManagerRegistry $registry)
  22.     {
  23.         parent::__construct($registryStats::class);
  24.         $this->__table $this->getClassMetadata()->getTableName();
  25.         $this->__table_object $this->getClassMetadata()->name;
  26.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  27.     }
  28.     //  {{{ setStats()
  29.     /** Enregistrement d'une statistique
  30.      *
  31.      * Permet l'enregistrement d'une statistique dans une table
  32.      *
  33.      * @access   public
  34.      * @param string $table Nom de la table de relation
  35.      * @param string $key Clé dans la tableau
  36.      * @param string $col Colonne
  37.      * @param array $array_values Valeur à enregistrer
  38.      * @param int $id Id de l'enregistrement principal
  39.      * @return   bool
  40.      */
  41.     public function setStats($infos$source null)
  42.     {
  43.         /* Vérification rapide des données passées */
  44.         if (empty($infos)) return;
  45.         if ($infos['type'] != 'article' && $infos['type'] != 'video') {
  46.             error_log('setStats: type incorrect: ' $infos['type']);
  47.             return;
  48.         }
  49.         if (empty($infos['module'])) {
  50.             error_log('setStats: module non spécifié');
  51.             return;
  52.         }
  53.         $lng strtolower($GLOBALS['lng']);
  54.         if (strlen($lng) != 2) {
  55.             error_log('setStats: code langue incorrect: ' $lng);
  56.             return;
  57.         }
  58.         $idcookie = new IdCookie('stats');
  59.         $uniqid $idcookie->get(60); /* 12 heures */
  60.         $md5url md5($infos['url']);
  61.         if ($uniqid) {
  62.             $data_uniqid $this->findBy(['remoteAddr' => $uniqid'idcontent' => (int)$infos['idcontent'], 'md5url' => $md5url]);
  63.             if (!empty($data_uniqid)) {
  64.                 return $data_uniqid[0];
  65.             }
  66.         }
  67. //        if (!$this->debug) $source = null;
  68.         // on supprime les paramètres le cas échéant
  69.         $querypos strpos($infos['url'], '?');
  70.         if ($querypos !== false) {
  71.             $infos['url'] = substr($infos['url'], 0$querypos);
  72.         }
  73.         //tableau pour insertion dans la table stats
  74.         $values = array(
  75.             'type' => $infos['type'],
  76.             'module' => $infos['module'],
  77.             'url' => $infos['url'],
  78.             'md5url' => $md5url,
  79.             'idcontent' => (int)$infos['idcontent'],
  80.             'object' => $infos['object'],
  81.             'idobject' => (int)$infos['idobject'],
  82.             'video' => (int)$infos['video'],
  83.             'lng' => $GLOBALS['lng'],
  84.             'remote_addr' => $uniqid,
  85.             'source' => $source
  86.         );
  87.         //print_r($values);
  88.         // champ a mettre a jour
  89.         $this->setUpdateFields($values);
  90.         //debug only
  91.         //if ($this->debug) return $this->setData(null,true);
  92.         // on insère ou on update
  93.         $ret false;
  94.         try {
  95. //            dump('à refaire ici');
  96.             $ret $this->setData(nulltrue);
  97.         } catch (\Exception $e) {
  98.             //on accepte les erreurs ici (double insertion)
  99.             //$error = $e->getError();
  100.         }
  101.         return $ret;
  102.     }
  103.     // }}}
  104.     // {{{ logVideoStats()
  105.     /** Insère les statistiques pour une video
  106.      *
  107.      *
  108.      * @param mixed $module
  109.      * @access public
  110.      * @return void
  111.      */
  112.     public function logVideoStats($module)
  113.     {
  114.         // deboguage: mettre à 1 le paramètre dbg dans makePlayerConf()
  115.         if (!empty($_GET['dbg'])) {
  116.             $debug_file '/tmp/logstats.txt';
  117.         } else {
  118.             $debug_file false;
  119.         }
  120.         if ($debug_file) {
  121.             file_put_contents($debug_filedate('Ymd His') . ' ' print_r($_REQUESTtrue), FILE_APPEND);
  122.         }
  123.         // verification de la clé, prévention flood
  124.         if ($_GET['key'] != md5(URL_THTV date('Ymd'))) return;
  125.         $infos = array();
  126.         // parametre envoyes par le lecteur
  127.         if (isset($_GET['url'])) {
  128.             $infos['url'] = urldecode($_GET['url']);
  129.         }
  130.         if (isset($_GET['idcontent'])) {
  131.             $infos['idcontent'] = urldecode($_GET['idcontent']);
  132.         }
  133.         if (isset($_GET['object'])) {
  134.             $infos['object'] = urldecode($_GET['object']);
  135.         }
  136.         if (isset($_GET['idobject'])) {
  137.             $infos['idobject'] = urldecode($_GET['idobject']);
  138.         }
  139.         $infos['type'] = 'video';
  140.         $infos['video'] = 1;
  141.         $infos['module'] = $module;
  142.         //insérer la statistique
  143.         if (!empty($infos['object']) && !empty($infos['idobject'])) {
  144.             $res $this->setStats($infos__FILE__ ':' __LINE__);
  145.             if ($debug_file) {
  146.                 file_put_contents($debug_filedate('Ymd His') . ' setStats(): ' print_r($restrue) . "\n"FILE_APPEND);
  147.             }
  148.         }
  149.     }
  150.     // }}}
  151. }