浏览代码

[OpenClassroomsBridge] add getURI() + code simplification

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
Pierre Mazière 7 年之前
父节点
当前提交
41dfc57103
共有 1 个文件被更改,包括 8 次插入10 次删除
  1. 8 10
      bridges/OpenClassroomsBridge.php

+ 8 - 10
bridges/OpenClassroomsBridge.php

@@ -10,6 +10,7 @@ class OpenClassroomsBridge extends BridgeAbstract{
         'u'=>array(
             'name'=>'Catégorie',
             'type'=>'list',
+            'required'=>true,
             'values'=>array(
                 'Arts & Culture'=>'arts',
                 'Code'=>'code',
@@ -24,21 +25,18 @@ class OpenClassroomsBridge extends BridgeAbstract{
         )
     ));
 
+    public function getURI(){
+      return $this->uri.'/courses?categories='.$this->getInput('u').'&'
+        .'title=&sort=updatedAt+desc';
+    }
 
     public function collectData(){
-        if (empty($this->getInput('u')))
-        {
-            $this->returnServerError('Error: You must chose a category.');
-        }
-
-        $html = '';
-        $link = 'https://openclassrooms.com/courses?categories='.$this->getInput('u').'&title=&sort=updatedAt+desc';
-
-        $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request OpenClassrooms.');
+        $html = $this->getSimpleHTMLDOM($this->getURI())
+          or $this->returnServerError('Could not request OpenClassrooms.');
 
         foreach($html->find('.courseListItem') as $element) {
                 $item = array();
-                $item['uri'] = 'https://openclassrooms.com'.$element->find('a', 0)->href;
+                $item['uri'] = $this->uri.$element->find('a', 0)->href;
                 $item['title'] = $element->find('h3', 0)->plaintext;
                 $item['content'] = $element->find('slidingItem__descriptionContent', 0)->plaintext;
                 $this->items[] = $item;