public static function update($values, $user) { $id = $values['id']; if ($id) { $q = new Doctrine_Query(); $q = $q->select('a.*')->from('Application a'); $q = $q->addWhere('id = ?', array($id)); if (!$user->getRole() == User::ADMIN) { $q = $q->addWhere('user_id = ?', array($user->getId())); } $application = $q->fetchOne(); } else { $application = new Application(); } if ($application) { $application->setName($values['name']); $application->setDescription($values['description']); $application->setSourceUrl($values['source_url']); if (!$application->getUserId()) { $application->setUserId($user->getId()); } $application->setApproved(false); $application->save(); $folderpath = $application->getFolderPath(); if (!is_dir($folderpath)) { mkdir($folderpath); } $screenshot = $values['screenshot']; if ($screenshot) { $screenshotpath = $folderpath . $application->getId() . $screenshot->getOriginalName(); $screenshot->save($screenshotpath); $smallThumb = new Thumbnail($screenshotpath); if ($smallThumb->getCurrentWidth() > 150 || $smallThumb->getCurrentHeight() > 150) { $smallThumb->resize(150, 150); } $smallThumb->show(100, $folderpath . 'smallthumb.png'); $bigThumb = new Thumbnail($screenshotpath); if ($bigThumb->getCurrentWidth() > 500 || $bigThumb->getCurrentHeight() > 500) { $bigThumb->resize(500, 500); } $bigThumb->show(100, $folderpath . 'bigthumb.png'); $screenshot = new Thumbnail($screenshotpath); $screenshot->show(100, $folderpath . 'screenshot.png'); unlink($screenshotpath); } return $application; } return null; }