Esempio n. 1
0
 public static function get_read_or_create_bys($table)
 {
     $read_or_create_bys = array();
     foreach (moojon_db::show_columns($table) as $column) {
         $name = $column['Field'];
         if ($column['Key'] != 'PRI') {
             $read_or_create_bys[] = "final static public function read_or_create_by_{$name}(\$value, \$data = null) {return self::read_or_create_by(get_class(), '{$name}', \$value, \$data);}";
         }
     }
     return implode("\n\t", $read_or_create_bys);
 }
Esempio n. 2
0
 public static function models()
 {
     moojon_files::attempt_mkdir(moojon_paths::get_project_models_directory());
     moojon_files::attempt_mkdir(moojon_paths::get_project_base_models_directory());
     moojon_db::show_tables();
     foreach (moojon_db::show_tables() as $table) {
         self::model($table);
     }
 }
 public function run($arguments)
 {
     $command = $this->prompt_until_in(array_shift($arguments), $this->get_commands(), 'What would you like to generate?');
     switch ($command) {
         case 'model':
             $tables = moojon_db::show_tables();
             if (!count($tables)) {
                 throw new moojon_exception('No tables to generate models from');
             }
             $arguments = self::check_arguments('moojon_generate_cli::model()', 1, $arguments);
             $table = $this->prompt_until_in($arguments[0], $tables, 'What table would you like to generate a model for?');
             moojon_generator::model($table);
             break;
         case 'models':
             $arguments = self::check_arguments('moojon_generate_cli::models()', 0, $arguments);
             moojon_generator::models();
             break;
         case 'migration':
             $arguments = self::check_arguments('moojon_generate_cli::migration()', 1, $arguments);
             $migration = $this->prompt_until($arguments[0], 'Please enter a migration name');
             moojon_generator::migration($migration);
             break;
         case 'app':
             $arguments = self::check_arguments('moojon_generate_cli::app()', 3, $arguments);
             $app = $this->prompt_until($arguments[0], 'Please enter an app name');
             $controller = $this->prompt_until($arguments[1], 'Please enter an app name', moojon_config::get('default_controller'));
             $action = $this->prompt_until($arguments[2], 'Please enter an action name', moojon_config::get('default_action'));
             moojon_generator::app($app, $controller, $action);
             break;
         case 'controller':
             $arguments = self::check_arguments('moojon_generate_cli::controller()', 3, $arguments);
             $app = $this->prompt_for_app($arguments[0]);
             $controller = $this->prompt_until($arguments[1], 'Please enter a controller name');
             $action = $this->prompt_until($arguments[2], 'Please enter an action name', 'index');
             moojon_generator::controller($app, $controller, $action);
             break;
         case 'helper':
             $arguments = self::check_arguments('moojon_generate_cli::helper()', 1, $arguments);
             $helper = $this->prompt_until($arguments[0], 'Please enter a name for this helper');
             moojon_generator::helper($helper);
             break;
         case 'layout':
             $arguments = self::check_arguments('moojon_generate_cli::layout()', 1, $arguments);
             $layout = $this->prompt_until($arguments[0], 'Please enter a layout name');
             moojon_generator::layout($layout);
             break;
         case 'view':
             $arguments = self::check_arguments('moojon_generate_cli::view()', 3, $arguments);
             $app = $this->prompt_for_app($arguments[0]);
             $controller = $this->prompt_for_controller($app, $arguments[1]);
             $view = $this->prompt_until($arguments[2], 'Please enter a view name');
             moojon_generator::view($app, $controller, $view);
             break;
         case 'partial':
             $arguments = self::check_arguments('moojon_generate_cli::partial()', 3, $arguments);
             $app = $this->prompt_for_app($arguments[0]);
             $controller = $this->prompt_for_controller($app, $arguments[1]);
             $partial = $this->prompt_until($arguments[2], 'Please enter a name for this partial');
             moojon_generator::partial($app, $controller, $partial);
             break;
         case 'scaffold':
             $arguments = self::check_arguments('moojon_generate_cli::scaffold()', 3, $arguments);
             $app = $this->prompt_for_app($arguments[0]);
             $models = array();
             foreach (moojon_files::directory_files(moojon_paths::get_project_models_directory()) as $path) {
                 $models[] = basename($path);
             }
             if (!count($models)) {
                 if ($this->prompt_until_in(null, array('y', 'n'), 'No models found. Would you like to generate models?') == 'y') {
                     moojon_generator::models();
                 } else {
                     throw new moojon_exception('Unable to generate scaffold (no models)');
                 }
             }
             $model = $this->prompt_until_in($arguments[1], moojon_db::show_tables(), 'What model would you like to generate a scaffold for?');
             $controller = $this->prompt_until($arguments[2], 'Please enter a controller name', $model);
             moojon_generator::scaffold($app, $model, $controller);
             break;
     }
 }
Esempio n. 4
0
 public final function delete($cascade = true)
 {
     $where = '';
     $param_values = array();
     foreach ($this->get_primary_key_columns() as $column) {
         $column_name = $column->get_name();
         $where .= "{$column_name} = :{$column_name} AND ";
         $param_values[":{$column_name}"] = $column->get_value();
     }
     moojon_db::delete($this->table, substr($where, 0, strlen($where) - 5), $param_values, $this->compile_param_data_types());
     if ($cascade) {
         foreach ($this->get_relationships() as $relationship) {
             if (get_class($relationship) == 'moojon_has_many_relationship' || get_class($relationship) == 'moojon_has_many_to_many_relationship') {
                 $relationship_name = $relationship->get_name();
                 $this->{$relationship_name}->delete($cascade);
             }
         }
     }
 }
Esempio n. 5
0
 public static function get()
 {
     if (!self::$instance) {
         self::$instance = new moojon_db();
     }
     return self::$instance;
 }
Esempio n. 6
0
 private static function find_or_create_schema_migrations_table()
 {
     if (!in_array('schema_migrations', moojon_db::show_tables(''))) {
         moojon_db::create_table('schema_migrations', array(new moojon_string_column('version')));
     }
 }
 protected final function remove_index($index_name, $table_name)
 {
     moojon_db::remove_index($index_name, $table_name);
 }