/** * setup * * @return void */ public function setUp() { parent::setUp(); $this->connection = ConnectionManager::get('test'); $this->user = TableRegistry::get('Users', ['table' => 'counter_cache_users', 'connection' => $this->connection]); $this->post = new PostTable(['alias' => 'Post', 'table' => 'counter_cache_posts', 'connection' => $this->connection]); }
/** * Get plugin list from database */ public static function getPlugins() { $conn = ConnectionManager::get('default'); $newQuery = $conn->newQuery(); $plugins = $newQuery->select('*')->from('spider_plugins_plugins')->where(['status' => 1])->order(['weight ASC'])->execute()->fetchAll('assoc'); return $plugins; }
/** * main * */ public function main() { $schemaPo = APP . 'Locale' . DS . 'schema.pot'; $conn = ConnectionManager::get('default'); $collection = $conn->schemaCollection(); $translations = new Translations(); $tables = $collection->listTables(); foreach ($tables as $table) { $translations->insert($table, Inflector::humanize(Inflector::underscore($table))); $translations->insert($table, Inflector::humanize(Inflector::underscore(Inflector::singularize($table)))); $columns = $collection->describe($table)->columns(); foreach ($columns as $column) { $c = $collection->describe($table)->column($column); $comment = $c['comment']; $t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore($column))); $translations[] = $t; $t->setTranslation($comment); $t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore(Inflector::singularize($table))) . ' ' . Inflector::humanize(Inflector::underscore($column))); $translations[] = $t; $t->setTranslation($comment); } } $poString = $translations->toPoString(); $caked = preg_replace('/msgctxt "([^"]+)"/i', '#: \\1', $poString); $this->createFile($schemaPo, $caked); }
public function save() { if ($this->request->is('post')) { $attemptId = $this->request->data['attemptId']; $token = $this->request->data['token']; $rawSamples = $this->request->data['samples']; $happiness = $this->request->data['happiness']; $this->infolog("Samples Save attempted. Attempt: " . $attemptId . "; Happiness: " . $happiness . "; Samples: " . serialize($rawSamples)); if ($attemptId && $token && $rawSamples && $this->Samples->Attempts->checkUserAttempt($this->Auth->user('id'), $attemptId, $token)) { $attempt = $this->Samples->Attempts->get($attemptId); //Get attempt, for saving happiness and identifying whether report has been submitted $samples = []; foreach ($rawSamples as $siteId => $schools) { foreach ($schools as $schoolId => $children) { foreach ($children as $childId => $types) { foreach ($types as $typeId => $value) { if ($value) { $sample = ['attempt_id' => $attemptId, 'site_id' => $siteId, 'school_id' => $schoolId, 'child_id' => $childId, 'sample_stage_id' => $typeId, 'before_submit' => !$attempt->report]; array_push($samples, $sample); } } } } } //Note: Always create new entry - should never already be saved entries $samplesData = $this->Samples->newEntities($samples); if (!is_null($happiness)) { $attempt->happiness = $happiness; $attempt->sampling = true; } else { $attempt = null; } $connection = ConnectionManager::get('default'); $connection->transactional(function () use($samplesData, $attempt, $attemptId) { foreach ($samplesData as $sample) { if (!$this->Samples->save($sample)) { $this->set('status', 'failed'); $this->infolog("Samples Save failed Attempt: " . $attemptId); return false; } } if (!is_null($attempt) && !$this->Samples->Attempts->save($attempt)) { $this->set('status', 'failed'); $this->infolog("Samples Save failed Attempt: " . $attemptId); return false; } $this->set('status', 'success'); $this->infolog("Samples Save succeeded. Attempt: " . $attemptId); }); } else { $this->set('status', 'denied'); $this->infolog("Samples Save denied. Attempt: " . $attemptId); } } else { $this->set('status', 'notpost'); $this->infolog("Samples Save not POST "); } $this->viewBuilder()->layout('ajax'); $this->render('/Element/ajaxmessage'); }
/** * Get/Create an instance from the registry. * * When getting an instance, if it does not already exist, * a new instance will be created using the provide alias, and options. * * @param string $alias The name of the alias to get. * @param array $options Configuration options for the type constructor. * @return \Cake\ElasticSearch\Type */ public static function get($alias, array $options = []) { if (isset(static::$instances[$alias])) { if (!empty($options) && static::$options[$alias] !== $options) { throw new RuntimeException(sprintf('You cannot configure "%s", it already exists in the registry.', $alias)); } return static::$instances[$alias]; } static::$options[$alias] = $options; list(, $classAlias) = pluginSplit($alias); $options = $options + ['name' => Inflector::underscore($classAlias)]; if (empty($options['className'])) { $options['className'] = Inflector::camelize($alias); } $className = App::className($options['className'], 'Model/Type', 'Type'); if ($className) { $options['className'] = $className; } else { if (!isset($options['name']) && strpos($options['className'], '\\') === false) { list(, $name) = pluginSplit($options['className']); $options['name'] = Inflector::underscore($name); } $options['className'] = 'Cake\\ElasticSearch\\Type'; } if (empty($options['connection'])) { $connectionName = $options['className']::defaultConnectionName(); $options['connection'] = ConnectionManager::get($connectionName); } static::$instances[$alias] = new $options['className']($options); return static::$instances[$alias]; }
/** * Dumps the current schema to be used when baking a diff * * @param \Symfony\Component\Console\Input\InputInterface $input the input object * @param \Symfony\Component\Console\Output\OutputInterface $output the output object * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->setInput($input); $this->bootstrap($input, $output); $this->output($output); $path = $this->getOperationsPath($input); $connectionName = $input->getOption('connection') ?: 'default'; $connection = ConnectionManager::get($connectionName); $collection = $connection->schemaCollection(); $options = ['require-table' => true, 'plugin' => $this->getPlugin($input)]; $tables = $this->getTablesToBake($collection, $options); $dump = []; if (empty($tables)) { $this->output()->writeln('<info>No tables were found : the dump file was not created</info>'); return; } foreach ($tables as $table) { $schema = $collection->describe($table); $dump[$table] = $schema; } $filePath = $path . DS . 'schema-dump-' . $connectionName . '.lock'; $output->writeln(sprintf('<info>Writing dump file `%s`...</info>', $filePath)); if (file_put_contents($filePath, serialize($dump))) { $output->writeln(sprintf('<info>Dump file `%s` was successfully written</info>', $filePath)); } else { $output->writeln(sprintf('<error>An error occurred while writing dump file `%s`</error>', $filePath)); } }
/** * Purge ConnectionManager configs. * * @return void */ public static function tearDownAfterClass() { foreach (self::$datasources as $ds => $configs) { \Cake\Datasource\ConnectionManager::drop($ds); } \Cake\Utility\Security::salt(''); }
/** * setup * * @return void */ public function setUp() { parent::setUp(); $this->connection = ConnectionManager::get('test'); $this->table = new Table(['table' => 'articles', 'connection' => $this->connection]); $this->fixtureData = [['id' => 1, 'author_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y'], ['id' => 2, 'author_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y'], ['id' => 3, 'author_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y']]; }
public function init() { parent::init(); // 1. Not all fixtures want to use the dev db. if (is_null($this->tableName)) { return; } // 2. We need to do this to ensure that the tables really do use the connection to the // dev db. TableRegistry::remove($this->tableName); $table = TableRegistry::get($this->tableName, ['connection' => ConnectionManager::get('dev')]); //if(!is_null($this->joinTableName)) { //TableRegistry::remove($this->joinTableName); //$n=TableRegistry::get($this->joinTableName, ['connection' => ConnectionManager::get('fixture')]); //} // 3. Now build the query to retrieve the source records $query = new Query(ConnectionManager::get('dev'), $table); $query->find('all'); //if(!is_null($this->order)) $query->order($this->order); //if(!is_null($this->joinTableName)) $query->leftJoin($this->joinTableName,'semesters.id = sections.semester_id'); //$c=$query->count(); // 4. Copy the records /* @var \Cake\ORM\Entity $record */ foreach ($query as $record) { $this->records[] = $record->toArray(); } // 5. Do this again to ensure that the table uses the 'test' connection. TableRegistry::remove($this->tableName); TableRegistry::get($this->tableName, ['connection' => ConnectionManager::get('test')]); //if(!is_null($this->joinTableName)) { //TableRegistry::remove($this->joinTableName); //TableRegistry::get($this->joinTableName, ['connection' => ConnectionManager::get('test')]); //} }
public function index() { $conn = ConnectionManager::get('default'); //Create gallery $query = 'CREATE TABLE gallery ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, category_id INT(11), title VARCHAR(50), description TEXT, img VARCHAR(50), created DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL )'; $conn->query($query); //Create gallery categories $query = 'CREATE TABLE category ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, title VARCHAR(50), description TEXT, img VARCHAR(50), created DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL )'; $conn->query($query); $this->Flash->success('Successfully installed.'); return $this->redirect(['controller' => 'category', 'action' => 'index']); }
/** * Add method * * @return void Redirects on successful add, renders view otherwise. */ public function add($crisis_id = null) { if ($this->Infos->find('all')->count() === 0) { ConnectionManager::get('default')->execute('ALTER TABLE infos AUTO_INCREMENT 1'); } if ($crisis_id != null) { $user_id = $this->Auth->user()['id']; $info = $this->Infos->newEntity(); if ($this->request->is('post')) { $info->crisis_id = $crisis_id; $info->user_id = $user_id; $info = $this->Infos->patchEntity($info, $this->request->data); if ($this->Infos->save($info)) { $this->Flash->success(__('L\'information a bien été enregistrée.')); return $this->redirect(['controller' => 'crisis', 'action' => 'view', $crisis_id]); } else { $this->Flash->error(__('L\'information n\'a pas pu être enregistrée.')); } } $Crisis = $this->Infos->Crisis->find('list', ['limit' => 200]); $users = $this->Infos->Users->find('list', ['limit' => 200]); $this->set(compact('info', 'Crisis', 'users', 'crisis_id')); $this->set('_serialize', ['info']); } else { $this->Flash->error(__('Vous devez spécifier la crise liée à cette information.')); return $this->redirect(['controller' => 'Homes', 'action' => 'index']); } }
public function add() { $palestrante = $this->Palestrantes->newEntity(); if ($this->request->is('post')) { if (is_uploaded_file($this->request->data['foto']['tmp_name'])) { $filename = $this->request->data['foto']['name']; $ext = pathinfo($filename, PATHINFO_EXTENSION); while (true) { $filename = uniqid(rand(), true) . '.' . $ext; if (!'imagestore/' . $filename) { break; } } move_uploaded_file($this->request->data['foto']['tmp_name'], 'imagestore/' . $filename); // store the filename in the array to be saved to the db $this->request->data['foto'] = $filename; } $palestrante = $this->Palestrantes->patchEntity($palestrante, $this->request->data); if ($this->Palestrantes->save($palestrante)) { $this->Flash->default(__('Palestrante adicionado com sucesso')); return $this->redirect(['action' => 'view', $palestrante->id]); } $this->Flash->error(__('Incrição não realizada, verifique se preencheu o formulário corretamente!')); } $connection = ConnectionManager::get('default'); $result = $connection->execute('SELECT id, nome FROM users')->fetchAll('assoc'); $usersList = array(); $usersList[null] = 'Selecione'; foreach ($result as $row) { $usersList[$row['id']] = $row['nome']; } $this->set('usersList', $usersList); $this->set('palestrante', $palestrante); }
public function insert(UploadDTO\CustomerFeedbackUploadDto $customerFeedback, $userInfo) { $conn = ConnectionManager::get('default'); $conn->begin(); $tableObj = $this->connect(); $customerFeedbackCounter = 0; try { foreach ($customerFeedback->feedback as $feedback) { $newCustomerFeedback = $tableObj->newEntity(); $newCustomerFeedback->CustId = $customerFeedback->custId; $newCustomerFeedback->UserId = $userInfo->userId; $newCustomerFeedback->FeedbackId = $feedback->feedbackId; $newCustomerFeedback->FeedbackRating = $feedback->feedbackRating; $newCustomerFeedback->CreatedDate = date(VB_DATE_TIME_FORMAT); if ($tableObj->save($newCustomerFeedback)) { $customerFeedbackCounter++; } else { $customerFeedbackCounter = 0; } } } catch (Exception $ex) { $conn->rollback(); return $customerFeedbackCounter; } if ($customerFeedbackCounter) { $conn->commit(); return $customerFeedbackCounter; } }
public function testWithPreMadeConnection() { ConnectionManager::config('default', ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite']); $module = new CakeDbModule('default'); $instance = (new Injector($module, $_ENV['TMP_DIR']))->getInstance('Cake\\Database\\Connection'); $this->assertSame(ConnectionManager::get('default'), $instance); }
public function getTotalInvoicesByPo($data) { $connection = ConnectionManager::get('default'); $results = $connection->execute('select sum(invoice_users.total) total from invoices,invoice_users where invoices.id=invoice_users.invoice_id and invoices.po_id=' . $data['po_id'])->fetchAll(); $this->log(print_r($results, true), 'debug'); return array('sum' => $results[0][0]); }
public function install() { $sql = []; $defaultSql = ['40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT', '40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS', '40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION', '40101 SET NAMES utf8', '40103 SET @OLD_TIME_ZONE=@@TIME_ZONE', '40103 SET TIME_ZONE=\'+00:00\'', '40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0', '40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0', '40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO\'', '40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0']; foreach ($defaultSql as $key => $value) { $sql[] = '/*!' . $value . ' */;'; } $sql[] = "\n"; $db = ConnectionManager::get('default'); $collection = $db->schemaCollection(); $tables = $collection->listTables(); if (count($tables) > 0) { foreach ($tables as $key => $value) { $table = $collection->describe($value)->createSql($db); $sql[] = '-- Inicio das estrutura da tabela `' . $value . '` --'; $sql[] = '/* !40101 SET character_set_client = utf8 */;'; $sql[] = 'DROP TABLE IF EXISTS `' . $value . '`;'; $sql[] = str_replace('CREATE TABLE ', 'CREATE TABLE IF NOT EXISTS ', $table[0]) . ';'; $sql[] = '-- Fim das estrutura da tabela `' . $value . '` --'; $sql[] = "\n"; } } $defaultSql = ['40101 SET SQL_MODE=@OLD_SQL_MODE', '40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS', '40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS', '40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT', '40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS', '40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION', '40111 SET SQL_NOTES=@OLD_SQL_NOTES']; foreach ($defaultSql as $key => $value) { $sql[] = '/* !' . $value . ' */;'; } $sql[] = "\n"; $this->save('kiterp.sql', $sql); }
/** * Add method * * @return void Redirects on successful add, renders view otherwise. */ public function add() { if ($this->Crisis->find('all')->count() === 0) { ConnectionManager::get('default')->execute('ALTER TABLE crisis AUTO_INCREMENT 1'); } $crisi = $this->Crisis->newEntity(); if (isset($this->request->data)) { $crisi = $this->Crisis->patchEntity($crisi, $this->request->data); //do magic here $crisis = $this->Crisis->find('all'); $delta_search = 0.5; foreach ($crisis as $crisi_db) { if (abs($crisi_db['latitude'] - $crisi['latitude']) < $delta_search && abs($crisi_db['latitude'] - $crisi['latitude']) < $delta_search && $crisi_db->state != 'over') { //1° lat/long-> 111 km $crisi_db->severity += 1; if ($this->Crisis->save($crisi_db)) { $this->Flash->success('Cette crise a déjà été signalée, nous incrémentons sa gravité.'); } else { $this->Flash->error('La crise n\'a pas pu être enregistrée.'); } return $this->redirect(['controller' => 'Homes', 'action' => 'index']); } } if ($this->Crisis->save($crisi)) { $this->Flash->success(__('La crise a bien été enregistrée.')); } else { $this->Flash->error(__('La crise n\'a pas pu être enregistrée.')); } return $this->redirect(['controller' => 'Homes', 'action' => 'index']); } }
/** * Override main() to handle action * * @return mixed */ public function main() { if ($this->args && $this->args[0] === 'view') { $this->out('<error>The view command has been renamed.</error>'); $this->out('To create template files, please use the template command:', 2); $args = $this->args; array_shift($args); $args = implode($args, ' '); $this->out(sprintf(' <info>`bin/cake bake template %s`</info>', $args), 2); return false; } $connections = ConnectionManager::configured(); if (empty($connections)) { $this->out('Your database configuration was not found.'); $this->out('Add your database connection information to config/app.php.'); return false; } $this->out('The following commands can be used to generate skeleton code for your application.', 2); $this->out('<info>Available bake commands:</info>', 2); $this->out('- all'); $names = []; foreach ($this->tasks as $task) { list(, $name) = pluginSplit($task); $names[] = Inflector::underscore($name); } sort($names); foreach ($names as $name) { $this->out('- ' . $name); } $this->out(''); $this->out('By using <info>`cake bake [name]`</info> you can invoke a specific bake task.'); return false; }
/** * setUp * * @return void */ public function setUp() { parent::setUp(); $this->Addresses = TableRegistry::get('Geo.Addresses'); $this->Addresses->addBehavior('Geo.Geocoder', array('real' => false)); $this->db = ConnectionManager::get('test'); }
/** * Returns the TMDB image helper from the API wrapper. * * @return object Image helper */ public function imageHelper() { $tmdb = \Cake\Datasource\ConnectionManager::get('Tmdb'); $configRepository = new \Tmdb\Repository\ConfigurationRepository($tmdb->getClient()); $config = $configRepository->load(); return new \Tmdb\Helper\ImageHelper($config); }
public function insert(UploadDTO\BillEntryDto $billEntry) { $conn = ConnectionManager::get('default'); $conn->begin(); try { $tableObj = $this->connect(); $newBill = $tableObj->newEntity(); $newBill->BillNo = $billEntry->billNo; $newBill->BillDate = date(VB_DATE_FORMAT); $newBill->BillTime = date(VB_TIME_FORMAT); $newBill->NetAmount = $billEntry->netAmt; $newBill->TotalTaxAmount = $billEntry->totalTaxAmt; $newBill->TotalPayAmount = $billEntry->totalPayAmt; $newBill->CreatedDate = date(VB_DATE_TIME_FORMAT); $newBill->UpdatedDate = date(VB_DATE_TIME_FORMAT); $newBill->UserId = $billEntry->userId; $newBill->RestaurantId = $billEntry->restaurantId; $newBill->CustId = $billEntry->custId; $newBill->TableId = $billEntry->tableId; $newBill->TakeawayNo = $billEntry->takeawayNo; $newBill->DeliveryNo = $billEntry->deliveryNo; if ($tableObj->save($newBill)) { Log::debug('Bill has been created for BillNo :-' . $billEntry->billNo); return $billEntry->billNo; } $conn->rollback(); Log::error('error ocurred in Bill creating for BillNo :-' . $billEntry->billNo); return 0; } catch (Exception $ex) { $conn->rollback(); return 0; } }
public function beforeFilter(Event $event) { $this->Auth->autoRedirect = FALSE; parent::beforeFilter($event); $this->viewBuilder()->layout('custom'); $conn = ConnectionManager::get('default'); }
public function index() { $this->autoRender = false; //array order is important for graph edge hierarchy $connections = array("HasOne", "HasMany", "BelongsTo", "HasAndBelongsToMany"); $connectionArray = array(); $db = ConnectionManager::get('default'); $collection = $db->schemaCollection(); $tables = $collection->listTables(); foreach ($tables as $table) { $connectionArray[$table] = []; foreach ($connections as $edgeRank => $connection) { $model = TableRegistry::get($table); echo $table . "<br />"; // debug($model->associations()); foreach ($model->associations() as $key => $association) { // debug($association); $class = get_class($association); $array = explode("\\", $class); $type = array_pop($array); echo "<span style='margin-left: 10px;'>" . $type . ": " . $key . "</span><br />"; // if (!empty($connectionArray[$table][$key])) { // $currentVL = $connectionArray[$table][$key]; // } else { // $currentVL = 0; // } // $connectionArray[$table][$key] = max(array($currentVL, $edgeRank)); } } // debug($connectionArray); // $connectionArray = array_map("unserialize", array_unique(array_map("serialize", $connectionArray))); // $connectionArray = array_intersect_key($connectionArray, array_unique(array_map('serialize', $connectionArray))); } // $this->set(compact('tables', 'connectionArray')); }
/** * Setup function * * @return void */ public function setUp() { parent::setUp(); $this->connection = ConnectionManager::get('test'); Cache::clear(false, '_cake_method_'); Cache::enable(); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); $this->connection = ConnectionManager::get('test'); $schema = ['id' => ['type' => 'integer'], '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]]; $schema1 = ['id' => ['type' => 'integer'], 'name' => ['type' => 'string'], 'phone' => ['type' => 'string'], '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]]; $schema2 = ['id' => ['type' => 'integer'], 'total' => ['type' => 'string'], 'placed' => ['type' => 'datetime'], '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]]; $this->table = $table = TableRegistry::get('foo', ['schema' => $schema]); $clients = TableRegistry::get('clients', ['schema' => $schema1]); $orders = TableRegistry::get('orders', ['schema' => $schema2]); $companies = TableRegistry::get('companies', ['schema' => $schema, 'table' => 'organizations']); $orderTypes = TableRegistry::get('orderTypes', ['schema' => $schema]); $stuff = TableRegistry::get('stuff', ['schema' => $schema, 'table' => 'things']); $stuffTypes = TableRegistry::get('stuffTypes', ['schema' => $schema]); $categories = TableRegistry::get('categories', ['schema' => $schema]); $table->belongsTo('clients'); $clients->hasOne('orders'); $clients->belongsTo('companies'); $orders->belongsTo('orderTypes'); $orders->hasOne('stuff'); $stuff->belongsTo('stuffTypes'); $companies->belongsTo('categories'); $this->clientsTypeMap = new TypeMap(['clients.id' => 'integer', 'id' => 'integer', 'clients.name' => 'string', 'name' => 'string', 'clients.phone' => 'string', 'phone' => 'string']); $this->ordersTypeMap = new TypeMap(['orders.id' => 'integer', 'id' => 'integer', 'orders.total' => 'string', 'total' => 'string', 'orders.placed' => 'datetime', 'placed' => 'datetime']); $this->orderTypesTypeMap = new TypeMap(['orderTypes.id' => 'integer', 'id' => 'integer']); $this->stuffTypeMap = new TypeMap(['stuff.id' => 'integer', 'id' => 'integer']); $this->stuffTypesTypeMap = new TypeMap(['stuffTypes.id' => 'integer', 'id' => 'integer']); $this->companiesTypeMap = new TypeMap(['companies.id' => 'integer', 'id' => 'integer']); $this->categoriesTypeMap = new TypeMap(['categories.id' => 'integer', 'id' => 'integer']); }
/** * {@inheritdoc} */ public function get() { if (is_string($this->config)) { return ConnectionManager::get($this->config); } return new Connection($this->config); }
/** * GET /clazzes/add?section_id=n * Returns the new clazz form. * * The section_id parameter is mandatory. Because... * A clazz needs an associated section. The entry form can easily enough present a select-list * of section choices. But if the request _does not_ specify a section then which sections should * appear in the select list? Including all of them will involve a long and cumbersome list * because it's filled with sections from semesters past. But pruning that list is a remarkably * slippery and needlessly tedious issue best left as an exercise for the reader. * * As a practical matter, this is a non-issue. The creation of a new clazz should be in the * context of a section (and its teacher and semester) that has already been determined. * We'll still use a select-list, but now we can populate it with only those sections from * the same semester, with the same teacher, as the section specified by the request. * * 1. The new class form can only be seen by an admin or the teacher of the specified section. * We don't want to leak _any_ information to users who are not properly authorized. This * form will contain a list of sections, so redirect to /clazzes/index if not properly authorized. * 2. A class must have an associated section. * 3. The form will present a select list of candidate sections and by default no option will be selected. * If (the section_id param matches an available choice) then * the value of that param will be used by the form to set the initial selection in the select list. * 4. The avail choices for the select list are: * all sections from the same semester, with the same teacher, as the section specified by the request. */ public function testAddGET() { // 1. Build a list of all sections that have the same semester and teacher // as the given typical section $query = "SELECT DISTINCT b.id\n FROM sections AS a, sections AS b\n WHERE a.semester_id=b.semester_id\n AND a.teacher_id=b.teacher_id\n AND a.id=" . FixtureConstants::sectionTypical; /* @var \Cake\Database\Connection $connection */ $connection = ConnectionManager::get('default'); $allSectionsForThisTeacherAndSemester = $connection->execute($query)->fetchAll('assoc'); // 2. Positive tests. Test of functionality that should be handled by the controller. // 2.1 admin GET /clazzes/add // Error. The section_id param is missing and mandatory. Doesn't matter who the user is. $this->tstAddGET(FixtureConstants::userAndyAdminUsername, FixtureConstants::userAndyAdminPw, 400, ClazzesController::NEED_SECTION_ID); // 2.2 teacher1 GET /clazzes/add?section_id=n // Note: Make sure that the teacher for sectionTypical is connected to userTommyTeacher. Success. $this->tstAddGET(FixtureConstants::userTommyTeacherUsername, FixtureConstants::userTommyTeacherPw, 200, null, FixtureConstants::sectionTypical, $allSectionsForThisTeacherAndSemester); // 2.3 teacher2 GET /clazzes/add?section_id=n // Note: Make sure that the teacher for sectionTypical is not connected to userTammyTeacher. Error. $this->tstAddGET(FixtureConstants::userTerryTeacherUsername, FixtureConstants::userTerryTeacherPw, 400, ClazzesController::UR_NOT_THE_TEACHER, FixtureConstants::sectionTypical, $allSectionsForThisTeacherAndSemester); // 2.4 admin GET /clazzes/add?section_id=n // An admin can do this but the select list is still populated with the same sections as for // a teacher. $this->tstAddGET(FixtureConstants::userAndyAdminUsername, FixtureConstants::userAndyAdminPw, 200, null, FixtureConstants::sectionTypical, $allSectionsForThisTeacherAndSemester); // 3. Negative tests. Requests that should _not_ get to the controller. // 3.1 Test that users who do not have correct roles will get redirected to the home page. $this->tstAddGET(FixtureConstants::userArnoldAdvisorUsername, FixtureConstants::userArnoldAdvisorPw, 302, null, FixtureConstants::sectionTypical, $allSectionsForThisTeacherAndSemester); $this->tstAddGET(FixtureConstants::userSallyStudentUsername, FixtureConstants::userSallyStudentPw, 302, null, FixtureConstants::sectionTypical, $allSectionsForThisTeacherAndSemester); // 3.2 Test that unauthenticated users will get redirected to the login url. $this->session(['Auth' => null]); $this->get('/clazzes/add'); $this->assertResponseCode(302); $this->assertRedirect('/users/login'); }
/** * setUp * * @return void */ public function setUp() { parent::setUp(); Configure::write('Geocoder', ['locale' => 'DE']); $this->Addresses = TableRegistry::get('Geo.Addresses'); $this->Addresses->addBehavior('Geocoder'); $this->db = ConnectionManager::get('test'); }
public function change() { $conn = ConnectionManager::get('default'); $this->table('xp')->addColumn('character_id', 'integer', ['default' => null, 'limit' => 11, 'null' => false])->addColumn('value', 'integer', ['default' => 0, 'limit' => 11, 'null' => false])->addColumn('note', 'string', ['default' => '', 'limit' => 45, 'null' => false])->addColumn('created', 'datetime', ['default' => null, 'limit' => null, 'null' => true])->addColumn('modified', 'datetime', ['default' => null, 'limit' => null, 'null' => true])->addForeignKey('character_id', 'characters', 'id', ['update' => 'NO_ACTION', 'delete' => 'CASCADE'])->create(); // Migrate XP data $conn->query("INSERT INTO xp (character_id, value, note, created, modified) " . "SELECT c.id, c.xp, 'Initial XP', NOW(), NOW() " . "FROM characters c " . "WHERE c.xp > 0 "); $this->table('characters')->removeColumn('xp')->update(); }
public function upgrade($roleID) { $db = ConnectionManager::get('sm_db'); $queries = ['delete from skill where ID in (30001,30003,30006,30007,30004,30002,30005,30008,30009,30010,30101,30102,30104,30103,30107,30108,30110,30109,30106,30105,30201,30202,30203,30204,30205,30206,30207,30208,30209,30210,30301,30302,30303,30304,30305,30306,30307,30308,30309,30310,30401,30403,30402,30404,30408,30410,30406,30409,30412,30413,30501,30502,30503,30504,30505,30506,30507,30508,30509,30510) and RoleID = ' . $roleID, 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30001,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30003,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30006,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30007,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30004,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30002,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30005,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30008,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30009,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30010,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30101,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30102,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30104,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30103,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30107,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30108,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30110,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30109,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30106,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30105,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30201,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30202,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30203,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30204,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30205,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30206,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30207,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30208,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30209,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30210,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30301,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30302,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30303,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30304,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30305,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30306,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30307,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30308,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30309,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30310,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30401,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30403,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30402,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30404,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30408,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30410,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30406,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30409,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30412,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30413,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30501,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30502,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30503,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30504,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30505,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30506,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30507,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30508,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30509,0,10,0,0,0)', 'insert into skill (RoleID,ID,BiddenLevel,SelfLevel,Proficiency,CoolDown,active_time) values (' . $roleID . ',30510,0,10,0,0,0)']; foreach ($queries as $q) { $db->query($q); } }