/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id)
 {
     $album = Album::model()->findByPk($id);
     if ($album === null) {
         throw new CHttpException(404, 'The requested album does not exists.');
     }
     $model = new AlbumImage();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['AlbumImage'])) {
         $model->attributes = $_POST['AlbumImage'];
         $model->album_id = $album->id;
         if ($model->save()) {
             PublicFile::attachPrecreated($model, $model->_image);
             $this->redirect(['/album/details', 'id' => $album->id]);
         }
     }
     $this->render('create', ['model' => $model, 'album' => $album]);
 }
예제 #2
0
 public function executeUpload(opMailRequest $request)
 {
     $member = $this->getRoute()->getMember();
     if (!$member) {
         return sfView::NONE;
     }
     $mailMessage = $request->getMailMessage();
     $album = Doctrine::getTable('Album')->find($request['id']);
     if (!$album || !$album->isAuthor($member->id)) {
         return sfView::NONE;
     }
     $files = $this->getImageFiles($mailMessage, 5);
     foreach ($files as $file) {
         $albumImage = new AlbumImage();
         $albumImage->setAlbum($album);
         $albumImage->setMember($member);
         $albumImage->setFile($file);
         $albumImage->save();
     }
     return sfView::NONE;
 }
 public function save()
 {
     foreach ($this->getValues() as $k => $v) {
         if (0 !== strpos($k, 'photo_')) {
             continue;
         }
         if (empty($v['file'])) {
             continue;
         }
         $file = new File();
         $file->setFromValidatedFile($v['file']);
         if (empty($v['description'])) {
             $description = $file->getName();
         } else {
             $description = $v['description'];
         }
         $albumImage = new AlbumImage();
         $albumImage->setAlbum($this->albumInstance);
         $albumImage->setFile($file);
         $albumImage->setDescription($description);
         $albumImage->save();
     }
 }
예제 #4
0
$albumImage2 = Doctrine::getTable('AlbumImage')->find(2);
$albumImage3 = Doctrine::getTable('AlbumImage')->find(3);
$conn = Doctrine::getTable('AlbumImage')->getConnection();
// isAuthor()
$t->cmp_ok($albumImage1->isAuthor(1), '===', true, '->isAuthor() returns true.');
$t->cmp_ok($albumImage1->isAuthor(2), '===', false, '->isAuthor() returns false.');
// getPrevious()
$t->cmp_ok($albumImage1->getPrevious(), '===', false, '->getPrevious() returns false.');
$result = $albumImage2->getPrevious();
$t->isa_ok($result, 'AlbumImage', "->getPrevious() returns AlbumImage's instance.");
$t->is($result->id, $albumImage1->id, '->getPrevious() returns previous AlbumImage corectlly.');
// getNext()
$result = $albumImage1->getNext();
$t->isa_ok($result, 'AlbumImage', "->getNext() returns AlbumImage's instance.");
$t->is($result->id, $albumImage2->id, '->getNext() returns next AlbumImage corectlly.');
$t->cmp_ok($albumImage2->getNext(), '===', false, '->getNext() returns false.');
// save()
$conn->beginTransaction();
$file_new = new File();
$data = array('tmp_name' => dirname(__FILE__) . '/../../../images/OpenPNE.jpg', 'type' => 'image/jpeg', 'size' => 8327, 'name' => 'OpenPNE.jpg');
$validatorFile = new opValidatorImageFile();
$validatedFile = $validatorFile->clean($data);
$file_new->setFromValidatedFile($validatedFile);
$albumImage_new = new AlbumImage();
$albumImage_new->setMember($member1);
$albumImage_new->setAlbum($album1);
$albumImage_new->setFile($file_new);
$albumImage_new->save();
$t->is($albumImage1->getFile()->getName(), 'a_1055_a_2_a_1_a_1_dummy_file', 'filename is setted by ->save()');
$t->is($albumImage_new->getFilesize(), 8327, 'filesize is setted by ->preSave().');
$conn->rollback();