Symfony2 Form generation collection - forms

I've started my learning of Symfony 2 a few days ago and I have a problem concerning a form :
I wish to have a webpage on which a teacher could edit the marks obtained by a student to his homeworks. Of course, I have Student, Homework and Mark entities. This last one is the owner of 2 ManyToOne relations with the two first entities.
The basic solution is to create a form for each homework. But on the long term, there will have too much forms on the same page. And by the way, it would be too boring to have to validate each form if he has to change a lot of values.
I think that I have to deal with a field with the type collection but I don't know how to exploit it :
How can I get the homework list (in order to generate a corresponding Mark form) ? And where to implement this task?
How to access to the homework entity's attributes from the view ? For example, to print the homework's dueDate.
Thank's a lot for your answers!

Related

Microsoft Master Data Services 2016 Additonal Domain Atrribute Referencing

Is it possible to reference additional columns apart from the 'Code' and 'Name' columns when using a domain attribute in an entity?
E.g. A person entity has a code of '1' and a name of 'Smith' and a Gender of 'Male'
In a customer entity there is a domain value referencing the person entity which displays the following 1 {Smith}. The users would like an additional read only attribute which would copy the Gender value of 'Male' into the customer entity based on the domain value. Can this be done using out of the box MDS UI?
I know this is duplicate data and breaks normal form but for usability this would be useful. It would be the equivalent of referencing additional columns in an MS Access drop down list.
Many thanks in advance for any help
This is not possible with the standard UI. One option would be to develop a custom UI where you can handle these kind of requests.
If you want to stick with the standard product I can see a workaround but this is a bit of a "dirty" one.
You can misuse (abuse) the Name attribute of the Person entity by adding a business rule to the Person entity that generates the content of the Name attribute as a concatenation of multiple attributes. You of course need an additional attribute that serves as a place holder for the original Name. The concatenated field will then show in your customer entity.
One question that does come to mind is why a user would like/need to see the gender of a person in a customer list? As you have a separate Person entity I expect you to have multiple persons per customers. What would the gender of one person - even if it is the main contact - matter?

Foreign entity in form into different kind of input

I have two entities: product and category (Symfony 2.3).
I want to create a form in which an user can choose a product by first selecting the category. A user selects the category by clicking on image, then I want to set the image's value into a hidden input, but I don't see how can I change a foreign entity choice list to a hidden input (http://symfony.com/doc/current/reference/forms/types/entity.html).
How can I accomplish this? (how to change form input to hidden)
If I set cascade validation to true, will it for example check if a category really exist. (To prevent putting products with non-existing category from malicious users) ?
Part 1
To do this you need to use a data transformer to do two things:
transform an entity into an identifier that is either a string or integer so a form can render it as a hidden field.
transform the string or integer identifier into the entity when the form is submitted so that the parent entity can be saved with the correct relationship
The symfony docs I linked to above (here too) actually walk though an entire example of using a data transformer with a form.
As a shameless plug (because I believe it is helpful) I have written a little tutorial on using a data transformer for a hidden field with an entity id: http://lrotherfield.com/blog/symfony2-forms-entity-as-hidden-field/
Part 2
If you are using the data transformer then you don't need to worry about malicious users. The data transformer will fail because it will not be able to reverse transform the category from the fake id. In my tutorial the transformer will throw a Symfony\Component\Form\Exception\TransformationFailedException exception.
You can also write a validator (potentially using a call back) if you wanted that checks that the submitted category is real if you want an error to show in the form. Doctrine wont allow you to persist a fake category relationship as the foreign key constraint will fail.

show many to many relationship field label in symfony2

I have an entity News bound to an entity Company with a many to many relationship.
Such relationship is set in a form through an entity field where I can select companies tied to my news.
Everything works fine except that company ids are showed as labels.
Is there a way to force another and more meaningful table field is showed as a label?
Have look at entity form field type reference. Specifically property option.
http://symfony.com/doc/current/reference/forms/types/entity.html#property

WPF data binding using ADO.NET Entity Framework 4

Good Morning All,
I'm having a small conceptual problem with ADO.NET EF4 (and perhaps ORM in general) and I was hoping someone could help fill in the gaps in my knowledge.
In my example I have a normalised Database with two Tables: User & Company
User //
UserId(PK),
CompanyId(FK),
FirstName,
LastName
Company //
CompanyId(PK),
CompanyName
I have created an Entity Data Model to match these tables in my application.
I now need to display a list of Users along with their Company Name in a listbox control. I realise I can display a list of Users using:
DatabaseEntities db = new DatabaseEntities();
Listbox1.ItemSource = db.Users;
Obviously the problem here is that it will display the CompanyId field as oppose to the CompanyName.
My question is; What is the best approach to get at the CompanyName Field? Do I create a stored procedure to return a different record set? Create a new entity with the fields I require?
I can think of several approaches but I'm not sure which is best practice.
Any help is greatly appreciated!
Figured it out, i wasn't aware you could specify bindings like:
<TextBlock Grid.Column="3" Padding="10,20,0,0" Text="{Binding Company.CompanyName}"/>

Can't insert entries of a many-to-many relationship in Entity Framework in a specific order

I have a many-to-many relationship between 2 entities in Entity Framework, like here . So, Employees and Projects. At one point, I would like to insert some Projects to a Employees entity in a specific order. By conserving the order I would like to know which was the first preference of the Employees for a Projects entity. The thing is that although I order the Student.Projectslist in the way I like before the insert, when selecting Employees.Projects.FirstOrDefault(), the entities are ordered after the ProjectsId and I don't get the first element I inserted. How can I conserve the order I want?
O course, I could make a new field PreferredProjects and save the other Projects in a random order, since only the preferred one is important for me. But this is not an option, being given the context of the current project's software design.
Thank you in advance...
It sounds like you simply want to have sorted child collection results when you do a query, rather than take full control of the insert order.
You can achieve that using the techniques described in Tip 1 of my tips series.
Hope this helps.
Alex
Program Manager Entity Framework Team.
Unfortunately, there is no easy solution. I have the same problem. The only solution is to save after adding each child item (project). This is the only way to save the order without using a new field column to sort input.
Try Employees.Projects.OrderBy(x => x).FirstOrDefault()