Exemplo n.º 1
0
 protected function column_value(Dao $dao, $name, $value)
 {
     if ($value === null) {
         return null;
     }
     try {
         switch ($dao->prop_anon($name, 'type')) {
             case 'boolean':
                 return (int) $value;
         }
     } catch (\Exception $e) {
     }
     return parent::column_value($dao, $name, $value);
 }
Exemplo n.º 2
0
 public function drop_table_sql(\org\rhaco\store\db\Dao $dao)
 {
     $quote = function ($name) {
         return '`' . $name . '`';
     };
     $sql = 'drop table ' . $quote($dao->table());
     return $sql;
 }
Exemplo n.º 3
0
 public static function get_dao_connection($package)
 {
     if (!is_object($package)) {
         $r = new \ReflectionClass('\\' . str_replace('.', '\\', $package));
         $package = $r->newInstance();
     }
     if (!is_subclass_of($package, '\\org\\rhaco\\store\\db\\Dao')) {
         throw new \RuntimeException('not Dao');
     }
     $connections = \org\rhaco\store\db\Dao::connections();
     $conf = explode("\\", get_class($package));
     while (!isset($connections[implode('.', $conf)]) && !empty($conf)) {
         array_pop($conf);
     }
     if (empty($conf)) {
         if (!isset($connections['*'])) {
             throw new \RuntimeException(get_class($package) . ' connection not found');
         }
         $conf = array('*');
     }
     $conf = implode('.', $conf);
     foreach ($connections as $k => $con) {
         if ($k == $conf) {
             return $con;
         }
     }
 }
Exemplo n.º 4
0
 /**
  * @module org.rhaco.Flow
  * @param \Exception $exception
  */
 public function flow_handle_exception(\Exception $exception)
 {
     \org\rhaco\store\db\Dao::rollback_all();
 }
Exemplo n.º 5
0
 public function exists_table_sql(\org\rhaco\store\db\Dao $dao)
 {
     $dbc = \org\rhaco\store\db\Dao::connection(get_class($dao));
     return sprintf('select count(*) from information_schema.tables where table_name=\'%s\' and table_schema=\'%s\'', $dao->table(), $dbc->name());
 }
Exemplo n.º 6
0
 public function filter(\org\rhaco\store\db\Dao $obj, $name)
 {
     if ($obj->prop_anon($name, 'master') !== null) {
         $options = array();
         $options[] = '<option value=""></option>';
         $master = $obj->prop_anon($name, 'master');
         if (!empty($master)) {
             $master = str_replace('.', "\\", $master);
             if ($master[0] !== "\\") {
                 $master = "\\" . $master;
             }
             $r = new \ReflectionClass($master);
             $mo = $r->newInstanceArgs();
             $primarys = $mo->primary_columns();
             if (sizeof($primarys) != 1) {
                 return sprintf('<input name="%s" type="text" />', $name);
             }
             foreach ($primarys as $primary) {
                 break;
             }
             $pri = $primary->name();
             foreach ($master::find() as $dao) {
                 $options[] = sprintf('<option value="%s">%s</option>', $dao->{$pri}(), (string) $dao);
             }
         }
         return sprintf('<select name="%s">%s</select>', $name, implode('', $options));
     } else {
         $type = $obj->prop_anon($name, 'type');
         switch ($type) {
             case 'boolean':
                 $options = array();
                 $options[] = '<option value=""></option>';
                 foreach (array('true', 'false') as $choice) {
                     $options[] = sprintf('<option value="%s">%s</option>', $choice, $choice);
                 }
                 return sprintf('<select name="search_%s_%s">%s</select>', $type, $name, implode('', $options));
             case 'choice':
                 $options = array();
                 $options[] = '<option value=""></option>';
                 foreach ($obj->prop_anon($name, 'choices') as $v) {
                     $options[] = sprintf('<option value="%s">%s</option>', $v, $v);
                 }
                 return sprintf('<select name="search_%s_%s">%s</select>', $type, $name, implode('', $options));
             case 'timestamp':
             case 'date':
                 return sprintf('<input name="search_%s_from_%s" type="text" class="span2" />', $type, $name) . ' : ' . sprintf('<input name="search_%s_to_%s" type="text" class="span2" />', $type, $name);
             default:
                 return sprintf('<input name="search_%s_%s" type="text" />', $type, $name);
         }
     }
 }