Пример #1
0
 public static function update($values, $user)
 {
     $id = $values['id'];
     if ($id) {
         $q = new Doctrine_Query();
         $q = $q->select('m.*')->from('Madule m');
         $q = $q->addWhere('id = ?', array($id));
         if (!$user->getRole() == User::ADMIN) {
             $q = $q->addWhere('user_id = ?', array($user->getId()));
         }
         $module = $q->fetchOne();
     } else {
         $module = new Madule();
     }
     if ($module) {
         $module->setName($values['name']);
         $module->setDescription($values['description']);
         $module->setSourceUrl($values['source_url']);
         if (!$module->getUserId()) {
             $module->setUserId($user->getId());
         }
         $module->setApplicationId($values['application_id']);
         $module->setApproved(false);
         $module->save();
         $folderpath = $module->getFolderPath();
         if (!is_dir($folderpath)) {
             mkdir($folderpath);
         }
         $screenshot = $values['screenshot'];
         if ($screenshot) {
             $screenshotpath = $folderpath . $module->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 $module;
     }
     return null;
 }