PHP Method Schema::model, someline-starter Code Examples

This page contains top rated real world PHP examples of method Schema::model from package someline-starter extracted from open source projects. You can rate examples to help us improve the quality of examples
Frequently Used Methods
Example #1
Show file File: SchemaTreeView.php Project: cebe/chive
0
 public function init()
 {
     // Add ordering
     $criteria = new CDbCriteria();
     $criteria->order = "SCHEMA_NAME ASC";
     $schemata = Schema::model()->findAll($criteria);
     $dbSeperator = "_";
     $items = $root = $children = $items = array();
     foreach ($schemata as $schema) {
         // Find prefix in name
         if ($position = strpos($schema->SCHEMA_NAME, $dbSeperator)) {
             $prefix = substr($schema->SCHEMA_NAME, 0, $position);
             $root[$prefix] = $prefix;
             $children[$prefix][] = substr($schema->SCHEMA_NAME, $position + 1);
         } else {
             $root[] = $schema->SCHEMA_NAME;
         }
     }
     $i = 0;
     foreach ($root as $key => $item) {
         $childs = array();
         $childrenCount = count($children[$item]);
         if ($childrenCount > 1) {
             foreach ($children[$item] as $child) {
                 $childs[] = array('text' => CHtml::link($child, SchemaController::createUrl("/schema/" . $item . $dbSeperator . $child)));
             }
         } else {
             if ($childrenCount == 1) {
                 $name = $item . $dbSeperator . $children[$item][0];
             } else {
                 $name = $item;
             }
             $items[] = array('text' => CHtml::link($name, SchemaController::createUrl("/schema/" . $name)));
             $i++;
             continue;
         }
         $items[] = array('text' => $childrenCount == 0 ? CHtml::link($item, SchemaController::createUrl("/schema/" . $item)) : $item, 'expanded' => $i == 0 ? true : false, 'children' => $childs);
         $i++;
     }
     $this->data = $items;
     parent::init();
 }
Example #2
Show file File: SchemaTest.php Project: cebe/chive
0
 /**
  * Tests to drop a database.
  */
 public function testDrop()
 {
     // Load schema
     $schema = Schema::model()->findByPk('schematest2');
     // Drop
     $this->assertEquals(true, $schema->delete());
     // Load again
     $this->assertEquals(null, Schema::model()->findByPk('schematest2'));
 }
Example #3
Show file File: SchemaController.php Project: cebe/chive
0
 /**
  * Loads the current schema.
  *
  * @return	Schema
  */
 public function loadSchema()
 {
     if (is_null($this->_schema)) {
         $this->_schema = Schema::model()->findByPk($this->schema);
         if (is_null($this->_schema)) {
             throw new CHttpException(500, 'The requested schema does not exist.');
         }
     }
     return $this->_schema;
 }
Example #4
Show file File: ExportPage.php Project: cebe/chive
0
 /**
  * Runs the form.
  */
 private function runForm()
 {
     // @todo: Load all exporters
     $exporterNames = array('SqlExporter', 'CsvExporter');
     // Instantiate supported exporters
     $this->exporters = array();
     foreach ($exporterNames as $exporter) {
         $supported = call_user_func(array($exporter, 'getSupportedModes'));
         if (in_array($this->mode, $supported)) {
             $this->exporters[] = new $exporter($this->mode);
         }
     }
     // Create the object list
     $this->objects = array();
     if ($this->mode == 'objects') {
         // Load schema
         $schema = Schema::model()->findByPk($this->schema);
         // Tables
         $tables = $schema->tables;
         if (count($tables) > 0) {
             $data = array();
             foreach ($tables as $table) {
                 $data['t:' . $table->TABLE_NAME] = $table->TABLE_NAME;
             }
             $this->objects[Yii::t('core', 'tables')] = $data;
         }
         // Views
         $views = $schema->views;
         if (count($views) > 0) {
             $data = array();
             foreach ($views as $view) {
                 $data['v:' . $view->TABLE_NAME] = $view->TABLE_NAME;
             }
             $this->objects[Yii::t('core', 'views')] = $data;
         }
         // Routines
         $routines = $schema->routines;
         if (count($routines) > 0) {
             $data = array();
             foreach ($routines as $routine) {
                 $data['r:' . $routine->ROUTINE_NAME] = $routine->ROUTINE_NAME;
             }
             $this->objects[Yii::t('core', 'routines')] = $data;
         }
     }
 }
Example #5
Show file File: PrivilegesController.php Project: cebe/chive
0
 public function actionCreateSchema()
 {
     $schema = new SchemaPrivilege();
     $schema->User = $this->user;
     $schema->Host = $this->host;
     if (isset($_POST['SchemaPrivilege'])) {
         $schema->attributes = $_POST['SchemaPrivilege'];
         if ($sql = $schema->save()) {
             $response = new AjaxResponse();
             $response->addNotification('success', Yii::t('core', 'successAddSchemaSpecificPrivileges', array('{user}' => $schema->User, '{host}' => $schema->Host, '{schema}' => $schema->Db)), null);
             $response->refresh = true;
             $this->sendJSON($response);
         }
     }
     // Prepare all schemata
     $schemata = $existing = array();
     $allSchemata = Schema::model()->findAll();
     $allExisting = SchemaPrivilege::model()->findAllByAttributes(array('User' => $this->user, 'Host' => $this->host));
     foreach ($allExisting as $existing1) {
         $existing[] = $existing1->Db;
     }
     foreach ($allSchemata as $schema1) {
         if (array_search($schema1->SCHEMA_NAME, $existing) === false) {
             $schemata[$schema1->SCHEMA_NAME] = $schema1->SCHEMA_NAME;
         }
     }
     $this->render('schemaPrivilegeForm', array('schema' => $schema, 'schemata' => $schemata));
 }