Beispiel #1
0
/**
 * @param array $post
 * @param array $files
 * @param Dommage $dommage
 * @return Dommage
 */
function hydrateDommage(array $post, array $files, Dommage $dommage = null)
{
    if ($dommage === null) {
        $dommage = new Dommage();
    }
    //TODO gestion erreurs notament min 1 fichier
    $errors = array();
    foreach ($post as $k => $v) {
        ${$k} = trim(stripslashes($v));
    }
    if (isset($taille)) {
        $dommage->setTaille($taille);
    }
    if (isset($type)) {
        $dommage->setType($type);
    }
    if (isset($peinture)) {
        $dommage->setPeinture($peinture);
    }
    $dommage->setCommentaire($commentaire);
    for ($i = 1; $i <= 3; ++$i) {
        if (isset($files['photo' . $i])) {
            $file = $files['photo' . $i];
            /* TODO better control (mime) */
            if ($file['name']) {
                $photo = new Photo();
                $photo->setFile($file);
                $dommage->addPhoto($photo);
            }
        }
    }
    return array('dommage' => $dommage, 'errors' => $errors);
}