Browse Source

add project entity #4

tags/Beta-2
Laszlo Lang 1 year 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:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
@@ -36,3 +36,14 @@ services:

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

###
# Sonata Admin Services
###

admin.project:
public: true
class: App\Admin\ProjectAdmin
arguments: [~, App\Entity\Project, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Project }

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

@@ -0,0 +1,104 @@
<?php

namespace App\Admin;

use App\Entity\Project;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
//use Sonata\AdminBundle\Form\Type\ModelListType;

/**
* Class ProjectAdmin
*
* @package App\Admin
* @author system7 <https://www.laszlolang.com>
*/
class ProjectAdmin extends AbstractAdmin
{
/** {@inheritdoc} */
protected $baseRouteName = 'project';

/** {@inheritdoc} */
protected $baseRoutePattern = 'project';

/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('Data', array('class' => 'col-md-6'))
->add(
'title',
null,
array(
'required' => true,
)
)
->add(
'codeName',
null,
array(
'required' => true,
)
)
// ->add(
// 'image',
// ModelListType::class,
// array(
// 'required' => false,
// 'btn_list' => false,
// ),
// array(
// 'link_parameters' => array(
// 'context' => 'project'
// )
// ))
->end();
}

/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('title');
}

/**
* {@inheritdoc}
*/
protected function configureListFields(ListMapper $listMapper)
{
/** Disable mosaic view */
unset($this->listModes['mosaic']);

$listMapper
->addIdentifier('title')
->add('codeName')
->add(
'_action',
null,
array(
'actions' => array(
'edit' => array(),
)
)
);
}

/**
* @param Project $object
*
* @return string
*/
public function toString($object)
{
return $object instanceof Project
? $object->getTitle()
: 'Project';
}
}

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

@@ -0,0 +1,108 @@
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Class Project
*
* @package App\Entity
* @author system7 <https://www.laszlolang.com>
*
* @ORM\Entity(repositoryClass="App\Repository\ProjectRepository")
*/
class Project
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;

/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255, nullable=false)
*/
private $title;

/**
* @var string
*
* @ORM\Column(name="code_name", type="string", length=255, nullable=false)
*/
private $codeName;

// /**
// * @var string
// *
// * @ORM\OneToOne(targetEntity="App\Application\Sonata\MediaBundle\Entity\Media")
// */
// private $image;

/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}

/**
* @return null|string
*/
public function getTitle(): ?string
{
return $this->title;
}

/**
* @param string $title
*
* @return Project
*/
public function setTitle(string $title): self
{
$this->title = $title;

return $this;
}

/**
* @return null|string
*/
public function getCodeName(): ?string
{
return $this->codeName;
}

/**
* @param string $codeName
*
* @return Project
*/
public function setCodeName(string $codeName): self
{
$this->codeName = $codeName;

return $this;
}

// /**
// * @return string
// */
// public function getImage()
// {
// return $this->image;
// }
//
// /**
// * @param string $image
// */
// public function setImage($image)
// {
// $this->image = $image;
// }
}

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

@@ -0,0 +1,60 @@
<?php

namespace App\Repository;

use App\Entity\Project;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
* Class ProjectRepository
*
* @package App\Repository
* @author system7 <https://www.laszlolang.com>
*
* @method Project|null find($id, $lockMode = null, $lockVersion = null)
* @method Project|null findOneBy(array $criteria, array $orderBy = null)
* @method Project[] findAll()
* @method Project[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ProjectRepository extends ServiceEntityRepository
{
/**
* ProjectRepository constructor.
*
* @param RegistryInterface $registry
*/
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Project::class);
}

// /**
// * @return Project[] Returns an array of Project objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('p')
->andWhere('p.exampleField = :val')
->setParameter('val', $value)
->orderBy('p.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/

/*
public function findOneBySomeField($value): ?Project
{
return $this->createQueryBuilder('p')
->andWhere('p.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

Loading…
Cancel
Save