Doctrine, Zend, Entity QueryException has no field or association named - exception

I'm having an OrderEntity. First time i just needed three properties from the table. But now I need two more.
So I'm adding this two properties to my entity:
namespace Stock\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="orders")
*/
class OrderEntity
{
/**
* #ORM\Id
* #ORM\Column(type="integer", name="orders_id")
*/
private $ordersId;
/**
* #ORM\Column(type="string", name="order_number")
*/
private $orderNumber;
/**
* #ORM\Column(type="integer", name="stores_id")
*/
private $storesId;
/**
* #ORM\Column(type="string", length=3, name="currency")
*/
private $currency;
/**
* #ORM\Column(type="decimal", precision=6, scale=14, name="currency_value")
*/
private $currencyValue;
public function getOrdersId()
{
return $this->ordersId;
}
public function setOrdersId($ordersId)
{
$this->ordersId = $ordersId;
}
public function getOrderNumber()
{
return $this->orderNumber;
}
public function setOrderNumber($orderNumber)
{
$this->orderNumber = $orderNumber;
}
public function getStoresId()
{
return $this->storesId;
}
public function setStoresId($storesId)
{
$this->storesId = $storesId;
}
public function getCurrency()
{
return $this->currency;
}
public function getCurrencyValue()
{
return $this->currencyValue;
}
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
public function setCurrencyValue($currencyValue)
{
$this->currencyValue = $currencyValue;
return $this;
}
The new properties are the currency and currencyValue.
$query = $this->getEm()->createQuery(
"SELECT o.ordersId, o.currency FROM "
. "Stock\Entity\OrderEntity o WHERE "
. "o.ordersId ='".$orderId."'"
);
If I want to create a query with using the newer properties I got a QueryException:
[Semantical Error] line 0, col 21 near 'currency FROM': Error: Class Stock\Entity\OrderEntity has no field or association named currency
I don't exactly understand where the problem is!

Related

EasyAdmin 3.1 CrudControllers Symfony

I have problems setting up my Crud Controller's association fields. I want to only see users of a certain ROLE_ in the klient_id_klienta field and I don't know how to set it up.
Here is my CrudController:
class AdresKlientaCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return AdresKlienta::class;
}
/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
];
}
*/
// public function configureFields(string $pageName): iterable
// {
// return [
// 'id',
// 'klient_id_klienta',
// 'miejscowosc',
// 'ulica',
// 'nr_domu',
// 'nr_lokalu',
// 'kod_pocztowy'
// ];
// }
public function configureFields(string $pageName): iterable
{
//moje
// $qb = new QueryBuilder($this->getDoctrine()->getManager());
// $qb->select('u')->from('User','u')->where('u.roles = ?ROLE_USER');
//
//
// dump(EntityFilter::new('klient_id_klienta')->apply($qb));
//koniec moje
$foreignKey = AssociationField::new('klient_id_klienta'); //here is my problem as it shows every user
return [
// IdField::new('id'),
TextField::new('miejscowosc'),
TextField::new('ulica'),
TextField::new('nr_domu'),
TextField::new('nr_lokalu'),
TextField::new('kod_pocztowy'),
//AssociationField::new('klient_id_klienta')
$foreignKey
];
}
}
And here is the user entity
<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* #ORM\Entity(repositoryClass=UserRepository::class)
*/
class User implements UserInterface
{
/**
* #ORM\Id()
* #ORM\GeneratedValue()
* #ORM\Column(type="integer")
*/
private $id;
/**
* #ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* #ORM\Column(type="json")
*/
private $roles = [];
/**
* #var string The hashed password
* #ORM\Column(type="string")
*/
private $password;
/**
* #ORM\Column(type="string", length=255)
*/
private $name;
/**
* #ORM\Column(type="string", length=255)
*/
private $surname;
/**
* #ORM\Column(type="string", length=255)
*/
private $tel;
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* #see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* #see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* #see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* #see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* #see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSurname(): ?string
{
return $this->surname;
}
public function setSurname(string $surname): self
{
$this->surname = $surname;
return $this;
}
public function getTel(): ?string
{
return $this->tel;
}
public function setTel(string $tel): self
{
$this->tel = $tel;
return $this;
}
//moje funkcje
public function __toString()
{
// TODO: Implement __toString() method.
$userAndRole = implode($this->roles);
return $this->email.'-'.$userAndRole;
}
}
I only want to see users who have ROLE_USER
I tried to use filters but from what I see in Easyadmin documentation filters allow me to set up choices based what they get so that wouldnt work for me. I also tried to use QueryBuilder to get Users with certain ROLE_ and that also failed.
I figured it out and I want to thank you for answering. I'm posting my solution because I don't want to be one of those people who say "I figured it out" and don't post how they actually figured that out.
public function configureFields(string $pageName): iterable
{
//utworzenie wyświetlania tylko tych użytkowników, którzy maja role ROLE_USER
$association = AssociationField::new('klient_id_klienta', 'Email klienta')
->setFormTypeOption(
'query_builder', function (UserRepository $userRepository){
return $userRepository->createQueryBuilder('u')
->andWhere('u.roles LIKE :role')->setParameter('role', '%"ROLE_USER"%');
}
);
return [
// IdField::new('id'),
TextField::new('miejscowosc', 'Miejscowość'),
TextField::new('ulica', 'Ulica'),
TextField::new('nr_domu', 'Numer domu'),
TextField::new('nr_lokalu', 'Numer Lokalu'),
TextField::new('kod_pocztowy', 'Kod pocztowy'),
$association,//wywołanie klucza obcego który odfiltrowuje użytkowników
];
}
As you can see I got the users with the certain role that I wanted to get by using query builder. Amazing tool, through that query buider I can get virtually anything I want from my databases and put it in my Crud Controllers. I hope it helps someone someday.
Try this :
public function configureFields(string $pageName): iterable
{
$users = $this->entityManager->getRepository(User::class)->findBy([
'roles' => 'ROLE_USER']);
yield AssociationField::new('klient_id_klienta')->onlyOnForms()->setFormTypeOptions(["choices" => $users->toArray()]);
}

How to bypass error "Invalid type "json_array""

I have an entity:
<?php
namespace App\Entity\Aero;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity(repositoryClass="App\Repository\Aero\ScheduleRepository")
*/
class Schedule
{
/**
* #ORM\Id()
* #ORM\GeneratedValue()
* #ORM\Column(type="integer")
*/
private $id;
/**
* #ORM\Column(type="date")
*/
private $dateOfFlight;
/**
* #ORM\Column(type="json")
*/
private $timeOfFlightAndStations = [];
public function getId(): ?int
{
return $this->id;
}
public function getDateOfFlight(): ?\DateTimeInterface
{
return $this->dateOfFlight;
}
public function setDateOfFlight(\DateTimeInterface $dateOfFlight): self
{
$this->dateOfFlight = $dateOfFlight;
return $this;
}
public function getTimeOfFlightAndStations(): ?array
{
return $this->timeOfFlightAndStations;
}
public function setTimeOfFlightAndStations(array $timeOfFlightAndStations): self
{
$this->timeOfFlightAndStations = $timeOfFlightAndStations;
return $this;
}
}
When I try to add field with type json_array via con make:entity it shows me error:
[ERROR] Invalid type "json_array".
My computer says that type "json_array" is invalid, but also says that it is in the list of valid types. How is it possible?
Please, help me, how to deal with this error?
Solved it by adding "json_array" manually instead of "json" in:
/**
* #ORM\Column(type="json_array")
*/

Doctrine persist:

I'm a beginner at Symfony. My problem is that I try to add values to my base MySQL and the problem is that I have the same id, but i verified my entity and i generate values #ORM/GeneratedValues, i don't understand where is my fault.
Routing :
esprit_parc_AjoutVoiture:
path: /Ajout_voiture/
defaults: { _controller: ParcBundle:Voiture:add }
My controller:
public function addAction (Request $Request)
{
$Voiture = new Voiture();
$form = $this->createForm(VoitureType::class,$Voiture);
$form->handleRequest($Request);
if ($form->isValid())
{
$em=$this->getDoctrine()->getManager();
$em->persist($Voiture);
$em->flush();
return $this->redirect($this->generateUrl(
'esprit_parc_Affichage'
));
}
return $this->render(
'ParcBundle:Voiture:ajout.html.twig',
array('form'=>$form->createView()
));
}
}
Entity Voiture:
<?php
namespace ParcBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class voiture
* #package ParcBundle\Entity
* #ORM\Entity
* #ORM\Table(name="Voiture")
*/
class Voiture
{
/**
* #ORM\Column( type="integer")
* #ORM\Id
* #ORM\GeneratedValue
*/
private $id;
/**
* #ORM\Column(type="string",length=255)
*
*/
private $Serie;
/**
* #ORM\Column(type="datetime",length=255)
*/
private $DateMiseCirculation;
/**
* #ORM\Column(type="string",length=255)
*/
private $Marque;
/**
* #ORM\ManyToOne(targetEntity="ParcBundle\Entity\Modele" )
* #ORM\JoinColumn(name="id", referencedColumnName="id");
*/
private $modele;
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
public function getModele()
{
return $this->modele;
}
public function setModele($modele)
{
$this->modele = $modele;
}
public function getSerie()
{
return $this->Serie;
}
public function setSerie($Serie)
{
$this->Serie = $Serie;
}
public function getDateMiseCirculation()
{
return $this->DateMiseCirculation;
}
public function setDateMiseCirculation($DateMiseCirculation)
{
$this->DateMiseCirculation = $DateMiseCirculation;
}
public function getMarque()
{
return $this->Marque;
}
public function setMarque($Marque)
{
$this->Marque = $Marque;
}
}
Error:
An exception occurred while executing 'INSERT INTO Voiture (serie, date_mise_circulation, marque, id) VALUES (?, ?, ?, ?)' with params ["2313", "2012-12-03 02:02:00", "sd", 1]:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'PRIMARY'
PS : i have values with id = "1" and it should increment automatically the id.
[EDIT]: Class VoitureType:
<?php
namespace ParcBundle\Form;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class VoitureType extends AbstractType
{
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('Serie')
->add('DateMiseCirculation')
->add('Marque')
->add('modele', EntityType::class, array(
"class" => "ParcBundle:Modele",
"choice_label"=> "libelle"
))
->add("Ajouter",SubmitType::class);
}
/**
* {#inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'ParcBundle\Entity\Voiture'
));
}
/**
* {#inheritdoc}
*/
public function getBlockPrefix()
{
return 'parcbundle_voiture';
}
}
You have an old schema in your database and MySQL does not know that attribute id is auto increment value. To update your schema you can use one of methods:
Internal tool from Doctrine: php bin/console doctrine:schema:update --force.
Use DoctrineMigrationsBundle.
Remember that sometimes schema do not want to update because of foreign keys. Solution for this is just remove existing data.

Symfony2: embedding form with many-to-many entities throws exception

Issue
I've been trying to follow the tutorial to embed a form in another one. What I'm trying to do here is add a task, and add multiple categories to it. I'm using the example at http://symfony.com/doc/current/book/forms.html#embedding-a-single-object, but I added some ORM annotations to make the relation many-to-many. As such, here is my code for the Task & Category entities:
Code
Task entity
<?php
namespace Acme\TaskBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Task
*
* #ORM\Table()
* #ORM\Entity
*/
class Task
{
/**
* #ORM\ManyToMany(targetEntity="Category", inversedBy="tasks")
* #ORM\JoinTable(name="tasks_categories")
*
* #Assert\Type(type="Acme\TaskBundle\Entity\Category")
*/
protected $categories;
// ...
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Task
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Constructor
*/
public function __construct()
{
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add categories
*
* #param \Acme\TaskBundle\Entity\Category $categories
* #return Task
*/
public function addCategorie(\Acme\TaskBundle\Entity\Category $categories)
{
$this->categories[] = $categories;
return $this;
}
/**
* Remove categories
*
* #param \Acme\TaskBundle\Entity\Category $categories
*/
public function removeCategorie(\Acme\TaskBundle\Entity\Category $categories)
{
$this->categories->removeElement($categories);
}
/**
* Get categories
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getCategories()
{
return $this->categories;
}
}
Category entity
<?php
namespace Acme\TaskBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
/**
* Category
*
* #ORM\Table()
* #ORM\Entity
*/
class Category
{
/**
* #ORM\ManyToMany(targetEntity="Task", mappedBy="categories")
*/
private $tasks;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Constructor
*/
public function __construct()
{
$this->tasks = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add tasks
*
* #param \Acme\TaskBundle\Entity\Task $tasks
* #return Category
*/
public function addTask(\Acme\TaskBundle\Entity\Task $tasks)
{
$this->tasks[] = $tasks;
return $this;
}
/**
* Remove tasks
*
* #param \Acme\TaskBundle\Entity\Task $tasks
*/
public function removeTask(\Acme\TaskBundle\Entity\Task $tasks)
{
$this->tasks->removeElement($tasks);
}
/**
* Get tasks
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getTasks()
{
return $this->tasks;
}
}
Both forms have been auto-generated by using the doctrine:generate:form command. I changed the TaskType form to include the categories:
TaskType form
<?php
namespace Acme\TaskBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class TaskType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('categories', new CategoryType())
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\TaskBundle\Entity\Task',
'cascade_validation' => true,
));
}
public function getName()
{
return 'task';
}
}
Now when I go to the create page for tasks, I get this error:
The form's view data is expected to be an instance of class
Acme\TaskBundle\Entity\Category, but is an instance of class
Doctrine\Common\Collections\ArrayCollection. You can avoid this error
by setting the "data_class" option to null or by adding a view
transformer that transforms an instance of class
Doctrine\Common\Collections\ArrayCollection to an instance of
Acme\TaskBundle\Entity\Category.
I honestly have no idea how to fix it since this seemed a pretty straight-forward thing but apparently it isn't. Could someone help me out here please?
in your Task Entity remove the validation for categories.
Symfony tries to validate a ArrayCollection as one Category!(hence the error)
* #Assert\Type(type="Acme\TaskBundle\Entity\Category")
*/
$categories;
It isn't necessary since it is a collection. (validation will be based on what type of objects are in the collection)
If you created a CategoryType form then this form should return Acme\TaskBundle\Entity\Category for it's data class.
class CategoryType {
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\TaskBundle\Entity\Category',
.....
));
}
}
Also, in your TaskType
$builder
->add('name')
->add('categories', new CategoryType()) // new CategoryType()
// is not really needed here,
// symfony will automatically detect
// it's relation and create a new
// CategoryType if necessary.

Doctrine Annotaion Exception

I have 5 servers running the same app (Zend + Doctrine) and on the last one server (installed recently) im I'm getting this exception:
Application error Exception information:
Message: Class Entity\User is not a valid entity or mapped super class. Stack trace:
#0 /home/library/vendor/doctrine/2.0/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php(138): Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass('Entity\User')
#1 /home/library/vendor/doctrine/2.0/Doctrine/ORM/Mapping/ClassMetadataFactory.php(282): Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('Entity\User', Object(Doctrine\ORM\Mapping\ClassMetadata))
#2 /home/library/vendor/doctrine/2.0/Doctrine/ORM/Mapping/ClassMetadataFactory.php(176): Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata('Entity\User')
#3 /home/library/vendor/doctrine/2.0/Doctrine/ORM/EntityManager.php(247): Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor('Entity\User')
#4 /home/library/vendor/doctrine/2.0/Doctrine/ORM/EntityManager.php(564): Doctrine\ORM\EntityManager->getClassMetadata('Entity\User')
#5 /home/imobfusion/public_html/application/modules/a1/controllers/IndexController.php(68): Doctrine\ORM\EntityManager->getRepository('Entity\User')
#6 /home/library/vendor/zend/1.11.3/Zend/Controller/Action.php(513): A1_IndexController->testDoctrineAction()
#7 /home/library/vendor/zend/1.11.3/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('testDoctrineAct...')
#8 /home/library/vendor/zend/1.11.3/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#9 /home/library/vendor/zend/1.11.3/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#10 /home/library/vendor/zend/1.11.3/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#11 /home/imobfusion/public_html/public/index.php(21): Zend_Application->run()
#12 {main}
Request Parameters:
array(3) { ["controller"]=> string(5) "index" ["action"]=> string(13) "test-doctrine" ["module"]=> string(2) "a1" }
looikng on AnnotationDriver.php(138):
// Evaluate Entity annotation
if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) {
$entityAnnot = $classAnnotations['Doctrine\ORM\Mapping\Entity'];
$metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
} else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) {
$metadata->isMappedSuperclass = true;
} else {
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
}
on else the exception is thrown
but I really do not know what happens!
Any Help or Tip?
Obs:
/home/library/ <----- this folder is the same(identical) on all servers;
The Entity\User is correcly pointed and is the same on both servers;
I disable cache and clear the cache before calling a Repository on Entity Manager and the erros occurss!!
The PHP Version on last one server is 5.3.8 and on server 4(running ok) is 5.3.10.
The errors occurs on All(18) entities on app, not only in Entity\User.
Tracking the problem i do this on my bootstrap (var_dump(),die()):
// AnnotationDriver
$driver = $config->newDefaultAnnotationDriver($options["entities_dir"]);
$config->setMetadataDriverImpl($driver);
var_dump($driver->getAllClassNames());
die();
And getAllClassNames() return a empty array only o server 5, this is the error, the classes is not loading on server 05, but why..??? Test Continue!!
Tracking more i found more
public function isTransient($className)
{
$classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className));
if($className=="Entity\User") // Debug
{ // Debug
var_dump($classAnnotations); // Debug
} // Debug
return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) &&
! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']);
}
This method on annotation driver return true $classAnnotations is a empty array.
Resuming on server 05 the load off annotation failure, but why!. Continue!
Discory the problem but not solved:
I found the origin, and create this test script to confirm:
require_once "../application/doctrine/Entity/User.php";
$class = new ReflectionClass("Entity\User");
echo $class->getName();
echo $class->getDocComment();
Output on other servers:
Entity\User/** #Entity * #HasLifecycleCallbacks * #Table(name="user")
*/
Output on server 05:
Entity\User
->getDocComment don't work only with this especific classes and server:
User class/entity:
<?php
/** #Entity
* #HasLifecycleCallbacks
* #Table(name="user")
*/
namespace Entity;
use Validation;
use \DateTime;
use \LogHelper;
class User
{
/////////////////////////////////////////////////////////////////////////
// Properties //
/////////////////////////////////////////////////////////////////////////
/**
* #Id
* #Column(type="integer")
* #generatedValue(strategy="AUTO")
*/
protected $id;
/**
* #Column(type="integer")
*/
protected $type = 0;
/**
* #Column(length=50)
*/
protected $name;
/**
* #Column(length=50)
*/
protected $user_name;
/**
* #Column(length=100)
*/
protected $email;
/**
* #Column(length=14)
*/
protected $phone;
/**
* #Column(length=14)
*/
protected $cell_phone;
/**
* #Column(length=36)
*/
protected $password;
/**
* #Column(type="text",length=1000)
*/
protected $permissions;
/**
* #Column(type="text",length=1000)
*/
protected $time_table;
/**
* #Column(type="text",length=1000,nullable=true)
*/
protected $desktop;
/**
* #Column(type="boolean",nullable=true)
*/
protected $chat_on = 0;
// Behaviors
/**
* #Column(type="datetime")
*/
protected $created_at;
/**
* #Column(type="datetime")
*/
protected $updated_at;
/**
* #Column(type="integer")
* #version
*/
protected $version;
/////////////////////////////////////////////////////////////////////////
// Relations //
/////////////////////////////////////////////////////////////////////////
/**
* #ManyToOne(targetEntity="Branch", inversedBy="users")
* #JoinColumn(name="branch_id", referencedColumnName="id")
*/
private $branch;
/**
* #OneToMany(targetEntity="Property", mappedBy="captivator");
*/
private $properties;
/**
* #OneToMany(targetEntity="KeyHistory", mappedBy="user");
*/
private $key_histories;
/**
* #OneToMany(targetEntity="Presentation", mappedBy="user");
*/
private $presentations;
/**
* #OneToMany(targetEntity="Log", mappedBy="user");
*/
private $logs;
/**
* #OneToMany(targetEntity="Chat", mappedBy="user");
*/
private $chats;
/////////////////////////////////////////////////////////////////////////
// ForeingKey //
/////////////////////////////////////////////////////////////////////////
/**
* #Column(type="integer")
*/
protected $branch_id;
/////////////////////////////////////////////////////////////////////////
// Getters/Setters //
/////////////////////////////////////////////////////////////////////////
public function setId($value) {$this->id = $value;}
public function getId() {return $this->id;}
public function setType($value) {$this->type = $value;}
public function getType() {return $this->type;}
public function setName($value) {$this->name = $value;}
public function getName() {return $this->name;}
public function setUserName($value) {$this->user_name = $value;}
public function getUserName() {return $this->user_name;}
public function setEmail($value) {$this->email = $value;}
public function getEmail() {return $this->email;}
public function setPhone($value) {$this->phone = $value;}
public function getPhone() {return $this->phone;}
public function setCellPhone($value) {$this->cell_phone = $value;}
public function getCellPhone() {return $this->cell_phone;}
public function setPassword($value) {$this->password = $value;}
public function getPassword() {return $this->password;}
public function setPermissions($value) {$this->permissions = $value;}
public function getPermissions() {return $this->permissions;}
public function setTimeTable($value) {$this->time_table = $value;}
public function getTimeTable() {return $this->time_table;}
public function setDesktop($value) {$this->desktop = $value;}
public function getDesktop() {return $this->desktop;}
public function setChatOn($value) {$this->chat_on = $value;}
public function getChatOn() {return $this->chat_on;}
public function setBranch($value) {$this->branch = $value;}
public function getBranch() {return $this->branch;}
public function setBranchId($value) {$this->branch_id = $value;}
public function getBranchId() {return $this->branch_id;}
public function getCreatedAt() {return $this->created_at->format("d/m/Y H:i:s");}
public function getUpdatedAt() {return $this->updated_at->format("d/m/Y H:i:s");}
public function getVersion() {return $this->version;}
/////////////////////////////////////////////////////////////////////////
// Constructor //
/////////////////////////////////////////////////////////////////////////
public function __construct()
{
$this->created_at = $this->updated_at = new DateTime("now");
}
/////////////////////////////////////////////////////////////////////////
// Hooks //
/////////////////////////////////////////////////////////////////////////
/**
* #PrePersist
* #PreUpdate
*/
public function Validate()
{
$this->ApplyBehaviors();
$e = new ValidationException();
if(empty($this->name))
{
$e->AppendError("O Campo nome não pode ser vazio.","name");
}
if(empty($this->user_name))
{
$e->AppendError("O Campo nome de usuário não pode ser vazio.","user_name");
}
if(empty($this->email))
{
$e->AppendError("O Campo email não pode ser vazio.","email");
}
if($e->hasError())
throw $e;
}
/**
* #PostPersist
*/
public function onPostPersist()
{
LogHelper::SaveAction(LogHelper::ACTION_ADD,LogHelper::ENTITY_USER,$this->getId());
}
/**
* #PostUpdate
*/
public function onPostUpdate()
{
LogHelper::SaveAction(LogHelper::ACTION_UPDATE,LogHelper::ENTITY_USER,$this->getId());
}
/**
* #PreRemove
*/
public function onPreRemove()
{
LogHelper::HoldId($this->id);
}
/**
* #PostRemove
*/
public function onPostRemove()
{
LogHelper::SaveAction(LogHelper::ACTION_DELETE,LogHelper::ENTITY_USER,$this->id);
}
private function ApplyBehaviors()
{
$this->updated_at = new DateTime("now");
}
/////////////////////////////////////////////////////////////////////////
// Helpers //
/////////////////////////////////////////////////////////////////////////
public function syncronize($data)
{
$this->setType($data["type"]);
$this->setName($data["name"]);
$this->setUserName($data["user_name"]);
$this->setEmail($data["email"]);
$this->setPhone($data["phone"]);
$this->setCellPhone($data["cell_phone"]);
$this->setPermissions($data["permissions"]);
$this->setTimeTable($data["time_table"]);
$this->setDesktop($data["desktop"]);
$this->setBranchId($data["branch_id"]);
$this->setChatOn($data["chat_on"]);
}
public function toArray()
{
$data["id"] = $this->getId();
$data["type"] = $this->getType();
$data["name"] = $this->getName();
$data["user_name"] = $this->getUserName();
$data["phone"] = $this->getPhone();
$data["cell_phone"] = $this->getCellPhone();
$data["email"] = $this->getEmail();
$data["password"] = $this->getPassword();
$data["permissions"] = $this->getPermissions();
$data["time_table"] = $this->getTimeTable();
$data["desktop"] = $this->getDesktop();
$data["branch_id"] = $this->getBranchId();
$data["chat_on"] = $this->getChatOn();
$data["created_at"] = $this->getCreatedAt();
$data["updated_at"] = $this->getUpdatedAt();
return $data;
}
}
Why getDocComment doe's not work with above class/entity only on server 05?
Continue....
Solved:
Wrong:
<?php
/** #Entity
* #HasLifecycleCallbacks
* #Table(name="user")
*/
namespace Entity;
use Validation;
use \DateTime;
use \LogHelper;
Right:
<?php
namespace Entity;
use Validation;
use \DateTime;
use \LogHelper;
/** #Entity
* #HasLifecycleCallbacks
* #Table(name="user")
*/
But on php 5.3.8 Wrong is Right, occurs only on php 5.3.10!!