/** * Automatically generated run method * * @param Request $request * @return Response */ public function run(Request $request) { try { $file = $request->files->get('file'); // check proper upload if (!$file->isValid()) { throw new \Exception('Something went wrong during file upload'); } // check extension $exts = ['csv']; $extMatch = false; foreach ($exts as $ext) { if (strtolower($file->getClientOriginalExtension()) == $ext) { $extMatch = true; } } if (!$extMatch) { throw new \Exception('No matching extension'); } // check event if (!$request->request->has('event-id')) { throw new \Exception('No event-id given'); } // check importer if (!$request->request->has('importer')) { throw new \Exception('No importer given'); } // clean event $event = EventQuery::create()->findOneById($request->request->get('event-id')); // clean startgroups foreach (StartgroupQuery::create()->filterByEvent($event) as $startgroup) { foreach ($startgroup->getRoutines() as $routine) { $this->deleteStatistics($routine); } $this->deleteStatistics($startgroup); } $this->deleteStatistics($event); StartgroupQuery::create()->filterByEvent($event)->delete(); $body = file_get_contents($file->getPathname()); $importer = ImporterFactory::generateImporter($request->request->get('importer')); $importer->import($body, $event); // analyze after import $analyzer = new PerformanceAnalyzer(); $analyzer->analyze($event); $payload = new Success(); } catch (\Exception $e) { $payload = new Failed(['exception' => $e]); } return $this->responder->run($request, $payload); }
/** * Updates Startgroups on Competition * * @param mixed $id * @param mixed $data * @return PayloadInterface */ public function updateStartgroups($id, $data) { // find $model = $this->get($id); if ($model === null) { return new NotFound(['message' => 'Competition not found.']); } // remove all relationships before StartgroupQuery::create()->filterByCompetition($model)->delete(); // add them $errors = []; foreach ($data as $entry) { if (!isset($entry['id'])) { $errors[] = 'Missing id for Startgroup'; } $related = StartgroupQuery::create()->findOneById($entry['id']); $model->addStartgroup($related); } if (count($errors) > 0) { return new NotValid(['errors' => $errors]); } // save and dispatch events $event = new CompetitionEvent($model); $dispatcher = $this->getServiceContainer()->getDispatcher(); $dispatcher->dispatch(CompetitionEvent::PRE_STARTGROUPS_UPDATE, $event); $dispatcher->dispatch(CompetitionEvent::PRE_SAVE, $event); $rows = $model->save(); $dispatcher->dispatch(CompetitionEvent::POST_STARTGROUPS_UPDATE, $event); $dispatcher->dispatch(CompetitionEvent::POST_SAVE, $event); if ($rows > 0) { return Updated(['model' => $model]); } return NotUpdated(['model' => $model]); }
/** * Get the associated ChildStartgroup object * * @param ConnectionInterface $con Optional Connection object. * @return ChildStartgroup The associated ChildStartgroup object. * @throws PropelException */ public function getStartgroup(ConnectionInterface $con = null) { if ($this->aStartgroup === null && $this->startgroup_id !== null) { $this->aStartgroup = ChildStartgroupQuery::create()->findPk($this->startgroup_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aStartgroup->addRoutines($this); */ } return $this->aStartgroup; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Competition is new, it will return * an empty collection; or if this Competition has previously * been saved, it will retrieve related Startgroups from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Competition. * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return ObjectCollection|ChildStartgroup[] List of ChildStartgroup objects */ public function getStartgroupsJoinPerformanceMusicAndTimingStatistic(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildStartgroupQuery::create(null, $criteria); $query->joinWith('PerformanceMusicAndTimingStatistic', $joinBehavior); return $this->getStartgroups($query, $con); }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @throws LogicException if no primary key is defined * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = ChildStartgroupQuery::create(); $criteria->add(StartgroupTableMap::COL_ID, $this->id); return $criteria; }
/** * Performs an INSERT on the database, given a Startgroup or Criteria object. * * @param mixed $criteria Criteria or Startgroup object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(StartgroupTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Startgroup object } if ($criteria->containsKey(StartgroupTableMap::COL_ID) && $criteria->keyContainsValue(StartgroupTableMap::COL_ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . StartgroupTableMap::COL_ID . ')'); } // Set the correct dbName $query = StartgroupQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }
/** * Returns one Startgroup with the given id from cache * * @param mixed $id * @return Startgroup|null */ protected function get($id) { if ($this->pool === null) { $this->pool = new Map(); } else { if ($this->pool->has($id)) { return $this->pool->get($id); } } $model = StartgroupQuery::create()->findOneById($id); $this->pool->set($id, $model); return $model; }