Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 918

Přidáno uživatelem Michal Kliment před více než 13 roky(ů)

Pokroceny prace na vetvi approval. Obzvlaste na nove feature watchdogy.

Zobrazit rozdíly:

freenetis/branches/approval/application/models/watchdog_user.php
<?php
/**
*
* @author Michal Kliment
* @copyright (c) 2011 Kliment Michal
* @license GNU GPLv3
* @license http://www.gnu.org/licenses/gpl.txt
*/
class Watchdog_user_Model extends ORM
{
protected $belongs_to = array('watchog');
}
?>
freenetis/branches/approval/application/models/watchdog.php
class Watchdog_Model extends ORM
{
protected $has_many = array('watchdog_conds');
protected $has_many = array('watchdog_conds', 'watchdog_users');
public function get_all_users_by_watchdog_id ($watchdog_id)
{
return $this->db->query("
SELECT wu.* FROM watchdogs w
JOIN watchdog_users wu ON w.id = wu.watchdog_id AND wu.enabled = 1
WHERE w.id = 1
", array ($watchdog_id));
}
public function get_all_users_ids_by_watchdog_id ($watchdog_id)
{
$arr_users = array ();
$users = $this->get_all_users_by_watchdog_id ($watchdog_id);
foreach ($users as $user)
$arr_users[] = $user->id;
return $arr_users;
}
}
?>
freenetis/branches/approval/application/controllers/watchdogs.php
* @param string $action
* @return array
*/
public static function get_users_by_object_table_action ($object, $table, $action = 'all')
public static function get_users_by_object_table_action ($object, $table, $action)
{
// creates model only once
if (!self::$model)
self::$model = new Watchdog_Model();
// finds all watchdogs belong to this table
$watchdogs = self::$model->like(array('table' => $table))->find_all();
// finds all watchdogs belong to this table and action
$watchdogs = self::$model->like(array('table' => $table, 'action' => '%|'.$action.'|%'),FALSE,FALSE)->find_all();
$arr_users = array();
......
{
$return = true;
$allowed_actions = explode(",",$watchdog->action);
if (!in_array($action, $allowed_actions) && !in_array('all', $allowed_actions))
continue;
foreach ($watchdog->watchdog_conds as $cond)
{
if (!isset($object->{$cond->column}))
......
if ($return == false)
continue;
$arr_users[] = $watchdog->user_id;
foreach ($watchdog->watchdog_users as $watchdog_user)
{
if (!isset ($arr_users[$watchdog_user->user_id]) || $arr_users[$watchdog_user->user_id]['priority'] > $watchdog_user->priority)
$arr_users[$watchdog_user->user_id] = array(
'priority' => $watchdog_user->priority,
'enabled' => $watchdog_user->enabled,
'notice_kinds' => explode ('|', $watchdog_user->notice_kind)
);
}
}
foreach ($arr_users as $user_id => $user)
{
if (!$user['enabled'])
unset ($arr_users[$user_id]);
}
return $arr_users;
}
......
* @param string $action
* @return arary
*/
public static function get_users_by_object_action ($object, $action = 'all')
public static function get_users_by_object_action ($object, $action)
{
return self::get_users_by_object_table_action ($object, $object->get_table_name(), $action = 'all');
return self::get_users_by_object_table_action ($object, $object->get_table_name(), $action);
}
}
freenetis/branches/approval/application/controllers/works.php
url::redirect(url_lang::base().'works/show_by_user/'.$work_user_id);
}
public function test ()
{
//$profiler = new Profiler();
$work = new Job_Model (5);
print_r (Watchdogs_Controller::get_users_by_object_action($work, 'add'));
//$profiler->render(TRUE);
}
/** CALLBACK FUNCTIONS **/
/**
freenetis/branches/approval/application/upgrade_sql/upgrade_sql_916.php
<?php
// array of sql queries that upgrade database
$upgrade_sql[916] = array(
"UPDATE `aro_groups_map` SET `group_id` = '22' WHERE `aro_groups_map`.`acl_id` = 73 AND `aro_groups_map`.`group_id` = 44;"
);
?>
freenetis/branches/approval/application/upgrade_sql/upgrade_sql.php
// array of sql queries that upgrade database
$upgrade_sql[get_SVN_rev()] = array(
"UPDATE `aro_groups_map` SET `group_id` = '22' WHERE `aro_groups_map`.`acl_id` = 73 AND `aro_groups_map`.`group_id` = 44;"
"CREATE TABLE IF NOT EXISTS `watchdogs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`table` varchar(255) COLLATE utf8_czech_ci NOT NULL,
`action` varchar(255) COLLATE utf8_czech_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;",
"CREATE TABLE IF NOT EXISTS `watchdog_conds` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`watchdog_id` int(11) NOT NULL,
`op` varchar(100) COLLATE utf8_czech_ci NOT NULL,
`value` varchar(255) COLLATE utf8_czech_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `watchdog_id` (`watchdog_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;",
"CREATE TABLE IF NOT EXISTS `watchdog_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`watchdog_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`priority` int(11) NOT NULL,
`enabled` tinyint(1) NOT NULL DEFAULT '1',
`notice_kind` varchar(255) COLLATE utf8_czech_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `watchdog_id` (`watchdog_id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;"
);
?>

Také k dispozici: Unified diff