Any IT specialist spends a significant part of his life sitting in front of a computer (hello KO!). Especially hard to those who work remotely or freelance. You don’t need to go to work, and there are days when you don’t leave the house for several days.
Wikipedia and
research suggests that you have to pay for everything. If you sit at a computer for 12-14 hours a day, by the age of 50 (or maybe even earlier) your quality of life may drop significantly.
I do not want to frighten, but the list of possible consequences really looks frightening: The solution - breaks in work and physical activity. Plus, if you work at home, and not in a team, then for a vigorous mental state it would be nice if the chosen type of physical activity is grouped and involves social interactions. But finding someone and where to play football is not such an easy task.
')

We decided to create a
site where all football, basketball, volleyball and hockey games will be collected. Try using technology to make life easier for both players and game organizers. Under Habrokat I'll talk about the essence of the project, the architecture and the technologies used.
To the players
For players, the
location of the sports ground is critical. If you have to spend an hour and a half on the way to the gym, then work on that day will not be so easy. Therefore, on the main page of the site there is a google-map with game location markers and their list. The list of games is sorted by date.

Search for games is conducted by sports and on the edges of the map viewport. Viewport - the visible area of ​​the google maps map. Now only pre-moderated games are displayed in the search, for which the Trusted flag is set in the database.
Equally important is the
level of players . If you are good at playing, it will not be interesting with newbies. In your profile, you can set the level of the game from 1 to 10, for each game indicated the estimated level, so you can navigate.

To the organizers
For organizers, the main problem is those who
declare and do not come . We give the organizer the opportunity to collect prepayment for the hall from the players. She is a guarantee that the person will come. If the player decides earlier than 12 hours before the game to refuse to participate, then the prepayment is returned to his account. If there are less than 12 hours left before the game, the prepayment leaves the organizer.
The organizer has a personal account with a list of his games, marked by status. In addition, the organizer sees a list of players who viewed the game's payment page, but encountered some problems and did not pay.

Game statuses
Depending on the three main parameters, the game has a number of states. Each parameter takes one of three values:

The organizer creates a recurring series of games:

Every day, based on the records of the created repetitive game series, games are created for a week ahead by cron. The Stripe.com payment system used by us can keep money in uncaptured status for only 7 days, after which it either makes a refund or seizes money. Therefore, we do not immediately create games for the long term.
The newly created game has statuses:
MONEY_NOT_YET - as long as we have not made a request for refund or capture of prepaid money
LESS_THEN_MIN_PLAYERS - until the minimum number of players has reached
BEFORE_LOCKPERIOD - there are still more than 12 hours left to play
If the organizer has indicated that the game will take place, with at least 8 players enrolling, then as soon as 8 players are recruited, LESS_THEN_MIN_PLAYERS changes to ALREADY_MIN_NOT_MAX_PLAYERS
The next important stage is the onset of lockperiod 12 hours before the start of the game. If at this moment we have the status ALREADY_MIN_NOT_MAX_PLAYERS or MAX_PLAYERS, then the game will take place, send stripe.com a request for capture of prepayments, and the game changes its status to: CAPTURED, ALREADY_MIN_NOT_MAX_PLAYERS, LOCKPERIOD. In the opposite case - we do refund and send notifications by SMS and mail that the game will not take place.
Subscriptions
The main thing is to overcome laziness and practice regularly. To do this, we have added the possibility of buying subscriptions - bought and not wriggle out. You play regularly - higher efficiency at work, and the joy in life will be much more, not up to depression.
Subscriptions make each lesson for players cheaper, and the games of the organizers are more stable.
The database stores the cost of N games for a specific series of games. If a player buys a subscription for 8 games starting on Tuesday, then we record it in the database on Tuesday, marking that he still has 8-1 = 7 games. We are looking for the next game in this series, if there is one, then we write it down and mark that it still has 7-1 = 6 games and so on.
When creating a new game of this series using cron, we are looking for subscription records in the last game. If they are, then we transfer them to a new game, reducing by one the player’s remaining number of games.
Chat
So that the players could find out the details, and the organizer could answer their questions with minimal effort, it was necessary to make an internal messaging system. Honestly, the chat is still unstable (as well as some other features), but it allows us to solve the problems of users, and we can deal with its instability.

Implemented fairly trivial, all the functionality in php, as the data warehouse uses a database. To speed up the work applied cache. The cache works as follows: when creating new messages and rooms, other users except the author himself write an entry about the new event in the cache. This allows us once again not to pull the database to receive new events for the user.
In the frontend, too, everything is simple - ajax requests for rooms, sending messages and other things. At a certain time interval, a request is made to the “observer” script, which notifies of new messages. In the future, the chat will most likely use the node.js interlayer.
Technology and architecture
It so happened that the very first version of
Topika was written on Livestreet cms. This was the legacy of our previous project, a fairly large blog site. The basic hypothesis was easier to test while continuing to develop on Livestreet.
But Livestreet is sharpened for completely different tasks and the development speed left much to be desired, the development of new features took considerable time. Therefore, as soon as we realized that the project was flying slowly, we decided to switch to something more suitable.
The choice fell on Yii2. Development using the namespace and all the buns of php 5.4 is much more efficient and interesting. The alpha version of the framework has its drawbacks and risks, you need to constantly be aware of changes in api, sometimes rewriting some parts of the code when refactoring the framework. But we were well aware of these risks and decided to make a choice in favor of performance and interesting development.
As a basis for the application, the
advanced application template is used . Split into 4 main parts of the site, frontend, admin, console and api. The template has a common base namespace. In his folder are models with minimal functionality for use in parts of the application, basic modules, components and extensions. It also stores the basic configuration of the entire site, common to all parts.
Almost all the functionality is divided into modules, this is a very common practice, but if the module requires its own unique functionality of the basic models and components, they are expanded in the context of the module.
As a test, the unit and acceptance tests are used in the codeception environment through the layer-extension yii2 - to correctly reproduce the framework environment, work with fixtures, and so on. You can read more about testing in yii2
here and
here . In general, the framework already has a very detailed, although in some places, inaccurate
documentation on the basic API.
Feedback
We recently started working on this concept, much more needs to be done and polished, but there is already a positive feedback from users and the first revenue.
I want to ask the distinguished community to express my opinion, what would you like to have in such a service? What obstacles can stop you from organizing your game / from joining such a game? And what can push?
I urge everyone to try to
add a platform near their home and try
to assemble the game already for this weekend, and we will do our best to help. We will be very happy if it is possible to revive the good tradition of
habrafutbola .
UPD Dmitry is up to Habrobasketball in St. Petersburg. Who wants to join - write to him or me in a personal
UPD2 Habrabetballball / habrafootball / habravoleball is planned in Voronezh, write to
Andrey