-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Clément
committed
Nov 4, 2020
1 parent
1d7367f
commit be5444a
Showing
10 changed files
with
613 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
/vendor/ | ||
.idea | ||
###< symfony/framework-bundle ### | ||
/public/uploads/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20201104092500 extends AbstractMigration | ||
{ | ||
public function getDescription() : string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema) : void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE personne_rattachee (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, nom VARCHAR(255) NOT NULL, prenom VARCHAR(255) NOT NULL, photo VARCHAR(255) NOT NULL, date_de_naissance DATE DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, telephone VARCHAR(255) DEFAULT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_44AB1594A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE personne_rattachee ADD CONSTRAINT FK_44AB1594A76ED395 FOREIGN KEY (user_id) REFERENCES fos_user (id)'); | ||
} | ||
|
||
public function down(Schema $schema) : void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('DROP TABLE personne_rattachee'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20201104093109 extends AbstractMigration | ||
{ | ||
public function getDescription() : string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema) : void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE personne_rattachee CHANGE photo photo VARCHAR(255) DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema) : void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE personne_rattachee CHANGE photo photo VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Admin; | ||
|
||
use Sonata\AdminBundle\Admin\AbstractAdmin; | ||
use Sonata\AdminBundle\Datagrid\DatagridMapper; | ||
use Sonata\AdminBundle\Datagrid\ListMapper; | ||
use Sonata\AdminBundle\Form\FormMapper; | ||
use Sonata\AdminBundle\Show\ShowMapper; | ||
use Sonata\Form\Type\DatePickerType; | ||
use Symfony\Component\Form\Extension\Core\Type\FileType; | ||
|
||
final class PersonneRattacheeAdmin extends AbstractAdmin | ||
{ | ||
|
||
public function preUpdate($user) | ||
{ | ||
$this->manageFileUpload($user); | ||
} | ||
public function prePersist($user) | ||
{ | ||
$this->manageFileUpload($user); | ||
} | ||
private function manageFileUpload($user) { | ||
if ($user->getFile()) { | ||
$user->refreshUpdated(); | ||
} | ||
} | ||
|
||
protected function configureFormFields(FormMapper $formMapper): void | ||
{ | ||
$user = $this->getSubject(); | ||
|
||
$fileFieldOptions = array('required' => false); | ||
if ($user && ($webPath = $user->getPhoto())) { | ||
$fileFieldOptions['help'] = '<img src="uploads/documents/'.$webPath.'" class="admin-preview" style="width: 300px;" />'; | ||
} | ||
|
||
$formMapper | ||
->with('Informations', array( | ||
'class' => 'col-md-6' | ||
)) | ||
|
||
->add('nom') | ||
->add('prenom') | ||
->add('dateDeNaissance', DatePickerType::class, array( | ||
'label' => 'Date de naissance', | ||
'required' => false, | ||
'format' => 'dd/MM/yyyy', | ||
'attr' => array( | ||
'data-date-format' => 'DD/MM/YYYY', | ||
'placeholder' => '31/01/1970' | ||
) | ||
)) | ||
->add('email') | ||
->add('telephone') | ||
->end() | ||
->with('Photo', array( | ||
'class' => 'col-md-6' | ||
)) | ||
->add('file', FileType::class, $fileFieldOptions) | ||
->end() | ||
; | ||
} | ||
|
||
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void | ||
{ | ||
$datagridMapper | ||
->add('id') | ||
->add('nom') | ||
->add('prenom') | ||
->add('photo') | ||
->add('dateDeNaissance') | ||
->add('email') | ||
->add('telephone') | ||
; | ||
} | ||
|
||
protected function configureListFields(ListMapper $listMapper): void | ||
{ | ||
$listMapper | ||
->addIdentifier('id') | ||
->addIdentifier('nom') | ||
->add('prenom') | ||
->add('photo') | ||
->add('dateDeNaissance') | ||
->add('email') | ||
->add('telephone'); | ||
} | ||
|
||
|
||
|
||
protected function configureShowFields(ShowMapper $showMapper): void | ||
{ | ||
$showMapper | ||
->add('id') | ||
->add('nom') | ||
->add('prenom') | ||
->add('photo') | ||
->add('dateDeNaissance') | ||
->add('email') | ||
->add('telephone') | ||
->add('updated') | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.