Created
March 22, 2013 15:17
-
-
Save alihammad-gist/5222060 to your computer and use it in GitHub Desktop.
usermanagerideas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
create user management table | |
users | |
-uid | |
-username | |
-password | |
editors | |
-id | |
-uid | |
-module [team, players] | |
-entityid [0=any, non-zero = specific entity] | |
*/ | |
DB::statement(" | |
CREATE TABLE `users` ( | |
id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, | |
name VARCHAR(40), | |
password VARCHAR(100), | |
email VARCHAR(100) | |
)ENGINE=INNODB; | |
"); | |
DB::statement(" | |
CREATE TABLE `editors` ( | |
id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, | |
uid MEDIUMINT UNSIGNED, | |
module TINYINT(1), | |
entityId MEDIUMINT, | |
FOREIGN KEY `fk_uid_userid` REFERENCES users (`id`) | |
)ENGINE=INNODB; | |
"); | |
//model users has this method | |
// $id = player's id | |
public function canEditPlayer($id) { | |
$this->editors()->where('module', MODULE_PLAYER_ID)->andWhere('entityID', $id) | |
->orWhere('entityId', 0); | |
} | |
public function canEditTeam($id) { | |
$this->editors()->where('module', MODULE_TEAM_ID)->andWhere('entityId', $id) | |
->orWhere('entityId', 0); | |
} | |
public function canEditAllPlayers() { | |
$this->editors()->where('module', MODULE_PLAYER_ID)->andWhere('entityId', 0); | |
} | |
public function canEditAllTeams() { | |
$this->editors()->where('module', MODULE_TEAM_ID)->andWhere('entityId', 0); | |
} | |
public function getEditablePlayers($limit) { | |
return $this->editors()->where('module', MODULE_PLAYER_ID); | |
} | |
public function getEditableTeams($limit) { | |
return $this->editors()->where('module', MODULE_TEAM_ID); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment