Skip to content

Instantly share code, notes, and snippets.

@zogot
Created June 18, 2015 13:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zogot/072f93c69f85265478de to your computer and use it in GitHub Desktop.
protected function map(SoundGroupModel $soundGroupModel)
{
$soundGroupArray = $soundGroupModel->toArray();
$soundGroup = $this->mapper->map($soundGroupArray);
$customFiles = $soundGroup->getCustomFiles();
foreach ($soundGroupModel->files as $soundGroupFileModel) {
// Needed variables
$name = $soundGroupFileModel->name;
$relativePath = $soundGroupFileModel->relative_path;
$absolutePath = $soundGroupFileModel->absolute_path;
// Get the root of the application and the custom folder for this sound file.
$root = str_replace("/$relativePath", '', $absolutePath);
$folder = str_replace("$name", '', $relativePath);
// Get the custom file.
$folderCollection = $customFiles->getFolder($folder);
$foundFile = $folderCollection->getFile($name);
$newFile = (new SoundFile($root, $relativePath))
->setAltered(true)
->setMigrating($soundGroupFileModel->migrating);
if ( is_null($foundFile)) {
$folderCollection->push($newFile);
} else {
$folderCollection->replaceFile($newFile);
}
}
return $soundGroup;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment