From 40d0619f10f5f73a79bb303b78bf443b18e7cee8 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 15 Oct 2015 08:06:01 -0400 Subject: [PATCH] Override Podcast->fromArray --- .../application/models/airtime/Podcast.php | 28 +++++++++++++++++-- .../application/services/PodcastService.php | 16 +++-------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/airtime_mvc/application/models/airtime/Podcast.php b/airtime_mvc/application/models/airtime/Podcast.php index d74690ece..9d201e8c4 100644 --- a/airtime_mvc/application/models/airtime/Podcast.php +++ b/airtime_mvc/application/models/airtime/Podcast.php @@ -27,12 +27,12 @@ class Podcast extends BasePodcast */ public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) { - $podcastArray = parent::toArray(BasePeer::TYPE_FIELDNAME); + $podcastArray = parent::toArray($keyType); $importedPodcast = ImportedPodcastQuery::create()->filterByDbPodcastId($this->getDbId())->findOne(); $stationPodcast = StationPodcastQuery::create()->filterByDbPodcastId($this->getDbId())->findOne(); if (!is_null($importedPodcast)) { - $importedPodcastArray = $importedPodcast->toArray(BasePeer::TYPE_FIELDNAME); + $importedPodcastArray = $importedPodcast->toArray($keyType); //unset these values because we already have the podcast id in $podcastArray //and we don't need the imported podcast ID @@ -43,7 +43,7 @@ class Podcast extends BasePodcast } else if (!is_null($stationPodcast)) { // For now just return $podcastArray because StationPodcast objects do not have any - // extra fields we want to return right now. This may change in the future. + // extra fields we want to return. This may change in the future. return $podcastArray; } else { return $podcastArray; @@ -51,4 +51,26 @@ class Podcast extends BasePodcast } + /** + * Override this function so it updates the child class as well. + * Child class will either be ImportedPodcast or StationPodcast + * + * @param array $arr + * @param string $keyType + * @throws Exception + * @throws PropelException + */ + public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) + { + parent::fromArray($arr, $keyType); + + $importedPodcast = ImportedPodcastQuery::create()->filterByDbPodcastId($this->getDbId())->findOne(); + if (!is_null($importedPodcast)) { + $importedPodcast->fromArray($arr, $keyType); + $importedPodcast->save(); + } else { + //TODO: station podcast + } + } + } diff --git a/airtime_mvc/application/services/PodcastService.php b/airtime_mvc/application/services/PodcastService.php index 7308fbb19..dc6a0ce03 100644 --- a/airtime_mvc/application/services/PodcastService.php +++ b/airtime_mvc/application/services/PodcastService.php @@ -278,19 +278,11 @@ class Application_Service_PodcastService throw new PodcastNotFoundException(); } - self::removePrivateFields($data); - self::validatePodcastMetadata($data); + self::removePrivateFields($data["podcast"]); + self::validatePodcastMetadata($data["podcast"]); - $importedPodcast = ImportedPodcastQuery::create()->filterByDbPodcastId($podcast->getDbId())->findOne(); - if (!is_null($importedPodcast)) { - $importedPodcast->fromArray($data, BasePeer::TYPE_FIELDNAME); - $importedPodcast->save(); - } else { - //TODO: station podcast - } - - //$podcast->fromArray($data, BasePeer::TYPE_FIELDNAME); - //$podcast->save(); + $podcast->fromArray($data["podcast"], BasePeer::TYPE_FIELDNAME); + $podcast->save(); return $podcast->toArray(BasePeer::TYPE_FIELDNAME); }