Exemple #1
0
 function getActions($table_name)
 {
     $single = StringFormat::variable($table_name);
     $pks = $this->getPrimaryKeys($table_name);
     if (count($pks) === 1) {
         $pk = $pks[0];
     } else {
         $pk = null;
     }
     $actions = array();
     if (!$pk) {
         return $actions;
     }
     $pk_method = StringFormat::classMethod('get' . StringFormat::titleCase($pk->getName()));
     foreach ($this->standardActions as &$staction) {
         $actions[$staction] = "<?php echo site_url('" . StringFormat::pluralURL($table_name) . '/' . strtolower($staction) . "/' . \$" . $single . '->' . $pk_method . '()) ?>';
     }
     $fkeys_to = $this->getForeignKeysToTable($table_name);
     foreach ($fkeys_to as $k => &$r) {
         $from_table = $r->getTableName();
         $local_columns = $r->getLocalColumns();
         $from_column = array_shift($local_columns);
         if (@$used_to[$from_table]) {
             unset($fkeys_to[$k]);
             continue;
         }
         $used_to[$from_table] = $from_column;
         $actions[ucwords(StringFormat::titleCase(StringFormat::plural($from_table), ' '))] = "<?php echo site_url('" . StringFormat::pluralURL($from_table) . "?{$from_column}=' . \$" . $single . '->' . $pk_method . '()) ?>';
     }
     return $actions;
 }
Exemple #2
0
 public function testVariable()
 {
     $this->assertEquals('my_var', StringFormat::variable('myVar'));
     $this->assertEquals('my_var', StringFormat::variable('my--var'));
     $this->assertEquals('my_var', StringFormat::variable('my  var'));
     $this->assertEquals('my_var', StringFormat::variable('my %^&*  var'));
     $this->assertEquals('my_var', StringFormat::variable('my____ var--'));
     $this->assertEquals('my_var', StringFormat::variable('my/ \\var'));
 }
Exemple #3
0
    }
    ?>
);
			if (null !== $pool_instance) {
				return $pool_instance;
			}
		}
		$q = new Query;
<?php 
    foreach ($PKs as $k => &$v) {
        ?>
		$q->add('<?php 
        echo $v;
        ?>
', $<?php 
        echo StringFormat::variable($v);
        ?>
);
<?php 
    }
    ?>
		return static::doSelectOne($q);
<?php 
}
?>
	}

<?php 
foreach ($this->getColumns($table_name) as $field) {
    ?>
	/**
Exemple #4
0
 function getTemplateParams($table_name)
 {
     $class_name = $this->getModelName($table_name);
     $column_names = $PKs = array();
     $auto_increment = false;
     $columns = $this->getColumns($table_name);
     $pks = $this->getPrimaryKeys($table_name);
     $pk = null;
     foreach ($columns as &$column) {
         $column_names[] = $column->getName();
         if ($column->isPrimaryKey()) {
             $PKs[] = $column->getName();
             if ($column->isAutoIncrement()) {
                 $auto_increment = true;
             }
         }
     }
     if (count($PKs) == 1) {
         $pk = $PKs[0];
     } else {
         $auto_increment = false;
     }
     return array('auto_increment' => $auto_increment, 'table_name' => $table_name, 'controller_name' => $this->getControllerName($table_name), 'model_name' => $class_name, 'column_names' => $column_names, 'plural' => StringFormat::pluralVariable($table_name), 'plural_url' => StringFormat::pluralURL($table_name), 'single' => StringFormat::variable($table_name), 'single_url' => StringFormat::url($table_name), 'pk' => $pk, 'primary_keys' => $pks, 'pk_method' => $pk ? StringFormat::classMethod('get' . StringFormat::titleCase($pk)) : null, 'pk_var' => $pk ? StringFormat::variable($pk) : null, 'actions' => $this->getActions($table_name), 'columns' => $columns);
 }
Exemple #5
0
		}
		if (null === $value && is_array($column) && Model::isTemporalType($type)) {
			$column = <?php 
echo $model_name;
?>
::coerceTemporalValue($column, $type);
		}
		return parent::addOr($column, $value, $operator, $quote);
	}

<?php 
foreach ($columns as $key => &$column) {
    $constant = $model_name . '::' . StringFormat::constant($column->getName());
    $php_name = StringFormat::titleCase($column->getName());
    $column_type = $model_name . '::COLUMN_TYPE_' . $column->getType();
    $value_param = '$' . StringFormat::variable($column->getType());
    foreach (array('and', 'or') as $verb) {
        foreach (array('', 'Not', 'Like', 'NotLike', 'Greater', 'GreaterEqual', 'Less', 'LessEqual', 'Null', 'NotNull', 'Between', 'BeginsWith', 'EndsWith', 'Contains') as $oper) {
            switch ($oper) {
                case 'Null':
                case 'NotNull':
                    $params = '';
                    break;
                case 'Between':
                    $params = $value_param . ', $from, $to';
                    break;
                default:
                    $params = $value_param;
                    break;
            }
            ?>