/**
  * do carbage collection
  *
  * @since 0.1.0
  * @access public
  * @return bool
  * @param int $lifetime
  */
 public function gc($lifetime)
 {
     $sql = 'DELETE FROM session WHERE session.timestamp < ?';
     $statement = $this->db->prepareStatement($sql);
     $statement->setString(1, time() - $lifetime);
     try {
         $statement->query();
     } catch (DatabaseException $e) {
         return false;
     }
     return true;
 }
Example #2
0
 public static function fromDatabaseSearchByCity($city)
 {
     $city = mb_strtolower(trim($city), 'utf-8');
     $city = str_replace(self::$replaceFrom, self::$replaceTo, $city);
     $words = explode(' ', $city);
     // Remove empty words and prepare for regex
     foreach ($words as $i => $word) {
         if ($word !== '') {
             $words[$i] = preg_quote($word);
         } else {
             unset($words[$i]);
         }
     }
     $sql = "SELECT * FROM office WHERE of_search REGEXP ? " . "ORDER BY of_city, of_address";
     $param = "(^| )(" . implode("|", $words) . ")(\$| )";
     $stmt = Database::prepareStatement($sql);
     if (!$stmt->execute(array($param))) {
         gfDebug(print_r($stmt->errorInfo(), true));
         gfDebug(print_r($words, true));
         throw new Exception(__METHOD__ . " Error while reading offices from database");
     }
     $rows = $stmt->fetchall(PDO::FETCH_ASSOC);
     $offices = array();
     foreach ($rows as $row) {
         $offices[] = self::newFromDatabaseRow($row);
     }
     // Sort results to show most relevant entries first
     $ranking = array();
     for ($i = 1; $i <= count($words); $i++) {
         $ranking[$i] = array();
     }
     foreach ($offices as $office) {
         $search = $office->getSearch();
         $level = 0;
         foreach ($words as $word) {
             gfDebug("Analizzo parola {$word} per {$search}");
             if (strpos($search, $word) !== false) {
                 gfDebug("La contiene e alzo il livello");
                 $level++;
             }
         }
         $ranking[$level][] = $office;
         gfDebug("La città {$office->getCity()} ha livello finale {$level}");
     }
     gfDebug(print_r($words, true));
     // Construct final array
     $ret = array();
     foreach ($ranking as $level) {
         $ret = array_merge($level, $ret);
     }
     return $ret;
 }
Example #3
0
 public static function fromDatabaseCompleteList()
 {
     $sql = "SELECT * FROM device ORDER BY dev_ip_address";
     $stmt = Database::prepareStatement($sql);
     if (!$stmt->execute()) {
         throw new Exception("fromDatabaseCompleteList: Error while reading device from database");
     }
     $output = array();
     $rows = $stmt->fetchall(PDO::FETCH_ASSOC);
     foreach ($rows as $row) {
         $output[] = self::newFromDatabaseRow($row);
     }
     return $output;
 }
Example #4
0
 public static function getUsedDeskNumbers()
 {
     $sql = "SELECT desk_number FROM desk ORDER BY desk_number";
     $stmt = Database::prepareStatement($sql);
     if (!$stmt->execute()) {
         throw new Exception("getUsedDeskNumbers: Error while reading data");
     }
     $output = array();
     $rows = $stmt->fetchall(PDO::FETCH_ASSOC);
     foreach ($rows as $row) {
         $output[] = $row['desk_number'];
     }
     return $output;
 }
Example #5
0
 public static function fromDatabaseCompleteList()
 {
     $sql = "SELECT * FROM operator ORDER BY op_code";
     $stmt = Database::prepareStatement($sql);
     if (!$stmt->execute()) {
         throw new Exception(__METHOD__ . " Error while reading operator from database");
     }
     $output = array();
     $rows = $stmt->fetchall(PDO::FETCH_ASSOC);
     foreach ($rows as $row) {
         $output[] = self::newFromDatabaseRow($row);
     }
     return $output;
 }
Example #6
0
 private static function fromDatabaseList($sqlWhere = '', $parameters = array())
 {
     $sql = "SELECT * FROM ticket_stats {$sqlWhere} ORDER BY ts_time_out";
     $stmt = Database::prepareStatement($sql);
     if (!$stmt->execute($parameters)) {
         throw new Exception(__METHOD__ . " Error while reading ticketStats from database");
     }
     $output = array();
     $rows = $stmt->fetchall(PDO::FETCH_ASSOC);
     foreach ($rows as $row) {
         $output[] = self::newFromDatabaseRow($row);
     }
     return $output;
 }
Example #7
0
 public static function fromDatabaseCompleteList($activeOnly = true)
 {
     $sql = "SELECT * FROM topical_domain";
     if ($activeOnly) {
         $sql .= " WHERE td_active=1";
     }
     $sql .= " ORDER BY td_code";
     $stmt = Database::prepareStatement($sql);
     if (!$stmt->execute()) {
         throw new Exception(__METHOD__ . " Error while reading topical domain from database");
     }
     $output = array();
     $rows = $stmt->fetchall(PDO::FETCH_ASSOC);
     foreach ($rows as $row) {
         $output[] = self::newFromDatabaseRow($row);
     }
     return $output;
 }
 public function delete()
 {
     if ($this->isNew) {
         throw new Exception('Cannot delete new record');
     }
     $idColumn = $this->idColumn;
     $sql = "DELETE FROM {$this->tableName} WHERE {$idColumn}=?";
     $stmt = Database::prepareStatement($sql);
     $result = $stmt->execute(array($this->{$idColumn}));
     if (!$result) {
         //Deletion failed
         return false;
     }
     return true;
 }
Example #9
0
 public static function sourceExists($ban_source, $ban_source_id)
 {
     $sql = "SELECT ban_id FROM ban " . "WHERE ban_source = ? AND ban_source_id = ? LIMIT 1";
     $stmt = Database::prepareStatement($sql);
     if (!$stmt->execute(array($ban_source, $ban_source_id))) {
         throw new Exception(__METHOD__ . " Error while reading ban from database");
     }
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     if ($row) {
         return true;
     } else {
         return false;
     }
 }
Example #10
0
 protected static function getMinMaxId()
 {
     $sql = "SELECT MAX( dm_id ) AS maxx, MIN( dm_id ) AS minn FROM display_main";
     $stmt = Database::prepareStatement($sql);
     if (!$stmt->execute()) {
         throw new Exception("Error while computing max or min index.");
     }
     $result = $stmt->fetch(PDO::FETCH_ASSOC);
     return array($result['minn'], $result['maxx']);
 }
Example #11
0
 protected static function countTicketBefore($code, $number)
 {
     $code = strtoupper($code);
     $number = (int) $number;
     $sql = "SELECT COUNT( ti_id ) FROM ticket_in " . "WHERE ti_code = ? AND ti_number < ?";
     $stmt = Database::prepareStatement($sql);
     if (!$stmt->execute(array($code, $number))) {
         throw new Exception(__METHOD__ . "Unable to count ticket");
     }
     $result = $stmt->fetch(PDO::FETCH_BOTH);
     return $result[0];
 }
Example #12
0
<?php

include '../Setup.php';
foreach (Database::$tables as $table) {
    $stmt = Database::prepareStatement("TRUNCATE {$table}");
    $stmt->execute();
}
?>
Tabelle svuotate correttamente