コード例 #1
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $sport = SportQuery::create()->findOneById($this->getParam('id'));
     $object = new Object();
     $object->setSport($sport);
     $data = ['sport' => $sport, 'object' => $object];
     $payload = new Blank($data);
     if ($request->isMethod('POST')) {
         $post = $request->request;
         $domain = new ObjectDomain($this->getServiceContainer());
         $serializer = Object::getSerializer();
         $fields = $serializer->getFields();
         $attribs = [];
         foreach ($fields as $field) {
             if ($post->has($field)) {
                 $attribs[$field] = $post->get($field);
             }
         }
         $attribs['fixed'] = $post->has('fixed');
         $payload = $domain->create(['attributes' => $attribs, 'relationships' => ['sport' => ['data' => ['id' => $sport->getId()]]]]);
         if ($payload instanceof NotValid) {
             $payload = new NotValid(array_merge($data, $payload->get()));
         }
     }
     return $this->responder->run($request, $payload);
 }
コード例 #2
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $id = $this->getParam('id');
     $sport = SportQuery::create()->findOneById($id);
     $data = ['sport' => $sport];
     $payload = new Blank($data);
     if ($request->isMethod('POST')) {
         $post = $request->request;
         $domain = new SportDomain($this->getServiceContainer());
         $serializer = Sport::getSerializer();
         $fields = $serializer->getFields();
         $attribs = [];
         foreach ($fields as $field) {
             if ($post->has($field)) {
                 $attribs[$field] = $post->get($field);
             }
         }
         $attribs['feature_composition'] = $post->has('feature_composition');
         $attribs['feature_tester'] = $post->has('feature_tester');
         $payload = $domain->update($id, ['meta' => $post->get('meta', []), 'attributes' => $attribs]);
         if ($payload instanceof NotValid) {
             $payload = new NotValid(array_merge($data, $payload->get()));
         }
     }
     return $this->responder->run($request, $payload);
 }
コード例 #3
0
 /**
  *
  * @return RouteCollection
  */
 private function generateRoutes()
 {
     $routes = new RouteCollection();
     $routes->add('info', new Route('/info'));
     $routes->add('help', new Route('/help'));
     $routes->add('manage', new Route('/manage'));
     $routes->add('manage-add', new Route('/manage/add'));
     $routes->add('manage-edit', new Route('/manage/{id}'));
     $routes->add('manage-delete', new Route('/manage/{id}/delete'));
     $routes->add('manage-default', new Route('/manage/{id}/default'));
     $routes->add('objects', new Route('/manage/{id}/objects'));
     $routes->add('objects-add', new Route('/manage/{id}/objects/add'));
     $routes->add('objects-edit', new Route('/manage/{id}/objects/{objectId}'));
     $routes->add('objects-delete', new Route('/manage/{id}/objects/{objectId}/delete'));
     $default = null;
     foreach (SportQuery::create()->find() as $sport) {
         $default = $sport->getIsDefault() ? $sport : $default;
         if (!$sport->getIsDefault()) {
             $routes->add('sport-' . $sport->getSlug(), new Route('/' . $sport->getSlug() . '{suffix}', ['suffix' => '', 'sport' => $sport->getId()], ['suffix' => '.*']));
         }
     }
     if ($default !== null) {
         $routes->add('sport', new Route('/{suffix}', ['suffix' => '', 'sport' => $default->getId()], ['suffix' => '.*']));
     } else {
         $routes->add('index', new Route('/'));
     }
     return $routes;
 }
コード例 #4
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $id = $this->getParam('id');
     $sport = SportQuery::create()->leftJoinGroup()->leftJoinSkill()->findOneById($id);
     $pictures = PictureQuery::create()->useSkillQuery()->filterBySportId($id)->endUse()->count();
     $videos = VideoQuery::create()->useSkillQuery()->filterBySportId($id)->endUse()->count();
     $references = ReferenceQuery::create()->useSkillReferenceQuery()->useSkillQuery()->filterBySportId($id)->endUse()->endUse()->count();
     $statistics = ['skills' => $sport->countSkills(), 'groups' => $sport->countGroups(), 'pictures' => $pictures, 'videos' => $videos, 'references' => $references];
     return $this->responder->run($request, new Blank($statistics));
 }
コード例 #5
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $sport = SportQuery::create()->findOneById($this->getParam('id'));
     if ($sport !== null) {
         $default = SportQuery::create()->findOneByIsDefault(true);
         $default->setIsDefault(false);
         $default->save();
         if ($sport->getId() != $default->getId()) {
             $sport->setIsDefault(true);
             $sport->save();
         }
     }
     return $this->responder->run($request);
 }
コード例 #6
0
 /**
  * @param Request $request
  * @param string $path
  */
 public function run(Request $request)
 {
     $kernel = $this->getServiceContainer()->getKernel();
     $account = $this->getServiceContainer()->getModuleManager()->load('keeko/account');
     $trixionary = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary-client');
     $widget = $account->loadAction('account-widget', 'html');
     $widget = $kernel->handle($widget, $request);
     $this->getPage()->setDefaultTitle('Trixionary');
     $this->getPage()->setTitlePrefix('Trixionary:');
     try {
         $routes = $this->generateRoutes();
         $context = new RequestContext($this->getBaseUrl());
         $matcher = new UrlMatcher($routes, $context);
         $match = $matcher->match($this->getDestination());
         $route = $match['_route'];
         $action = null;
         switch ($route) {
             case 'account':
             case 'account-index':
                 $action = $account->loadAction('account', 'html');
                 $action->setBaseUrl($this->getBaseUrl() . '/account');
                 $action->setDestination(str_replace($action->getBaseUrl(), '', $request->getUri()));
                 break;
             case 'trixionary':
             default:
                 $action = $trixionary->loadAction('trixionary');
                 $action->setBaseUrl($this->getBaseUrl());
                 $action->setDestination($this->getDestination());
                 break;
         }
         $kernel = $this->getServiceContainer()->getKernel();
         $response = $kernel->handle($action, $request);
         if ($response instanceof RedirectResponse) {
             return $response;
         }
         $main = $response->getContent();
     } catch (PermissionDeniedException $e) {
         $main = 'Permission Denied';
     } catch (\Exception $e) {
         $main = 'Error: ' . $e->getMessage();
     }
     $sports = SportQuery::create()->orderByTitle()->find();
     $response = new Response();
     $response->setContent($this->render('/gossi/trixionary-app/templates/main.twig', ['account_widget' => $widget->getContent(), 'main' => $main, 'sports' => $sports]));
     return $response;
 }
コード例 #7
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $id = $this->getParam('id');
     $sport = SportQuery::create()->findOneById($id);
     $data = ['sport' => $sport];
     $payload = null;
     if ($request->isMethod('POST')) {
         if ($request->request->get('name') == $sport->getTitle()) {
             $sport->delete();
             $payload = new Success();
         } else {
             $data['error'] = 'Name is wrong';
         }
     }
     if ($payload === null) {
         $payload = new Blank($data);
     }
     return $this->responder->run($request, $payload);
 }
コード例 #8
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $url = str_replace($request->getRequestUri(), '', $request->getUri());
     $baseurl = str_replace($url, '', $this->getBaseUrl());
     $sport = SportQuery::create()->findOneById($this->getParam('sport'));
     if (!$sport->getIsDefault()) {
         $baseurl .= '/' . $sport->getSlug();
     }
     // load assets
     $page = $this->getServiceContainer()->getKernel()->getApplication()->getPage();
     $repo = $this->getServiceContainer()->getResourceRepository();
     $page->addStyles($repo->find('/gossi/trixionary-client/public/app/assets/*.css')->getPaths());
     $page->addScripts($repo->find('/gossi/trixionary-client/public/app/assets/vendor-*.js')->getPaths());
     $page->addScripts($repo->find('/gossi/trixionary-client/public/app/assets/trixionary-*.js')->getPaths());
     // set configuration
     $prefs = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences();
     $config = ['modulePrefix' => 'trixionary', 'environment' => 'production', 'rootURL' => $baseurl, 'locationType' => 'auto', 'APP' => ['name' => 'trixionary', 'version' => '0.0.0+0d11dfba'], 'keeko' => ['api' => $prefs->getApiUrl(), 'trixionary' => ['sportId' => $sport->getId(), 'slug' => ['skill' => $sport->getSkillSlug(), 'group' => $sport->getGroupSlug(), 'object' => $sport->getObjectSlug()]]]];
     $meta = new Meta();
     $meta->setName('trixionary/config/environment');
     $meta->setContent(rawurlencode(Json::encode($config)));
     $page->addMeta($meta);
     return $this->responder->run($request, new Blank(['sport' => $sport]));
 }
コード例 #9
0
ファイル: Group.php プロジェクト: gossi/trixionary
 /**
  * Get the associated ChildSport object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildSport The associated ChildSport object.
  * @throws PropelException
  */
 public function getSport(ConnectionInterface $con = null)
 {
     if ($this->aSport === null && $this->sport_id !== null) {
         $this->aSport = ChildSportQuery::create()->findPk($this->sport_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->aSport->addGroups($this);
            */
     }
     return $this->aSport;
 }
コード例 #10
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $sports = SportQuery::create()->find();
     return $this->responder->run($request, new Blank(['sports' => $sports]));
 }
コード例 #11
0
ファイル: SportTableMap.php プロジェクト: gossi/trixionary
 /**
  * Performs an INSERT on the database, given a Sport or Criteria object.
  *
  * @param mixed               $criteria Criteria or Sport 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(SportTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Sport object
     }
     if ($criteria->containsKey(SportTableMap::COL_ID) && $criteria->keyContainsValue(SportTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . SportTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = SportQuery::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);
     });
 }
コード例 #12
0
ファイル: SportDomainTrait.php プロジェクト: gossi/trixionary
 /**
  * Returns one Sport with the given id from cache
  * 
  * @param mixed $id
  * @return Sport|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 = SportQuery::create()->findOneById($id);
     $this->pool->set($id, $model);
     return $model;
 }
コード例 #13
0
ファイル: SportQuery.php プロジェクト: gossi/trixionary
 /**
  * Returns a new ChildSportQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildSportQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildSportQuery) {
         return $criteria;
     }
     $query = new ChildSportQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
コード例 #14
0
 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $sport = SportQuery::create()->leftJoinObject()->findOneById($this->getParam('id'));
     return $this->responder->run($request, new Blank(['sport' => $sport]));
 }
コード例 #15
0
ファイル: Sport.php プロジェクト: gossi/trixionary
 /**
  * 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 = ChildSportQuery::create();
     $criteria->add(SportTableMap::COL_ID, $this->id);
     return $criteria;
 }