? '<span class="positive">✔</span>'
: '<span class="negative">✘</span>';
case 'timestamp':
- return Text::escape(self::formatDate($value));
+ return Text::escape($this->formatDate($value));
default:
return Text::escape($value);
}
}
- protected static function formatDate($str, $format='Y-m-d H:i:s', $tz=null)
+ private function formatDate($str)
{
- if (!$tz)
- $tz = IPF::get('time_zone');
$date = new DateTime($str, new DateTimeZone('UTC'));
- $date->setTimeZone(new DateTimeZone($tz));
- return gmdate($format, $date->format('U') + $date->getOffset());
+ $date->setTimeZone(new DateTimeZone($this->tz));
+ return gmdate('Y-m-d H:i:s', $date->format('U') + $date->getOffset());
}
protected function columnTitle($column)
}
}
-class IPF_Admin_Model_OwnedFilter extends IPF_Admin_Model_Filter
-{
- private $column, $selected = null;
-
- function __construct($modelName, $column, $title)
- {
- $this->column = $column;
- $this->title = $title;
- $this->paramName = 'filter_'.$this->column;
- }
-
- function setParams($params)
- {
- $this->selected = \PFF\Arr::get($params, $this->paramName);
- }
-
- function applyToQuery($q)
- {
- // check ???
- if ($this->selected)
- $q->addWhere($this->column.' = ?', array($this->selected));
- }
-
- function getItems()
- {
- $items = [];
-
- // reset filter
- $items[] = array(
- 'id' => null,
- 'label' => __('All'),
- 'selected' => !$this->selected,
- );
-
- foreach (\PFF\Container::auth()->userQuery()->fetchAll() as $val) {
- $id = $val->id;
- $items[] = array(
- 'id' => $id,
- 'label' => (string)$val,
- 'selected' => $this->selected == $id,
- );
- }
-
- return $items;
- }
-}
-
class BooleanFilter extends IPF_Admin_Model_Filter
{
private $column, $trueTitle, $falseTitle, $selected;
abstract function getModelName();
- public function getApplication()
- {
- foreach (IPF_Project::getInstance()->appList() as $app)
- foreach (IPF_Legacy_ORM_App::appModelList($app) as $model)
- if ($model == $this->getModelName())
- return $app;
- return null;
- }
-
function getAddNum()
{
return 4;
class IPF_Legacy_ORM_App extends IPF_Application
{
+ private $apps;
+ private $project_root;
+
+ public function configure(\Pimple\Container $container, IPF_Settings $settings)
+ {
+ $this->apps = $container['apps'];
+ $this->project_root = $container['settings']->get('project_root');
+ }
+
private static $appModels = array();
public static function appModelList($app)
if (!array_key_exists($app->getName(), self::$appModels)) {
$models = array();
try {
- $it = new DirectoryIterator($app->getPath().DIRECTORY_SEPARATOR.'models');
+ $it = new DirectoryIterator($app->getPath() . DIRECTORY_SEPARATOR . 'models');
foreach ($it as $file) {
$e = explode('.', $file->getFileName(), 2);
if (count($e) == 2 && $e[1] === 'php') {
public function commands()
{
return array(
- new IPF_Legacy_ORM_Command_BuildModels,
- new IPF_Legacy_ORM_Command_Sql,
- new IPF_Legacy_ORM_Command_SyncDB,
- new IPF_Legacy_ORM_Command_Fixtures,
+ new IPF_Legacy_ORM_Command_BuildModels($this->apps),
+ new IPF_Legacy_ORM_Command_Sql($this->apps),
+ new IPF_Legacy_ORM_Command_SyncDB($this->apps),
+ new IPF_Legacy_ORM_Command_Fixtures($this->apps, $this->project_root . DIRECTORY_SEPARATOR . 'project'),
);
}
}
-
public $command = 'buildmodels';
public $description = 'Build all model classes';
+ private $apps;
+
+ function __construct($apps)
+ {
+ $this->apps = $apps;
+ }
+
public function run($args=null)
{
print "Build all model classes\n\n";
- $project = IPF_Project::getInstance();
-
$paths = array();
- foreach ($project->appList() as $app)
+ foreach ($this->apps as $app)
$paths[] = $app->getPath();
IPF_ORM::generateModelsFromYaml($paths, array());
}
}
-
public $command = 'fixtures';
public $description = 'Load fixtures into database';
+ private $apps;
+ private $project_root;
+
+ function __construct(array $apps, $project_root)
+ {
+ $this->apps = $apps;
+ $this->project_root = $project_root;
+ }
+
public function run($args=null)
{
print "Load project fixtures to database\n";
- $project = IPF_Project::getInstance();
-
- $paths = array(IPF::get('project_root').DIRECTORY_SEPARATOR.'project');
- foreach ($project->appList() as $app)
+ $paths = array($this->project_root);
+ foreach ($this->apps as $app)
$paths[] = $app->getPath();
$fixtures = array();
}
}
}
-
public $command = 'sql';
public $description = 'Show all SQL DDL from model classes';
+ private $apps;
+
+ function __construct(array $apps)
+ {
+ $this->apps = $apps;
+ }
+
public function run($args=null)
{
print "Show all SQL DDL from model classes\n";
- foreach (IPF_Project::getInstance()->appList() as $app)
+ foreach ($this->apps as $app)
print IPF_ORM::generateSqlFromModels($app)."\n";
}
}
-
public $command = 'syncdb';
public $description = 'Create tables from model classes';
+ private $apps;
+
+ function __construct(array $apps)
+ {
+ $this->apps = $apps;
+ }
+
public function run($args=null)
{
print "Create tables from model classes\n";
- $project = IPF_Project::getInstance();
-
$models = array();
- foreach ($project->appList() as $app)
+ foreach ($this->apps as $app)
$models = array_merge($models, IPF_Legacy_ORM_App::appModelList($app));
IPF_ORM::createTablesFromModels($models);
}
}
-
$form_field = new IPF_Form_Field_Float($params);
break;
case 'date':
- $format = IPF::get('date_format');
+ $format = @$extra['date_format'];
if ($format)
$params['widget_attrs'] = array('format' => $format);
$form_field = new IPF_Form_Field_Date($params);
break;
case 'datetime':
case 'timestamp':
- $format = IPF::get('datetime_format');
+ $format = @$extra['datetime_format'];
if ($format)
$params['widget_attrs'] = array('format' => $format);
$form_field = new IPF_Form_Field_Datetime($params);
+++ /dev/null
-<?php
-
-class IPF_ORM_Template_Listener_Owned
-{
- private $columnName;
-
- public function __construct($columnName)
- {
- $this->columnName = $columnName;
- }
-
- public function preInsert(IPF_ORM_Event $event)
- {
- $this->setOwner($event->getInvoker());
- }
-
- public function preUpdate(IPF_ORM_Event $event)
- {
- $this->setOwner($event->getInvoker());
- }
-
- private function setOwner($obj)
- {
- $columnName = $this->columnName;
- if ($obj->$columnName)
- return;
-
- $request = IPF_Project::getInstance()->request;
- if ($request && !$request->user->isAnonymous()) {
- $obj->$columnName = $request->user->id;
- }
- }
-}
-
+++ /dev/null
-<?php
-
-class IPF_ORM_Template_Owned extends IPF_ORM_Template
-{
- private $name = 'owner';
- private $columnName = 'owner_id';
- private $exclude = true;
- private $verbose = 'owner';
-
- public function __construct(array $options=array())
- {
- if ($options) {
- if (array_key_exists('column', $options))
- $this->columnName = $options['column'];
- if (array_key_exists('name', $options))
- $this->name = $options['name'];
- if (array_key_exists('exclude', $options))
- $this->exclude = $options['exclude'];
- if (array_key_exists('verbose', $options))
- $this->verbose = $options['verbose'];
- }
- }
-
- public function getColumnName()
- {
- return $this->columnName;
- }
-
- public function setTableDefinition(IPF_ORM_Table $table)
- {
- $table->setColumn($this->columnName, 'integer', null, array(
- 'exclude' => $this->exclude,
- 'verbose' => $this->verbose,
- ));
-
- $fks = $table->getOption('foreignKeys', array());
- $fks[] = array(
- 'local' => $this->columnName,
- 'foreign' => 'id',
- 'foreignTable' => 'auth_users',
- 'onUpdate' => null,
- 'onDelete' => 'CASCADE',
- );
- $table->setOption('foreignKeys', $fks);
-
- $table->listeners['Owned_'.$this->columnName] = new IPF_ORM_Template_Listener_Owned($this->columnName);
- }
-}
-