Symfony 2 - create a form with a parent entity filtering the options of the child entity - html

I am new to symfony and PHP.
I have a problem that I hope someone can help:
supose we have 3 entities.
Groups, specialities, works; works belong to a speciality, speciality belong to a group.
Supose that I want to have a form to create a "work". I want to filter my specialities according to a select with the list of groups ( much like on a travel site where we get the destinations filtered by the origin).
So my form will only have 2 fields. The speciality and a name for the work. But in my view i must have 3 fields, 1 for groups that will filter the specialities and the fields belonging to the form.
Much like a booking flights site I must see the fields from the begining.
This as to be so simple, but I'm really stuck on it.
Thank you

At this moment I can come up with 2 solutions:
1) Use ajax.
On the request populate a selectbox with the groups. when you select one of the groups, all the specialities come into a different selectbox of that group.
2)
Use uri segments. Let the user first choose group, then go to a next page and let them choose a speciality. After that the user gets a form where he fills in the data.

Related

Repeatable Multi-Colum Data Rows in Wordpress Custom Post Type

I'm moving a sports website from .asp to wordpress.
I have two custom post types:
Players
Tournaments
I need to be able to enter scores into the tournaments for players from the player post type.
The scoring tablulation is as follows:
Player ID First Name Last Name City State Points Place Scores
And I need to be able to add more rows, selecting the players to add the above info for.
The current ASP tables look like this, for each tournament:
And I need to be able to add unlimited rows (repeater).
It would be easy if it was just one column, I could use something like Advanced Custom Fields repeater field, but I do not know how to add rows of related multi-column data, which I can then query and display on the front-end.
Also, I would make each scoring row it's own post, but it would be waaay too many posts.
What I want, is for each tournament (stored in the tournaments CPT), to be able to add the scoring rows there, selecting the player from the player post type, and filling out the columns, as seen, with the ability to add as many rows as there are players for each tournament.
Thank you for your help follow programmers! I've been doing this a fairly long time, but this is a new use-case for me.
You can use Meta Box Group plugin. It allows you to create repeatable group of fields.
So, in your situation, you need to create a group of player (post field), first name, last name, city, state, points, place, score. Then make the whole group repeatable. (In Meta Box, it uses another term clone).

Access Form Wizard for Two Simple Subforms

In Access 2013, I can't use the Form Wizard to add two subforms. Well, the wizard, to be exact, skips the 'choose the main form' step, and upon completion fails to display the main form, only the header. I've replicated this on another computer.
For example, see 3 tables...
First called 'Users' with an ID (PK) and a 'Full name' field.
Second called 'Music' with an ID(PK), a UserID(Number) and 'Song' field.
Third called 'Movies' with an ID(PK), a UserID(Number) and a 'Movie' field.
The relationships are linking the ID of the Users table to UserID of the Music and Movies tables. All very simple. Distilled to its most simple form.
I use the Form Wizard to add 2 fields to show the 'Full Name' of the Users table and the 'Song' field of the Music table, then all is well, and the wizard produces a workable, if unsightly, Form.
Adding the 'Movie' field on top of the 'Song' field (accessing two other linked tables instead of one) means that the next step, choosing the main form, is skipped and the resulting form is empty is User mode but shows fields (no subforms) in Design mode.
Is this a bug in Access or I'm doing it wrong?
Thank you for you time.
Here's a link to some screenshots and database I made for you (It's a OneDrive shared folder). http://1drv.ms/1yrZyvt
Your problem is exclusively by relation between tables.
You connect USERS to MUSIC and MOVIES for 1 to 1, in this case you need almost one register to see information... and can't add any new in one of other tables.
If you modify the relation and main select of the form, the you can run normally.
Put this on the form and you can see that run perfect:
SELECT Users.FullName, Music.Song, Movies.Movie
FROM (Users LEFT JOIN Music ON Users.[ID] = Music.[UserID]) LEFT JOIN Movies ON Users.[ID] = Movies.[UserID];
Some help for this configuration:
Do relationship on tool.. not on every form. It's more easy to maintain
Do always relations based on main registry (normally 1 to many)
When insert any form into another, you can decide how to see and which field maintain the relation between.
Good luck

Using ActiveRecord to achieve complex relations in Rails

From another question of mine:
What I need to achieve is this: Create multiple categories with their
own designated information fields (ie. Cars have different fields from
Pets) and once such a category is created, the commands I need will be
invoked and a new table for each category will be made. I know I could
store all fields as some sort of string and then process it to display
it properly, but I need a advanced search function for my web app and
creating separate tables for each category seems the best way to
achieve it. I would really like to hear alternatives for this
So I have this situation where I need categories to hold all input fields needed for that certain category. So in administration I'd have this form where I'd be able to add the category name, some other relevant information to the category itself, and then these fields that would collect information on what HTML fields to present to the user when making an entry to this certain category.
For example this would be a Dog category:
Category name: Dog
Category enabled: 1
Category parent: Pets
Fields:
Title - text field (will be auto added to each category)
Breed - select field
Age - number field
Color - text field
Price - number field (will be auto added to each category)
Description - text area field (will be auto added to each category)
So now at this stage when the user created all these certain fields for the Dog category, Im having trouble figuring what would happen when the user hits the submit button to save this category. I thought of these two solutions:
Create a new model/table for each new category (Read linked question above) with all the HTML fields as columns and also store a row on the categories table with some basic info about this category
Store everything in the categories table and have a fields_json column which will store all HTML field information (I wont be actually storing HTML, but basic info what the fields are about then create the HTML form fields dynamically in a controller) as a JSON string. I would be able to present the fields nicely on create, but on update it would be a hassle to populate those fields (maybe) and a search function would not be very efficient with this alternative.
So what I'm looking for is a third alternative so I can fix my problem. What would be an efficient way to solve this problem and be able to have categories with different input fields and also be able to efficiently perform searches on these categories?
The project I'm working on is being created in Ruby on Rails 4 and the database is in MySQL.
For given scenario I would:
create table categories to store each category
create table category_fields to store each category field
create table collected_categories to store all collected data from category fields in serialized hash
Collected data can be easily (de)serialized into text column (no matter of db engine you will use).
Check those sources which utilize your problem: dynamic forms

How to eliminate database table row duplication

I have a question on databases and how information is displayed in regards to Primary and Foreign keys.
For example, there are three tables; Employees, Employee_tickets and Employee_comments.
Each employeecan have multiple tickets and also multiple comments. A foreign key is placed in the Employee tickets and Employee Comments table. My application is built in vb.net with Visual Studio and it is a desktop application. How can I query say.. Employee Name ('Jon Doe') and display all of his tickets in a grid as well as all of the comments people have made on him over time? I have created a View on the sql database which returns all of the information I require but for each ticket listed under ('Jon Doe') the View displays and Employee Name for every single ticket. Is there a way to display the employee name only once and then every ticket listed under that particular individual without displaying the Employee Name again or do I have to make Separate windows to segregate all of this?
This seems like a really dumb question and I cannot for the life of me figure out how to correctly display what is required in this situation.
Here is an example of what I am trying to explain:
So for troy there is one employee name entered in the Employee Names table, There is one CWB ticket entered in the CWB table but there are TWO PQ Cards entered in the PQR Ticket table. How Can I Display only one row for Troy and one Row for his CWB because there are only one of each entered in the tables then the two rows for the PQR Cards under his name?
I have created a view which gathers this information all into the one single view itself then bound the datagridview's to this View.
Your problem has nothing to do with databases. Rather, the issue is that you have an entity (the employee) that has two separate collections associated with it (tickets and comments) and you want to show the contents of both collections.
Doing this in a datagrid is difficult because in its simplest incarnation it's intended to show one collection of like items.
I can think of a number of possibilities:
In your code, convert each collection to a single string value and display that single string value on the row with the employee's name. This conversion could be to comma-separate a stringified version of each item in the collection (as suggested by BS123 in the comments) or could simply be a summary (eg "5 Tickets").
Put the basic employee information in one data grid and then have two additional data grids below it, one bound to the Tickets collection and one to the Comments collection.
Embed data grids directly in the main data grid, one in the Tickets column and one in the Comments column, and bind each one to the appropriate collection in the employee.
Your database structure is correct so don't change that, you simply need to solve the issue of presentation.
What you're missing here is a controller between your view and your model. Your view is presenting exactly what it was given to present - it's up to you to format it.
There are several possible solutions to this, and the correct one partially depends on needs and infrastructure.
If you infrastructure is solid and your needs are near real time, consider dropping separately querying to fill your second and third tables based on what is picked in the first. This will increase the load on the database, but your data will almost always be correct, and the data will come from the database the way you want to see it.
If the database-centered solution is not good for you, LINQ provides some good ways to filter your data into typed collections that would present exactly what you want the user to see.
To get the users:
Dim users = From l In data.lines
Group By FirstName = l.firstName, LastName = l.lastName
Into Tickets = Group, Count()
You can then present this object to your grid. While dynamic typing works here, I think it would be easier to manage view interactions with defined classes. I'll leave that part up to you. Do some searching on LINQ to fill in the rest of the blanks. It's pretty neat stuff.

MS Access. Editable Selection. Grouping of Items based on data other than primary key

I hope I can explain this clearly. I have a table, lets call it Widgets, that contains information (Color, Size, etc) about many many different widgets that are specified by an ID# which is the primary key. I also have a table, call it Tests, that is related to Widgets through a one to many relationship. Each row in this table represents a test on a particular widget and has information like WidgetID, Date, Info1, Info2, etc. Each WidgetID may have multiple tests in the table Tests. What I'm doing with these is simply displaying various reports that contain data from both tables based on various queryies. I do not have write privileges to either of these two tables.
Ok now that that is set up here is what I want to do. I'd like to set up a new table that contains a correlation between the Color of a widget and a new piece of data that I'll call Group. In short, I'd like to be able to define "Groups" of widgets where all the blue, green, and red widgets would be in one group and all of the yellow and orange widgets in another group, etc. (there is no overlap...ie each color correpsonds to only one group) I also want to set up forms that allow the user to add a Group and define which colors go in it, delete a Group, or edit a Group (truthfully add and delete would be enough).
What is the best way to do this? I'm not necessarily looking for code, but more so just direction. The best situation would be if each widget had a column in the Widgets table that contained the Groups data, but I do not have write access and neither will the users and I would like to make the Group data editable by the user.
It should be simple enough to set up a table:
Colour
Group
Users add data via a form by selecting the colour from the list and either entering a new or existing group. The whole thing should be possible without any coding, only wizards.
The new table is then joined to widgets on colour to create the various reports that you require.
EDIT re Comments
How you set up the table depends on the results you want returned, let us say that only the colours that are in groups are included, and we have this SQL to join to the widgets table:
SELECT WidgetID, GroupID FROM Widgets
INNER JOIN GroupColour
ON Widgets.Colour=GroupColour.Colour
Only the widgets that have a colour that is listed in the GroupColour table will be included in the listing, this is because of INNER JOIN. If the SQL was:
SELECT WidgetID, GroupID FROM Widgets
LEFT JOIN GroupColour
ON Widgets.Colour=GroupColour.Colour
You would get all widgets returned, but a Null for GroupID when there was no match in GroupColour. This can be quite useful.
You may wish to read http://www.devshed.com/c/a/MySQL/Understanding-SQL-Joins/, which is about MySQL, but works quite well for Jet SQL.