public function testSlugifyOptionsOverrideSluggerOptions()
 {
     $slugger = new \EasySlugger\Slugger('+');
     $input = ' a+A+ - a+A_a _';
     $output = $slugger->slugify($input, '_');
     $this->assertSame('a_a_a_a_a', $output);
 }
 public function saving($model)
 {
     if (is_null($model->slug)) {
         $model->slug = $model->name;
     }
     $model->slug = Slugger::slugify($model->slug);
 }
Esempio n. 3
0
 public function index()
 {
     $models = config('anavel-crud.models');
     if (empty($models)) {
         throw new \Exception("No models configured.");
     }
     $modelSlug = Slugger::slugify(key($models));
     return new RedirectResponse(route('anavel-crud.model.index', $modelSlug));
 }
 public function downloadAction()
 {
     $id = $this->request->query->get('id');
     /** @var Test $entity */
     $entity = $this->em->getRepository('AppBundle:Test')->find($id);
     $filename = sprintf("%s-%s-%s.%s", Slugger::slugify($entity->getSubject()->getName()), Slugger::slugify($entity->getSeason()), Slugger::slugify($entity->getYear()), pathinfo($entity->getFilename(), PATHINFO_EXTENSION));
     $fileToDownload = $this->get('vich_uploader.storage')->resolvePath($entity, 'file');
     $response = new BinaryFileResponse($fileToDownload);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     return $response;
 }
Esempio n. 5
0
 public function index(ModelAbstractorFactory $modelFactory)
 {
     $models = config('anavel-crud.models');
     if (empty($models)) {
         throw new \Exception('No models configured.');
     }
     foreach ($models as $modelName => $model) {
         $modelSlug = Slugger::slugify($modelName);
         $modelAbstractor = $modelFactory->getByName($modelSlug);
         $config = $modelAbstractor->getConfig();
         if (!array_key_exists('authorize', $config) || ($config['authorize'] === true && Gate::allows('adminIndex', $modelAbstractor->getInstance()) || $config['authorize'] === false)) {
             return new RedirectResponse(route('anavel-crud.model.index', $modelSlug));
         }
     }
     abort(403);
 }
 /**
  * @ApiDoc(
  *  resource=true,
  *  description="Download a file test",
  *  https=true,
  *  requirements={
  *      {"name": "id", "dataType"="integer", "requirement"="\d+", "description"="Test id"},
  *  }
  * )
  * @Route("/tests/{id}/download")
  * @ParamConverter("test", class="AppBundle:Test", options={"mapping": {"id": "id"}})
  * @QueryParam(name="show", requirements="[01]", default="0", description="0: The file is downloaded, 1: The file is opened on the browser.")
  */
 public function getTestDownloadAction(Test $test, ParamFetcher $paramFetcher)
 {
     $filename = sprintf("%s-%s-%s.%s", Slugger::slugify($test->getSubject()->getName()), Slugger::slugify($test->getSeason()), Slugger::slugify($test->getYear()), pathinfo($test->getFilename(), PATHINFO_EXTENSION));
     $responseType = ResponseHeaderBag::DISPOSITION_ATTACHMENT;
     if ($page = $paramFetcher->get('show') === "1") {
         $responseType = ResponseHeaderBag::DISPOSITION_INLINE;
     }
     $fileToDownload = $this->get('vich_uploader.storage')->resolvePath($test, 'file');
     $response = new BinaryFileResponse($fileToDownload);
     $response->trustXSendfileTypeHeader();
     $response->setContentDisposition($responseType, $filename, iconv('UTF-8', 'ASCII//TRANSLIT', $filename));
     $em = $this->getDoctrine()->getManager();
     $test->incrementDownloads();
     $em->persist($test);
     $em->flush();
     return $response;
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $c = $this->getContainer()->get('doctrine.dbal.default_connection');
     $table = $input->getOption('table');
     switch ($table) {
         case 'elects':
             $query = 'SELECT t.id, t.first_name, t.last_name, t.slug FROM ' . $table . ' AS t';
             $getSlugBase = function ($data) {
                 return $data['first_name'] . ' ' . $data['last_name'];
             };
             break;
         default:
             $query = 'SELECT t.id, t.name, t.slug FROM ' . $table . ' AS t';
             $getSlugBase = function ($data) {
                 return $data['name'];
             };
             break;
     }
     $sql = $c->prepare($query);
     $sql->execute();
     $datas = $sql->fetchAll();
     $nbRows = count($datas);
     $pg = new ProgressBar($output, $nbRows);
     $pg->setFormat('very_verbose');
     $start = true;
     $i = 1;
     foreach ($datas as $data) {
         if ($start) {
             $query = 'START TRANSACTION;';
             $start = false;
         }
         $query .= 'UPDATE ' . $table . " SET slug = '" . Slugger::uniqueSlugify($getSlugBase($data)) . "' WHERE id = " . $data['id'] . ';';
         if ($i % 1000 === 0 || $i == $nbRows) {
             $query .= 'COMMIT;';
             $start = true;
             $sql = $c->prepare($query);
             $sql->execute();
         }
         $pg->advance();
         ++$i;
     }
 }
Esempio n. 8
0
 /**
  * Generate unique slug
  *
  * @param  string  $text
  * @return string
  */
 function uniqueSlugify($text)
 {
     return Slugger::uniqueSlugify($text);
 }