| gère un set contenant les notices contenues |--------->|
|--------------------------| | | dans des paniers de notices | |
| gère un cache de valeurs | | '---------------------------------------------' |
'--------------------------' | |
hérite de ^ | .---------------------------------------------. |
| | | connector_out_set_explcaddie | |
| | |---------------------------------------------| |
.-------------------------------. |-------------->| gère un set contenant les notices contenues |--------->|
| connector_out_setcache_notice | | | dans des paniers d'exemplaires | |
|-------------------------------| | '---------------------------------------------' |
| gère un cache d'une | | |
| liste de notices | | .------------------------------------------------. |
'-------------------------------' | | connector_out_set_emprcaddie | |
| |------------------------------------------------| |
|-------------->| gère un set contenant les emprunteurs contenus |------>|
| | dans des paniers d'emprunteurs | |
| '------------------------------------------------' |
| |
**************************************** | .---------------------------------------------------. |
* function:new_connector_out_set_typed * | | connector_out_set_noticemulticritere | |
**************************************** | |---------------------------------------------------| |
* instantie la bonne classe d'un *----------------------->| gère un set contenant les notices contenues |----'
* set selon son id * instantie au | dans les résultats d'une recherche multi-critères |
**************************************** choix '---------------------------------------------------'
|
.................................. |
. external_services_searchcache . |
.................................. |
. effectue des recherches et les .<-----'
. met en cache . utilise
..................................
====================================================================================================================================
*/
global $class_path, $include_path;
require_once ($class_path."/caddie.class.php");
require_once ($class_path."/empr_caddie.class.php");
require_once ($class_path."/search.class.php");
require_once ($class_path."/external_services_searchcache.class.php");
require_once ($class_path."/search_perso.class.php");
require_once ($class_path."/equation.class.php");
require_once($include_path."/connecteurs_out_common.inc.php");
$connector_out_set_types = array(
1, //Paniers de notices
2, //Recherche multi-critères de notices
3, //Paniers d'exemplaires
4 //Paniers de lecteurs
);
$connector_out_set_types_msgs = array(
1 => "connector_out_set_types_msg_1",
2 => "connector_out_set_types_msg_2",
3 => "connector_out_set_types_msg_3",
4 => "connector_out_set_types_msg_4"
);
$connector_out_set_types_classes = array(
1 => "connector_out_set_noticecaddie",
2 => "connector_out_set_noticemulticritere",
3 => "connector_out_set_explcaddie",
4 => "connector_out_set_emprcaddie"
);
class connector_out_set {
public $id=0;
public $caption="";
public $type=0;
public $config=array();
public $cache=NULL;
public $error="";
protected static $already_included_sets = array();
public function __construct($id=0, $nocache=false) {
//nocache permet de ne pas instancier le cache, si une classe fille veut le faire d'elle même
$id=intval($id);
$sql = "SELECT * FROM connectors_out_sets WHERE connector_out_set_id = ".$id;
$row = pmb_mysql_fetch_assoc(pmb_mysql_query($sql));
$this->id = $row["connector_out_set_id"];
$this->caption = $row["connector_out_set_caption"];
$this->type = $row["connector_out_set_type"];
$this->config = unserialize($row["connector_out_set_config"]);
$this->config = stripslashes_array($this->config);
if (!$nocache)
$this->cache = new connector_out_setcache($id);
}
public function get_form() {
global $msg, $charset;
global $connector_out_set_types, $connector_out_set_types_msgs, $out_of_form_result;
if($this->id) {
$config_form=array($this, 'get_config_form');
$cache_config_form=array($this->cache, 'get_config_form');
} else {
$config_form=NULL;
$cache_config_form=NULL;
}
//caption
$content_form = '
';
}
$interface_form = new interface_admin_form('form_outset');
if(!$this->id){
$interface_form->set_label($msg['admin_connecteurs_set_add']);
}else{
$interface_form->set_label($msg['admin_connecteurs_set_edit']);
}
$interface_form->set_object_id($this->id)
->set_confirm_delete_msg($msg['confirm_suppr_de']." ".$this->caption." ?")
->set_content_form($content_form)
->set_table_name('connectors_out_sets')
->set_field_focus('set_caption');
$display = $interface_form->get_display();
if (!empty($out_of_form_result)) {
//Formulaire caché à placer en dehors du formulaire principal
$display .= $out_of_form_result;
}
return $display;
}
public function set_properties_from_form() {
global $set_type, $set_caption;
$this->type = $set_type;
$this->caption = stripslashes($set_caption);
}
public function get_query_if_exists() {
return " SELECT count(1) FROM connectors_out_sets WHERE (connector_out_set_caption='".addslashes($this->caption)."' AND connector_out_set_id!='".$this->id."' )";
}
public static function caption_exists($caption) {
$sql = "SELECT connector_out_set_id FROM connectors_out_sets WHERE connector_out_set_caption = '".addslashes($caption)."'";
$res = pmb_mysql_query($sql);
return pmb_mysql_num_rows($res) > 0 ? pmb_mysql_result($res, 0, 0) : 0;
}
public static function add_new() {
$sql = "INSERT INTO connectors_out_sets () VALUES ()";
pmb_mysql_query($sql);
$new_set_id = pmb_mysql_insert_id();
$cache = connector_out_setcache::add($new_set_id);
return new connector_out_set($new_set_id);
}
public function commit_to_db() {
//on oublie pas que includes/global_vars.inc.php s'amuse à tout addslasher tout seul donc on le fait pas ici
$this->type+=0;
$this->config = addslashes_array($this->config);
$serialized = serialize($this->config);
$sql = "UPDATE connectors_out_sets SET connector_out_set_caption = '".addslashes($this->caption)."', connector_out_set_type = ".$this->type.", connector_out_set_config = '".addslashes($serialized)."' WHERE connector_out_set_id = ".$this->id."";
pmb_mysql_query($sql);
}
public static function check_data_from_form() {
global $set_caption;
if(empty($set_caption)) {
return false;
}
return true;
}
public static function delete($id) {
$id = intval($id);
if($id) {
//Deletons le set
$sql = "DELETE FROM connectors_out_sets WHERE connector_out_set_id = ".$id;
pmb_mysql_query($sql);
}
}
public function get_config_form(&$out_of_form_result) {
//$out_of_form_result: résultat à renvoyer qui devra être placé à l'extérieur du formulaire. Exemple: un autre formulaire.
//rien
return "";
}
public function update_config_from_form() {
//rien
return;
}
public function get_third_column_info() {
//rien
return "";
}
public function update_if_expired() {
if ($this->cache->is_cache_expired())
$this->update_cache();
}
public function update_cache() {
//rien
return "";
}
public function clear_cache($also_clear_date=false) {
$this->cache->clear($also_clear_date);
}
public function get_values($first=false, $count=false) {
return $this->cache->get_values($first, $count);
}
public function get_value_count() {
return $this->cache->get_value_count();
}
public static function set_already_included_sets($already_included_sets = array()) {
static::$already_included_sets = $already_included_sets;
}
public static function get_already_included_sets() {
return static::$already_included_sets;
}
}
//Set correspondant à des paniers de notices.
class connector_out_set_noticecaddie extends connector_out_set {
public function __construct($id) {
parent::__construct($id, true);
$this->cache = new connector_out_setcache_notice($id);
}
public function get_config_form(&$out_of_form_result) {
global $msg, $charset;
$config_form="";
$caddies=array();
$caddies_sql = "SELECT idcaddie FROM caddie WHERE type = 'NOTI'";
$caddies_res = pmb_mysql_query($caddies_sql);
while($row=pmb_mysql_fetch_assoc($caddies_res)) {
$acaddie = new caddie($row["idcaddie"]);
$caddies[] = $acaddie;
}
$config_form .= '
';
if (!isset($this->config["included_caddies"]))
$this->config["included_caddies"]=array();
if (!isset($this->config["include_full_base"]))
$this->config["include_full_base"] = false;
$config_form .= '
';
$config_form .= '';
$config_form .= '
';
return $config_form;
}
public function update_config_from_form() {
global $set_included_caddies, $set_includefullbase;
if (!is_array($set_included_caddies))
$set_included_caddies=array($set_included_caddies);
array_walk($set_included_caddies, function(&$a) {$a = intval($a);});//Soyons sûr de ne stocker que des entiers dans le tableau.
$this->config["included_caddies"] = !$this->config["include_full_base"] ? $set_included_caddies : array();
$this->config["include_full_base"] = isset($set_includefullbase);
return;
}
public function get_third_column_info() {
global $msg;
if (isset($this->config["include_full_base"]) && $this->config["include_full_base"])
return sprintf($msg["admin_connecteurs_set_noticecaddie_includedcount_fullbase"], $this->cache->get_value_count());
else
return sprintf($msg["admin_connecteurs_set_noticecaddie_includedcount"], count($this->config["included_caddies"]), $this->cache->get_value_count());
}
public function update_cache() {
//Valeurs par défault
if (!isset($this->config["included_caddies"]))
$this->config["included_caddies"]=array();
if (!isset($this->config["include_full_base"]))
$this->config["include_full_base"] = false;
//On remplit
if ($this->config["include_full_base"]) {
$sql = "SELECT ".$this->cache->id.", notice_id FROM notices";
}
else {
array_walk($this->config["included_caddies"], function(&$a) {$a = intval($a);});//Soyons sûr de ne stocker que des entiers dans le tableau.
$sql = "SELECT distinct ".$this->cache->id.", object_id FROM caddie_content WHERE caddie_id IN (".implode(",", $this->config["included_caddies"]).")";
}
$this->cache->updatedb_from_sqlselect($sql);
}
public static function get_notice_setlist($notice_id) {
$sql = "SELECT connectors_out_setcache_setnum FROM connectors_out_setcache_values LEFT JOIN connectors_out_setcaches ON (connectors_out_setcache_id =connectors_out_setcache_values_cachenum) WHERE connectors_out_setcache_values_value = ".$notice_id;
$res = pmb_mysql_query($sql);
$results = array();
while($row=pmb_mysql_fetch_assoc($res))
$results[] = $row["connectors_out_setcache_setnum"];
return $results;
}
public function get_values($first=false, $count=false, $datefrom=false, $dateuntil=false, $use_items_update_date=false) {
return $this->cache->get_values($first, $count, $datefrom, $dateuntil, $use_items_update_date);
}
public function get_value_count($datefrom=false, $dateuntil=false, $use_items_update_date=false) {
return $this->cache->get_value_count($datefrom, $dateuntil, $use_items_update_date);
}
//Fonction qui renvoie la date de modification la plus vieille (pour l'oai)
public function get_earliest_updatedate() {
return $this->cache->get_earliest_updatedate();
}
}
//Set correspondant à des paniers d'exemplaires.
class connector_out_set_noticemulticritere extends connector_out_set {
public function __construct($id) {
parent::__construct($id, true);
$this->cache = new connector_out_setcache_notice($id);
}
public function get_config_form(&$out_of_form_result) {
global $msg, $charset;
$config_form="";
if (!isset($this->config["search"]))
$this->config["search"] = "";
$serialized_search = $this->config["search"];
if ($serialized_search) {
$sc = new search(false);
$sc->unserialize_search($serialized_search);
$human_query = $sc->make_human_query();
}
else
$human_query = $msg["admin_connecteurs_set_multicritere_searchis_none"];
//Recherche humaine
$button_modif_requete = "";
$config_form .= '
';
//Form caché de la recherche
$form_modif_requete = $this->make_hidden_search_form($serialized_search);
//Mettons le dans $out_of_form_result comme ça il sera placé en dehors du formulaire
$out_of_form_result = $form_modif_requete;
return $config_form;
}
public function update_config_from_form() {
global $search_updateaction;
//Si on ne change rien, on ne change rien
if (!$search_updateaction || $search_updateaction == 'none')
return;
if (preg_match("/dsieq_(\d+)/", $search_updateaction, $m)) {
$dsi_eq_id = $m[1];
$equation = new equation($dsi_eq_id);
$this->config["search"] = $equation->requete;
$this->clear_cache(true);
}
return;
}
public function get_third_column_info() {
global $msg;
global $msg;
return sprintf($msg["admin_connecteurs_set_multicritere_includedcount"], $this->cache->get_value_count());
}
public function update_cache() {
if (!isset($this->config["search"]))
$this->config["search"] = "";
//On ne va pas chercher à effectuer une recherche vide
if (!$this->config["search"])
return;
//on marque le set comme en cours de rafraichissement
$query = "update connectors_out_sets set being_refreshed = 1 where connector_out_set_id = ".$this->id;
pmb_mysql_query($query);
//Utilisons la classe de caches de recherche pour effectuer la recherche.
$cache_duration = $this->cache->cache_duration_in_seconds();
$es_search_cache = new external_services_searchcache('search_fields', '', -1, -1, $cache_duration, 'conset', true);
$es_search_cache->unserialize_search($this->config["search"]);
$es_search_cache->update();
$values = $es_search_cache->get_results(0, $es_search_cache->get_result_count(false),'',false);
$this->cache->values = $values;
$this->cache->commit_values_into_db();
$this->cache->values = array();
//on marque le set comme en cours de rafraichissement
$query = "update connectors_out_sets set being_refreshed = 0 where connector_out_set_id = ".$this->id;
pmb_mysql_query($query);
}
public static function get_notice_setlist($notice_id) {
$sql = "SELECT connectors_out_setcache_setnum FROM connectors_out_setcache_values LEFT JOIN connectors_out_setcaches ON (connectors_out_setcache_id = connectors_out_setcache_values_cachenum) WHERE connectors_out_setcache_values_value = ".$notice_id;
$res = pmb_mysql_query($sql);
$results = array();
while($row=pmb_mysql_fetch_assoc($res))
$results[] = $row["connectors_out_setcache_setnum"];
return $results;
}
public function get_values($first=false, $count=false, $datefrom=false, $dateuntil=false, $use_items_update_date=false) {
return $this->cache->get_values($first, $count, $datefrom, $dateuntil, $use_items_update_date);
}
public function get_value_count($datefrom=false, $dateuntil=false, $use_items_update_date=false) {
return $this->cache->get_value_count($datefrom, $dateuntil, $use_items_update_date);
}
//Fonction qui renvoie la date de modification la plus vieille (pour l'oai)
public function get_earliest_updatedate() {
return $this->cache->get_earliest_updatedate();
}
//copié et adapté de equation.class.php
public function make_hidden_search_form($serialized_search) {
global $search;
global $charset;
global $page;
$url = "./catalog.php?categ=search&mode=6" ;
// remplir $search
$sc = new search(false);
$sc->unserialize_search($serialized_search);
$r="";
return $r;
}
}
//Set correspondant à des paniers d'exemplaires.
class connector_out_set_explcaddie extends connector_out_set {
public function get_config_form(&$out_of_form_result) {
global $msg, $charset;
$config_form="";
$caddies=array();
$caddies_sql = "SELECT idcaddie FROM caddie WHERE type = 'EXPL'";
$caddies_res = pmb_mysql_query($caddies_sql);
while($row=pmb_mysql_fetch_assoc($caddies_res)) {
$acaddie = new caddie($row["idcaddie"]);
$caddies[] = $acaddie;
}
$config_form .= '
';
if (!isset($this->config["included_caddies"]))
$this->config["included_caddies"]=array();
if (!isset($this->config["include_full_base"]))
$this->config["include_full_base"] = false;
$config_form .= '
';
$config_form .= '';
$config_form .= '
';
return $config_form;
}
public function update_config_from_form() {
global $set_included_caddies, $set_includefullbase;
if (!is_array($set_included_caddies))
$set_included_caddies=array($set_included_caddies);
array_walk($set_included_caddies, function(&$a) {$a = intval($a);});//Soyons sûr de ne stocker que des entiers dans le tableau.
$this->config["included_caddies"] = !$this->config["include_full_base"] ? $set_included_caddies : array();
$this->config["include_full_base"] = isset($set_includefullbase);
return;
}
public function get_third_column_info() {
global $msg;
if (isset($this->config["include_full_base"]) && $this->config["include_full_base"])
return sprintf($msg["admin_connecteurs_set_explcaddie_includedcount_fullbase"], $this->cache->get_value_count());
else
return sprintf($msg["admin_connecteurs_set_explcaddie_includedcount"], (is_array($this->config["included_caddies"]) ? count($this->config["included_caddies"]) : 0), $this->cache->get_value_count());
}
public function update_cache() {
//Valeurs par défault
if (!isset($this->config["included_caddies"]))
$this->config["included_caddies"]=array();
if (!isset($this->config["include_full_base"]))
$this->config["include_full_base"] = false;
//On remplit
if ($this->config["include_full_base"]) {
$sql = "SELECT ".$this->cache->id.", expl_id FROM exemplaires";
}
else {
array_walk($this->config["included_caddies"], function(&$a) {$a = intval($a);});//Soyons sûr de ne stocker que des entiers dans le tableau.
$sql = "SELECT distinct ".$this->cache->id.", object_id FROM caddie_content WHERE caddie_id IN (".implode(",", $this->config["included_caddies"]).")";
}
$this->cache->updatedb_from_sqlselect($sql);
}
}
//Set correspondant à des paniers d'emprunteurs.
class connector_out_set_emprcaddie extends connector_out_set {
public function get_config_form(&$out_of_form_result) {
global $msg, $charset;
$config_form="";
$caddies=array();
$caddies_sql = "SELECT idemprcaddie FROM empr_caddie";
$caddies_res = pmb_mysql_query($caddies_sql);
while($row=pmb_mysql_fetch_assoc($caddies_res)) {
$acaddie = new empr_caddie($row["idemprcaddie"]);
$caddies[] = $acaddie;
}
if (!isset($this->config["included_caddies"]))
$this->config["included_caddies"]=array();
$config_form .= '
';
$config_form .= '';
$config_form .= '
';
return $config_form;
}
public function update_config_from_form() {
global $set_included_caddies;
if (!is_array($set_included_caddies))
$set_included_caddies=array($set_included_caddies);
array_walk($set_included_caddies, function(&$a) {$a = intval($a);});//Soyons sûr de ne stocker que des entiers dans le tableau.
$this->config["included_caddies"] = $set_included_caddies;
return;
}
public function get_third_column_info() {
global $msg;
return sprintf($msg["admin_connecteurs_set_emprcaddie_includedcount"], (is_array($this->config["included_caddies"]) ? count($this->config["included_caddies"]) : 0), $this->cache->get_value_count());
}
public function update_cache() {
array_walk($this->config["included_caddies"], function(&$a) {$a = intval($a);});//Soyons sûr de ne stocker que des entiers dans le tableau.
$sql = "SELECT distinct ".$this->cache->id.", object_id FROM empr_caddie_content WHERE empr_caddie_id IN (".implode(",", $this->config["included_caddies"]).")";
$this->cache->updatedb_from_sqlselect($sql);
}
}
function class_connector_out_set_typed($id, $type=0) {
global $connector_out_set_types_classes;
if (!$type) {
$sql = "SELECT connector_out_set_type FROM connectors_out_sets WHERE connector_out_set_id = ".($id+0);
$type = pmb_mysql_result(pmb_mysql_query($sql), 0, 0);
}
if (!$type) $type=1;
return $connector_out_set_types_classes[$type];
}
function new_connector_out_set_typed($id, $type=0) {
$class = class_connector_out_set_typed($id, $type);
return new $class($id);
}
class connector_out_sets {
public $sets=array();
public function __construct() {
$sql = "SELECT connector_out_set_id, connector_out_set_type FROM connectors_out_sets ORDER BY connector_out_set_type";
$res = pmb_mysql_query($sql);
while ($row=pmb_mysql_fetch_assoc($res)) {
$aesuser = new_connector_out_set_typed($row["connector_out_set_id"], $row["connector_out_set_type"]);
$this->sets[] = clone $aesuser;
}
}
public static function get_typed_set_count($type) {
global $dbh;
$sql = "SELECT COUNT(1) FROM connectors_out_sets WHERE connector_out_set_type = ".($type+0);
$result = pmb_mysql_result(pmb_mysql_query($sql), 0, 0);
return $result;
}
}
/*
* Catégories
* */
class connector_out_setcateg {
public $id=0;
public $name="";
public $sets=array();
public function __construct($id) {
$this->id = intval($id);
//Main information
$sql = "SELECT * FROM connectors_out_setcategs WHERE connectors_out_setcateg_id = ".$this->id;
$res = pmb_mysql_query($sql);
$row = pmb_mysql_fetch_assoc($res);
$this->name = $row["connectors_out_setcateg_name"];
//Categ content
$sql = "SELECT connectors_out_setcategset_setnum FROM connectors_out_setcateg_sets WHERE connectors_out_setcategset_categnum = ".$this->id;
$res=pmb_mysql_query($sql);
while($row=pmb_mysql_fetch_assoc($res)) {
$this->sets[] = $row["connectors_out_setcategset_setnum"];
}
}
public function get_form() {
global $msg;
global $charset;
//name
$content_form = '
';
$interface_form = new interface_admin_form('form_outsetcateg');
if(!$this->id){
$interface_form->set_label($msg['admin_connecteurs_setcateg_add']);
}else{
$interface_form->set_label($msg['admin_connecteurs_setcateg_edit']);
}
$interface_form->set_object_id($this->id)
->set_confirm_delete_msg($msg['confirm_suppr_de']." ".$this->name." ?")
->set_content_form($content_form)
->set_table_name('connectors_out_setcategs')
->set_field_focus('setcateg_name');
return $interface_form->get_display();
}
public function set_properties_from_form() {
global $setcateg_name, $setcateg_sets;
$this->name = stripslashes($setcateg_name);
$this->sets = $setcateg_sets;
}
public function get_query_if_exists() {
return " SELECT count(1) FROM connectors_out_setcategs WHERE (connectors_out_setcateg_name='".addslashes($this->name)."' AND connectors_out_setcateg_id!='".$this->id."' )";
}
public function save() {
if ($this->id == 0) {
$sql = "INSERT INTO connectors_out_setcategs (connectors_out_setcateg_name) VALUES ('".addslashes($this->name)."')";
pmb_mysql_query($sql);
$this->id = pmb_mysql_insert_id();
} else {
$sql = "UPDATE connectors_out_setcategs SET connectors_out_setcateg_name = '".addslashes($this->name)."' WHERE connectors_out_setcateg_id = ".$this->id."";
pmb_mysql_query($sql);
}
//Vidage de la catégorie
$sql = "DELETE FROM connectors_out_setcateg_sets WHERE connectors_out_setcategset_categnum = ".$this->id;
pmb_mysql_query($sql);
//Remplissage de la catégorie
if (count($this->sets)) {
$sql = "INSERT INTO connectors_out_setcateg_sets (connectors_out_setcategset_setnum ,connectors_out_setcategset_categnum) VALUES ";
$values=array();
foreach ($this->sets as $asetid) {
$asetid+=0;//Conversion en int.
if (!$asetid) continue;
$values[] = '('.$asetid.', '.$this->id.')';
}
$sql .= implode(",", $values);
pmb_mysql_query($sql);
}
}
public static function add_new() {
$sql = "INSERT INTO connectors_out_setcategs () VALUES ()";
pmb_mysql_query($sql);
$new_setcateg_id = pmb_mysql_insert_id();
return new connector_out_setcateg($new_setcateg_id);
}
public static function check_data_from_form() {
global $setcateg_name;
if(empty($setcateg_name)) {
return false;
}
return true;
}
public static function delete($id) {
$id = intval($id);
if($id) {
//Deletons l'user
$sql = "DELETE FROM connectors_out_setcategs WHERE connectors_out_setcateg_id = ".$id;
pmb_mysql_query($sql);
//Vidons la catégorie
$sql = "DELETE FROM connectors_out_setcateg_sets WHERE connectors_out_setcategset_categnum = ".$id;
pmb_mysql_query($sql);
}
}
}
class connector_out_setcategs {
public $categs=array();
public function __construct() {
$sql = "SELECT connectors_out_setcateg_id FROM connectors_out_setcategs";
$res = pmb_mysql_query($sql);
while ($row=pmb_mysql_fetch_assoc($res)) {
$acateg = new connector_out_setcateg($row["connectors_out_setcateg_id"]);
$this->categs[] = clone $acateg;
}
}
}
/*
* Cache
* */
class connector_out_setcache {
public $id=0;
public $set_id=0;
public $last_updated_date='';
public $life_lifeduration=0;
public $life_lifeduration_unit='';
public $values=array();
public function __construct($set_id) {
$set_id=intval($set_id);
//Main information
$sql = "SELECT * FROM connectors_out_setcaches WHERE connectors_out_setcache_setnum=".$set_id;
$res = pmb_mysql_query($sql);
$row = pmb_mysql_fetch_assoc($res);
$this->id = $row["connectors_out_setcache_id"];
$this->set_id = $set_id;
$this->last_updated_date = $row["connectors_out_setcache_lastupdatedate"];
$this->life_lifeduration = $row["connectors_out_setcache_lifeduration"];
$this->life_lifeduration_unit = $row["connectors_out_setcache_lifeduration_unit"];
}
public static function add($set_id) {
$sql = "INSERT INTO connectors_out_setcaches (connectors_out_setcache_setnum) VALUES (".$set_id.")";
pmb_mysql_query($sql);
$new_row_id = pmb_mysql_insert_id();
return new connector_out_setcache($set_id);
}
public function delete() {
//Deletons le cache
$sql = "DELETE FROM connectors_out_setcaches WHERE connectors_out_setcache_id = ".$this->id;
pmb_mysql_query($sql);
//Vidons le cache
$sql = "DELETE FROM connectors_out_setcache_values WHERE connectors_out_setcache_values_cachenum = ".$this->id;
pmb_mysql_query($sql);
}
public function clear($also_clear_date=false) {
//Vidons le cache
$sql = "DELETE FROM connectors_out_setcache_values WHERE connectors_out_setcache_values_cachenum = ".$this->id;
pmb_mysql_query($sql);
if ($also_clear_date) {
$sql = "UPDATE connectors_out_setcaches SET connectors_out_setcache_lastupdatedate = '0000-00-00 00:00:00' WHERE connectors_out_setcache_id = ".$this->id;
pmb_mysql_query($sql);
}
}
public function get_values($first=false, $count=false) {
if ($this->values) {
return $this->values;
}
//Values
if ($first !== false && $count !== false)
$limit = "LIMIT ".$first.", ".$count;
else
$limit = "";
$sql = "SELECT connectors_out_setcache_values_value FROM connectors_out_setcache_values WHERE connectors_out_setcache_values_cachenum = ".$this->id." ".$limit;
$res = pmb_mysql_query($sql);
while($row=pmb_mysql_fetch_assoc($res)) {
$this->values[] = $row["connectors_out_setcache_values_value"];
}
return $this->values;
}
public function get_value_count() {
$sql = "SELECT count(1) FROM connectors_out_setcache_values WHERE connectors_out_setcache_values_cachenum = ".$this->id;
if (count(connector_out_set::get_already_included_sets())) {
$sql.= " and connectors_out_setcache_values_value not in (select connectors_out_setcache_values_value from connectors_out_setcache_values where connectors_out_setcache_values_cachenum in (".implode(",", connector_out_set::get_already_included_sets())."))";
}
return pmb_mysql_result(pmb_mysql_query($sql), 0, 0);
}
public function commit_to_db($also_commit_values=false) {
$sql = "UPDATE connectors_out_setcaches SET connectors_out_setcache_lifeduration = ".$this->life_lifeduration.", connectors_out_setcache_lastupdatedate = '".$this->last_updated_date."', connectors_out_setcache_lifeduration_unit = '".$this->life_lifeduration_unit."' WHERE connectors_out_setcache_id = ".$this->id;
pmb_mysql_query($sql);
}
public function commit_values_into_db() {
//On stocke l'état actuel dans une table temporaire
$temporary_table = "tmp_connectors_out_setcache_values_".$this->id;
$query = "create temporary table ".$temporary_table." engine myisam select connectors_out_setcache_values_value from connectors_out_setcache_values where connectors_out_setcache_values_cachenum = ".$this->id;
pmb_mysql_query($query);
//On vide
$sql = "DELETE FROM connectors_out_setcache_values WHERE connectors_out_setcache_values_cachenum = ".$this->id;
pmb_mysql_query($sql);
//Et on remplit
//Des fois qu'il y en ait beaucoup on va pas tout mysqler d'un coup. Faisons des paquets de 100.
$davalues = array_chunk($this->values, 100);
foreach ($davalues as $some_values) {
$sql = "INSERT INTO connectors_out_setcache_values (connectors_out_setcache_values_cachenum, connectors_out_setcache_values_value) VALUES ";
$values=array();
foreach ($some_values as $avalue) {
if (!$avalue) continue;
$values[] = '('.$this->id.', '.$avalue.')';
}
$sql .= implode(",", $values);
pmb_mysql_query($sql);
}
$this->update_deleted_records($temporary_table);
//On met à jour la date
$sql = "UPDATE connectors_out_setcaches SET connectors_out_setcache_lastupdatedate = NOW() WHERE connectors_out_setcache_id = ".$this->id;
pmb_mysql_query($sql);
}
public function updatedb_from_sqlselect($sql_select) {
//on marque le set comme en cours de rafraississement
$query = "update connectors_out_sets set being_refreshed = 1 where connector_out_set_id = ".$this->id;
pmb_mysql_query($query);
//On vide
$sql = "DELETE FROM connectors_out_setcache_values WHERE connectors_out_setcache_values_cachenum = ".$this->id;
pmb_mysql_query($sql);
$sql = "INSERT INTO connectors_out_setcache_values (connectors_out_setcache_values_cachenum, connectors_out_setcache_values_value) ".$sql_select;
pmb_mysql_query($sql);
//On met à jour la date
$sql = "UPDATE connectors_out_setcaches SET connectors_out_setcache_lastupdatedate = NOW() WHERE connectors_out_setcache_id = ".$this->id;
pmb_mysql_query($sql);
//rafraississement terminé, on retire le marqueur
$query = "update connectors_out_sets set being_refreshed = 0 where connector_out_set_id = ".$this->id;
pmb_mysql_query($query);
//Et on vide le cache actuel
$this->values = array();
}
public function get_config_form() {
global $msg, $charset;
$this->life_lifeduration+=0;
$config_form = '';
$config_form .= '