Ejemplo n.º 1
1
 protected function header($str)
 {
     header($str);
     mdi::debug_print_backtrace();
 }
Ejemplo n.º 2
1
 private function &_value_to_has_many_object($model, &$value)
 {
     $object = NULL;
     if (!isset($value) || is_mdinull($value)) {
         $object = new $model();
     } else {
         if (is_object($value)) {
             if ($value->model != $model) {
                 mdi::error(get_class($this) . '::_value_to_has_many_object' . ' - model type of value is different(' . $value->model . ')');
                 ///
             }
             $object =& $this->_modelarray_to_object($model, array($value));
         } else {
             if (is_array($value)) {
                 if (empty($value)) {
                     $object = new $model();
                 } else {
                     if (is_numeric_array($value)) {
                         $object = new $model();
                         $object->where_in('id', $value)->get();
                     } else {
                         $object =& $this->_modelarray_to_object($model, $value);
                     }
                 }
             } else {
                 if (is_numeric($value)) {
                     $object = new $model();
                     $object->where_in('id', array($value))->get();
                 } else {
                     mdi::error(get_class($this) . '::_value_to_has_many_object' . ' - type that is not allowed in related field(' . gettype($value) . ')');
                     ///
                 }
             }
         }
     }
     return $object;
 }
Ejemplo n.º 3
1
 protected function _MDIRelation($object, &$outQueryDict)
 {
     $dbbuilder = self::getCI()->mdi->dbbuilder;
     $querydict_group_rel =& $dbbuilder->get_group($outQueryDict, 'RELATED');
     $this_object = $object;
     $this_model = strtolower(get_class($this_object));
     $this_table = $this_object->table;
     foreach (array('has_one', 'has_many') as $arr) {
         foreach ($this_object->{$arr} as $this_field => $this_field_attr) {
             $other_class = NULL;
             $other_field = NULL;
             $join_table = NULL;
             if (is_int($this_field)) {
                 $this_field = $this_field_attr;
                 $other_class = $this_field_attr;
                 $other_field = $this_model;
                 $this_field_attr = array('class' => $other_class, 'other_field' => $this_model, 'related_type' => $arr);
             } else {
                 if (!empty($this_field_attr['class'])) {
                     $other_class = $this_field_attr['class'];
                 } else {
                     mdi::error("DBSyncher::_MDIRelation Error - class did not defined" . "(field:" . $this_field . ")" . "(table:" . $this_table . ")");
                     ///
                 }
                 if (!empty($this_field_attr['other_field'])) {
                     $other_field = $this_field_attr['other_field'];
                 } else {
                     $other_field = $this_model;
                 }
                 if (!empty($this_field_attr['join_table'])) {
                     $join_table = $this_field_attr['join_table'];
                 }
                 //middle.fixme
                 /*
                 if (!empty($this_field_attr['model_path'])) {
                     $other_class_path = $this_field_attr['model_path'].'/'.$other_class;
                 } else {
                     $other_class_path = strtolower($other_class);
                 }
                 */
                 $this_field_attr['related_type'] = $arr;
             }
             // other class model
             $other_object = new $other_class(NULL, TRUE);
             $other_object_related_fields = array();
             $other_table = $other_object->table;
             DBSyncher::_getMDIRelationFields($other_object, $other_object_related_fields);
             if (!array_key_exists($other_field, $other_object_related_fields)) {
                 mdi::error("DBSyncher::_MDIRelation Error - reverse relationship of field must exist at " . $other_class . " model" . "(field:" . $this_field . ")");
             } else {
                 $other_field_attr = $other_object_related_fields[$other_field];
             }
             if (empty($other_field_attr['class']) || $other_field_attr['class'] !== $this_model) {
                 mdi::error("DBSyncher::_MDIRelation Error - did not matched class of " . $other_field . " field in " . $other_class . " model " . "(field:" . $this_field . ")" . "(table:" . $this_table . ")");
                 ///
             }
             if (!empty($other_field_attr['other_field']) && $other_field_attr['other_field'] !== $this_field) {
                 mdi::error("DBSyncher::_MDIRelation Error - current field did not matched 'other_field' option of " . $other_field . " field in " . $other_class . " model" . "(field:" . $this_field . ")" . "(table:" . $this_table . ")");
                 ///
             }
             if (!empty($other_field_attr['join_table'])) {
                 if ($join_table == NULL) {
                     mdi::error("DBSyncher::_MDIRelation Error - 'join_table' field did not matched " . $other_field . " field in " . $other_class . " model" . "(field:" . $this_field . ")" . "(table:" . $this_table . ")");
                     ///
                 }
             } else {
                 if ($join_table != NULL) {
                     mdi::error("DBSyncher::_MDIRelation Error - 'join_table' field did not matched " . $other_field . " field in " . $other_class . " model" . "(field:" . $this_field . ")" . "(table:" . $this_table . ")");
                     /////
                 }
             }
             $join_table = $this->_getMDIJoinTable($this_object, $other_object, $this_field_attr);
             if ($this_model <= $other_class) {
                 $target_object = $object;
             } else {
                 $target_object = $other_object;
             }
             if (!empty($this_field_attr['join_self_as'])) {
                 $this_db_field_name = $this_field_attr['join_self_as'];
             } else {
                 $this_db_field_name = $other_field;
             }
             if (!empty($other_field_attr['join_self_as'])) {
                 $other_db_field_name = $other_field_attr['join_self_as'];
             } else {
                 $other_db_field_name = $this_field;
             }
             if ($arr == 'has_one') {
                 if ($other_field_attr['related_type'] == 'has_one') {
                     // oto
                     ///////////////////////////////////////////////////////////
                     if ($target_object === $object) {
                         $new_querydict = $dbbuilder->make_field_querydict($this_table, $other_db_field_name . '_id', 'ADD', array('_OPTION' => 'COLUMN', '_DATATYPE' => 'KEY'));
                         $querydict_group_rel = array_merge($querydict_group_rel, $new_querydict);
                     } else {
                         if ($dbbuilder->is_table_exists($target_object->table)) {
                             if (!$dbbuilder->is_field_exists($other_table, $this_db_field_name . '_id')) {
                                 $new_querydict = $dbbuilder->make_field_querydict($other_table, $this_db_field_name . '_id', 'ADD', array('_OPTION' => 'COLUMN', '_DATATYPE' => 'KEY'));
                                 $querydict_group_rel = array_merge($querydict_group_rel, $new_querydict);
                             }
                         } else {
                             // sync of other class will generate relation ID, instead of
                         }
                     }
                 } else {
                     // otm
                     ///////////////////////////////////////////////////////////
                     $new_querydict = $dbbuilder->make_field_querydict($this_table, $other_db_field_name . '_id', 'ADD', array('_OPTION' => 'COLUMN', '_DATATYPE' => 'KEY'));
                     $querydict_group_rel = array_merge($querydict_group_rel, $new_querydict);
                 }
             } else {
                 if ($other_field_attr['related_type'] == 'has_one') {
                     // m2o
                     ///////////////////////////////////////////////////////////
                     if ($dbbuilder->is_table_exists($other_table)) {
                         if (!$dbbuilder->is_field_exists($other_table, $this_db_field_name . '_id')) {
                             $new_querydict = $dbbuilder->make_field_querydict($other_table, $this_db_field_name . '_id', 'ADD', array('_OPTION' => 'COLUMN', '_DATATYPE' => 'KEY'));
                             $querydict_group_rel = array_merge($querydict_group_rel, $new_querydict);
                         }
                     } else {
                         // sync of other class will generate relation ID, instead of
                     }
                 } else {
                     // m2m
                     ///////////////////////////////////////////////////////////
                     if ($dbbuilder->is_table_exists($join_table)) {
                         if (!$dbbuilder->is_field_exists($join_table, $this_db_field_name . '_id')) {
                             // add field
                             $new_querydict = $dbbuilder->make_field_querydict($join_table, $this_db_field_name . '_id', 'ADD', array('_OPTION' => 'COLUMN', '_DATATYPE' => 'KEY'));
                             $querydict_group_rel = array_merge($querydict_group_rel, $new_querydict);
                         }
                         if (!$dbbuilder->is_field_exists($join_table, $other_db_field_name . '_id')) {
                             $new_querydict = $dbbuilder->make_field_querydict($join_table, $other_db_field_name . '_id', 'ADD', array('_OPTION' => 'COLUMN', '_DATATYPE' => 'KEY'));
                             $querydict_group_rel = array_merge($querydict_group_rel, $new_querydict);
                         }
                     } else {
                         // create table
                         $new_querydict = $dbbuilder->make_table_querydict($join_table, 'CREATE', array('_IF_NOT_EXISTS' => TRUE));
                         $querydict_group_rel = array_merge($querydict_group_rel, $new_querydict);
                         // add field
                         $new_querydict = $dbbuilder->make_field_querydict($join_table, $this_db_field_name . '_id', 'ADD', array('_OPTION' => 'COLUMN', '_DATATYPE' => 'KEY'));
                         $querydict_group_rel = array_merge($querydict_group_rel, $new_querydict);
                         $new_querydict = $dbbuilder->make_field_querydict($join_table, $other_db_field_name . '_id', 'ADD', array('_OPTION' => 'COLUMN', '_DATATYPE' => 'KEY'));
                         $querydict_group_rel = array_merge($querydict_group_rel, $new_querydict);
                     }
                 }
             }
         }
     }
     return TRUE;
 }
Ejemplo n.º 4
1
 protected function _field_option_column($table, $label, $attribute)
 {
     if (!array_key_exists('_DATATYPE', $attribute)) {
         mdi::error('DBBuilder::_field_option_column Error - "_DATATYPE" key does not exist' . "(field:" . $label . ")" . "(table:" . $table . ")");
         ///
     }
     $field = array();
     $datatype = strtoupper($attribute['_DATATYPE']);
     switch ($datatype) {
         case 'KEY':
             $field['type'] = 'INT';
             $field['unsigned'] = TRUE;
             break;
         case 'BOOLEAN':
         case 'SMALLINT':
         case 'BIGINT':
         case 'TINYINT':
         case 'INT':
             if ($datatype == 'BOOLEAN') {
                 $field['type'] = 'INT';
                 $field['constraint'] = 1;
                 $field['unsigned'] = TRUE;
             } else {
                 $field['type'] = $attribute['_DATATYPE'];
                 if ($attribute['_DATATYPE'] == 'INT') {
                     if (array_key_exists('_DATASIZE', $attribute) && !empty($attribute['_DATASIZE'])) {
                         $field['constraint'] = $attribute['_DATASIZE'];
                     }
                 }
                 if (array_key_exists('_UNSIGNED', $attribute)) {
                     if ($attribute['_UNSIGNED']) {
                         $field['unsigned'] = TRUE;
                     }
                 }
             }
             break;
         case 'CHAR':
         case 'VARCHAR':
             if (!array_key_exists('_DATASIZE', $attribute) || empty($attribute['_DATASIZE'])) {
                 mdi::error('DBBuilder::_field_option_column Error - "_DATASIZE" key does not exist' . "(field:" . $label . ")" . "(table:" . $table . ")");
                 ///
             }
             $field['type'] = $attribute['_DATATYPE'];
             $field['constraint'] = $attribute['_DATASIZE'];
             break;
         case 'TEXT':
         case 'DATE':
         case 'DATETIME':
             if (array_key_exists('_DATASIZE', $attribute) && !empty($attribute['_DATASIZE'])) {
                 mdi::error('DBBuilder::_field_option_column Error - "_DATASIZE" key is deprecated' . "(field:" . $label . ")" . "(table:" . $table . ")");
                 ///
             }
             $field['type'] = $attribute['_DATATYPE'];
             break;
         default:
             mdi::error("DBBuilder::_field_option_column Error - unknown data type" . "(" . $datatype . ")" . "(field:" . $label . ")" . "(table:" . $table . ")");
             ///
     }
     if (array_key_exists('_DEFAULT', $attribute)) {
         if (array_key_exists('_AUTO_INCREMENT', $attribute)) {
             mdi::error('DBBuilder::_field_option_column Error - You can not use the "DEFAULT" with  "AUTO_INCREMENT" attribute at the same time' . "(" . $datatype . ")" . "(field:" . $label . ")" . "(table:" . $table . ")");
             ///
         }
         $field['default'] = NULL;
         if (!is_null($attribute['_DEFAULT'])) {
             $default = $attribute['_DEFAULT'];
             switch ($datatype) {
                 case 'TINYINT':
                 case 'BOOLEAN':
                     $default = $default ? 1 : 0;
                     break;
             }
             $field['default'] = $default;
         }
     }
     if (array_key_exists('_AUTO_INCREMENT', $attribute)) {
         if ($attribute['_AUTO_INCREMENT']) {
             $field['auto_increment'] = TRUE;
         }
     }
     $field['null'] = TRUE;
     if (array_key_exists('_NULL', $attribute)) {
         if (!$attribute['_NULL']) {
             $field['null'] = FALSE;
         }
     }
     return $field;
 }
Ejemplo n.º 5
0
 protected function _create_default_admin()
 {
     $user = new Model_User();
     $user->where('email', mdi::config('admin_default_email'))->get();
     if ($user->exists()) {
         return;
     }
     $credential = new MDI_Credential_Native();
     $credential->email = mdi::config('admin_default_email');
     $credential->password = mdi::config('admin_default_password');
     $credential->_need_encrpyt = TRUE;
     $credential->save();
     $user->email = mdi::config('admin_default_email');
     $user->grade = mdi::config('admin_default_grade');
     $user->name = 'Admin';
     $user->phone = '0000-0000';
     $user->save($credential, 'credential_native');
 }
Ejemplo n.º 6
0
 public function __construct()
 {
     $this->getCI()->load->library('email', mdi::config('mail'));
 }
Ejemplo n.º 7
0
 public static function get_session_user()
 {
     $ci =& get_instance();
     $ci->load->library('session');
     if ($ci->session->userdata('user_id') == FALSE) {
         return NULL;
     }
     $model = mdi::get_user_model();
     $user = new $model();
     $user->where('id', $ci->session->userdata('user_id'))->get();
     if ($user->exists()) {
         return $user;
     }
     return NULL;
 }
Ejemplo n.º 8
0
 protected function _annotation_require_admin($enabled)
 {
     $this->_force_type_casting('boolean', $enabled);
     if ($enabled) {
         $this->_annotation_require_auth($enabled);
         if ($this->user->grade < mdi::config('admin_accessible_grade')) {
             $this->_annotation_error('require_admin', 'forbidden');
         }
     }
 }
Ejemplo n.º 9
-1
 protected function _options($kwargs = array())
 {
     $name = array_get($kwargs['name'], 'files');
     $dir = mdi::config('media') . array_get($kwargs['dir'], 'tmp/');
     $filename = array_get($kwargs['filename'], NULL);
     $filename_enc = array_get($kwargs['filename_enc'], TRUE);
     $filename_timestamp = array_get($kwargs['filename_timestamp'], TRUE);
     $image_only = array_get($kwargs['image_only'], FALSE);
     $image_versions = array_get($kwargs['image_versions'], $this->get_default_image_versions());
     if ($this->_is_filename_array($name)) {
         $name = substr($name, 0, -2);
     }
     if ($image_only) {
         $accept_file_types = '/\\.(gif|jpe?g|png|svg)$/i';
     } else {
         $accept_file_types = '/.+$/i';
     }
     return array('param_name' => $name, 'file_name' => $filename, 'file_name_enc' => $filename_enc, 'file_name_timestamp' => $filename_timestamp, 'upload_dir' => $dir, 'upload_url' => base_url() . $dir, 'accept_file_types' => $accept_file_types, 'image_versions' => $image_versions);
 }
Ejemplo n.º 10
-1
 public function jquery_flush()
 {
     if (!empty(mdi::$jqueries)) {
         echo "\n" . "<script>" . "\n";
         echo "\$(document).ready(function(){\n";
         echo implode("\n", mdi::$jqueries) . "\n";
         echo "});\n";
         echo "</script>" . "\n";
     }
     mdi::$jqueries = array();
 }