I have a symfony application where people can create a "object". The symfony form gets built with the structure provided in a config yaml file. Once the user then submits the form, the whole structure from the config file will then be persisted into my database and all the formdata will be saved into one big array in the database.
Here is my config file:
parameters:
stmoritz:
fw:
enabled: true
name: 'Configuration St. Moritz'
category: 'Configuration St. Moritz'
template: admin/operational-plans/fw_stmoritz.html.twig
ioiTemplate: admin/operational-plans/fw_stmoritz.html.twig
options:
maxChars: ~
maxImages: ~
stamp: FW_STMORITZ
wrapClass: 'stmoritz'
view_structure:
object_location:
- name
- category
- address
- zip_city
- coordinates
object_contact:
- objcontact
- important_numbers
- contact
firefighting:
- keybox
- key_coordinates
- bmt
- bmt_coordinates
- bma_code
- plans
damage_organisation:
- entryway
- waitingroom
- watersources
- trafficdiversion
- important_tools
- required_tools
- matdepot
- persdepot
- evacuation
- woundedcamp
object_info:
- buildtype
- likelyness
- potential_damages
- floors
- stairs
- elevators
- fireclosures
- lower_floors
- ground_floor
- upper_floors
- escaperoutes
- dangers
- special
attachment_choices:
-
- keybox
- bmt
- plans
- entryway
- waitingroom
- watersources
- trafficdiversion
- evacuation
- woundedcamp
- fireclosures
- lower_floors
- ground_floor
- upper_floors
- escaperoutes
- special
components:
- name: name
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: true
mapped: true
operation_view: true
- name: category
type: \Symfony\Component\Form\Extension\Core\Type\ChoiceType
options:
required: true
mapped: true
multiple: true
expanded: true
operation_view: true
- name: address
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: true
mapped: true
operation_view: true
- name: zip_city
type: \Symfony\Component\Form\Extension\Core\Type\ChoiceType
options:
required: true
mapped: true
multiple: false
expanded: false
operation_view: true
- name: coordinates
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: true
mapped: true
operation_view: true
- name: objcontact
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: important_numbers
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: contact
type: \Symfony\Bridge\Doctrine\Form\Type\EntityType
options:
multiple: false
expanded: false
required: false
mapped: true
class: \App\Entity\Contact
operation_view: true
- name: keybox
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: key_coordinates
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: bmt
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: bmt_coordinates
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: bma_code
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: plans
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: entryway
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: waitingroom
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: watersources
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: trafficdiversion
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: important_tools
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: required_tools
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: matdepot
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: persdepot
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: evacuation
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: woundedcamp
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: buildtype
type: \Symfony\Component\Form\Extension\Core\Type\ChoiceType
options:
required: false
mapped: true
multiple: true
expanded: true
operation_view: true
- name: likelyness
type: \Symfony\Component\Form\Extension\Core\Type\ChoiceType
options:
required: false
mapped: true
multiple: true
expanded: true
operation_view: true
- name: potential_damages
type: \Symfony\Component\Form\Extension\Core\Type\ChoiceType
options:
required: false
mapped: true
multiple: true
expanded: true
operation_view: true
- name: floors
type: \Symfony\Component\Form\Extension\Core\Type\IntegerType
options:
required: false
mapped: true
operation_view: true
- name: stairs
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: elevators
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: fireclosures
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: lower_floors
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: false
- name: ground_floor
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: false
- name: upper_floors
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: false
- name: escaperoutes
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
- name: dangers
type: \Symfony\Component\Form\Extension\Core\Type\ChoiceType
options:
required: false
mapped: true
multiple: true
expanded: true
operation_view: true
- name: special
type: \Symfony\Component\Form\Extension\Core\Type\TextType
options:
required: false
mapped: true
operation_view: true
And here is my entity:
<?php
namespace App\Entity;
use App\Repository\ObjectsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity(repositoryClass=ObjectsRepository::class)
*/
class Objects
{
/**
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(type="integer")
*/
private $id;
/**
* #ORM\Column(type="json")
*/
private $formdata = [];
/**
* #ORM\Column(type="array")
*/
private $structure = [];
/**
* #ORM\OneToMany(targetEntity=Attachment::class, mappedBy="object", orphanRemoval=true)
*/
private $attachments;
/**
* #ORM\ManyToOne(targetEntity=Contact::class, inversedBy="objects")
* #ORM\JoinColumn(nullable=false)
*/
private $contact;
/**
* #ORM\Column(type="datetime")
*/
private $date_updated;
/**
* #ORM\Column(type="datetime")
*/
private $date_validated;
/**
* #ORM\Column(type="string", length=255)
*/
private $status;
public function __construct()
{
$this->attachments = new ArrayCollection();
}
public function __toString()
{
$string = implode("", $this->formdata);
return json_decode($string);
}
public function getId(): ?int
{
return $this->id;
}
public function getFormdata(): ?array
{
return $this->formdata;
}
public function setFormdata(array $formdata): self
{
$this->formdata = $formdata;
return $this;
}
public function getStructure(): ?array
{
return $this->structure;
}
public function setStructure(array $structure): self
{
$this->structure = $structure;
return $this;
}
/**
* #return Collection|Attachment[]
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
public function addAttachment(Attachment $attachment): self
{
if (!$this->attachments->contains($attachment)) {
$this->attachments[] = $attachment;
$attachment->setObject($this);
}
return $this;
}
public function removeAttachment(Attachment $attachment): self
{
if ($this->attachments->removeElement($attachment)) {
// set the owning side to null (unless already changed)
if ($attachment->getObject() === $this) {
$attachment->setObject(null);
}
}
return $this;
}
public function getContact(): ?Contact
{
return $this->contact;
}
public function setContact(?Contact $contact): self
{
$this->contact = $contact;
return $this;
}
public function getDateUpdated(): ?\DateTimeInterface
{
return $this->date_updated;
}
public function setDateUpdated(\DateTimeInterface $date_updated): self
{
$this->date_updated = $date_updated;
return $this;
}
public function getDateValidated(): ?\DateTimeInterface
{
return $this->date_validated;
}
public function setDateValidated(\DateTimeInterface $date_validated): self
{
$this->date_validated = $date_validated;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
}
I have made custom fields to extract some of the values I want from that array to then show it in my easyadmin index, but my problem is now whenever I try to sort one of the columns it sorts (or tries to sort) all the columns that use data from the array as you can see in the picture below:
I think this is cause because easyadmin makes a db request everytime one of the sorts is being pressed but I have no idea how I could bypass this and fix the sorting.
If there is any more files that I should provide please let me know
Related
easy_admin:
entities:
User:
class: App\Entity\User
disabled_actions: ['new']
avatar_property_path: 'picture'
form:
fields:
- {property: 'rank'}
- { property: 'roles',
type: choice,type_options: { mapped: true, expanded: true, multiple: true},
choices: [role_admin: 'ROLE_ADMIN' , role_user: 'ROLE_USER'] }
this is the code that i wrote and this is the result :
enter image description here
you should do like this instead of form
easy_admin:
entities:
User:
class: App\Entity\User
disabled_actions: ['new']
avatar_property_path: 'picture'
new:
fields:
- {property: 'rank'}
- { property: 'roles',
type: choice,type_options: { mapped: true, expanded: true, multiple: true},
choices: [role_admin: 'ROLE_ADMIN' , role_user: 'ROLE_USER'] }
edit:
fields:
- {property: 'rank'}
- { property: 'roles',
type: choice,type_options: { mapped: true, expanded: true, multiple: true},
choices: [role_admin: 'ROLE_ADMIN' , role_user: 'ROLE_USER'] }
I have a problem with behat in symfony 2. I have two entities:
//Transaction
DM\MultiStepFormBundle\Entity\Transaction:
type: entity
repositoryClass: DM\MultiStepFormBundle\Repository\Transaction\TransactionRepository
table: rb_multistepform_transaction
indexes:
transaction_id_index:
columns: [ transaction_id ]
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
created_at:
type: datetime
nullable: false
transaction_id:
type: string
length: 128
nullable: false
is_client_new:
type: boolean
options:
default: false
utm_source:
type: string
length: 255
nullable: true
utm_medium:
type: string
length: 255
nullable: true
utm_campaign:
type: string
length: 255
nullable: true
user_agent:
type: text
nullable: true
http_referer:
type: string
length: 255
nullable: true
ip:
type: string
length: 32
nullable: true
status:
type: smallint
nullable: false
options:
default: 0
continue_service_run:
type: boolean
nullable: false
options:
default: false
continue_serivce_run_datetime:
type: datetime
nullable: true
oneToMany:
items:
targetEntity: DM\MultiStepFormBundle\Entity\TransactionItem
mappedBy: transaction
cascade: [persist, merge, remove]
manyToOne:
client:
targetEntity: DM\KlienciBundle\Entity\Client
inversedBy: multistepform_transactions
joinColumn:
name: client_id
referencedColumnName: id
//TransactionItem
DM\MultiStepFormBundle\Entity\TransactionItem:
type: entity
repositoryClass: DM\MultiStepFormBundle\Repository\Transaction\TransactionRepository
table: rb_multistepform_transaction_item
id:
id:
type: integer
generator: { strategy: AUTO }
indexes:
partner_status_index:
columns: [ partner_name, status ]
fields:
type:
type: smallint
nullable: false
partner_name:
type: string
length: 128
nullable: true
status:
type: smallint
nullable: false
options:
default: 0
link_id:
type: integer
nullable: true
product_id:
type: integer
nullable: true
pixelconversion_hash:
type: string
length: 128
nullable: true
partner_api_response:
type: json_array
nullable: true
clicked:
type: boolean
nullable: false
options:
default: 0
clicked_datetime:
type: datetime
nullable: true
order_nr:
type: integer
nullable: true
highlighted:
type: boolean
nullable: false
options:
default: false
manyToOne:
transaction:
targetEntity: DM\MultiStepFormBundle\Entity\Transaction
inversedBy: items
cascade: [persist, merge, remove]
joinColumn:
name: transaction_id
referencedColumnName: id
When i testing a service where I have such loops:
$transactions = $this->transactionRepository->getTransactionsByContinueServiceRunInDateRange(0, $minDateTime, $maxDateTime);
foreach ($transactions as $transactionKey => $singleTransaction) {
//in this place, relationships are not taken
$transactionItems = $singleTransaction->getItems();
//when it performs a test query items are downloaded correctly
$transactionItemsQuery = $this->transactionRepository->getItems($singleTransaction->getId());
}
In which i needs to get items from the reverse relation. With a normal call to the site in symfony, the relationships are correct and everything is ok.
In the case of activating test in behat, relations in the variable $transactionItems are an empty collection. The data surely exists in the database because in the variable $transactionItemsQuery as I get data from query I have correct data.
Has anyone ever encountered something like that in behat?
I have the following configuration:
fos_rest:
view:
view_response_listener: 'force'
formats:
json: true
xml: true
html: false
body_listener:
decoders:
json: fos_rest.decoder.json
xml: fos_rest.decoder.xml
body_converter:
enabled: true
format_listener:
enabled: true
rules:
- { path: '^/api', priorities: ['xml', 'json'], fallback_format: xml, prefer_extension: false }
param_fetcher_listener: force
routing_loader:
# default_format: xml
include_format: false
serializer:
serialize_null: true
and the following Controller:
/**
* #Rest\View(serializerGroups={"o-all-getCDashboard"})
*/
public function cgetAction($_format)
{
$handler = $this->getHandler();
die(dump($_format));
return $handler->getAll();
}
within a class that extends FOSRestController implements ClassResourceInterface
which always dumps null. If I re-enable default_format: xml what I get is always xml notwithstanding the Accept header I send. What's wrong with it? Why does not the format_listener work?
You using uncorrected format_listeners config.
Try using my config like this:
fos_rest:
body_listener: true
param_fetcher_listener: true
view:
view_response_listener: 'force'
formats:
jsonp: true
json: true
xml: false
rss: false
mime_types:
json: ['application/json', 'application/x-json']
jpg: ['image/jpeg']
png: ['image/png']
jsonp_handler: ~
routing_loader:
default_format: json
include_format: false
format_listener:
rules:
- { path: /api, priorities: [ json, jsonp ], fallback_format: json, prefer_extension: true }
exception:
enabled: true
Addition just settings section formats and fallback_format for yourself.
In my controller I using
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\RouteResource;
/**
* #RouteResource("someName")
*/
class myController extends FOSRestController implements ClassResourceInterface {
/**
* #param Request $request
* #Rest\Post("/someLink")
*/
public function insertLinkAction(Request $request) {}
}
I hope that help you.
I'm trying to attach a idempresa field to the sfDoctrineGuardPlugin but can't get it to work. This is the schema.yml (just relevant tables) for those tables:
SdrivingEmpresa:
connection: doctrine
tableName: sdriving_empresa
columns:
idempresa:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: true
idlogotipo:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: false
nombre_empresa:
type: string(250)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
ruta_emp:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SdrivingLogotipo:
local: idlogotipo
foreign: idlogotipo
type: one
SdrivingEmisor:
local: idempresa
foreign: idempresa
type: many
SdrivingMaquina:
local: idempresa
foreign: idempresa
type: many
SdrivingOperador:
local: idempresa
foreign: idempresa
type: many
SdrivingTurno:
local: idempresa
foreign: idempresa
type: many
SfGuardUserProfile:
local: idempresa
foreign: idempresa
type: many
SfGuardUserProfile:
connection: doctrine
tableName: sf_guard_user_profile
columns:
user_id:
type: integer(8)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
idempresa:
type: integer(4)
fixed: false
unsigned: true
primary: true
autoincrement: false
relations:
SfGuardUser:
local: user_id
foreign: id
type: one
SdrivingEmpresa:
local: idempresa
foreign: idempresa
type: one
If I run this:
# php symfony doctrine:dql "FROM sfGuardUser u, u.SfGuardUserProfile p"
>> doctrine executing dql query
I get this error:
>> DQL: FROM sfGuardUser u, u.SfGuardUserProfile p
>> Unknown relation alias SfGuardUserProfile
What I'm doing wrong? Where is my mistake?
try adding a foreignAlias for sfGuardUser in SfGuardUserProfile entity, like:
relations:
SfGuardUser:
local: user_id
foreign: id
type: one
foreignAlias: SfGuardUserProfile
I have followd this tutorialJoobeet 1.4 Day 3
<code> JobeetCategory:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true, unique: true }
JobeetJob:
actAs: { Timestampable: ~ }
columns:
category_id: { type: integer, notnull: true }
type: { type: string(255) }
company: { type: string(255), notnull: true }
logo: { type: string(255) }
url: { type: string(255) }
position: { type: string(255), notnull: true }
location: { type: string(255), notnull: true }
description: { type: string(4000), notnull: true }
how_to_apply: { type: string(4000), notnull: true }
token: { type: string(255), notnull: true, unique: true }
is_public: { type: boolean, notnull: true, default: 1 }
is_activated: { type: boolean, notnull: true, default: 0 }
email: { type: string(255), notnull: true }
expires_at: { type: timestamp, notnull: true }
relations:
JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs }
JobeetAffiliate:
actAs: { Timestampable: ~ }
columns:
url: { type: string(255), notnull: true }
email: { type: string(255), notnull: true, unique: true }
token: { type: string(255), notnull: true }
is_active: { type: boolean, notnull: true, default: 0 }
relations:
JobeetCategories:
class: JobeetCategory
refClass: JobeetCategoryAffiliate
local: affiliate_id
foreign: category_id
foreignAlias: JobeetAffiliates
JobeetCategoryAffiliate:
columns:
category_id: { type: integer, primary: true }
affiliate_id: { type: integer, primary: true }
relations:
JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id }
JobeetAffiliate: { onDelete: CASCADE, local: affiliate_id, foreign: id } </code>
Your code is working in me.
1. Check schema.yml for syntax error.
2.
2.1 Back Up your project.
2.2 (I think this is help you). Go to the lib/model/doctrine/base - and delete all files.
Make :
$ php symfony doctrine:build --all --and-load --no-confirmation
UPD : Delete all files also in : lib/form/doctrine/base, lib/filter/doctrine/base