/** * copy new site tables and set default values for some table. * * @param integer $site_id * @return boolean */ public function copyNewSiteTable($site_id = '') { if (!is_numeric($site_id)) { return false; } // get module's multisite tables. $this->hookGetMultisiteTables(); // copy tables foreach ($this->multisite_tables as $table) { $table_withprefix = \DB::table_prefix($table); $table_site_withprefix = \DB::table_prefix($site_id . '_' . $table); if ($table == 'config') { $sql = 'CREATE TABLE IF NOT EXISTS ' . $table_site_withprefix . ' SELECT * FROM ' . $table_withprefix . ' WHERE config_core = 1'; } else { $sql = 'CREATE TABLE IF NOT EXISTS ' . $table_site_withprefix . ' LIKE ' . $table_withprefix; } \DB::query($sql)->execute(); // create default values if ($table == 'account_level_group') { $sql = "INSERT INTO `" . $table_site_withprefix . "` (`level_group_id`, `level_name`, `level_description`, `level_priority`) VALUES\n (1, 'Super administrator', 'For site owner or super administrator.', 1),\n (2, 'Administrator', NULL, 2),\n (3, 'Member', 'For registered user.', 999),\n (4, 'Guest', 'For non register user.', 1000);"; \DB::query($sql)->execute(); } } unset($sql, $table, $table_site_withprefix, $table_withprefix); // loop get account and add default levels $exist_account_id = array(); $result = \DB::select('*')->from('account_level')->as_object()->execute(); foreach ($result as $row) { // check and set level group id $lvg = \Model_AccountLevelGroup::getHighestPriorityAccountLevel($row->account_id); if ($lvg !== false && $lvg->level_group_id == '1') { $level_group_id = '1'; } else { $level_group_id = '3'; // 3 is just member. always set to 3 for non super-administrator for safety. } if (!in_array($row->account_id, $exist_account_id)) { \DB::insert($site_id . '_account_level')->set(array('level_group_id' => $level_group_id, 'account_id' => $row->account_id))->execute(); $exist_account_id = array_merge($exist_account_id, array($row->account_id)); } } // done return true; }