Example #1
0
 /**
  * Automatically generated run method
  * 
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     if ($request->request->has('event-id')) {
         $event = EventQuery::create()->findOneById($request->request->get('event-id'));
         $analyzer = new PerformanceAnalyzer();
         $analyzer->analyze($event);
         $payload = new Success();
     } else {
         $payload = new Failed(['exception' => new \Exception('No event-id given')]);
     }
     return $this->responder->run($request, $payload);
 }
Example #2
0
 /**
  * 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);
 }
Example #3
0
 /**
  * Returns a new ChildEventQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildEventQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildEventQuery) {
         return $criteria;
     }
     $query = new ChildEventQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Example #4
0
 /**
  * Returns one Event with the given id from cache
  * 
  * @param mixed $id
  * @return Event|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 = EventQuery::create()->findOneById($id);
     $this->pool->set($id, $model);
     return $model;
 }
Example #5
0
 /**
  * Get the associated ChildEvent object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildEvent The associated ChildEvent object.
  * @throws PropelException
  */
 public function getEvent(ConnectionInterface $con = null)
 {
     if ($this->aEvent === null && $this->event_id !== null) {
         $this->aEvent = ChildEventQuery::create()->findPk($this->event_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->aEvent->addStartgroups($this);
            */
     }
     return $this->aEvent;
 }
Example #6
0
File: Event.php Project: iuf/junia
 /**
  * Get the slug, ensuring its uniqueness
  *
  * @param    string $slug            the slug to check
  * @param    string $separator       the separator used by slug
  * @param    int    $alreadyExists   false for the first try, true for the second, and take the high count + 1
  * @return   string                   the unique slug
  */
 protected function makeSlugUnique($slug, $separator = '-', $alreadyExists = false)
 {
     if (!$alreadyExists) {
         $slug2 = $slug;
     } else {
         $slug2 = $slug . $separator;
         $count = \iuf\junia\model\EventQuery::create()->filterBySlug($this->getSlug())->filterByPrimaryKey($this->getPrimaryKey())->count();
         if (1 == $count) {
             return $this->getSlug();
         }
     }
     $adapter = \Propel\Runtime\Propel::getServiceContainer()->getAdapter('keeko');
     $col = 'q.Slug';
     $compare = $alreadyExists ? $adapter->compareRegex($col, '?') : sprintf('%s = ?', $col);
     $query = \iuf\junia\model\EventQuery::create('q')->where($compare, $alreadyExists ? '^' . $slug2 . '[0-9]+$' : $slug2)->prune($this);
     if (!$alreadyExists) {
         $count = $query->count();
         if ($count > 0) {
             return $this->makeSlugUnique($slug, $separator, true);
         }
         return $slug2;
     }
     $adapter = \Propel\Runtime\Propel::getServiceContainer()->getAdapter('keeko');
     // Already exists
     $object = $query->addDescendingOrderByColumn($adapter->strLength('slug'))->addDescendingOrderByColumn('slug')->findOne();
     // First duplicate slug
     if (null == $object) {
         return $slug2 . '1';
     }
     $slugNum = substr($object->getSlug(), strlen($slug) + 1);
     if (0 == $slugNum[0]) {
         $slugNum[0] = 1;
     }
     return $slug2 . ($slugNum + 1);
 }
Example #7
0
 /**
  * Returns the number of related Event objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related Event objects.
  * @throws PropelException
  */
 public function countEventsRelatedByPerformanceMusicAndTimingStatisticId(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collEventsRelatedByPerformanceMusicAndTimingStatisticIdPartial && !$this->isNew();
     if (null === $this->collEventsRelatedByPerformanceMusicAndTimingStatisticId || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collEventsRelatedByPerformanceMusicAndTimingStatisticId) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getEventsRelatedByPerformanceMusicAndTimingStatisticId());
         }
         $query = ChildEventQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByPerformanceMusicAndTimingStatistic($this)->count($con);
     }
     return count($this->collEventsRelatedByPerformanceMusicAndTimingStatisticId);
 }
 /**
  * Updates Events on PerformanceStatistic
  * 
  * @param mixed $id
  * @param mixed $data
  * @return PayloadInterface
  */
 public function updateEvents($id, $data)
 {
     // find
     $model = $this->get($id);
     if ($model === null) {
         return new NotFound(['message' => 'PerformanceStatistic not found.']);
     }
     // remove all relationships before
     EventQuery::create()->filterByPerformanceMusicAndTimingStatistic($model)->delete();
     // add them
     $errors = [];
     foreach ($data as $entry) {
         if (!isset($entry['id'])) {
             $errors[] = 'Missing id for Event';
         }
         $related = EventQuery::create()->findOneById($entry['id']);
         $model->addEvent($related);
     }
     if (count($errors) > 0) {
         return new NotValid(['errors' => $errors]);
     }
     // save and dispatch events
     $event = new PerformanceStatisticEvent($model);
     $dispatcher = $this->getServiceContainer()->getDispatcher();
     $dispatcher->dispatch(PerformanceStatisticEvent::PRE_EVENTS_UPDATE, $event);
     $dispatcher->dispatch(PerformanceStatisticEvent::PRE_SAVE, $event);
     $rows = $model->save();
     $dispatcher->dispatch(PerformanceStatisticEvent::POST_EVENTS_UPDATE, $event);
     $dispatcher->dispatch(PerformanceStatisticEvent::POST_SAVE, $event);
     if ($rows > 0) {
         return Updated(['model' => $model]);
     }
     return NotUpdated(['model' => $model]);
 }
Example #9
0
 /**
  * Performs an INSERT on the database, given a Event or Criteria object.
  *
  * @param mixed               $criteria Criteria or Event 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(EventTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Event object
     }
     if ($criteria->containsKey(EventTableMap::COL_ID) && $criteria->keyContainsValue(EventTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . EventTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = EventQuery::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);
     });
 }