|[Symfony2] Finding the best object organization|
I need some help to elaborate my project
| 7:27 pm on Feb 24, 2014 (gmt 0)|
I'm struggling with a personal project for some months. It is very simple, really. But when it's time to choose the objects I will use, it's very complicated. I can't get through.
What is the project: You sign in and you find a table of 100 cells (from 0 to 99. This will never change). In every cell, there are several words (every word can only belong to one cell). These words are the same for every user. The user can choose a word by cell (among the available words) and finally create a customized table. The available words are the same for all, but everyone can do a personal combination and save it.. In addition, a user can propose to the admin a word to integrate in a cell.
The problem: As you can see, my project is very simple. But I'm really struggling about the structure of objects. I tried many times to find something correct (sometimes with help on IRC), but I never found something fitting to my expectations. I know I must have a User and a Word entities. But for the rest, I'm not with it.
For now, I have a User, a Word and a Number (for the cell) entities. No Table entity or something. But I must refound my code totally because I get an alarming number of database queries on some pages (202). So the form to edit the custom table is not a formType based on an object, but something very dirty made of custom queries. All the words are saved by iteration, in every cell. It's very dirty, unmanageable, and very VERY slow. Then I must completely refound my code and I'm looking for a clean and relatively efficient solution.
Some precise difficulties:
- Should I create a Number entity or should I only create an int attribute in Word entity? Using an entity wouldn't be more logical given that they are always the same 100 numbers? Besides, every number has explanations ont the type of words it contains. So I made a $rules attribute (type="text") in the entity Number. If I don't have a Number entity anymore, where should I put the rules about them? In a Rules entity with an int $number attribute?
- Should I create a Table entity or should I simply stock the chosen words in a $words attribute of the User, with validation (and removing if so) that there is no word already for cell, all this done in the controller ?
- Someone proposed me to hash and serialize the table. However, shouldn't I avoid doing this, given that the words can be edited or removed?
- How to do the form editing the table? For now, I did it in a dirty way, directly in the controller (yum). Should I do a form collection or one big form? Will my formType be based on a class (WordType?) or will it have a null data_class ?
Here are the questions I wonder and the difficulties I am confronted with. If you have some ideas...
Thank you very much in advance :)
| 4:13 am on Feb 26, 2014 (gmt 0)|
Hey there. If I understood correctly your project is really simple but I don't really get it on why you choose SF2 to get around doing it. Personal project? you can choose a better tool for it, unless is some homework on SF. While I "got it" I still have doubts on your explanation:
|What is the project: You sign in and you find a table of 100 cells (from 0 to 99. This will never change). In every cell, there are several words (every word can only belong to one cell). These words are the same for every user. |
A cell is a single piece of a table located in specific column and row. I mean you say 100 cells, but how and where? you can have cell 0 to 99 on a single row right? or you can have the same amount of cells on several combinations of rows and columns, right?
|The user can choose a word by cell (among the available words) and finally create a customized table. The available words are the same for all, but everyone can do a personal combination and save it.. In addition, a user can propose to the admin a word to integrate in a cell. |
One word per cell? the easier solution would be a cell matrix, table style just like excel (rows and columns, letters and numbers), basically X/Y coordinates. Same table with same words for everyone? let them toggle select by any JS trick or just cookie playing to build the list with your front end / back end and save the coordinates as a list on a table/database. You could do that with CSV file and PHP or better: PERL. From where I'm standing is piece of cake.
Symfony? I've been playing with the framework, I don't really see how you can get around simple table positions like previous example unless you just use the table to store it and then display it playing around with JS again. I'm not an expert SF user but my knowledge leads me to where you are: too complex, more trouble than needed. What I mean is SF is a framework, nice/ugly useful/not so useful depending on the task, but as a framework it is good and strong on what it was built to do, it is not a language, that's why it sounds a lot easier to do with Perl alone or PHP.
Right now I'm just thinking about how many files I would use to build that in Perl:
1 file for the table (CSV)
1 login file script self sustained
1 file to show the data with all the JS and stuff
1 file per user to save the data OR better, one file for all the data
That's 4 files, not even 50K.
Now when I think about SF... that would be lots and lots of files, configs, routes, yml, classes and don't forget the SF cache... easy like 3K files weighting like 5MB on the cheap, am I right?
| 4:16 am on Feb 26, 2014 (gmt 0)|
|If you have some ideas... |
Unless SF has any way to tell you the position of the record on the database... I would use a crud for creating the matrix of row/column/DATA x 100, then display it to the user parsing the data properly to build a matrix with some JS enable, fairly easy.
Then toggle select with JS to build the list using a cookie and showing a button "SAVE" to save the data on a record, one row on the database. Doing it by user per user that's 20 more cents.