public function createStream($channel, $firstUpdate) { $db = new Database(); /** @var TwitterEntity $result */ $result = $this->getStreamByChannel($channel); if ($result) { //Si existe deja, et nouvelle date plus ancienne, alors on modifie le firstUpdate a la nouvelle date donnee if (strtotime($firstUpdate) < strtotime($result->getFirstUpdate())) { $db->execute('UPDATE stream_twitter SET firstUpdate = ? WHERE channel = ?', array(date(Database::DATE_FORMAT, strtotime($firstUpdate)), $channel)); } return $result; } else { //Sinon, on cree le flux $twitterEntity = new TwitterEntity(); $twitterEntity->setChannel($channel); $twitterEntity->setFirstUpdate($firstUpdate); $twitterEntity->setLastUpdate(date(Database::DATE_FORMAT)); $twitterEntity->persist(); return $twitterEntity; } }