[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/plugins/clickheat/libs/classes/ -> HeatmapFromDatabase.class.php (source)

   1  <?php
   2  /**
   3   * ClickHeat : Classe de génération des cartes depuis une base de données MySQL / Maps generation class from a MySQL database
   4   * 
   5   * Cette classe est VOLONTAIREMENT écrite pour PHP 4
   6   * This class is VOLUNTARILY written for PHP 4
   7   * 
   8   * Utilisation : jettez un oeil au répertoire /examples/
   9   * Usage: have a look into /examples/ directory
  10   * 
  11   * @author Yvan Taviaud - LabsMedia - www.labsmedia.com
  12   * @since 19/05/2007
  13  **/
  14  
  15  class HeatmapFromDatabase extends Heatmap
  16  {
  17      /** @var string $host Hôte (serveur) MySQL / MySQL host (server) */
  18      var $host = 'localhost';
  19      /** @var string $user Utilisateur MySQL / MySQL user */
  20      var $user = '';
  21      /** @var string $password Mot de passe de l'utilisateur MySQL / MySQL user's password */
  22      var $password = '';
  23      /** @var string $database Nom de la base de données MySQL / MySQL database name */
  24      var $database = '';
  25      /** @var integer $limit Limite du nombre de résultats renvoyés par la requête à chaque appel / Maximum number of results returned by each request call */
  26      var $limit = 1000;
  27      /** @var resource $link Lien (interne) MySQL / MySQL (internal) link */
  28      var $link = false;
  29      /** @var string $query Requête renvoyant les coordonnées des clics / Clicks coordinates query */
  30      var $query = 'SELECT COORDS_X, COORDS_Y FROM CLICKS WHERE COORDS_Y BETWEEN %d AND %d';
  31      /** @var string $maxQuery Requête renvoyant la coordonnées Y maximale / Max Y coordinate query */
  32      var $maxQuery = 'SELECT MAX(COORDS_Y) FROM CLICKS';
  33  
  34      /**
  35       * Do some tasks before drawing (database connection...)
  36      **/
  37  	function startDrawing()
  38      {
  39          $this->link = @mysql_connect($this->host, $this->user, $this->password);
  40          if ($this->link === false)
  41          {
  42              return $this->raiseError('Database connection error: '.mysql_error());
  43          }
  44          if (mysql_select_db($this->database) === false)
  45          {
  46              return $this->raiseError('Database selection error: '.$this->database);
  47          }
  48          $result = mysql_query($this->maxQuery);
  49          if ($result === false)
  50          {
  51              return $this->raiseError('Query failed: '.mysql_error());
  52          }
  53          $max = mysql_fetch_row($result);
  54          $this->maxY = $max[0];
  55          mysql_free_result($result);
  56          return true;
  57      }
  58  
  59      /**
  60       * Find pixels coords and draw these on the current image
  61       *
  62       * @param integer $image Number of the image (to be used with $this->height)
  63       * @return boolean Success
  64      **/
  65  	function drawPixels($image)
  66      {
  67          $limit = 0;
  68          do
  69          {
  70              /** Select with limit */
  71              $result = mysql_query(sprintf($this->query, $image * $this->height, ($image + 1) * $this->height - 1).' LIMIT '.$limit.','.$this->limit);
  72              if ($result === false)
  73              {
  74                  return $this->raiseError('Query failed: '.mysql_error());
  75              }
  76              $count = mysql_num_rows($result);
  77  
  78              while ($click = mysql_fetch_row($result))
  79              {
  80                  $x = (int) $click[0];
  81                  $y = (int) ($click[1]  - $image * $this->height);
  82                  if ($x < 0 || $x >= $this->width)
  83                  {
  84                      continue;
  85                  }
  86                  /** Apply a calculus for the step, with increases the speed of rendering : step = 3, then pixel is drawn at x = 2 (center of a 3x3 square) */
  87                  $x -= $x % $this->step - $this->startStep;
  88                  $y -= $y % $this->step - $this->startStep;
  89                  /** Add 1 to the current color of this pixel (color which represents the sum of clicks on this pixel) */
  90                  $color = imagecolorat($this->image, $x, $y) + 1;
  91                  imagesetpixel($this->image, $x, $y, $color);
  92                  $this->maxClicks = max($this->maxClicks, $color);
  93                  if ($image === 0)
  94                  {
  95                      /** Looking for the maximum height of click */
  96                      $this->maxY = max($y, $this->maxY);
  97                  }
  98              }
  99              /** Free resultset */
 100              mysql_free_result($result);
 101  
 102              $limit += $this->limit;
 103          } while ($count === $this->limit);
 104          return true;
 105      }
 106  
 107      /**
 108       * Do some cleaning or ending tasks (close database, reset array...)
 109      **/
 110  	function finishDrawing()
 111      {
 112          /** Close connection */
 113          mysql_close($this->link);
 114          return true;
 115      }
 116  }
 117  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics