id+= $id; $this->fetch_datas(); } // end of member function __construct /* * Getters & setters */ public function get_id(){ return $this->id; } public function set_id($id){ $this->id = $id; } public function get_title(){ return $this->title; } public function set_title($title){ $this->title = $title; } public function get_added_date(){ return $this->added_date; } public function set_added_date($added_date){ $this->added_date = $added_date; } public function get_publication_date(){ return $this->publication_date; } public function set_publication_date($publication_date){ $this->publication_date = $publication_date; } public function get_source_id(){ return $this->source_id; } public function set_source_id($source_id){ $this->source_id = $source_id; } public function get_source() { return $this->source; } public function get_watch() { return $this->watch; } public function get_hash(){ return $this->hash; } public function set_hash($hash){ //$this->hash = $this->gen_hash(); ? } public function get_summary(){ return $this->summary; } public function set_summary($summary){ $this->summary = $summary; } public function get_content(){ return $this->content; } public function set_content($content){ $this->content = $content; } public function get_url(){ return $this->url; } public function set_url($url){ $this->url = $url; } public function get_logo_url(){ return $this->logo_url; } public function set_logo_url($logo_url){ $this->logo_url = $logo_url; } public function get_descriptors(){ return $this->descriptors; } public function set_descriptors($descriptors){ $this->descriptors = $descriptors; } public function get_concepts(){ return $this->concepts; } public function set_concepts($concepts){ $this->concepts = $concepts; } public function get_tags(){ return $this->tags; } public function set_tags($tags){ $this->tags = $tags; } public function get_status(){ return $this->status; } public function set_status($status){ $this->status = $status; } public function get_interesting(){ return $this->interesting; } public function set_interesting($interesting){ $this->interesting = $interesting; } public function get_type(){ return $this->type; } public function set_type($type){ $this->type = $type; } public function get_num_article(){ return $this->num_article; } public function set_num_article($num_article){ $this->num_article = $num_article; } public function get_num_notice(){ return $this->num_notice; } public function set_num_notice($num_notice){ $this->num_notice = $num_notice; } public function get_num_section(){ return $this->num_section; } public function set_num_section($num_section){ $this->num_section = $num_section; } public function get_num_watch() { return $this->num_watch; } public function set_num_watch($num_watch) { $this->num_watch = $num_watch; } public function get_descriptors_isbd() { return $this->descriptors_isbd; } public function get_concepts_isbd() { return $this->concepts_isbd; } public function get_tags_isbd() { return $this->tags_isbd; } public function create_notice() { global $dbh; global $pmb_keyword_sep; $fields=" tit1='".addslashes($this->title)."', n_resume='".addslashes($this->summary)."', lien='".addslashes($this->url)."', thumbnail_url='".addslashes($this->logo_url)."', date_parution='".addslashes($this->publication_date)."', index_l='".addslashes(implode($pmb_keyword_sep,$this->tags))."' "; $req="INSERT INTO notices SET $fields "; pmb_mysql_query($req, $dbh); $num_notice=pmb_mysql_insert_id(); if(!$num_notice) return array(); $query.= "update docwatch_items set item_num_notice = '".$num_notice."' where id_item = '".$this->id."'"; pmb_mysql_query($query, $dbh); // Mise à jour de tous les index de la notice notice::majNoticesTotal($num_notice); return array('id'=>$num_notice, 'title'=> $this->title,'link'=>"./catalog.php?categ=isbd&id=".$num_notice); } public function create_section($section_num_parent=0) { global $dbh; global $pmb_keyword_sep; $section = new cms_section(); $section->id = 0; $section->num_type = 0; // ? $section->num_parent = 0; // ? $section->title = $this->title; $section->resume = $this->summary; $section->start_date = $this->publication_date; $section->publication_state = 0; // ? $descriptors = array(); if(count($this->descriptors)) { foreach($this->descriptors as $descriptor){ $descriptors[] = $descriptor['id']; } } $section->set_descriptors($descriptors); //$section->logo->id ? $section->save(); if(!$section->id) return array(); $query.= "update docwatch_items set item_num_section = '".$section->id."' where id_item = '".$this->id."'"; pmb_mysql_query($query, $dbh); return array('id'=>$section->id, 'title'=> $this->title,'link'=>""); } public function create_article($section_num_parent=0) { global $dbh; global $pmb_keyword_sep; $article = new cms_article(); $article->id = 0; $article->num_type = 0; // ? $article->num_parent = 0; // ? $article->title = $this->title; $article->resume = $this->summary; $article->contenu = $this->content; $article->start_date = $this->publication_date; $article->publication_state = 0; // ? $descriptors = array(); if(count($this->descriptors)) { foreach($this->descriptors as $descriptor){ $descriptors[] = $descriptor['id']; } } $article->set_descriptors($descriptors); //$article->logo->id ? $article->save(); if(!$article->id) return array(); $query.= "update docwatch_items set item_num_article = '".$article->id."' where id_item = '".$this->id."'"; pmb_mysql_query($query, $dbh); return array('id'=>$article->id, 'title'=> $this->title,'link'=>""); } /** * Méthode permettant d'initialiser un item * * @return void * @access public */ public function fetch_datas(){ global $dbh; $this->title = ""; $this->added_date = "0000-00-00 00:00:00"; $this->publication_date = "0000-00-00 00:00:00"; $this->source_id = 0; $this->hash = ""; $this->summary = ""; $this->content = ""; $this->url = ""; $this->logo_url = ""; $this->descriptors = array(); $this->concepts = array(); $this->tags = array(); $this->status = 0; $this->interesting = 0; $this->type = ""; $this->num_notice = 0; $this->num_article = 0; $this->num_section = 0; $this->num_watch = 0; $this->tags_isbd=""; $this->descriptors_isbd=""; if($this->id){ $query = "select * from docwatch_items where id_item = '".$this->id."'"; $result = pmb_mysql_query($query, $dbh); if (pmb_mysql_num_rows($result)) { $row = pmb_mysql_fetch_object($result); $this->title = $row->item_title; $this->added_date = $row->item_added_date; $this->publication_date = $row->item_publication_date; $this->source_id = $row->item_num_datasource; $this->hash = $row->item_hash; $this->summary = $row->item_summary; $this->content = $row->item_content; $this->url = $row->item_url; if($row->item_logo_url) $this->logo_url = $row->item_logo_url; else $this->logo_url = ""; $this->status = $row->item_status; $this->interesting = $row->item_interesting; $this->type = $row->item_type; $this->num_notice = $row->item_num_notice; $this->num_article = $row->item_num_article; $this->num_section = $row->item_num_section; $this->num_watch = $row->item_num_watch; $this->tags = array(); $query = "select docwatch_items_tags.num_tag, docwatch_tags.tag_title from docwatch_items_tags join docwatch_tags on docwatch_items_tags.num_tag = docwatch_tags.id_tag where docwatch_items_tags.num_item = '".$this->id."'"; $result = pmb_mysql_query($query, $dbh); if (pmb_mysql_num_rows($result)) { while($row=pmb_mysql_fetch_object($result)){ $this->tags[] = array( "id" => $row->num_tag, "label" => $row->tag_title ); if($this->tags_isbd)$this->tags_isbd.="; "; $this->tags_isbd.= $row->tag_title; } } $this->descriptors = array(); $query = "select docwatch_items_descriptors.num_noeud, categories.libelle_categorie from docwatch_items_descriptors join categories on docwatch_items_descriptors.num_noeud = categories.num_noeud where docwatch_items_descriptors.num_item ='".$this->id."'"; $result = pmb_mysql_query($query, $dbh); if (pmb_mysql_num_rows($result)) { while($row=pmb_mysql_fetch_object($result)){ $this->descriptors[] = array( "id" => $row->num_noeud, "label" => $row->libelle_categorie ); if($this->descriptors_isbd)$this->descriptors_isbd.="; "; $this->descriptors_isbd.= $row->libelle_categorie; } } $this->concepts = array(); $query = "select num_concept from index_concept where index_concept.num_object ='".$this->id."' and type_object = '".TYPE_DOCWATCH."'"; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result)) { while($row=pmb_mysql_fetch_object($result)){ $label = index_concept::get_concept_label_from_id($row->num_concept); $this->concepts[] = array( "id" => $row->num_concept, "label" => $label ); if($this->concepts_isbd)$this->concepts_isbd.="; "; $this->concepts_isbd.= $label; } } $query = "select datasource_title from docwatch_datasources where id_datasource ='".$this->source_id."'"; $result = pmb_mysql_query($query, $dbh); if (pmb_mysql_num_rows($result)) { if($row=pmb_mysql_fetch_object($result)){ $this->source = array( "title" => $row->datasource_title ); } } $query = "select id_watch,watch_title,watch_last_date, watch_desc, watch_logo_url from docwatch_watches where id_watch ='".$this->num_watch."'"; $result = pmb_mysql_query($query, $dbh); if (pmb_mysql_num_rows($result)) { if($row=pmb_mysql_fetch_object($result)){ $this->watch = array( "id" => $row->id_watch, "title" => $row->watch_title, "last_date" => $row->watch_last_date, "desc" => $row->watch_desc, "logo_url" => $row->watch_logo_url ); } } } } } /** * Calcul du hash * * @return string * @access public */ public function gen_hash() { $this->hash = md5($this->num_watch."_".$this->source_id."_".$this->url); } // end of member function gen_hash /** * Fonction de sauvegarde d'un item * @return boolean */ public function save(){ global $dbh; $query = ""; $clause = ""; $date = ""; if(!$this->id){ $query .= "insert into "; }else{ $query.= "update "; $clause.= " where id_item = '".$this->id."'"; } $query.= "docwatch_items set item_type = '".addslashes($this->type)."', item_title = '".addslashes($this->title)."', item_summary = '".addslashes($this->summary)."', item_content = '".addslashes($this->content)."', item_added_date = now(), item_publication_date = '".$this->publication_date."', item_hash = '".addslashes($this->hash)."', item_url = '".addslashes($this->url)."', item_logo_url = '".addslashes($this->logo_url)."', item_status = '".$this->status."', item_interesting = '".$this->interesting."', item_num_article = '".$this->num_article."', item_num_section = '".$this->num_section."', item_num_notice = '".$this->num_notice."', item_num_datasource = '".$this->source_id."', item_num_watch = '".$this->num_watch."'"; $query.=$clause; if(!pmb_mysql_query($query, $dbh)){ return false; }else{ if(!$this->id) $this->id = pmb_mysql_insert_id(); return true; } } public function delete(){ global $dbh; $query = "delete from docwatch_items where id_item = '".$this->id."' "; if(pmb_mysql_query($query, $dbh)){ $query = "delete from docwatch_items_tags where num_item = '".$this->id."'"; if(!pmb_mysql_query($query, $dbh)){ return false; } $query = "delete from docwatch_tags where id_tag not in (select num_tag from docwatch_items_tags)"; if(!pmb_mysql_query($query, $dbh)){ return false; } $query = "delete from docwatch_items_descriptors where num_item = '".$this->id."' "; if(!pmb_mysql_query($query, $dbh)){ return false; } }else{ return false; } return true; } public function index($data){ global $dbh; $query = "delete from docwatch_items_descriptors where num_item = '".$this->id."' "; if(!pmb_mysql_query($query, $dbh)){ return false; } if(count($data["descriptors"])) { foreach($data["descriptors"] as $id){ $query = "insert into docwatch_items_descriptors set num_noeud='".$id."', num_item = '".$this->id."' "; pmb_mysql_query($query, $dbh); } } $query = "delete from docwatch_items_tags where num_item = '".$this->id."' "; if(!pmb_mysql_query($query, $dbh)){ return false; } if(count($data["tags"])) { foreach($data["tags"] as $label){ if($charset != 'utf-8'){ $label=utf8_decode($label); } $query = "select id_tag from docwatch_tags where tag_title = '".addslashes($label)."'"; $result = pmb_mysql_query($query, $dbh); if (!pmb_mysql_num_rows($result)) { $query = "insert into docwatch_tags set tag_title = '".addslashes($label)."'"; pmb_mysql_query($query, $dbh); $num_tag = pmb_mysql_insert_id(); }else{ $row=pmb_mysql_fetch_object($result); $num_tag=$row->id_tag; } $query = "insert into docwatch_items_tags set num_tag='".$num_tag."', num_item = '".$this->id."' "; pmb_mysql_query($query, $dbh); } } $this->fetch_datas(); return true; } public function mark_as_deleted(){ global $dbh; $query = "update docwatch_items set item_status = '2' where id_item = '".$this->id."' "; if(pmb_mysql_query($query, $dbh)){ return true; }else{ return false; } } public function mark_as_purged(){ if(docwatch_watch::check_watch_rights($this->num_watch)){ $query = "update docwatch_items set item_status = '3' where id_item = '".$this->id."' "; if(pmb_mysql_query($query)){ return true; }else{ return false; } } } public function get_normalized_item(){ return array( "id"=>$this->id, "type"=>$this->type, "title"=>$this->title, "content"=>$this->content, "summary"=>$this->summary, "hash"=>$this->hash, "url"=>$this->url, "logo_url"=>$this->logo_url, "status"=>$this->status, "num_article"=>$this->num_article, "num_section"=>$this->num_section, "num_notice"=>$this->num_notice, "num_datasource"=>$this->source_id, "source"=>$this->source, "datasource_title"=>$this->source["title"], "num_watch"=>$this->num_watch, "watch"=>$this->watch, "publication_date"=>formatdate($this->publication_date,1), "formated_publication_date"=>date("c",strtotime($this->publication_date)), "interesting"=>$this->interesting, "descriptors_isbd"=>$this->descriptors_isbd, "tags_isbd"=>$this->tags_isbd, "descriptors"=>$this->descriptors, "tags"=>$this->tags ); } } // end of docwatch_item