const CHANGE = 2;
const DELETION = 3;
- public static function logAction($request, $object, $action_flag, $message='')
+ public static function logAction($request, $object, $action_flag, $object_url=null, $message='')
{
- $log = new AdminLog();
- $log->username = $request->user->username;
- $log->user_id = $request->user->id;
- $log->object_id = (int)$object[$object->getTable()->getIdentifier()];
- $log->object_class = get_class($object);
- $log->object_repr = (string)$object;
- $log->action_flag = $action_flag;
- $log->change_message = $message;
+ $log = new AdminLog;
+ $log->username = $request->user->username;
+ $log->user_id = $request->user->id;
+
+ $log->object_id = (int)$object[$object->getTable()->getIdentifier()];
+ $log->object_class = get_class($object);
+ $log->object_repr = (string)$object;
+
+ if (!$object_url) {
+ $app = IPF_Utils::appByModel($log->object_class);
+ if ($app)
+ $object_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_EditItem', array($app->getSlug(), strtolower($log->object_class), $log->object_id));
+ }
+
+ $log->object_url = $object_url;
+
+ $log->action_flag = $action_flag;
+ $log->change_message = $message;
+
$log->save();
}
public function is_addition()
{
- if ($this->action_flag==AdminLog::ADDITION)
- return true;
- return false;
+ return $this->action_flag == AdminLog::ADDITION;
}
public function is_change()
{
- if ($this->action_flag==AdminLog::CHANGE)
- return true;
- return false;
+ return $this->action_flag == AdminLog::CHANGE;
}
public function is_deletion()
{
- if ($this->action_flag==AdminLog::DELETION)
- return true;
- return false;
- }
-
- public function GetAdminUrl()
- {
- return IPF_HTTP_URL::urlForView('IPF_Admin_Views_Index').IPF_Utils::appLabelByModel($this->object_class).'/'.strtolower($this->object_class).'/'.$this->object_id.'/';
+ return $this->action_flag == AdminLog::DELETION;
}
}
$table->setColumn('object_id', 'integer', null, array('type' => 'integer'));
$table->setColumn('object_class', 'string', 200, array('type' => 'string', 'length' => '200'));
$table->setColumn('object_repr', 'string', 200, array('type' => 'string', 'length' => '200'));
+ $table->setColumn('object_url', 'string', 200, array('type' => 'string', 'length' => '200'));
$table->setColumn('action_flag', 'integer', null, array('type' => 'integer'));
$table->setColumn('change_message', 'string', 200, array('type' => 'string', 'length' => '200'));
- $table->addIndex('idx_object_id', array('fields' => 'object_id'));
- $table->addIndex('idx_object_class', array('fields' => 'object_class'));
$table->addIndex('idx_created_at', array('fields' => 'created_at'));
- $table->addIndex('idx_action_flag', array('fields' => 'action_flag'));
$table->setOption('type', 'INNODB');
$table->setOption('collate', 'utf8_unicode_ci');
$table->setOption('charset', 'utf8');