diff --git a/src/Pluf.php b/src/Pluf.php index 2b3a1ee..29e93f7 100644 --- a/src/Pluf.php +++ b/src/Pluf.php @@ -91,7 +91,7 @@ class Pluf } foreach ($apps as $app) { $m = require $app.'/relations.php'; - $GLOBALS['_PX_models'] = array_merge($m, $GLOBALS['_PX_models']); + $GLOBALS['_PX_models'] = array_merge_recursive($m, $GLOBALS['_PX_models']); } // $GLOBALS['_PX_signal'] is automatically set by the require // statement and possibly in the configuration file. diff --git a/src/Pluf/Auth/LdapBackend.php b/src/Pluf/Auth/LdapBackend.php index d58b972..5349082 100644 --- a/src/Pluf/Auth/LdapBackend.php +++ b/src/Pluf/Auth/LdapBackend.php @@ -35,8 +35,9 @@ class Pluf_Auth_LdapBackend */ public static function getUser($user_id) { + $user_model = Pluf::f('pluf_custom_user','Pluf_User'); $sql = new Pluf_SQL('login=%s', array($user_id)); - return Pluf::factory('Pluf_User')->getOne($sql->gen()); + return Pluf::factory($user_model)->getOne($sql->gen()); } /** @@ -123,7 +124,8 @@ class Pluf_Auth_LdapBackend } // Need to create it ldap_close($ldap); - $user = new Pluf_User(); + $user_model = Pluf::f('pluf_custom_user','Pluf_User'); + $user = new $user_model(); $user->active = true; $user->login = $login; $user->password = $password; diff --git a/src/Pluf/Auth/ModelBackend.php b/src/Pluf/Auth/ModelBackend.php index 4205a00..03819fa 100644 --- a/src/Pluf/Auth/ModelBackend.php +++ b/src/Pluf/Auth/ModelBackend.php @@ -33,8 +33,9 @@ class Pluf_Auth_ModelBackend */ public static function getUser($user_id) { + $user_model = Pluf::f('pluf_custom_user','Pluf_User'); $sql = new Pluf_SQL('login=%s', array($user_id)); - return Pluf::factory('Pluf_User')->getOne($sql->gen()); + return Pluf::factory($user_model)->getOne($sql->gen()); } /** diff --git a/src/Pluf/Group.php b/src/Pluf/Group.php index 65c3731..63fa776 100644 --- a/src/Pluf/Group.php +++ b/src/Pluf/Group.php @@ -59,6 +59,15 @@ class Pluf_Group extends Pluf_Model 'model' => 'Pluf_Permission', ), ); + if (Pluf::f('pluf_custom_group',false)) $this->extended_init(); + } + + /** + * Hook for extended class + */ + function extended_init() + { + return; } function __toString() diff --git a/src/Pluf/Message.php b/src/Pluf/Message.php index a63214d..71a7984 100644 --- a/src/Pluf/Message.php +++ b/src/Pluf/Message.php @@ -40,7 +40,7 @@ class Pluf_Message extends Pluf_Model 'user' => array( 'type' => 'Pluf_DB_Field_Foreignkey', - 'model' => 'Pluf_User', + 'model' => Pluf::f('pluf_custom_user','Pluf_User'), 'blank' => false, 'verbose' => __('user'), ), diff --git a/src/Pluf/Middleware/Session.php b/src/Pluf/Middleware/Session.php index 9423be6..4367a3e 100644 --- a/src/Pluf/Middleware/Session.php +++ b/src/Pluf/Middleware/Session.php @@ -46,7 +46,8 @@ class Pluf_Middleware_Session function process_request(&$request) { $session = new Pluf_Session(); - $user = new Pluf_User(); + $user_model = Pluf::f('pluf_custom_user','Pluf_User'); + $user = new $user_model(); if (!isset($request->COOKIE[$session->cookie_name])) { // No session is defined. We set an empty user and empty // session. @@ -70,7 +71,7 @@ class Pluf_Middleware_Session $set_lang = false; if (isset($data[$user->session_key])) { // We can get the corresponding user - $found_user = new Pluf_User($data[$user->session_key]); + $found_user = new $user_model($data[$user->session_key]); if ($found_user->id == $data[$user->session_key]) { // User found! $request->user = $found_user; diff --git a/src/Pluf/Migrations/5UserDetails.php b/src/Pluf/Migrations/5UserDetails.php index 15ad886..43fad26 100644 --- a/src/Pluf/Migrations/5UserDetails.php +++ b/src/Pluf/Migrations/5UserDetails.php @@ -31,7 +31,8 @@ function Pluf_Migrations_5UserDetails_up($params=null) $db->begin(); // Start a transaction try { // Add 2 new fields. - $guser = new Pluf_User(); + $user_model = Pluf::f('pluf_custom_user','Pluf_User'); + $guser = new $user_model(); $table = $guser->getSqlTable(); $sql = 'ALTER TABLE '.$table."\n" .'ADD COLUMN language VARCHAR(5) DEFAULT \'en\','."\n" @@ -49,7 +50,8 @@ function Pluf_Migrations_5UserDetails_down($params=null) $db = Pluf::db(); $db->begin(); // Start a transaction try { - $guser = new Pluf_User(); + $user_model = Pluf::f('pluf_custom_user','Pluf_User'); + $guser = new $user_model(); $table = $guser->getSqlTable(); $sql = 'ALTER TABLE '.$table."\n" .'DROP COLUMN language,'."\n" diff --git a/src/Pluf/Migrations/Backup.php b/src/Pluf/Migrations/Backup.php index a3b4f5b..6f71b88 100644 --- a/src/Pluf/Migrations/Backup.php +++ b/src/Pluf/Migrations/Backup.php @@ -35,8 +35,8 @@ function Pluf_Migrations_Backup_run($folder, $name=null) { $models = array('Pluf_DB_SchemaInfo', 'Pluf_Session', - 'Pluf_User', - 'Pluf_Group', + Pluf::f('pluf_custom_user','Pluf_User'), + Pluf::f('pluf_custom_group','Pluf_Group'), 'Pluf_Message', 'Pluf_Permission', 'Pluf_RowPermission', @@ -70,8 +70,8 @@ function Pluf_Migrations_Backup_restore($folder, $name) { $models = array('Pluf_DB_SchemaInfo', 'Pluf_Session', - 'Pluf_User', - 'Pluf_Group', + Pluf::f('pluf_custom_user','Pluf_User'), + Pluf::f('pluf_custom_group','Pluf_Group'), 'Pluf_Message', 'Pluf_Permission', 'Pluf_RowPermission', diff --git a/src/Pluf/Migrations/Install.php b/src/Pluf/Migrations/Install.php index 1482f97..b10dee0 100644 --- a/src/Pluf/Migrations/Install.php +++ b/src/Pluf/Migrations/Install.php @@ -31,8 +31,8 @@ function Pluf_Migrations_Install_setup($params=null) { $models = array('Pluf_DB_SchemaInfo', 'Pluf_Session', - 'Pluf_User', - 'Pluf_Group', + Pluf::f('pluf_custom_user','Pluf_User'), + Pluf::f('pluf_custom_group','Pluf_Group'), 'Pluf_Message', 'Pluf_Permission', 'Pluf_RowPermission', @@ -58,8 +58,8 @@ function Pluf_Migrations_Install_teardown($params=null) 'Pluf_RowPermission', 'Pluf_Permission', 'Pluf_Message', - 'Pluf_Group', - 'Pluf_User', + Pluf::f('pluf_custom_group','Pluf_Group'), + Pluf::f('pluf_custom_user','Pluf_User'), 'Pluf_Session', 'Pluf_DB_SchemaInfo', ); diff --git a/src/Pluf/Permission.php b/src/Pluf/Permission.php index 2b1e900..d5d5d6f 100644 --- a/src/Pluf/Permission.php +++ b/src/Pluf/Permission.php @@ -81,7 +81,9 @@ class Pluf_Permission extends Pluf_Model 'col' => 'application', ), ); - $t_asso = $this->_con->pfx.'pluf_group_pluf_permission_assoc'; + $hay = array(strtolower(Pluf::f('pluf_custom_group', 'Pluf_Group')), strtolower($this->_a['model'])); + sort($hay); + $t_asso = $this->_con->pfx.$hay[0].'_'.$hay[1].'_assoc'; $t_perm = $this->_con->pfx.'permissions'; $this->_a['views'] = array( 'join_group' => diff --git a/src/Pluf/User.php b/src/Pluf/User.php index 1f120f5..b4143be 100644 --- a/src/Pluf/User.php +++ b/src/Pluf/User.php @@ -93,7 +93,8 @@ class Pluf_User extends Pluf_Model array( 'type' => 'Pluf_DB_Field_Manytomany', 'blank' => true, - 'model' => 'Pluf_Group', + 'model' => Pluf::f('pluf_custom_group','Pluf_Group'), + 'relate_name' => 'users', ), 'permissions' => array( @@ -163,6 +164,15 @@ class Pluf_User extends Pluf_Model ), ); $this->_a['views'] = array(); + if (Pluf::f('pluf_custom_user',false)) $this->extended_init(); + } + + /** + * Hook for extended class + */ + function extended_init() + { + return; } /** @@ -311,7 +321,8 @@ class Pluf_User extends Pluf_Model } if (count($ids) > 0) { $gperm = new Pluf_Permission(); - $perms = array_merge($perms, (array) $gperm->getList(array('filter' => 'pluf_group_id IN ('.join(', ', $ids).')', + $f_name = strtolower(Pluf::f('pluf_custom_group', 'Pluf_Group')).'_id'; + $perms = array_merge($perms, (array) $gperm->getList(array('filter' => $f_name.' IN ('.join(', ', $ids).')', 'view' => 'join_group'))); } foreach ($perms as $perm) { @@ -325,7 +336,7 @@ class Pluf_User extends Pluf_Model array($this->id, 'Pluf_User')); if (count($ids) > 0) { $sql2 = new Pluf_SQL('owner_id IN ('.join(', ', $ids).') AND owner_class=%s', - array('Pluf_Group')); + array(Pluf::f('pluf_custom_group','Pluf_Group'))); $sql->SOr($sql2); } $perms = $growp->getList(array('filter' => $sql->gen(), diff --git a/src/Pluf/Views.php b/src/Pluf/Views.php index d48e377..27094df 100644 --- a/src/Pluf/Views.php +++ b/src/Pluf/Views.php @@ -130,7 +130,8 @@ class Pluf_Views */ function logout($request, $match, $success_url='/') { - $request->user = new Pluf_User(); + $user_model = Pluf::f('pluf_custom_user','Pluf_User'); + $request->user = new $user_model(); $request->session->clear(); $request->session->setData('logout_time', gmdate('Y-m-d H:i:s')); if (0 !== strpos($success_url, 'http')) { diff --git a/src/Pluf/relations.php b/src/Pluf/relations.php index ca17aa6..c90c4dd 100644 --- a/src/Pluf/relations.php +++ b/src/Pluf/relations.php @@ -27,10 +27,34 @@ * to retrieve related models from each model. */ -$m = array(); -$m['Pluf_User'] = array('relate_to_many' => array('Pluf_Group', 'Pluf_Permission')); -$m['Pluf_Group'] = array('relate_to_many' => array('Pluf_Permission')); -$m['Pluf_Message'] = array('relate_to' => array('Pluf_User'), ); -$m['Pluf_RowPermission'] = array('relate_to' => array('Pluf_Permission'), ); -$m['Pluf_Search_Occ'] = array('relate_to' => array('Pluf_Search_Word'), ); -return $m; +$user_model = Pluf::f('pluf_custom_user','Pluf_User'); +$group_model = Pluf::f('pluf_custom_group', 'Pluf_Group'); + +return array( + $user_model => array( + 'relate_to_many' => array( + $group_model, + 'Pluf_Permission', + ), + ), + $group_model => array( + 'relate_to_many' => array( + 'Pluf_Permission', + ), + ), + 'Pluf_Message' => array( + 'relate_to' => array( + $user_model, + ), + ), + 'Pluf_RowPermission' => array( + 'relate_to' => array( + 'Pluf_Permission', + ), + ), + 'Pluf_Search_Occ' => array( + 'relate_to' => array( + 'Pluf_Search_Word', + ), + ), + );