/** * @return Client */ public function toClient() { $name = $this->getClientName(); $hasName = $name !== null && strlen($name) > 0; $grantTypes = $this->getGrantTypes(); $clientUri = $this->getClientUri(); $tosUri = $this->getTosUri(); $clientName = $this->getClientName(); $redirectUris = $this->getRedirectUris(); $client = new Client(); if ($grantTypes) { $client->setAllowedGrantTypes($grantTypes); } if ($clientUri) { $client->setLandingPageUrl($clientUri)->setSiteUrl($clientUri); } if ($tosUri) { $client->setTermsOfUseUrl($tosUri); } if ($clientName) { $client->setName($clientName); } if ($redirectUris) { $client->setRedirectUris($redirectUris); } $client->setVisible($hasName)->setPublished(false); return $client; }
/** * @Route("/populate/{id}", name="lc_admin_app_populate") * @Template() */ public function populateAction($id) { $em = $this->getDoctrine()->getManager(); $clientManager = $this->container->get('fos_oauth_server.client_manager'); $em->beginTransaction(); $input = 'Lorem Ipsum '; $person = $em->getRepository('PROCERGSLoginCidadaoCoreBundle:Person')->find($id); foreach (range(1, 1) as $val1) { $client = new Client(); $client->setPerson($person); $client->setName("Sample client {$val1} " . uniqid()); $client->setDescription('Sample client'); $client->setSiteUrl("http://localhost"); $client->setRedirectUris(array('http://localhost')); $client->setLandingPageUrl('http://localhost'); $client->setTermsOfUseUrl('http://localhost'); $client->setAllowedGrantTypes(Client::getAllGrants()); $client->setPublished(0); $client->setVisible(0); $clientManager->updateClient($client); $list = array(); foreach (range(1, 20) as $val2) { $cm = "Sample category {$val2} "; $category = new Category(); $category->setClient($client); $category->setName($cm . uniqid()); $category->setDefaultIcon('glyphicon glyphicon-envelope'); $category->setDefaultTitle($cm . " title"); $category->setDefaultShortText($cm . " shorttext"); $category->setMailTemplate("%title%\r\n%shorttext%\r\n"); $category->setMailSenderAddress($person->getEmail()); $category->setEmailable(true); $category->setMarkdownTemplate("%title%\r\n--\r\n\r\n> %shorttext%\r\n\r\n"); $category->setHtmlTemplate(MarkdownExtra::defaultTransform($category->getMarkdownTemplate())); $em->persist($category); foreach (range(1, 20) as $val3) { $r = rand(1, 19); $msg = array(); if ($r % 2) { $msg['title'] = str_repeat($input, $r); $msg['shorttext'] = str_repeat($input, $r); } $not = new Notification(); $not->setPerson($person); $not->setCategory($category); $not->setIcon($category->getDefaultIcon()); $not->setTitle(isset($msg['title']) ? $msg['title'] : $category->getDefaultTitle()); $not->setShortText(isset($msg['shorttext']) ? $msg['shorttext'] : $category->getDefaultShortText()); $not->parseHtmlTemplate($category->getHtmlTemplate()); $em->persist($not); $list[] =& $not; } $list[] =& $category; } $em->flush(); $em->clear($client); foreach ($list as &$entityes) { $em->clear($entityes); } } $em->commit(); return new Response("ok"); }