public function create(Request $request, Application $app)
 {
     $file = $request->files->get('picture');
     if ($file === null) {
         return $this->json(['status' => 'picture missing']);
     }
     $path = __DIR__ . '/../../../www/upload/';
     $originalFilename = $file->getClientOriginalName();
     $ext = strtolower(substr($originalFilename, strrpos($originalFilename, '.')));
     $filename = uniqid() . $ext;
     $file->move($path, $filename);
     // resizing
     self::resize($path . $filename, 680, 800);
     $username = $request->get('username');
     $user = UserQuery::create()->findOneByName($username);
     if ($user == null) {
         $user = new User();
         $user->setName($username);
         $user->save();
     }
     $wine = new Wine();
     $wine->setName($request->get('name'));
     $wine->setSubmitter($user->getIdUser());
     $wine->setYear($request->get('year'));
     $wine->setPicture($filename);
     $wine->save();
     return $this->json(['id' => $wine->getIdWine()]);
 }
Пример #2
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aUser !== null) {
             if ($this->aUser->isModified() || $this->aUser->isNew()) {
                 $affectedRows += $this->aUser->save($con);
             }
             $this->setUser($this->aUser);
         }
         if ($this->aWine !== null) {
             if ($this->aWine->isModified() || $this->aWine->isNew()) {
                 $affectedRows += $this->aWine->save($con);
             }
             $this->setWine($this->aWine);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Пример #3
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aWineRelatedByVote1 !== null) {
             if ($this->aWineRelatedByVote1->isModified() || $this->aWineRelatedByVote1->isNew()) {
                 $affectedRows += $this->aWineRelatedByVote1->save($con);
             }
             $this->setWineRelatedByVote1($this->aWineRelatedByVote1);
         }
         if ($this->aWineRelatedByVote2 !== null) {
             if ($this->aWineRelatedByVote2->isModified() || $this->aWineRelatedByVote2->isNew()) {
                 $affectedRows += $this->aWineRelatedByVote2->save($con);
             }
             $this->setWineRelatedByVote2($this->aWineRelatedByVote2);
         }
         if ($this->aWineRelatedByVote3 !== null) {
             if ($this->aWineRelatedByVote3->isModified() || $this->aWineRelatedByVote3->isNew()) {
                 $affectedRows += $this->aWineRelatedByVote3->save($con);
             }
             $this->setWineRelatedByVote3($this->aWineRelatedByVote3);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         if ($this->winesScheduledForDeletion !== null) {
             if (!$this->winesScheduledForDeletion->isEmpty()) {
                 $pks = array();
                 foreach ($this->winesScheduledForDeletion as $entry) {
                     $entryPk = [];
                     $entryPk[0] = $this->getIdUser();
                     $entryPk[1] = $entry->getIdWine();
                     $pks[] = $entryPk;
                 }
                 \WineTasting\Model\TastedWineQuery::create()->filterByPrimaryKeys($pks)->delete($con);
                 $this->winesScheduledForDeletion = null;
             }
         }
         if ($this->collWines) {
             foreach ($this->collWines as $wine) {
                 if (!$wine->isDeleted() && ($wine->isNew() || $wine->isModified())) {
                     $wine->save($con);
                 }
             }
         }
         if ($this->winesRelatedBySubmitterScheduledForDeletion !== null) {
             if (!$this->winesRelatedBySubmitterScheduledForDeletion->isEmpty()) {
                 \WineTasting\Model\WineQuery::create()->filterByPrimaryKeys($this->winesRelatedBySubmitterScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->winesRelatedBySubmitterScheduledForDeletion = null;
             }
         }
         if ($this->collWinesRelatedBySubmitter !== null) {
             foreach ($this->collWinesRelatedBySubmitter as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->tastedWinesScheduledForDeletion !== null) {
             if (!$this->tastedWinesScheduledForDeletion->isEmpty()) {
                 \WineTasting\Model\TastedWineQuery::create()->filterByPrimaryKeys($this->tastedWinesScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->tastedWinesScheduledForDeletion = null;
             }
         }
         if ($this->collTastedWines !== null) {
             foreach ($this->collTastedWines as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }