public function save(&$model) { return parent::save($model); // TODO: // Ensure that the acl_repo_id is != 0 - ie. that this resource is related to a repository // If not, and this resource has a parent, then perhaps default to using the same repo as the parent. }
/** * * @param $exception \Exception * * @throws \Exception * @return void */ private function handleException($exception) { $request = new \Enlight_Controller_Request_RequestHttp(); $response = new \Enlight_Controller_Response_ResponseHttp(); if ($this->isModelException($exception)) { $generator = $this->container->get('models')->createModelGenerator(); $result = $generator->generateAttributeModels(); if ($result['success'] === true) { $response->setRedirect($request->getRequestUri()); setcookie(self::redirectCookieString, true, time() + 5); $response->sendResponse(); exit; } else { die(sprintf("Failed to create the attribute models, please check the permissions of the '%s' directory", $generator->getPath())); } } }
/** * Execute all data in queue. */ protected function executeQueue() { foreach ($this->queueActions as $key => $action) { if (self::QUEUE_ACTION_PERSIST === $action) { $this->doPersist($this->queueManagerNames[$key], $this->queueModels[$key], $this->queueIds[$key]); } else { $this->manager->getPool()->getManager($this->queueManagerNames[$key])->remove($this->queueModels[$key]); } } $this->cleanQueue(); }
public function repos($params) { $view = new View(); if (!Core::hasAdminAccess()) { return Core::getLoginView($view); } $view->setSource(Config::get('ext.acl.dir.views') . '/repos.tpl'); if (isset($_GET['id'])) { $view->setSource(Config::get('ext.acl.dir.views') . '/repos.edit.tpl'); $repo = Model::create('AclRepo'); if ($_GET['id'] > 0) { $repo->id = (int) $_GET['id']; if (!$repo->getModelManager()->load($repo)) { SystemLog::add(array('Failed to load repository #%s', $repo->id), SystemLog::WARNING); $view->setSource(NULL); return $view; } } // Save if (isset($_POST['name'])) { $repo->name = $_POST['name']; if ($repo->getModelManager()->save($repo)) { SystemLog::add('Data saved!', SystemLog::INFO); } else { SystemLog::add('Failed to save data.', SystemLog::WARNING); } } else { if (isset($_GET['remove']) && $repo->isInDatabase()) { if ($repo->getModelManager()->delete($repo)) { SystemLog::add('Data removed!', SystemLog::INFO); $repo = Model::create('AclRepo'); } else { SystemLog::add('Failed to remove data.', SystemLog::WARNING); } } } // View $view->repo = $repo; return $view; } // View $view->repos = ModelManager::select('AclRepo'); return $view; }
if (strcmp($file_parts['extension'], "json") == 0) { $readFile = new JsonFileManager(); $readFile->setNamaFile($nama_file); $readFile->importToVariable(); echo $nama_file . "\n"; echo $hostname . "\n"; echo $username . "\n"; echo $password . "\n"; echo $databaseName . "\n"; } else { $readFile = new TextFileManager(); $readFile->setNamaFile($nama_file); $readFile->importToVariable(); echo $hostname . "\n"; echo $username . "\n"; echo $password . "\n"; echo $databaseName . "\n"; } } // tulis model ke php $dbManager = new DatabaseManager(); if ($dbManager->createDatabase()) { // Generate yii model foreach ($tables as $table) { $model = new ModelManager(); $model->makeModel($table->tabelname, $table->params); echo "create model for table " . $table->tabelname . " success\n"; } } else { echo "database fail\n"; }
static function get_all($model) { $def = ModelManager::get_model_definition($model); $ns = $def->namespace; $name = $def->name; $q = "SELECT * FROM `{$ns}`.`{$name}`"; return ModelManager::find_where($model, $q); // $models = array(); // $def = ModelManager::get_model_definition($model); // $ns = $def->namespace; // $name = $def->name; // $q = "SELECT * FROM `$ns`.`$name`"; // $results = DB::query($q); // if($results) // { // foreach($results as $result) // { // $m = new Model($model); // foreach($def->get_properties_list() as $prop) // { // $type = $def->get_data_type($prop); // if($type == "integer") // $val = (int)$result[$prop]; // else // $val = $result[$prop]; // $m->$prop = $val; // } // $m->exists_in_db = TRUE; // $models[] = $m; // } // } // return $models; }
/** * @return int */ static function upgradeManagementModel() { $change_column_num = 0; foreach (ModelManager::getModels() as $k => $v) { $model = new $v(); $change_column_num += $model->upgrade(); } foreach (ModelManager::getModels() as $k => $v) { $model = new $v(); $change_column_num += $model->addReference(); } return $change_column_num; }
public function uninstall() { // Get DB connection try { $DB = Database::getConnection(); } catch (Exception $e) { SystemLog::add('This extension requires a database. (' . $e->getMessage() . ')', SystemLog::WARNING); return FALSE; } // Table definitions $tables = array('acl_repo', 'acl_role', 'acl_resource', 'acl_role_member', 'acl_type', 'acl_entry'); // Create tables try { $DB->beginTransaction(); foreach ($tables as $table) { if (!ModelManager::sqlQuery('DROP TABLE IF EXISTS ' . $table)) { throw new PDOException("Invalid SQL"); } } $DB->commit(); return TRUE; } catch (PDOException $e) { SystemLog::add($e->getMessage(), SystemLog::WARNING); try { $DB->rollBack(); } catch (PDOException $e) { SystemLog::add($e->getMessage(), SystemLog::WARNING); } } // Catch-all result return FALSE; }
header('Location: ./index.php'); } else { $login = "******"; } } //////////////////////////////////////////////// if (!$bCronEnabled) { if ($oR3DCQuery->ELOIsActive()) { $oR3DCQuery->ELOCreateRatings(); } $oR3DCQuery->MangeGameTimeOuts(); } DB::init($config); $db = DB::query_getone('select database() as `db`'); $db = $db['db']; $players = ModelManager::get_all("{$db}::player"); $player_list = array(); foreach ($players as $player) { $player_list[$player->player_id] = $player->userid; } $tbl_opts = array('url' => 'admin_game_list.php', 'model' => "{$db}::game", 'title' => __l('Manage Games'), 'order' => array('game_id', 'initiator', 'w_player_id', 'b_player_id', 'status', 'completion_status', 'start_time', 'board'), 'columns' => array('game_id' => array('label' => __l('Game ID')), 'initiator' => array('label' => __l('Initiator')), 'start_time' => array('render_as' => 'date_time', 'width' => 150, 'label' => __l('Start Time')), 'status' => array('label' => __l('Status'), 'values' => array('A' => __l('Active'), 'C' => __l('Completed'), 'W' => __l('Waiting to be accepted'), 'P' => __l('Pending'), 'I' => 'I', 'T' => 'T'), 'required' => TRUE), 'completion_status' => array('label' => __l('Completion<br/>Status'), 'values' => array('W' => __l('White Won'), 'B' => __l('Black Won'), 'D' => __l('Draw'), 'A' => 'A', 'I' => __l('Incomplete'))), 'w_player_id' => array('label' => __l('White'), 'values' => $player_list, 'render_as' => 'select'), 'b_player_id' => array('label' => __l('Black'), 'values' => $player_list, 'render_as' => 'select'), 'initiator' => array('values' => $player_list, 'render_as' => 'select', 'required' => TRUE), 'board' => array('label' => __l('View Board'), 'render_as' => 'preview_board')), 'controllers' => array('create' => array('label' => __l('Add')), 'update' => array('label' => __l('Edit'))), 'form_options' => array('default' => array('order' => array('game_id', 'initiator', 'w_player_id', 'b_player_id', 'status', 'completion_status', 'start_time', 'next_move', 'cast_ws', 'cast_wl', 'cast_bs', 'cast_bl', 'draw_requests', 'board'), 'fields' => array('next_move' => array('label' => __l('Next Move'), 'values' => array('w' => __l('White'), 'b' => __l('Black'))), 'cast_ws' => array('label' => __l('Castle White Short'), 'render_as' => 'tick'), 'cast_wl' => array('label' => __l('Castle White Long'), 'render_as' => 'tick'), 'cast_bs' => array('label' => __l('Castle Black Short'), 'render_as' => 'tick'), 'cast_bl' => array('label' => __l('Castle Black Long'), 'render_as' => 'tick'), 'board' => array('label' => __l('View Board'), 'render_as' => 'edit_game', 'set' => array('location' => '../modules/RealTimeInterface/img_chess/', 'white_files' => array('wkw.gif', 'wqw.gif', 'wbw.gif', 'wnw.gif', 'wrw.gif', 'wpw.gif'), 'black_files' => array('bkw.gif', 'bqw.gif', 'bbw.gif', 'bnw.gif', 'brw.gif', 'bpw.gif'))))), 'update' => array('fields' => array('game_id' => array('render_as' => 'static'), 'w_player_id' => array('render_as' => 'static'), 'b_player_id' => array('render_as' => 'static'), 'initiator' => array('render_as' => 'static'))), 'create' => array('order' => array('w_player_id', 'b_player_id', 'rated', 'game_time', 'fen', 'tc'), 'fields' => array('fen' => array('render_as' => 'board2fen', 'label' => 'FEN'), 'rated' => array('label' => __l('Rate Game?'), 'values' => array('1' => __l('Yes'), '0' => __l('No')), 'value' => '1', 'render_as' => 'radio', 'required' => TRUE), 'game_time' => array('label' => 'Game Time', 'render_as' => 'select', 'values' => array('C-Blitz' => GetStringFromStringTable("IDS_CREATE_GAME_OPT_1", $config), 'C-Short' => GetStringFromStringTable("IDS_CREATE_GAME_OPT_2", $config), 'C-Normal' => GetStringFromStringTable("IDS_CREATE_GAME_OPT_3", $config), 'C-Slow' => GetStringFromStringTable("IDS_CREATE_GAME_OPT_4", $config), 'C-Snail' => GetStringFromStringTable("IDS_CREATE_GAME_OPT_5", $config))), 'tc' => array('label' => 'Time Controls', 'render_as' => 'time_controls', 'value' => '')), 'controllers' => array('create' => array('callback' => create_game, 'save' => FALSE))), 'delete' => array('controllers' => array('delete' => array('callback' => delete_game, 'delete' => FALSE)))), 'usepager' => TRUE, 'useRp' => TRUE, 'rp' => 15, 'action_callback' => 'admin_game_list.php', 'height' => 500, 'findtext' => __l('Find'), 'pagestat' => __l('Displaying {from} to {to} of {total} items'), 'pagetext' => __l('Page'), 'outof' => __l('of'), 'findtext' => __l('Find'), 'procmsg' => __l('Processing, please wait ...'), 'nomsg' => __l('No items'), 'errormsg' => __l('Connection Error')); $table = new Table(); //$table->model_value_processors['client']['phpchess::player'] = test; if ($_POST['page'] || $_POST['tbl_action'] || $_POST['form_action']) { header("Content-type: application/json"); if (isset($_POST['page'])) { $result = $table->handle_table_action('data', $tbl_opts); } elseif (isset($_POST['tbl_action'])) { CSession::initialise($config); $table->model_value_processors['client']["{$db}::game"] = process_game_values; $result = $table->handle_table_action($_POST['tbl_action'], $tbl_opts);
/** * Utility function (internal use only) : Manager instance getter * @method Manager * @return ModelManager */ function Manager() { static $manager; isset($manager) or $manager = ModelManager::getInstance(); return $manager; }
public function save(&$model) { return parent::save($model); // TODO: // Ensure that the acl_repo_id is != 0 - ie. that this role is related to a repository }
/** * Returns an instance of the ModelManager that is used to manage Models of * $this type. * * @return \Buan\ModelManager */ function getModelManager() { return ModelManager::create($this->modelName); }
/** * @return null */ protected function getReference() { if ($this->connection && !$this->reference) { $reference = null; // create reference if ($model_name = ModelManager::find($this->connection->getTargetName())) { $model = new $model_name(); $column_name = $this->connection->getTargetColumn(); if ($model && $model->isExists($column_name)) { $column = $model->getColumn($column_name); $reference = new ModelReference($model, $column); if ($this->connection->getDelete()) { $reference->setDelete($this->connection->getDelete()); } if ($this->connection->getUpdate()) { $reference->setUpdate($this->connection->getUpdate()); } $this->reference = $reference; } else { throw new \Exception('not found connection target paramater.column name is "' . $this->connection->getTargetName() . '"'); } } else { throw new \Exception('not found connection target paramater.column name is "' . $this->connection->getTargetName() . '"'); } } return $this->reference; }
/** * {@inheritdoc} */ public function transactional($func) { if (!is_callable($func)) { throw new \InvalidArgumentException('Expected argument of type "callable", got "' . gettype($func) . '"'); } return parent::transactional($func); }
public function whichAllowed($permissions, $resource, $resultFormat = self::RETURN_OBJECTS) { // Load resource from a given alias $alias = $resource; if (is_string($resource) && !($resource = $this->loadResourceByAlias($resource))) { throw new BuanException("Could not find AclResource with an alias of '{$alias}'"); return FALSE; } // If $resource is not persistent, we have to test all in-memory child // resources and return as an array, ignoring $resultFormat. // TODO: Why ignore $resultFormat? if (!$resource->isInDatabase()) { $childResources = $resource->getRelatedModels('AclResource', ModelRelation::REF_PARENT); $allowed = array(); foreach ($childResources as $child) { if ($this->isAllowed($permissions, $child)) { $allowed[] = $child; } } return $allowed; } // Get inheritable result first $inheritable = $this->isAllowed($permissions, $resource); // Convert $permissions to an array if (!is_array($permissions)) { $permissions = explode(",", preg_replace("/[^a-z0-9_\\-\\*,]/i", "", strtolower($permissions))); } $permissions = array_unique($permissions); // Build list of AclRole IDs which affect $role. // TODO: Order may be significant when I get around to using it. ie. A // User is more significant, has more weight, than it's parent group, // and so on up the hierarchy. $parents = $this->getAncestors(); $roleIds = array(); foreach ($parents as $p) { $roleIds[] = $p->id; } $roleIds[] = $this->id; // TODO // The code below doesn't yet take into account any AclEntry models // that may just be in-memory, eg from: // $role->load(); // $role->allow('view', 'resource'); // $role->whichAllowed(); // // It only searches in the DB. Change to look through in-memory AclEntries // too. // Gather all allowable resources $resultFields = $resultFormat == self::RETURN_OBJECTS ? 'R.*' : 'R.id'; $sql = 'SELECT ' . $resultFields . ' FROM acl_resource AS R LEFT JOIN acl_entry AS E ON R.id=E.acl_resource_id WHERE R.parent_id=' . $resource->id . ' AND ('; if ($inheritable) { $sql .= 'E.acl_resource_id IS NULL OR (E.acl_role_id<>' . implode(" AND E.acl_role_id<>", $roleIds) . ') OR (E.pdeny<>"*" AND NOT FIND_IN_SET("' . implode('", pdeny) AND NOT FIND_IN_SET("', $permissions) . '", pdeny))'; } else { $sql .= 'E.acl_role_id=' . implode(" OR E.acl_role_id=", $roleIds) . ' AND (E.pallow="*" OR (FIND_IN_SET("' . implode('") AND FIND_IN_SET("', $permissions) . '", pallow)))'; } $sql .= ') GROUP BY R.id'; $stmt = ModelManager::sqlQuery($sql); $idList = array(); while ($row = $stmt->fetch(PDO::FETCH_OBJ)) { $idList[] = $resultFormat == self::RETURN_IDS ? (int) $row->id : $row; } return $idList; }