Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1233

Přidáno uživatelem Ondřej Fibich před asi 13 roky(ů)

Novinky:

- vytvareni kopie neschvalene prace
- pridano schvalovani vykazu bez vicekoloveho hlasovani

Upravy:

- vylepseni rozhrani vykazu
- presun funkce get_state z Votes_Controlleru do Job_Modelu
- doplneni @property k approval modelum

Zobrazit rozdíly:

freenetis/branches/testing/application/i18n/cs_CZ/texts.php
'country code' => 'Kód země',
'create backup' => 'Vytvořit zálohu',
'create date' => 'Datum vytvoření',
'create new work from rejected' => 'Vytvoř novou práci ze zamítnuté',
'creating of all records' => 'Vytváření všech záznamů',
'creating of own records' => 'Vytváření vlastních záznamů',
'credit' => 'Kredit',
......
'page after canceling redirection' => 'Stránka po zrušení přesměrování',
'page title' => 'Titulek stránky',
'parse' => 'Parsovat',
'partially' => 'Částečně',
'password for voip account' => 'Heslo pro VoIP účet',
'password has been successfully changed' => 'Heslo bylo úspěšně změněno.',
'password' => 'Heslo',
......
'pre-installation check' => 'Předinstalační kontrola',
'preview' => 'Náhled',
'previous' => 'Předchozí',
'previous rejected work' => 'Předchozí odmítnutá práce',
'previous transfer' => 'Předchozí převod',
'prepaid' => 'Předplacený',
'price' => 'Cena',
......
'sent message' => 'Odeslaná zpráva',
'september' => 'Září',
'service' => 'Služba',
'set votes to' => 'Nastavit hlasy na',
'set whitelist to member' => 'Nastavit bílou listinu členovi',
'settings' => 'Nastavení',
'settings for configuration files has been successfully updated' => 'Nastavení pro kofigurační soubory bylo úspěšně upraveno',
freenetis/branches/testing/application/vendors/unit_tester/unit_testing_config.xml
<input></input>
</values>
</method>
<method name="update_paths" autogenerate="on">
<attributes></attributes>
<method name="update_paths" autogenerate="off">
<attributes/>
<values>
<input></input>
</values>
</method>
<method name="insert_path" autogenerate="on">
<attributes></attributes>
<method name="insert_path" autogenerate="off">
<attributes/>
<values>
<input></input>
</values>
</method>
<method name="member_name" autogenerate="on">
......
</input>
</values>
</method>
<method name="get_state" autogenerate="on">
<attributes>
<attribute name="object" default_value="" />
<attribute name="type" default_value="" />
</attributes>
<values>
<input>
<param value="" />
<param value="" />
</input>
</values>
</method>
</controller>
<controller name="web_interface">
<method name="index" autogenerate="on">
......
</model>
<model name="allowed_subnets_count"></model>
<model name="approval_template">
<method name="count_all_approval_templates" autogenerate="on">
<attributes></attributes>
<values>
<input></input>
</values>
</method>
<method name="get_state" autogenerate="off">
<attributes>
<attribute name="approval_template_id" default_value=""/>
......
<param value="1"/>
</input>
</values>
</method>
</model>
</method></model>
<model name="approval_template_item">
<method name="get_all_items_by_template_id" autogenerate="off">
<attributes>
......
<param value="1"/>
</input>
</values>
</method>
<method name="check_user_vote_rights" autogenerate="off">
<attributes>
<attribute name="template_id" default_value=""/>
<attribute name="user_id" default_value=""/>
<attribute name="suggest_amount" default_value="0"/>
</attributes>
<values>
<input>
<param value=""/>
<param value=""/>
<param value=""/>
</input>
<input>
<param value="1"/>
<param value="1"/>
<param value="10000"/>
</input>
<input>
<param value="sefs$#"/>
<param value="aad$#$@"/>
<param value="454.,mmf14"/>
</input>
</values>
</method>
<method name="get_aro_groups_by_approval_template_id" autogenerate="off">
<attributes>
<attribute name="template_id" default_value=""/>
<attribute name="suggest_amount" default_value="0"/>
<attribute name="user_id" default_value="0"/>
</attributes>
<values>
<input>
<param value=""/>
<param value=""/>
<param value=""/>
</input>
<input>
<param value="1"/>
<param value="1"/>
<param value="10000"/>
</input>
<input>
<param value="sefs$#"/>
<param value="aad$#$@"/>
<param value="454.,mmf14"/>
</input>
</values>
</method>
<method name="get_aro_group_by_approval_template_id_and_user_id" autogenerate="off">
<attributes>
<attribute name="template_id" default_value=""/>
<attribute name="user_id" default_value=""/>
<attribute name="suggest_amount" default_value="0"/>
</attributes>
<values>
<input>
<param value=""/>
<param value=""/>
<param value=""/>
</input>
<input>
<param value="1"/>
<param value="1"/>
<param value="10000"/>
</input>
<input>
<param value="sefs$#"/>
<param value="aad$#$@"/>
<param value="454.,mmf14"/>
</input>
</values>
</method>
<method name="get_aro_ids_by_approval_template_id" autogenerate="off">
<attributes>
<attribute name="template_id" default_value=""/>
<attribute name="suggest_amount" default_value="0"/>
</attributes>
<values>
<input>
<param value=""/>
<param value=""/>
</input>
<input>
<param value="1"/>
<param value="1"/>
</input>
<input>
<param value="sef%f.sef"/>
<param value="sef%f.sef"/>
</input>
</values>
</method></model>
<model name="approval_type">
<method name="count_all_approval_types" autogenerate="on">
<attributes></attributes>
<values>
<input></input>
</values>
</method>
<method name="get_state" autogenerate="off">
<attributes>
<attribute name="approval_type_id" default_value=""/>
......
<param value="sef'%sef."/>
</input>
</values>
</method>
</model>
</method></model>
<model name="aro_group">
<method name="get_parent_id_by_id" autogenerate="off">
<attributes>
......
<param value="'sef$"/>
</input>
</values>
</method>
<method name="get_state" autogenerate="off">
<attributes>
<attribute name="type" default_value=""/>
</attributes>
<values>
</values>
</method></model>
<model name="job_report">
<method name="get_state" autogenerate="on">
......
</method>
</helper>
<helper name="callback">
<method name="work_approved" autogenerate="off">
<attributes>
<attribute name="item" default_value=""/>
<attribute name="name" default_value=""/>
</attributes>
<values>
</values>
</method>
<method name="limited_text" autogenerate="off">
<attributes>
<attribute name="item" default_value=""/>
freenetis/branches/testing/application/helpers/callback.php
class callback
{
/**
* Callback for true false values.
*
* @author Ondrej Fibich
* @param object $item
* @param string $name
*/
public static function work_approved($item, $name)
{
$bool = $item->$name;
echo html::image(array
(
'src' => 'media/images/states/' . ($bool ? 'agree.png' : 'disagree.png')
));
}
/**
* Callback for limited text, text over 50 character is stripped and added to title.
*
* @author Ondrej Fibich
freenetis/branches/testing/application/models/approval_template.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is release under GPLv3 licence.
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
......
*
* @author Michal Kliment
* @package Model
*
* @property string $name
* @property string $comment
* @property integer $state
* @property ORM $approval_template_items
* @property ORM $jobs
* @property ORM $job_reports
*/
class Approval_template_Model extends ORM
{
......
* @param array $filter_values
* @return Mysql_Result object
*/
public function get_all_approval_templates($limit_from = 0, $limit_results = 50,
$order_by = 'id', $order_by_direction = 'ASC', $filter_values = array())
public function get_all_approval_templates(
$limit_from = 0, $limit_results = 50, $order_by = 'id',
$order_by_direction = 'ASC', $filter_values = array())
{
// order by direction check
if (strtolower($order_by_direction) != 'desc')
......
}
/**
* Function to count all approval templates
*
* @author Michal Kliment
* @return number
*/
public function count_all_approval_templates()
{
return $this->db->query("
SELECT COUNT(at.id) AS count
FROM approval_templates at
")->current()->count;
}
/**
* Function to get state of approval template
*
* @author Michal Kliment
......
}
return $this->db->query("
SELECT IFNULL((MAX(j.state)+1),0) AS state FROM approval_templates t
SELECT IFNULL((MAX(j.state)+1),0) AS state
FROM approval_templates t
LEFT JOIN jobs j ON j.approval_template_id = t.id
WHERE j.state < 2 AND t.id = ?
", array($approval_template_id))->current()->state;
freenetis/branches/testing/application/models/approval_type.php
*
* @author Michal Kliment
* @package Model
*
* @property string $name
* @property string $comment
* @property integer $type
* @property integer $majority_percent
* @property integer $aro_group_id
* @property Aro_group_Model $aro_group
* @property string $time
* @property integer $default_vote
* @property integer $min_suggested_amount
*/
class Approval_type_Model extends ORM
{
......
* @param array $filter_values
* @return Mysql_Result object
*/
public function get_all_approval_types($limit_from = 0, $limit_results = 50,
$order_by = 'id', $order_by_direction = 'ASC', $filter_values = array())
public function get_all_approval_types(
$limit_from = 0, $limit_results = 50, $order_by = 'id',
$order_by_direction = 'ASC', $filter_values = array())
{
// order by check
if (!$this->has_column($order_by))
......
}
/**
* Function to count all approval types
*
* @author Michal Kliment
* @return number
*/
public function count_all_approval_types()
{
return $this->db->query("
SELECT COUNT(at.id) AS count
FROM approval_types at
")->current()->count;
}
/**
* Function to get state of approval type
*
* @author Michal Kliment
* @param number $approval_type_id
* @return number
*/
public function get_state($approval_type_id)
public function get_state($approval_type_id = NULL)
{
if ($approval_type_id == NULL && $this->id)
{
$approval_type_id = $this->id;
}
return $this->db->query("
SELECT IFNULL(MAX(templates.state),0) AS state
FROM approval_types AS types
LEFT JOIN approval_template_items AS items ON types.id = items.approval_type_id
LEFT JOIN approval_templates AS templates ON items.approval_template_id = templates.id
WHERE types.id = ?
SELECT IFNULL(MAX(te.state),0) AS state
FROM approval_types AS t
LEFT JOIN approval_template_items i ON t.id = i.approval_type_id
LEFT JOIN approval_templates te ON i.approval_template_id = te.id
WHERE t.id = ?
", array($approval_type_id))->current()->state;
}
freenetis/branches/testing/application/models/approval_template_item.php
*
* @author Michal Kliment
* @package Model
*
* @property integer $priority
* @property integer $approval_template_id
* @property Approval_template_Model $approval_template
* @property integer $approval_type_id
* @property Approval_type_Model $approval_type
*/
class Approval_template_item_Model extends ORM
{
......
* @param number $user_id
* @return bool
*/
public function check_user_vote_rights($template_id, $user_id, $suggest_amount = 0)
public function check_user_vote_rights(
$template_id, $user_id, $suggest_amount = 0)
{
return (bool) $this->get_aro_group_by_approval_template_id_and_user_id($template_id, $user_id, $suggest_amount);
return (bool) $this->get_aro_group_by_approval_template_id_and_user_id(
$template_id, $user_id, $suggest_amount
);
}
/**
......
* @param number $user_id
* @return Mysql Result object
*/
public function get_aro_groups_by_approval_template_id($template_id, $suggest_amount = 0, $user_id = 0)
public function get_aro_groups_by_approval_template_id(
$template_id, $suggest_amount = 0, $user_id = 0)
{
$cond = ($suggest_amount) ? ' AND t.min_suggest_amount <= '.doubleval($suggest_amount) : '';
$cond = '';
if ($suggest_amount)
{
$cond = ' AND t.min_suggest_amount <= '.doubleval($suggest_amount);
}
return $this->db->query("
SELECT a.id, a.name FROM approval_template_items i
......
* @param number $suggest_amount
* @return Mysql Result object
*/
public function get_aro_group_by_approval_template_id_and_user_id($template_id, $user_id, $suggest_amount = 0)
public function get_aro_group_by_approval_template_id_and_user_id(
$template_id, $user_id, $suggest_amount = 0)
{
$cond = ($suggest_amount) ? ' AND t.min_suggest_amount <= '.doubleval($suggest_amount) : '';
$cond = '';
if ($suggest_amount)
{
$cond = ' AND t.min_suggest_amount <= '.doubleval($suggest_amount);
}
$result = $this->db->query("
SELECT a.id, a.name FROM approval_template_items i
......
WHERE i.approval_template_id = ? AND m.aro_id = ? $cond
ORDER BY i.priority
", array($template_id, $user_id));
// no record, returns null
if (!$result || $result->count() != 1)
{
......
* @param number $suggest_amount
* @return Mysql Result object
*/
public function get_aro_ids_by_approval_template_id($template_id, $suggest_amount = 0)
public function get_aro_ids_by_approval_template_id(
$template_id, $suggest_amount = 0)
{
$cond = ($suggest_amount) ? ' AND t.min_suggest_amount <= '.doubleval($suggest_amount) : '';
$cond = '';
if ($suggest_amount)
{
$cond = ' AND t.min_suggest_amount <= '.doubleval($suggest_amount);
}
return $this->db->query("
SELECT g.aro_id AS id FROM approval_template_items i
freenetis/branches/testing/application/models/job.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is release under GPLv3 licence.
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
......
* @property string $create_date
* @property double $hours
* @property integer $km
* @property integer $previous_rejected_work_id
* @property Job_Model $previous_rejected_work
*/
class Job_Model extends ORM
{
protected $belongs_to = array
(
'user', 'added_by' => 'user',
'approval_template', 'job_report'
'approval_template', 'job_report',
'previous_rejected_work' => 'job'
);
/**
......
LIMIT " . intval($limit_from) . ", " . intval($limit_results) . "
", array
(
url_lang::lang('texts.Agree'),
url_lang::lang('texts.Disagree'),
url_lang::lang('texts.Abstain'),
__('Agree'),
__('Disagree'),
__('Abstain'),
Session::instance()->get('user_id')
));
}
......
LIMIT " . intval($limit_from) . ", " . intval($limit_results) . "
", array
(
url_lang::lang('texts.Agree'),
url_lang::lang('texts.Disagree'),
url_lang::lang('texts.Abstain')
__('Agree'),
__('Disagree'),
__('Abstain')
));
}
......
LIMIT " . intval($limit_from) . ", " . intval($limit_results) . "
", array
(
url_lang::lang('texts.Agree'),
url_lang::lang('texts.Disagree'),
url_lang::lang('texts.Abstain'),
__('Agree'),
__('Disagree'),
__('Abstain'),
Session::instance()->get('user_id')
));
}
......
WHERE j.state <= 1 AND j.job_report_id IS NULL AND j.user_id = ?) AS q"
, array
(
url_lang::lang('texts.Agree'),
url_lang::lang('texts.Disagree'),
url_lang::lang('texts.Abstain'),
__('Agree'),
__('Disagree'),
__('Abstain'),
Session::instance()->get('user_id'),
$user_id
));;
......
WHERE j.state = 2 AND j.job_report_id IS NULL AND j.user_id = ?) AS q"
, array
(
url_lang::lang('texts.Agree'),
url_lang::lang('texts.Disagree'),
url_lang::lang('texts.Abstain'),
__('Agree'),
__('Disagree'),
__('Abstain'),
$user_id
));
}
......
WHERE j.state = 3 AND j.job_report_id IS NULL AND j.user_id = ?) AS q"
, array
(
url_lang::lang('texts.Agree'),
url_lang::lang('texts.Disagree'),
url_lang::lang('texts.Abstain'),
__('Agree'),
__('Disagree'),
__('Abstain'),
$user_id
));
}
......
public function get_all_works_by_job_report_id($job_report_id)
{
return $this->db->query("
SELECT j.id, j.user_id, j.approval_template_id, j.description,
j.suggest_amount, date, hours, km, v.vote, v.comment
SELECT q.*, (agree_count - disagree_count) AS approval_state,
IF(IFNULL(q.transfer_id, 0), 1, 0) AS approved
FROM (SELECT j.*, CONCAT(u.name, ' ', u.surname) AS uname, v.vote, v.comment,
(
SELECT COUNT(*)
FROM votes
WHERE vote = 1 AND votes.fk_id = j.id AND votes.type = 1
) AS agree_count,
(
SELECT COUNT(*)
FROM votes
WHERE vote = -1 AND votes.fk_id = j.id AND votes.type = 1
) AS disagree_count,
(
SELECT COUNT(*)
FROM votes
WHERE vote = 0 AND votes.fk_id = j.id AND votes.type = 1
) AS abstain_count,
(
SELECT COUNT(*)
FROM comments c
WHERE j.comments_thread_id = c.comments_thread_id
) AS comments_count,
(
SELECT GROUP_CONCAT(user, ' (',SUBSTRING(c.datetime,1,10),'): \n',c.text SEPARATOR ', \n\n') FROM
(
SELECT c.*, CONCAT(u.surname,' ',u.name) AS user
FROM comments c
LEFT JOIN users u ON c.user_id = u.id
ORDER BY datetime DESC
) AS c
WHERE c.comments_thread_id = j.comments_thread_id
GROUP BY c.comments_thread_id
) AS comments,
(
SELECT GROUP_CONCAT(comment SEPARATOR ', \n\n') FROM
(
SELECT v.fk_id, v.type, CONCAT(u.surname,' ',u.name,' (',SUBSTRING(v.time,1,10),'): \n',
IF(v.vote=1,?,IF(v.vote=-1,?,?)),
IF(v.comment NOT LIKE '',' - ',''), v.comment) AS comment
FROM votes v
LEFT JOIN users u ON v.user_id = u.id
ORDER BY v.vote DESC
) AS v
WHERE v.fk_id = j.id AND v.type = 1
GROUP BY fk_id
) AS vote_comments
FROM jobs j
LEFT JOIN votes v ON j.id = v.fk_id AND v.type = 1 AND v.user_id = ?
WHERE j.job_report_id = ?
LEFT JOIN users u ON j.user_id = u.id
LEFT JOIN votes v ON j.id = v.fk_id AND v.type =1 AND v.user_id = ?
WHERE j.job_report_id = ?) AS q
ORDER BY date
", Session::instance()->get('user_id'), $job_report_id);
", array
(
__('Agree'),
__('Disagree'),
__('Abstain'),
Session::instance()->get('user_id'),
$job_report_id
));
}
/**
* Function to get state of work approval from all votes
* by approval template and type.
*
* @author Michal Kliment
* @param integer $type
* @return integer
*/
public function get_state($type)
{
if (!$this->id)
{
throw new Exception('Invalid call of method, object has to be loaded.');
}
$approval_template_item_model = new Approval_template_item_Model();
$groups_aro_map_model = new Groups_aro_map_Model();
$vote_model = new Vote_Model();
$votes_count = $vote_model->where('type', $type)
->where('fk_id', $this->id)
->count_all();
// 0 votes - vote not yet started
if (!$votes_count)
{
$state = 0;
return $state;
}
$approval_template_items = $approval_template_item_model
->where('approval_template_id', $this->approval_template_id)
->orderby('priority')
->find_all();
$arr_users = array();
$state = 3;
foreach ($approval_template_items as $approval_template_item)
{
if (!$this->suggest_amount ||
$approval_template_item->approval_type->min_suggest_amount <= $this->suggest_amount)
{
$count = 0;
$total_votes = 0;
$agree = 0;
$abstain = 0;
$users = $groups_aro_map_model->get_all_users_by_group_id(
$approval_template_item->approval_type->aro_group_id
);
foreach ($users as $user)
{
if (in_array($user->id, $arr_users))
{
continue;
}
$arr_users[] = $user->id;
$count++;
$vote = $vote_model->where('user_id', $user->id)
->where('type', $type)
->where('fk_id', $this->id)
->find();
if ((!$vote || !$vote->id))
{
$interval = date::hour_diff(
$approval_template_item->approval_type->interval
);
if (!$interval)
$state = 1;
}
else
{
$total_votes++;
if ($approval_template_item->approval_type->type == Approval_type_Model::$simple &&
$vote->vote == 0)
{
$abstain++;
}
if ($vote->vote == 1)
$agree++;
}
}
if (!$count)
continue;
if ($count == $total_votes)
{
$total_votes -= $abstain;
$percent = ($total_votes) ? round($agree/$total_votes*100, 2) : 0;
if ($percent < $approval_template_item->approval_type->majority_percent)
{
$state = 2;
return $state;
}
}
else
{
$interval = date::hour_diff($approval_template_item->approval_type->interval);
if ($interval)
{
$count -= $abstain;
$percent = ($count) ? round($agree/$count*100, 2) : 0;
if ($percent < $approval_template_item->approval_type->majority_percent)
{
$agree += ($count - $total_votes + $abstain);
$percent = ($count) ? round($agree/$count*100, 2) : 0;
if ($percent < $approval_template_item->approval_type->majority_percent)
{
$state = 2;
return $state;
}
else
$state = 1;
}
}
else
$state = 1;
}
}
}
return $state;
}
}
freenetis/branches/testing/application/models/job_report.php
* @property double $price_per_hour
* @property double $price_per_km
* @property boolean $concept
* @property unknown_type $jobs
* @property ORM $jobs
* @property integer $transfer_id
* @property Transfer_Model $transfer
*/
class Job_report_Model extends ORM
{
protected $belongs_to = array('user', 'approval_template');
protected $belongs_to = array('user', 'approval_template', 'transfer');
protected $has_many = array('jobs');
......
SELECT r.id, r.user_id, CONCAT(u.name, \' \', u.surname) as uname,
r.description, SUM(j.suggest_amount) AS suggest_amount,
MIN(j.date) AS date_from, MAX(j.date) AS date_to, r.type,
SUM(j.hours) AS hours, SUM(j.km) AS km, MAX(j.state) AS state
SUM(j.hours) AS hours, SUM(j.km) AS km, MAX(j.state) AS state,
r.transfer_id, t.amount AS rating
FROM job_reports r
LEFT JOIN users u ON u.id = r.user_id
LEFT JOIN transfers t ON t.id = r.transfer_id
LEFT JOIN jobs j ON r.id = j.job_report_id
WHERE r.concept = 0 AND r.user_id = ?
GROUP BY r.id
freenetis/branches/testing/application/models/vote.php
public static $vote_options = array
(
NULL => 'None',
0 => 'Abstain',
1 => 'Agree',
-1 => 'Disagree',
0 => 'Abstain'
);
/**
freenetis/branches/testing/application/models/transfer.php
class Transfer_Model extends ORM
{
protected $belongs_to = array('origin' => 'account', 'destination' => 'account');
protected $has_many = array('job_reports');
// special types of transfers
// (column 'type' in the table)
freenetis/branches/testing/application/controllers/votes.php
$vote->time = date('Y-m-d H:i:s');
$vote->save();
$work->state = $this->get_state($work, Vote_Model::$work);
$work->state = $work->get_state(Vote_Model::$work);
// work is approved
if ($work->state == 3)
......
{
// vote about work
case Vote_Model::$work:
$work->state = $this->get_state($work, Vote_Model::$work);
$work->state = $work->get_state(Vote_Model::$work);
// work is approved
if ($work->state == 3)
......
$vote->delete();
status::success('Vote has been successfully deleted.');
$work->state = $this->get_state($work, Vote_Model::$work);
$work->state = $work->get_state(Vote_Model::$work);
$work->save();
// set up state of approval template
$approval_template = new Approval_template_Model(
......
}
/**
* Function to get state of approval
*
* @author Michal Kliment
* @param ORM object $object
* @param int $type
* @return int
*/
public function get_state($object, $type)
{
$approval_template_item_model = new Approval_template_item_Model();
$groups_aro_map_model = new Groups_aro_map_Model();
$vote_model = new Vote_Model();
$votes_count = $vote_model->where('type', $type)
->where('fk_id', $object->id)
->count_all();
// 0 votes - vote not yet started
if (!$votes_count)
{
$state = 0;
return $state;
}
$approval_template_items = $approval_template_item_model
->where('approval_template_id', $object->approval_template_id)
->orderby('priority')
->find_all();
$arr_users = array();
$state = 3;
foreach ($approval_template_items as $approval_template_item)
{
if (!$object->suggest_amount ||
$approval_template_item->approval_type->min_suggest_amount <= $object->suggest_amount)
{
$count = 0;
$total_votes = 0;
$agree = 0;
$abstain = 0;
$users = $groups_aro_map_model->get_all_users_by_group_id(
$approval_template_item->approval_type->aro_group_id
);
foreach ($users as $user)
{
if (in_array($user->id, $arr_users))
continue;
else
{
$arr_users[] = $user->id;
$count++;
$vote = $vote_model->where('user_id', $user->id)
->where('type', $type)
->where('fk_id', $object->id)
->find();
if ((!$vote || !$vote->id))
{
$interval = date::hour_diff(
$approval_template_item->approval_type->interval
);
if (!$interval)
$state = 1;
}
else
{
$total_votes++;
if ($approval_template_item->approval_type->type == Approval_type_Model::$simple &&
$vote->vote == 0)
{
$abstain++;
}
if ($vote->vote == 1)
$agree++;
}
}
}
if (!$count)
continue;
if ($count == $total_votes)
{
$total_votes -= $abstain;
$percent = ($total_votes) ? round($agree/$total_votes*100, 2) : 0;
if ($percent < $approval_template_item->approval_type->majority_percent)
{
$state = 2;
return $state;
}
}
else
{
$interval = date::hour_diff($approval_template_item->approval_type->interval);
if ($interval)
{
$count -= $abstain;
$percent = ($count) ? round($agree/$count*100, 2) : 0;
if ($percent < $approval_template_item->approval_type->majority_percent)
{
$agree += ($count - $total_votes + $abstain);
$percent = ($count) ? round($agree/$count*100, 2) : 0;
if ($percent < $approval_template_item->approval_type->majority_percent)
{
$state = 2;
return $state;
}
else
$state = 1;
}
}
else
$state = 1;
}
}
}
return $state;
}
}
freenetis/branches/testing/application/controllers/approval_templates.php
$limit_results = (int) $this->input->get('record_per_page');
$approval_template_model = new Approval_template_Model();
$total_approval_templates = $approval_template_model->count_all_approval_templates();
$total_approval_templates = $approval_template_model->count_all();
if (($sql_offset = ($page - 1) * $limit_results) > $total_approval_templates)
$sql_offset = 0;
......
'base_url' => Config::get('lang').'/approval_templates/show_all/'
. $limit_results.'/'.$order_by.'/'.$order_by_direction ,
'uri_segment' => 'page',
'total_items' => $total_approval_templates,
'total_items' => $total_approval_templates,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
freenetis/branches/testing/application/controllers/work_reports.php
$grid_approved->field('km');
$grid_approved->callback_field('suggested_amount')
->label('Rating')
$grid_approved->callback_field('suggest_amount')
->callback('Works_Controller::suggest_amount');
$grid_approved->callback_field('rating')
->callback('Works_Controller::rating');
$actions = $grid_approved->grouped_action_field();
......
Controller::error(ACCESS);
}
$transfer = new Transfer_Model($work_report->transfer_id);
$works = ORM::factory('job')->get_all_works_by_job_report_id($work_report->id);
$approval_template_item_model = new Approval_template_item_Model();
......
// test if user can vote
$can_vote = FALSE;
if ($work_report->state <= 1)
if (!$work_report_model->concept && $work_report->state <= 1)
{
foreach ($works as $work)
{
......
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($works)
));
));
$works_grid->field('date')
->label(__('Date'));
if ($can_vote)
{
$works_grid->add_new_button(
'#', __('Set votes to') . ' ' . __('Abstain', '', 1),
array('id' => 'mark_all_abstain')
);
if ($this->user_id != $work_report_model->user_id)
{
$works_grid->add_new_button(
'#', __('Set votes to') . ' ' . __('Disagree', '', 1),
array('id' => 'mark_all_disagree')
);
$works_grid->add_new_button(
'#', __('Set votes to') . ' ' . __('Agree', '', 1),
array('id' => 'mark_all_agree')
);
}
}
$works_grid->field('description')
->label(__('Description'));
if ($work_report->state >= 2)
{
$works_grid->callback_field('approved')
->label('')
->callback('callback::work_approved');
}
$works_grid->field('date');
$works_grid->field('hours')
->label(__('Hours'));
$works_grid->field('description');
$works_grid->field('km')
->label(__('Km'));
$works_grid->field('hours');
$works_grid->field('km');
$works_grid->callback_field('suggest_amount')
->label(__('Suggest amount'))
->callback('Works_Controller::suggest_amount');
if (!$work_report_model->concept)
{
$works_grid->callback_field('approval_state')
->label(__('State'))
->help(help::hint('approval_state'))
->callback('callback::vote_state_field');
$works_grid->callback_field('comments_count')
->label(__('Comments'))
->callback('callback::comments_field');
}
if ($can_vote)
{
$works_grid->form_field('vote')
->label(__('Vote'))
->type('dropdown')
->rules('required')
->options(array
......
))->callback('Works_Controller::vote_form_field');
$works_grid->form_field('comment')
->label(__('Comment'))
->type('textarea')
->callback('Works_Controller::comment_form_field');
}
......
break;
case 3:
$state_text = '<span style="color: green;">'.__('Approved').'</span>';
$state_text = '<span style="color: green;">'.__('Approved');
if ($work_report->suggest_amount != $work_report_model->transfer->amount)
{
$state_text .= ' (' . __('Partially') . ')';
}
$state_text .= '</span>';
$breadcrumbs->link('work_reports/approved', 'Approved');
break;
}
......
);
}
$links = implode(' | ',$links);
$links = implode(' | ', $links);
// post votes
/* if (isset ($_POST) && count ($_POST))
if (isset($_POST) && count($_POST))
{
$post_votes = $_POST['vote'];
$validate = TRUE;
foreach ($post_votes as $post_vote)
{
if ($post_vote == "")
if ($post_vote == '')
{
$validate = FALSE;
break;
......
$approved_works_ids = array();
$rejected_works_ids = array();
$pending_works_ids = array();
$work_model = new Job_Model();
foreach ($post_votes as $id => $post_vote)
{
$work = $work_model->where('id',$id)->find();
$work = $work_model->find($id);
if (!$work || !$work->id)
{
continue;
}
// finding aro group of logged user
$aro_group = $approval_template_item_model->get_aro_group_by_approval_template_id_and_user_id(
$work->approval_template_id,
......
}
// set up state of work
$work->state = Votes_Controller::get_state($work, Vote_Model::$work);
$work->state = $work->get_state(Vote_Model::$work);
$work->save();
switch ($work->state)
......
{
if (count($approved_works_ids))
{
if (count($rejected_works_ids))
{
$rejected_work_report = new Job_report_Model();
$rejected_work_report->description = $work_report->description;
$rejected_work_report->save();
// if (count($rejected_works_ids))
// {
// $rejected_work_report = new Job_report_Model();
// $rejected_work_report->description = $work_report->description;
// $rejected_work_report->save();
//
// foreach ($rejected_works_ids as $rejected_work_id)
// {
// $rejected_work = new Job_Model($rejected_work_id);
//
// $rejected_work->job_report_id = $rejected_work_report->id;
// $rejected_work->save();
// }
// }
// // rejected works of work report
// if (count($rejected_works_ids))
// {
// $rejected_work_report = new Job_report_Model();
// $rejected_work_report->description = $work_report->description;
// $rejected_work_report->save();
//
// foreach ($rejected_works_ids as $rejected_work_id)
// {
// $rejected_work = new Job_Model($rejected_work_id);
//
// $rejected_work->job_report_id = $rejected_work_report->id;
// $rejected_work->save();
// }
// }
foreach ($rejected_works_ids as $rejected_work_id)
{
$rejected_work = new Job_Model($rejected_work_id);
$rejected_work->job_report_id = $rejected_work_report->id;
$rejected_work->save();
}
}
// creates new transfer
$account_model = new Account_Model();
$operating = $account_model->where(
$operating_id = $account_model->where(
'account_attribute_id', Account_attribute_Model::$operating
)->find();
)->find()->id;
$credit = $account_model->where('member_id', $work->user->member_id)
$credit_id = $account_model->where('member_id', $work->user->member_id)
->where('account_attribute_id', Account_attribute_Model::$credit)
->find();
->find()
->id;
$transfer_id = Transfer_Model::insert_transfer(
$operating->id, $credit->id, null, null,
$operating_id, $credit_id, null, null,
$this->session->get('user_id'), null, date('Y-m-d'),
date('Y-m-d H:i:s'), __('Work report approval'),
$amount
);
$work_report_model->transfer_id = $transfer_id;
$work_report_model->save();
foreach ($approved_works_ids as $approved_work_id)
{
......
}
}
url::redirect(url::base(TRUE).url::current(TRUE));
}*/
}
$view = new View('main');
$view->title = __('Show work report');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('work_reports/show');
$view->content->work_report = $work_report;
$view->content->transfer = $transfer;
$view->content->transfer = $work_report_model->transfer;
$view->content->links = $links;
$view->content->state_text = $state_text;
$view->content->works_grid = $works_grid;
......
{
$form_data = $_POST;
// transaction
$work_report = new Job_report_Model();
$work_report->transaction_start();
// check
if (!isset($form_data['user_id']) ||
!isset($form_data['description']) ||
!isset($form_data['price_per_hour']) ||
!isset($form_data['type']) ||
!isset($form_data['price_per_km']))
{
throw new Exception('Invalid post');
}
// transaction
$work_report = new Job_report_Model();
$work_report->transaction_start();
// approval template
if (isset($form_data['approval_template_id']) &&
......
$work_report->price_per_hour = $form_data['price_per_hour'];
$work_report->concept = TRUE;
if (!empty($form_data['type']) &&
if (isset($form_data['type']) &&
preg_match('/^[0-9]{4}-[0-9]{1,2}$/', $form_data['type']))
{
$work_report->type = $form_data['type'];
freenetis/branches/testing/application/controllers/works.php
foreach ($post_votes as $id => $post_vote)
{
$work = $work_model->where('id',$id)->find();
$work = $work_model->where('id', $id)->find();
// finding aro group of logged user
$aro_group = $approval_template_item_model->get_aro_group_by_approval_template_id_and_user_id(
......
}
// set up state of work
$work->state = Votes_Controller::get_state($work, Vote_Model::$work);
$work->state = $work->get_state(Vote_Model::$work);
// work is approved
if ($work->state == 3)
......
}
// set up state of work
$work->state = Votes_Controller::get_state($work, Vote_Model::$work);
$work->state = $work->get_state(Vote_Model::$work);
// work is approved
if ($work->state == 3)
......
// breadcrumbs navigation
$this->breadcrumbs = breadcrumbs::add();
if (url::slice(url_lang::uri(path::previous()),1,1) == 'show_by_user')
if ($work->job_report_id)
{
$this->breadcrumbs->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/'.$work->user->member->id,
'ID ' . $work->user->member->id . ' - ' .
$work->user->member->name,
$this->acl_check_view(
'Members_Controller', 'members',
$work->user->member->id
)
)->enable_translation()
->link('users/show_by_member/' . $work->user->member_id,
'Users',
$this->acl_check_view(
'Users_Controller', 'users',
$work->user->member_id
)
)->disable_translation()
->link('users/show/'.$work->user->id,
$work->user->name . ' ' . $work->user->surname .
' (' . $work->user->login . ')',
$this->acl_check_view(
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff