public function testAdd_element()
 {
     $collection = new Bridge_Api_ContainerCollection();
     $i = 0;
     while ($i < 5) {
         $container = $this->getMock("Bridge_Api_ContainerInterface");
         $collection->add_element(new $container());
         $i++;
     }
     $this->assertEquals(5, sizeof($collection->get_elements()));
 }
 /**
  * @Todo recupérer la thumbnail d'une playlist
  *
  * @param  string                         $object
  * @param  int                            $offset_start
  * @param  int                            $quantity
  * @return Bridge_Api_ContainerCollection
  */
 public function list_containers($object, $offset_start = 0, $quantity = 10)
 {
     switch ($object) {
         case self::CONTAINER_TYPE_PLAYLIST:
             $username = $this->get_user_name();
             $params = ['fields' => ['description', 'id', 'name'], 'page' => !$offset_start ? 1 : $offset_start];
             //add quantity
             if (!!$quantity) {
                 $params["limit"] = $quantity;
             }
             $url = sprintf('/me/%ss', $object);
             $result = $this->_api->call($url, $params, $this->oauth_token);
             $container_collection = new Bridge_Api_ContainerCollection();
             $container_collection->set_items_per_page($result["limit"]);
             $total = sizeof($result["list"]);
             $current_page = $result["limit"];
             $total_page = null;
             $container_collection->set_total_items($total);
             $container_collection->set_current_page($current_page);
             $container_collection->set_total_page($total_page);
             foreach ($result['list'] as $entry) {
                 //get 1st image
                 $list_element = $this->list_containers_content($object, $entry['id'], ['thumbnail_medium_url'], 1);
                 $elements = $list_element->get_elements();
                 $first_element = array_shift($elements);
                 $thumbnail = $first_element instanceof Bridge_Api_Dailymotion_Element ? $first_element->get_thumbnail() : '';
                 $url = $this->get_url_playlist($entry['id'], $entry['name'], $username);
                 $container_collection->add_element(new Bridge_Api_Dailymotion_Container($entry, $object, $thumbnail, $url));
             }
             return $container_collection;
             break;
         default:
             throw new Bridge_Exception_ElementUnknown('Unknown element ' . $object);
             break;
     }
 }
Exemple #3
0
 /**
  *
  * @param  string                         $object
  * @param  int                            $offset_start
  * @param  int                            $quantity
  * @return Bridge_Api_ContainerCollection
  */
 public function list_containers($object, $offset_start = 0, $quantity = 10)
 {
     switch ($object) {
         case self::CONTAINER_TYPE_PLAYLIST:
             $playlist_feed = $this->get_user_object_list_feed($object, $offset_start, $quantity);
             $container_collection = new Bridge_Api_ContainerCollection();
             $container_collection->set_items_per_page($playlist_feed->getItemsPerPage()->getText());
             $total = $playlist_feed->getTotalResults()->getText();
             $current_page = floor((int) $playlist_feed->getStartIndex()->getText() / (int) $playlist_feed->getItemsPerPage()->getText());
             $total_page = ceil((int) $total / (int) $playlist_feed->getItemsPerPage()->getText());
             $container_collection->set_total_items($total);
             $container_collection->set_current_page($current_page);
             $container_collection->set_total_page($total_page);
             foreach ($playlist_feed as $entry) {
                 $playlist_video_feed = $this->_api->getPlaylistVideoFeed($entry->getPlaylistVideoFeedUrl());
                 $thumbnail = null;
                 if (!is_null($playlist_video_feed)) {
                     foreach ($playlist_video_feed as $entry2) {
                         $playlist_thumbnails = $entry2->getVideoThumbnails();
                         foreach ($playlist_thumbnails as $playlist_thumbnail) {
                             if (120 == $playlist_thumbnail['width'] && 90 == $playlist_thumbnail['height']) {
                                 $thumbnail = $playlist_thumbnail['url'];
                                 break;
                             }
                         }
                         break;
                     }
                 }
                 $container_collection->add_element(new Bridge_Api_Youtube_Container($entry, $object, $thumbnail));
             }
             return $container_collection;
             break;
         default:
             throw new Bridge_Exception_ElementUnknown('Unknown element ' . $object);
             break;
     }
 }
Exemple #4
0
 /**
  *
  * @param type $object
  * @param type $offset_start
  * @param type $quantity
  */
 public function list_containers($object, $offset_start = 0, $quantity = 10)
 {
     switch ($object) {
         case self::CONTAINER_TYPE_PHOTOSET:
             $params = [];
             if ($quantity) {
                 $params['per_page'] = $quantity;
             }
             $params['page'] = $quantity != 0 ? floor($offset_start / $quantity) + 1 : 1;
             $params['user_id'] = $user_id = $this->get_user_id();
             $response = $this->_api->executeMethod('flickr.photosets.getList', $params);
             if (!$response->isOk()) {
                 throw new Bridge_Exception_ApiConnectorRequestFailed('Unable to retrieve container list ' . $object);
             }
             $photosets = new Bridge_Api_ContainerCollection();
             $xml = $response->getXml();
             $photosets->set_current_page((int) $xml->photosets['page'])->set_items_per_page((int) $xml->photosets['perpage'])->set_total_items((int) $xml->photosets['total'])->set_total_page((int) $xml->photosets['pages']);
             foreach ($xml->photosets->children() as $child) {
                 $primary_photo = $this->get_element_from_id((string) $child['primary'], self::ELEMENT_TYPE_PHOTO);
                 $photosets->add_element(new Bridge_Api_Flickr_Container($child, $user_id, $object, $primary_photo->get_thumbnail()));
             }
             $photosets->set_total_items(count($photosets->get_elements()));
             return $photosets;
             break;
         default:
             throw new Bridge_Exception_ObjectUnknown('Unknown object ' . $object);
             break;
     }
 }