Hi all,
I need help to structure my application. The main question is how to structure the Yii to work with users.
I have a table nested set that perfectly meets my model
Company 01
[indent]User 01
User 02
User 03[/indent]
Company 02
[indent]User 04
User 05
User 06[/indent]
Franchisee 01
[indent]Company 03
User 07
User 08
User 09[/indent]
CREATE TABLE `usuario` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(200) NOT NULL DEFAULT '',
`login` varchar(20) NOT NULL DEFAULT '',
`senha` varchar(20) NOT NULL DEFAULT '',
`email` varchar(50) NOT NULL DEFAULT '',
`inclusao` datetime NOT NULL,
`modificacao` datetime NOT NULL,
`ativo` tinyint(1) NOT NULL,
`expira` int(11) NOT NULL,
`grupo_id` int(11) NOT NULL,
`lft` int(11) NOT NULL,
`rgt` int(11) NOT NULL,
`level` int(11) NOT NULL,
`root` int(11) NOT NULL,
`key` int(11) DEFAULT NULL,
`tentativa` int(11) DEFAULT NULL,
`data_tentativa` datetime DEFAULT NULL,
`rememberMe` tinyint(1) DEFAULT NULL,
`id_antigo` int(11) DEFAULT NULL,
`id_cliente` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`login`),
UNIQUE KEY `email` (`email`),
KEY `u_grupo_id` (`grupo_id`),
CONSTRAINT `u_grupo_id` FOREIGN KEY (`grupo_id`) REFERENCES `UsuarioGrupo` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=6699 DEFAULT CHARSET=utf8;
That way I can create a tree where all users have a login / password and are organized into groups. Each of these users has a grupoId that identifies which type it is (ex company, Franchisee, vendor, basic, super administrator, etc.) and each type is associated with a ROLE (used the auth) establishing rules for access to the system.
The idea is that when an user Company logins, he will only see menu items corresponding to him.
All the users, except for the Basic, have the right to create other users who will be grouped under its own id.
Assuming a user Franchisee is logged, he will only see the permitted buttons and one of them is create users. These users may be Companies, which in turn may be associated with other Basic users. In the case of Companies, the button users will also be visible, but she can only create Basic users.
Now comes my doubt …
All these interactions are made in the same table, users, who already have a Model that lists all the content (the case of the Super Admin). I’m having trouble understanding how I will do that only with the franchisees can view, create, edit and delete users Child, or Enterprise with users that follow the same logic.
I do not know if I create a model / view / controller for each of the types of users, and every time inventing a new type, ride the same scheme.
In this case it would be this madness
Models
FranchiseeUser
CompanyUser
SuperadminUser
…
Controllers
FranchiseeUserController
CompanyUserController
SuperadminUserController
…
Views
FranchiseeUser
CompanyUser
superadminUser
…
Now imagine this logic extended to my other tables (statistics, movies, categories, etc.). If each one of my models I have to make a version for each of the types of users, that application will be huge!
Another possibility would be to create views for each type of users which will significantly reduce the volume. Or use if (User_tipo == ‘Franchisee’) {- FRANCHISEE OF COD -} elseif (…) {…} in views.
The point is, when you have different types of interaction, viewing filtered data and can do certain things, with different forms, how we structure this in Yii?
Thank you