Browse Source

add project entity #4

Laszlo Lang 11 months ago
parent
commit
9c5e127b57
4 changed files with 285 additions and 2 deletions
  1. 13
    2
      config/services.yaml
  2. 104
    0
      src/Admin/ProjectAdmin.php
  3. 108
    0
      src/Entity/Project.php
  4. 60
    0
      src/Repository/ProjectRepository.php

+ 13
- 2
config/services.yaml View File

@@ -19,8 +19,8 @@ services:
19 19
         autowire: true      # Automatically injects dependencies in your services.
20 20
         autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
21 21
         public: false       # Allows optimizing the container by removing unused services; this also means
22
-                            # fetching services directly from the container via $container->get() won't work.
23
-                            # The best practice is to be explicit about your dependencies anyway.
22
+          # fetching services directly from the container via $container->get() won't work.
23
+        # The best practice is to be explicit about your dependencies anyway.
24 24
 
25 25
     # makes classes in src/ available to be used as services
26 26
     # this creates a service per class whose id is the fully-qualified class name
@@ -36,3 +36,14 @@ services:
36 36
 
37 37
     # add more service definitions when explicit configuration is needed
38 38
     # please note that last definitions always *replace* previous ones
39
+
40
+    ###
41
+    # Sonata Admin Services
42
+    ###
43
+
44
+    admin.project:
45
+        public: true
46
+        class: App\Admin\ProjectAdmin
47
+        arguments: [~, App\Entity\Project, ~]
48
+        tags:
49
+        - { name: sonata.admin, manager_type: orm, label: Project }

+ 104
- 0
src/Admin/ProjectAdmin.php View File

@@ -0,0 +1,104 @@
1
+<?php
2
+
3
+namespace App\Admin;
4
+
5
+use App\Entity\Project;
6
+use Sonata\AdminBundle\Admin\AbstractAdmin;
7
+use Sonata\AdminBundle\Datagrid\DatagridMapper;
8
+use Sonata\AdminBundle\Datagrid\ListMapper;
9
+use Sonata\AdminBundle\Form\FormMapper;
10
+//use Sonata\AdminBundle\Form\Type\ModelListType;
11
+
12
+/**
13
+ * Class ProjectAdmin
14
+ *
15
+ * @package App\Admin
16
+ * @author  system7 <https://www.laszlolang.com>
17
+ */
18
+class ProjectAdmin extends AbstractAdmin
19
+{
20
+    /** {@inheritdoc} */
21
+    protected $baseRouteName = 'project';
22
+
23
+    /** {@inheritdoc} */
24
+    protected $baseRoutePattern = 'project';
25
+
26
+    /**
27
+     * {@inheritdoc}
28
+     */
29
+    protected function configureFormFields(FormMapper $formMapper)
30
+    {
31
+        $formMapper
32
+            ->with('Data', array('class' => 'col-md-6'))
33
+            ->add(
34
+                'title',
35
+                null,
36
+                array(
37
+                    'required' => true,
38
+                )
39
+            )
40
+            ->add(
41
+                'codeName',
42
+                null,
43
+                array(
44
+                    'required' => true,
45
+                )
46
+            )
47
+//            ->add(
48
+//                'image',
49
+//                ModelListType::class,
50
+//                array(
51
+//                    'required' => false,
52
+//                    'btn_list' => false,
53
+//                ),
54
+//                array(
55
+//                    'link_parameters' => array(
56
+//                        'context' => 'project'
57
+//                    )
58
+//                ))
59
+            ->end();
60
+    }
61
+
62
+    /**
63
+     * {@inheritdoc}
64
+     */
65
+    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
66
+    {
67
+        $datagridMapper
68
+            ->add('title');
69
+    }
70
+
71
+    /**
72
+     * {@inheritdoc}
73
+     */
74
+    protected function configureListFields(ListMapper $listMapper)
75
+    {
76
+        /** Disable mosaic view */
77
+        unset($this->listModes['mosaic']);
78
+
79
+        $listMapper
80
+            ->addIdentifier('title')
81
+            ->add('codeName')
82
+            ->add(
83
+                '_action',
84
+                null,
85
+                array(
86
+                    'actions' => array(
87
+                        'edit' => array(),
88
+                    )
89
+                )
90
+            );
91
+    }
92
+
93
+    /**
94
+     * @param Project $object
95
+     *
96
+     * @return string
97
+     */
98
+    public function toString($object)
99
+    {
100
+        return $object instanceof Project
101
+            ? $object->getTitle()
102
+            : 'Project';
103
+    }
104
+}

+ 108
- 0
src/Entity/Project.php View File

@@ -0,0 +1,108 @@
1
+<?php
2
+
3
+namespace App\Entity;
4
+
5
+use Doctrine\ORM\Mapping as ORM;
6
+
7
+/**
8
+ * Class Project
9
+ *
10
+ * @package App\Entity
11
+ * @author  system7 <https://www.laszlolang.com>
12
+ *
13
+ * @ORM\Entity(repositoryClass="App\Repository\ProjectRepository")
14
+ */
15
+class Project
16
+{
17
+    /**
18
+     * @ORM\Id()
19
+     * @ORM\GeneratedValue()
20
+     * @ORM\Column(type="integer")
21
+     */
22
+    private $id;
23
+
24
+    /**
25
+     * @var string
26
+     *
27
+     * @ORM\Column(name="title", type="string", length=255, nullable=false)
28
+     */
29
+    private $title;
30
+
31
+    /**
32
+     * @var string
33
+     *
34
+     * @ORM\Column(name="code_name", type="string", length=255, nullable=false)
35
+     */
36
+    private $codeName;
37
+
38
+//    /**
39
+//     * @var string
40
+//     *
41
+//     * @ORM\OneToOne(targetEntity="App\Application\Sonata\MediaBundle\Entity\Media")
42
+//     */
43
+//    private $image;
44
+
45
+    /**
46
+     * @return int|null
47
+     */
48
+    public function getId(): ?int
49
+    {
50
+        return $this->id;
51
+    }
52
+
53
+    /**
54
+     * @return null|string
55
+     */
56
+    public function getTitle(): ?string
57
+    {
58
+        return $this->title;
59
+    }
60
+
61
+    /**
62
+     * @param string $title
63
+     *
64
+     * @return Project
65
+     */
66
+    public function setTitle(string $title): self
67
+    {
68
+        $this->title = $title;
69
+
70
+        return $this;
71
+    }
72
+
73
+    /**
74
+     * @return null|string
75
+     */
76
+    public function getCodeName(): ?string
77
+    {
78
+        return $this->codeName;
79
+    }
80
+
81
+    /**
82
+     * @param string $codeName
83
+     *
84
+     * @return Project
85
+     */
86
+    public function setCodeName(string $codeName): self
87
+    {
88
+        $this->codeName = $codeName;
89
+
90
+        return $this;
91
+    }
92
+
93
+//    /**
94
+//     * @return string
95
+//     */
96
+//    public function getImage()
97
+//    {
98
+//        return $this->image;
99
+//    }
100
+//
101
+//    /**
102
+//     * @param string $image
103
+//     */
104
+//    public function setImage($image)
105
+//    {
106
+//        $this->image = $image;
107
+//    }
108
+}

+ 60
- 0
src/Repository/ProjectRepository.php View File

@@ -0,0 +1,60 @@
1
+<?php
2
+
3
+namespace App\Repository;
4
+
5
+use App\Entity\Project;
6
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
7
+use Symfony\Bridge\Doctrine\RegistryInterface;
8
+
9
+/**
10
+ * Class ProjectRepository
11
+ *
12
+ * @package App\Repository
13
+ * @author  system7 <https://www.laszlolang.com>
14
+ *
15
+ * @method Project|null find($id, $lockMode = null, $lockVersion = null)
16
+ * @method Project|null findOneBy(array $criteria, array $orderBy = null)
17
+ * @method Project[]    findAll()
18
+ * @method Project[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
19
+ */
20
+class ProjectRepository extends ServiceEntityRepository
21
+{
22
+    /**
23
+     * ProjectRepository constructor.
24
+     *
25
+     * @param RegistryInterface $registry
26
+     */
27
+    public function __construct(RegistryInterface $registry)
28
+    {
29
+        parent::__construct($registry, Project::class);
30
+    }
31
+
32
+//    /**
33
+//     * @return Project[] Returns an array of Project objects
34
+//     */
35
+    /*
36
+    public function findByExampleField($value)
37
+    {
38
+        return $this->createQueryBuilder('p')
39
+            ->andWhere('p.exampleField = :val')
40
+            ->setParameter('val', $value)
41
+            ->orderBy('p.id', 'ASC')
42
+            ->setMaxResults(10)
43
+            ->getQuery()
44
+            ->getResult()
45
+        ;
46
+    }
47
+    */
48
+
49
+    /*
50
+    public function findOneBySomeField($value): ?Project
51
+    {
52
+        return $this->createQueryBuilder('p')
53
+            ->andWhere('p.exampleField = :val')
54
+            ->setParameter('val', $value)
55
+            ->getQuery()
56
+            ->getOneOrNullResult()
57
+        ;
58
+    }
59
+    */
60
+}

Loading…
Cancel
Save