/** * This method takes the YouniversityPlaylist.id and a YoutubePlaylist object and inserts all of the associated images into the DB. * If an invalid (non-numeric or numeric less than one) YouniversityPlaylist.id is provided, returns false; otherwise, returns the number of successful inserts. * @param integer $youniversityPlaylistId * @param YoutubePlaylist $youtubePlaylistObject * @return false|integer * @see YoutubePlaylist::getAllThumbnails() * @see Model::query() */ public function saveImagesFromYoutubePlaylistObject($youniversityPlaylistId, YoutubePlaylist $youtubePlaylistObject) { $return = false; $youniversityPlaylistId = (int) $youniversityPlaylistId; if ($youniversityPlaylistId > 0) { // Validate "Youniversity Playlist ID" Parameter $return = 0; foreach ($youtubePlaylistObject->getAllThumbnails(true) as $currentThumbnailName => $currentThumbnailData) { // Loop through Thumbnails if (!empty($currentThumbnailData->url)) { // Verify Thumbnail Has URL $query = $this->query(sprintf('INSERT IGNORE INTO `youniversity_playlist_images` VALUES (NULL, %d, "%s", "%s", %d, %d) ON DUPLICATE KEY UPDATE `url` = VALUES(`url`), `width` = VALUES(`width`), `height` = VALUES(`height`)', $youniversityPlaylistId, strtoupper($currentThumbnailName), $currentThumbnailData->url, $currentThumbnailData->width, $currentThumbnailData->height)); if (is_array($query) || true === $query) { // Check Query Execution $return++; } // End of Check Query Execution } // End of Verify Thumbnail Has URL } // End of Loop through Thumbnails } // End of Validate "Youniversity Playlist ID" Parameter return $return; }