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()]);
 }
 /**
  * @param Request $request
  * @param Application $app
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function register(Request $request, Application $app)
 {
     $name = $request->get('name');
     $existingUser = UserQuery::create()->findByName($name);
     if (count($existingUser) > 0) {
         return $this->json(['id' => $existingUser[0]->getIdUser()]);
     }
     $user = new User();
     $user->setName($name);
     $user->save();
     return $this->json(['id' => $user->getIdUser()]);
 }
예제 #3
0
 /**
  * Declares an association between this object and a ChildUser object.
  *
  * @param  ChildUser $v
  * @return $this|\WineTasting\Model\TastedWine The current object (for fluent API support)
  * @throws PropelException
  */
 public function setUser(ChildUser $v = null)
 {
     if ($v === null) {
         $this->setIdUser(NULL);
     } else {
         $this->setIdUser($v->getIdUser());
     }
     $this->aUser = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildUser object, it will not be re-added.
     if ($v !== null) {
         $v->addTastedWine($this);
     }
     return $this;
 }
 /**
  * Filter the query by a related \WineTasting\Model\User object
  *
  * @param \WineTasting\Model\User|ObjectCollection $user The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @throws \Propel\Runtime\Exception\PropelException
  *
  * @return ChildTastedWineQuery The current query, for fluid interface
  */
 public function filterByUser($user, $comparison = null)
 {
     if ($user instanceof \WineTasting\Model\User) {
         return $this->addUsingAlias(TastedWineTableMap::COL_IDUSER, $user->getIdUser(), $comparison);
     } elseif ($user instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(TastedWineTableMap::COL_IDUSER, $user->toKeyValue('PrimaryKey', 'IdUser'), $comparison);
     } else {
         throw new PropelException('filterByUser() only accepts arguments of type \\WineTasting\\Model\\User or Collection');
     }
 }
예제 #5
0
 /**
  * Exclude object from result
  *
  * @param   ChildUser $user Object to remove from the list of results
  *
  * @return $this|ChildUserQuery The current query, for fluid interface
  */
 public function prune($user = null)
 {
     if ($user) {
         $this->addUsingAlias(UserTableMap::COL_IDUSER, $user->getIdUser(), Criteria::NOT_EQUAL);
     }
     return $this;
 }