public function get_new_items($watch_owner) { global $dbh; $selector_object = $this->get_selected_selector(); if ($selector_object) { $selector_values = $selector_object->get_value(); $selector_values = $this->filter_datas($selector_values, $watch_owner); $items_datas = $this->get_items_datas($selector_values); $datasource_items = $this->fetch_datasource_items(); for ($i = 0; $i < count($items_datas); $i++) { $item = new docwatch_item(); if ($this->default_interesting) { $item->set_interesting(1); } $item->set_type($items_datas[$i]['type']); if ($this->clean_html) { $item->set_title(strip_tags($items_datas[$i]['title'])); $item->set_summary(strip_tags($items_datas[$i]['summary'])); $item->set_content(strip_tags($items_datas[$i]['content'])); } else { $item->set_title($items_datas[$i]['title']); $item->set_summary($items_datas[$i]['summary']); $item->set_content($items_datas[$i]['content']); } $item->set_publication_date($items_datas[$i]['publication_date']); $item->set_url($items_datas[$i]['url']); $item->set_logo_url($items_datas[$i]['logo_url']); $item->set_num_notice($items_datas[$i]['num_notice']); $item->set_source_id($this->id); $item->set_num_watch($this->num_watch); $item->set_num_article($items_datas[$i]['num_article']); $item->set_num_section($items_datas[$i]['num_section']); $item->gen_hash(); if (!in_array($item->get_hash(), $datasource_items)) { $query_hash = "select id_item from docwatch_items where item_hash = '" . $item->get_hash() . "'"; $resultat = pmb_mysql_query($query_hash, $dbh); if (!pmb_mysql_num_rows($resultat)) { $item->save(); } } else { $key = array_search($item->get_hash(), $datasource_items); unset($datasource_items[$key]); } } //Il y'a des items a supprimer de la table (ils ne sont plus dans le flux) if (count($datasource_items)) { foreach ($datasource_items as $key => $value) { $item = new docwatch_item($key); //On peut supprimer directement if ($item->get_status > 1) { $item->delete(); } else { //Check le ttl $query = "select docwatch_items.id_item from docwatch_items join docwatch_watches on docwatch_watches.id_watch=" . $this->num_watch . " where id_item = '" . $item->get_id() . "' and date_add(docwatch_items.item_added_date, interval docwatch_watches.watch_ttl hour) < now()"; $result = pmb_mysql_query($query, $dbh); if ($result) { $item->delete(); } } } } } }