[SensCritiqueBridge] code simplification

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-29 22:53:38 +02:00
parent aed7815f05
commit 82b150baa8

View file

@ -3,7 +3,7 @@ class SensCritiqueBridge extends BridgeAbstract {
public $maintainer = "kranack"; public $maintainer = "kranack";
public $name = "Sens Critique"; public $name = "Sens Critique";
public $uri = "http://www.senscritique.com"; public $uri = "http://www.senscritique.com/";
public $description = "Sens Critique news"; public $description = "Sens Critique news";
public $parameters = array( array( public $parameters = array( array(
@ -34,71 +34,27 @@ class SensCritiqueBridge extends BridgeAbstract {
)); ));
public function collectData(){ public function collectData(){
if (($this->getInput('m') && $this->getInput('m'))) { $categories=array();
$this->collectMoviesData(); foreach($this->parameters[$this->queriedContext] as $category=>$properties){
} else if (($this->getInput('s') && $this->getInput('s'))) { if($this->getInput($category)){
$this->collectSeriesData(); $uri=$this->uri;
} else if (($this->getInput('g') && $this->getInput('g'))) { switch($category){
$this->collectGamesData(); case 'm': $uri.='films/cette-semaine'; break;
} else if (($this->getInput('b') && $this->getInput('b'))) { case 's': $uri.='series/actualite'; break;
$this->collectBooksData(); case 'g': $uri.='jeuxvideo/actualite'; break;
} else if (($this->getInput('bd') && $this->getInput('bd'))) { case 'b': $uri.='livres/actualite'; break;
$this->collectBDsData(); case 'bd': $uri.='bd/actualite'; break;
} else if (($this->getInput('mu') && $this->getInput('mu'))) { case 'mu': $uri.='musique/actualite'; break;
$this->collectMusicsData(); }
} else { $html = $this->getSimpleHTMLDOM($uri)
$this->returnClientError('You must choose a category'); or $this->returnServerError('No results for this query.');
} $list = $html->find('ul.elpr-list', 0);
$this->extractDataFromList($list);
}
}
} }
private function collectMoviesData() {
$html = '';
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/films/cette-semaine') or $this->returnServerError('No results for this query.');
$list = $html->find('ul.elpr-list', 0);
$this->extractDataFromList($list);
}
private function collectSeriesData() {
$html = '';
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/series/actualite') or $this->returnServerError('No results for this query.');
$list = $html->find('ul.elpr-list', 0);
$this->extractDataFromList($list);
}
private function collectGamesData() {
$html = '';
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/jeuxvideo/actualite') or $this->returnServerError('No results for this query.');
$list = $html->find('ul.elpr-list', 0);
$this->extractDataFromList($list);
}
private function collectBooksData() {
$html = '';
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/livres/actualite') or $this->returnServerError('No results for this query.');
$list = $html->find('ul.elpr-list', 0);
$this->extractDataFromList($list);
}
private function collectBDsData() {
$html = '';
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/bd/actualite') or $this->returnServerError('No results for this query.');
$list = $html->find('ul.elpr-list', 0);
$this->extractDataFromList($list);
}
private function collectMusicsData() {
$html = '';
$html = $this->getSimpleHTMLDOM('http://www.senscritique.com/musique/actualite') or $this->returnServerError('No results for this query.');
$list = $html->find('ul.elpr-list', 0);
$this->extractDataFromList($list);
}
private function extractDataFromList($list) { private function extractDataFromList($list) {
if ($list === null) { if ($list === null) {
$this->returnClientError('Cannot extract data from list'); $this->returnClientError('Cannot extract data from list');