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()]); }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aUser) { $this->aUser->removeTastedWine($this); } if (null !== $this->aWine) { $this->aWine->removeTastedWine($this); } $this->iduser = null; $this->idwine = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * 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'); } }
/** * 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; }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aUserRelatedBySubmitter) { $this->aUserRelatedBySubmitter->removeWineRelatedBySubmitter($this); } $this->idwine = null; $this->name = null; $this->picture = null; $this->year = null; $this->idsubmitter = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * Filter the query by a related \WineTasting\Model\User object * * @param \WineTasting\Model\User|ObjectCollection $user the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildWineQuery The current query, for fluid interface */ public function filterByUserRelatedByVote3($user, $comparison = null) { if ($user instanceof \WineTasting\Model\User) { return $this->addUsingAlias(WineTableMap::COL_IDWINE, $user->getVote3(), $comparison); } elseif ($user instanceof ObjectCollection) { return $this->useUserRelatedByVote3Query()->filterByPrimaryKeys($user->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByUserRelatedByVote3() only accepts arguments of type \\WineTasting\\Model\\User or Collection'); } }