Welcome Guest, Not a member yet? Register   Sign In
Big website(transferring it from procedural to codeigniter(mvc) )
#1

[eluser]FinalDestiny[/eluser]
Ok guys, it is going to be a long story, I hope you have some time to read everything.

Ok, I have a website ..almost similar to football competitions like Europa league/ Champions league, etc. I think almost everyone knows how they work. Let's say 8 groups with 4 teams / group, a total of 32 teams. From every group, after they play every match, the first two teams with the most points go forward in the next phase. So we'll have 2 teams x 8 groups = 16 teams in the next phase. We'll split them 1vs1. From those 16 teams, only 8 will go forward, the winners.
We'll have Quarterfinals now. Again, we make a 1vs1 and we'll have semifinals with 4 teams. The last 2 teams will play the final and the winner takes the competition.

This is the way my website works, but with some minor changes: Instead of groups and then elimination tournament, I have 2 more ways a championship can run: ladders and simple championship.

1) The Ladder.

Let's say we have 32 teams. We split them into 16 matches, 1vs1. The winners are going to the next phase where we'll have 8 matches and 16 teams. Again, we go to quarterfinals, semifinals and final and the winner takes the competition. So it's almost the same as the groups -> elimination phases. You can see one example here: http://upload.wikimedia.org/wikipedia/co...-large.png

2) Simple championship.

Almost everyone knows ..Let's say.... England - Premier League. There are 20 teams(Chelsea, Liverpool, Man.United, etc etc). Okay, in this one we don't have any elimination stuff, we have only the 20 teams. Each one will have 19 matches(every team plays with all the other teams). 19 because the team can't play with the same team. Chelsea can't play with Chelsea, for example..obviously.

So after all the matches are played ( we'll have 19 matches x 20 teams), we make a classification and the team with most points( win match = 3 points, draw = 1 point and lost match means 0 points) wins the competition.

Some examples for every competition types:

1) Simple competition and after that single-elimination tournament: http://ecupe.ro/cupe/ceva-special-605/meciuri
2) Championship: http://ecupe.ro/cupe/campionatul-spaniei-227/meciuri
3) Ladder 1vs1 http://ecupe.ro/cupe/cupa-dedicata-lui-m...01/meciuri

Pretty easy, right? We have 3 ways of competitions, but all 3 have many things in common: title, players, etc.

In the case of groups, we have title, players and groups. But, if we have ladder, we don't need the groups anymore, we need only the players. Same with the championships..basically we have only one group and X teams that will play with all the other teams.


The website is ready, but it's created using procedural PHP, so I created so many files with thousands of line codes, repeating in many files.

BUT, THE MOST IMPORTANT THING: ITS NOT ABOUT REAL FOOTBALL TEAMS OR SOMETHING ,THAT WAS JUST AN EXAMPLE. THE WEBSITE IS CREATED FOR GAMERS(FIFA, CHESS, BACKGAMMON, ETC SO WE'LL DO THE SAME COMPETITIONS USING REAL PLAYERS AND GAMES)

So basically let's say..Each competition has one status: The status can be "waiting"(one administrator must approve it before the players start to register), "signup"(the competition was approved and the players can signup), "running"(all the players registered and we created the matches), "finished"(all the matches were played and we have a winner now, so the competition is marked as finished), "rejected"(the competition was rejected by one administrator, that means no players, no infos, nothing more to do), and "deleted"(same as rejected).

So, for every competition I'll have different pages:

- the basic informations page where I'll show the details: when the competition was submitted, the one who added it, the game, the number of players registered(if its in the signup status), etc.

For example, if we have a competition in the deleted status, we don't want to show the number of registered players, of course. That's useless. But if the competition is in the signup status, we have to show it. Right now I use a PHP switch and show the details based on different cases. But it's too much code. OOP is meant to simplify the work and I think I can do it in a different way, but I never worked with OOP.

I'll have a ,,results" page, a classification page, etc. But in the results page I want to show different stuff based on status. If the status is finished, we may want to show the winner of the competition. But in the ,,running" status we don't want to show the winner, cause we don't have one, yet. Or, in the running status we may want to show ,,Started on 03-01-2010 14:20". Of course, if the competition is finished, we want to show "Finished on 03-01-2010 16:40" instead of "started on". Again, I'm using the "switch"
option from PHP.

But I want to write as less code as possible, if there's a easier way to do all this stuff, please help me. I really need help.
#2

[eluser]Nick_MyShuitings[/eluser]
Refactoring is an interesting process, and there are tools that will help you like a good IDE. You need to see how many times you are repeating specific functions in various areas of the page. Those would be good candidates for a custom library in the codeigniter modality. From there you want to grab a sitemap, and on first glance you can count on one controller for each unique area of your sitemap. Etc, etc.

Refactoring is important, but remember that sometimes its almost easier just to start from scratch using the knowledge and logic that you defined in the initial prototype version.




Theme © iAndrew 2016 - Forum software by © MyBB