Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c1bdc1c4

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

Release 1.1.0

Zobrazit rozdíly:

application/controllers/work_reports.php
*/
class Work_reports_Controller extends Controller
{
/**
* Only checks whether works are enabled
*
* @author Michal Kliment
*/
public function __construct()
{
parent::__construct();
// works are not enabled
if (!Settings::get('works_enabled'))
Controller::error (ACCESS);
}
/**
* Redirects to pending
*/
public function index()
{
url::redirect('work_reports/pending');
url::redirect('work_reports/show_all');
}
/**
* Shows pending works
* Shows all work reports
*
* @param integer $limit_results
* @param string $order_by
......
* @param integer $page_word
* @param integer $page
*/
public function pending(
$limit_results = 100, $order_by = 'id', $order_by_direction = 'ASC',
public function show_all(
$limit_results = 20, $order_by = 'id', $order_by_direction = 'ASC',
$page_word = null, $page = 1)
{
// acccess control
if (!$this->acl_check_view('Users_Controller', 'work'))
if (!$this->acl_check_view('Work_reports_Controller', 'work_report'))
{
Controller::error(ACCESS);
}
// gets new selector
if (is_numeric($this->input->get('record_per_page')))
if (is_numeric($this->input->post('record_per_page')))
{
$limit_results = (int) $this->input->get('record_per_page');
$limit_results = (int) $this->input->post('record_per_page');
}
$filter_form = new Filter_form('wr');
$filter_form->add('state')
->type('select')
->values(Vote_Model::get_states());
$filter_form->add('description');
$filter_form->add('uname')
......
$work_report_model = new Job_report_Model();
$total_work_reports = $work_report_model->count_all_pending_work_reports(
$filter_form->as_sql()
);
// hide grid on its first load (#442)
$hide_grid = Settings::get('grid_hide_on_first_load') && $filter_form->is_first_load();
if (!$hide_grid)
{
try
{
$total_work_reports = $work_report_model->count_all_work_reports(
$filter_form->as_sql()
);
if (($sql_offset = ($page - 1) * $limit_results) > $total_work_reports)
$sql_offset = 0;
if (($sql_offset = ($page - 1) * $limit_results) > $total_work_reports)
$sql_offset = 0;
$work_reports = $work_report_model->get_all_pending_work_reports(
$sql_offset, (int)$limit_results, $order_by, $order_by_direction,
$filter_form->as_sql()
);
$work_reports = $work_report_model->get_all_work_reports(
$sql_offset, (int)$limit_results, $order_by, $order_by_direction,
$filter_form->as_sql(), $this->user_id
);
}
catch (Exception $e)
{
if ($filter_form->is_loaded_from_saved_query())
{
status::error('Invalid saved query', $e);
// disable default query (loop protection)
if ($filter_form->is_loaded_from_default_saved_query())
{
ORM::factory('filter_query')->remove_default($filter_form->get_base_url());
}
$this->redirect(url_lang::current());
}
throw $e;
}
}
// create grid
$grid = new Grid('work_reports/pending', __('List of all pending work reports'), array
$grid = new Grid('work_reports/show_all', null, array
(
'use_paginator' => true,
'use_selector' => true,
'current' => $limit_results,
'selector_increace' => 100,
'selector_min' => 100,
'selector_increace' => 20,
'selector_min' => 20,
'selector_max_multiplier' => 20,
'base_url' => Config::get('lang').'/work_reports/pending/'
'base_url' => Config::get('lang').'/work_reports/show_all/'
. $limit_results.'/'.$order_by.'/'.$order_by_direction,
'uri_segment' => 'page',
'total_items' => $total_work_reports,
'total_items' => isset($total_work_reports) ? $total_work_reports : 0,
'items_per_page' => $limit_results,
'style' => 'classic',
'filter' => $filter_form,
......
'limit_results' => $limit_results
));
if ($this->acl_check_new('Users_Controller', 'work'))
if ($this->acl_check_new('Work_reports_Controller', 'work_report'))
{
$grid->add_new_button('work_reports/add', __('Add new work report'));
$grid->add_new_button(
'work_reports/add',
__('Add new work report')
);
}
$grid->order_field('id')
......
$grid->order_callback_field('suggest_amount')
->callback('callback::money');
$grid->order_callback_field('approval_state')
->label(__('State'))
->help(help::hint('approval_state'))
->callback('callback::vote_state_field');
$grid->order_callback_field('your_votes')
->callback('callback::votes_of_voter');
->callback('callback::votes_of_voter')
->class('center');
$actions = $grid->grouped_action_field();
if ($this->acl_check_view('Users_Controller', 'work'))
if ($this->acl_check_view('Work_reports_Controller', 'work_report'))
{
$actions->add_action()
->icon_action('show')
->url('work_reports/show');
}
if ($this->acl_check_edit('Users_Controller', 'work'))
if ($this->acl_check_edit('Work_reports_Controller', 'work_report'))
{
$actions->add_action()
$actions->add_conditional_action('id')
->icon_action('edit')
->condition('is_item_new')
->url('work_reports/edit');
}
$grid->datasource($work_reports);
$breadcrumbs = breadcrumbs::add()
->text('Work reports')
->text('Pending work reports');
$view = new View('main');
$view->title = __('Pending work reports');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('work_reports/show_all');
$view->content->grid = $grid;
$view->render(TRUE);
}
/**
* Shows approved works
*
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param integer $page_word
* @param integer $page
*/
public function approved(
$limit_results = 100, $order_by = 'id', $order_by_direction = 'ASC',
$page_word = null, $page = 1)
{
// acccess control
if (!$this->acl_check_view('Users_Controller', 'work'))
Controller::error(ACCESS);
// gets new selector
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
$filter_form = new Filter_form('wr');
$filter_form->add('description');
$filter_form->add('uname')
->label('Worker')
->callback('json/user_fullname');
$filter_form->add('suggest_amount')
->type('number')
->label('Suggest amount');
$filter_form->add('hours')
->type('number');
$filter_form->add('km')
->type('number');
$filter_form->add('date_from')
->type('date');
$filter_form->add('date_to')
->type('date');
$filter_form->add('payment_type')
->type('select')
->values(Job_report_Model::get_payment_types());
$work_report_model = new Job_report_Model();
$total_work_reports = $work_report_model->count_all_approved_work_reports(
$filter_form->as_sql()
);
if (($sql_offset = ($page - 1) * $limit_results) > $total_work_reports)
$sql_offset = 0;
$work_reports = $work_report_model->get_all_approved_work_reports(
$sql_offset, (int)$limit_results, $order_by, $order_by_direction,
$filter_form->as_sql()
);
// create grid
$grid = new Grid(
'work_reports/approved',
__('List of all approved work reports'), array
(
'use_paginator' => true,
'use_selector' => true,
'current' => $limit_results,
'selector_increace' => 100,
'selector_min' => 100,
'selector_max_multiplier' => 20,
'base_url' => Config::get('lang').'/work_reports/approved/'
. $limit_results.'/'.$order_by.'/'.$order_by_direction ,
'uri_segment' => 'page',
'total_items' => $total_work_reports,
'items_per_page' => $limit_results,
'style' => 'classic',
'filter' => $filter_form,
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results
));
$grid->order_field('id')
->label(__('Id'));
$grid->order_link_field('user_id')
->link('users/show', 'uname')
->label('Worker');
$grid->order_field('description');
$grid->order_callback_field('type')
->callback('callback::work_report_type');
$grid->order_callback_field('hours')
->callback('callback::round');
$grid->order_callback_field('km')
->callback('callback::round');
$grid->order_callback_field('suggest_amount')
->callback('callback::money');
$grid->order_callback_field('rating')
->callback('callback::work_report_rating');
// access control
if ($this->acl_check_view('Users_Controller','work'))
if ($this->acl_check_delete('Work_reports_Controller', 'work_report'))
{
$grid->grouped_action_field()
->add_action()
->icon_action('show')
->url('work_reports/show');
$actions->add_conditional_action('id')
->icon_action('delete')
->condition('is_item_new')
->url('work_reports/delete')
->class('delete_link');
}
$grid->datasource($work_reports);
$breadcrumbs = breadcrumbs::add()
->text('Work reports')
->text('Approved work reports');
$view = new View('main');
$view->title = __('Approved work reports');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('work_reports/show_all');
$view->content->grid = $grid;
$view->render(TRUE);
}
/**
* Shows rejected works
*
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param integer $page_word
* @param integer $page
*/
public function rejected(
$limit_results = 100, $order_by = 'id', $order_by_direction = 'ASC',
$page_word = null, $page = 1)
{
// acccess control
if (!$this->acl_check_view('Users_Controller', 'work'))
Controller::error(ACCESS);
// gets new selector
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
$filter_form = new Filter_form('wr');
$filter_form->add('description');
$filter_form->add('uname')
->label('Worker')
->callback('json/user_fullname');
$filter_form->add('suggest_amount')
->type('number')
->label('Suggest amount');
$filter_form->add('hours')
->type('number');
$filter_form->add('km')
->type('number');
$filter_form->add('date_from')
->type('date');
$filter_form->add('date_to')
->type('date');
$filter_form->add('payment_type')
->type('select')
->values(Job_report_Model::get_payment_types());
$work_report_model = new Job_report_Model();
$total_work_reports = $work_report_model->count_all_rejected_work_reports(
$filter_form->as_sql()
);
if (($sql_offset = ($page - 1) * $limit_results) > $total_work_reports)
$sql_offset = 0;
$work_reports = $work_report_model->get_all_rejected_work_reports(
$sql_offset, (int)$limit_results, $order_by, $order_by_direction,
$filter_form->as_sql()
);
// create grid
$grid = new Grid(
'work_reports/rejected',
__('List of all rejected work reports'), array
(
'use_paginator' => true,
'use_selector' => true,
'current' => $limit_results,
'selector_increace' => 100,
'selector_min' => 100,
'selector_max_multiplier' => 20,
'base_url' => Config::get('lang').'/work_reports/rejected/'
. $limit_results.'/'.$order_by.'/'.$order_by_direction ,
'uri_segment' => 'page',
'total_items' => $total_work_reports,
'items_per_page' => $limit_results,
'style' => 'classic',
'filter' => $filter_form,
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results
));
$grid->order_field('id');
$grid->order_link_field('user_id')
->link('users/show', 'uname')
->label('Worker');
$grid->order_field('description');
$grid->order_callback_field('type')
->callback('callback::work_report_type');
$grid->order_callback_field('hours')
->callback('callback::round');
$grid->order_callback_field('km')
->callback('callback::round');
$grid->order_callback_field('suggest_amount')
->callback('callback::money');
$actions = $grid->grouped_action_field();
if (!$hide_grid)
$grid->datasource($work_reports);
if ($this->acl_check_view('Users_Controller', 'work'))
{
$actions->add_action()
->icon_action('show')
->url('work_reports/show');
}
$title = __('Work reports');
$grid->datasource($work_reports);
$breadcrumbs = breadcrumbs::add()
->text('Work reports')
->text('Rejected work reports');
$view = new View('main');
$view->title = __('Rejected work reports');
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('work_reports/show_all');
$view->content->grid = $grid;
$view->title = $title;
$view->breadcrumbs = $title;
$view->content = new View('show_all');
$view->content->table = $grid;
$view->content->headline = __('List of all work reports');
$view->render(TRUE);
}
......
Controller::error(RECORD);
}
if (!$this->acl_check_view('Users_Controller', 'work', $user->member_id))
if (!$this->acl_check_view('Work_reports_Controller', 'work_report', $user->member_id))
{
Controller::error(ACCESS);
}
......
'total_items' => count($concepts)
));
if ($this->acl_check_new('Users_Controller', 'work', $user->member_id))
if ($this->acl_check_new('Work_reports_Controller', 'work_report', $user->member_id))
{
$grid_concepts->add_new_button(
'work_reports/add/' . $user->id,
......
$actions = $grid_concepts->grouped_action_field();
if ($this->acl_check_view('Users_Controller', 'work', $user->member_id))
if ($this->acl_check_view('Work_reports_Controller', 'work_report', $user->member_id))
{
$actions->add_action()
->icon_action('show')
->url('work_reports/show');
->url('users/show_work_report');
}
if ($this->acl_check_edit('Users_Controller', 'work', $user->member_id))
if ($this->acl_check_edit('Work_reports_Controller', 'work_report', $user->member_id))
{
$actions->add_action()
->icon_action('edit')
->url('work_reports/edit');
}
if ($this->acl_check_delete('Users_Controller', 'work', $user->member_id))
if ($this->acl_check_delete('Work_reports_Controller', 'work_report', $user->member_id))
{
$actions->add_action()
->icon_action('delete')
......
$actions = $grid_pending->grouped_action_field();
if ($this->acl_check_view('Users_Controller', 'work', $user->member_id))
if ($this->acl_check_view('Work_reports_Controller', 'work_report', $user->member_id))
{
$actions->add_action()
->icon_action('show')
->url('work_reports/show');
->url('users/show_work_report');
}
if ($this->acl_check_edit('Work_reports_Controller', 'work_report'))
{
$actions->add_conditional_action('id')
->icon_action('edit')
->condition('is_item_new')
->url('work_reports/edit');
}
if ($this->acl_check_delete('Work_reports_Controller', 'work_report'))
{
$actions->add_conditional_action('id')
->icon_action('delete')
->condition('is_item_new')
->url('work_reports/delete')
->class('delete_link');
}
$grid_pending->datasource($pendings);
......
$actions = $grid_approved->grouped_action_field();
if ($this->acl_check_view('Users_Controller', 'work', $user->member_id))
if ($this->acl_check_view('Work_reports_Controller', 'work_report', $user->member_id))
{
$actions->add_action()
->icon_action('show')
......
$actions = $grid_rejected->grouped_action_field();
if ($this->acl_check_view('Users_Controller', 'work', $user->member_id))
if ($this->acl_check_view('Work_reports_Controller', 'work_report', $user->member_id))
{
$actions->add_action()
->icon_action('show')
......
$view->title = $headline;
$view->breadcrumbs = $breadcrumbs->html();
$view->content = new View('work_reports/show_by_user');
$view->content->headline = $headline;
$view->content->headline = $headline . ' ' . help::hint('work_report_description');
$view->content->user = $user;
$view->content->show_concepts = ($user->id == $this->user_id);
$view->content->grid_concepts = $grid_concepts;
......
$member_id = $work_report_model->user->member_id;
// concept can be viewed only by owner
if (!$this->acl_check_view('Users_Controller', 'work', $member_id) || (
if (!$this->acl_check_view('Work_reports_Controller', 'work_report', $member_id) || (
$work_report->concept &&
$this->user_id != $work_report_model->user_id &&
$this->user_id != $work_report_model->added_by_id
......
}
$works = ORM::factory('job')->get_all_works_by_job_report_id($work_report->id);
$vote_model = new Vote_Model();
$approval_template_item_model = new Approval_template_item_Model();
$items_to_vote = $vote_model->get_all_items_user_can_vote(
$this->user_id
);
// test if user can vote
$can_vote = FALSE;
if (!$work_report_model->concept && $work_report->state <= 1)
$works_to_vote = array();
if (array_key_exists(Vote_Model::WORK, $items_to_vote))
{
$works_to_vote = $items_to_vote[Vote_Model::WORK];
foreach ($works as $work)
{
if ($approval_template_item_model->check_user_vote_rights(
$work->id,
Session::instance()->get('user_id'),
$work_report->suggest_amount
))
{
$can_vote = TRUE;
break;
}
if (in_array($work->id, $works_to_vote))
$can_vote = TRUE;
}
}
......
'use_selector' => false,
'total_items' => count($works),
'id' => 'work_reports__show_grid'
));
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->add_new_button(
url::base().url::current(),
'Show whole descriptions',
array
(
'id' => 'work_report__show_descr'
)
);
if ($work_report->state >= 2)
{
......
->callback('callback::comments_field');
}
if ($can_vote)
if (!$work_report_model->concept && $can_vote)
{
$works_grid->form_field('vote')
->type('dropdown')
->rules('required')
->options(array
(
NULL => '----------------',
1 => __('Agree'),
-1 => __('Disagree'),
0 => __('Abstain')
))->callback('Works_Controller::vote_form_field');
NULL => '----- '.__('Select vote').' -----'
))->callback(
'Votes_Controller::vote_form_field',
$works_to_vote,
Vote_Model::WORK
);
$works_grid->form_field('comment')
->type('textarea')
->callback('Works_Controller::comment_form_field');
->callback(
'Votes_Controller::comment_form_field',
$works_to_vote,
Vote_Model::WORK
);
}
// access control
if ($this->acl_check_view('Users_Controller', 'work', $member_id))
if ($this->acl_check_view('Works_Controller', 'work', $member_id))
{
$works_grid->grouped_action_field()
->add_action()
......
$links = array();
// breadcrumbs and links back
$breadcrumbs = breadcrumbs::add();
$breadcrumbs = breadcrumbs::add()
->link('work_reports', 'Work reports',
$this->acl_check_view('Users_Controller', 'work'));
switch ($work_report->state)
{
case 0:
case 1:
$state_text = __('Pending');
$breadcrumbs->link('work_reports/pending', 'Pending',
$this->acl_check_view('Users_Controller', 'work'));
break;
case 2:
$state_text = '<span style="color: red;">'.__('Rejected').'</span>';
$breadcrumbs->link(
'work_reports/rejected', 'Rejected',
$this->acl_check_view('Users_Controller', 'work')
);
break;
case 3:
$state_text = '<span style="color: green;">'.__('Approved');
if ($work_report->suggest_amount != $work_report_model->get_rating())
{
$state_text .= ' (' . __('Partially') . ')';
}
$state_text .= '</span>';
$breadcrumbs->link(
'work_reports/approved', 'Approved',
$this->acl_check_view('Users_Controller', 'work')
);
break;
if (url_lang::current(1) == 'users')
{
// breadcrumbs navigation
$breadcrumbs->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/'.$work_report_model->user->member->id,
'ID ' . $work_report_model->user->member->id . ' - ' . $work_report_model->user->member->name,
$this->acl_check_view(
'Members_Controller', 'members',
$work_report_model->user->member->id
)
)->enable_translation()
->link('users/show_by_member/' . $work_report_model->user->member_id,
'Users',
$this->acl_check_view(
'Users_Controller', 'users',
$work_report_model->user->member_id
)
)->disable_translation()
->link('users/show/'.$work_report_model->user->id,
$work_report_model->user->name . ' ' . $work_report_model->user->surname .
' (' . $work_report_model->user->login . ')',
$this->acl_check_view(
'Users_Controller','users',
$work_report_model->user->member_id
)
)->enable_translation()
->link('work_reports/show_by_user/'.$work_report_model->user->id, 'Work reports',
$this->acl_check_view(
'Work_reports_Controller', 'work_report',
$work_report_model->user->member_id
)
);
}
else
{
$breadcrumbs->link('work_reports', 'Work reports',
$this->acl_check_view('Work_reports_Controller','work_report'));
}
$breadcrumbs->disable_translation()
->link('work_reports/show_by_user/' . $work_report_model->user_id,
$work_report_model->user->get_full_name())
->text(text::limit_chars($work_report_model->description, 40));
$breadcrumbs->text('ID '.$work_report_model->id);
if ($this->acl_check_edit('Users_Controller', 'work', $work_report->member_id) &&
$work_report->state == 0)
if ($work_report->state == Vote_Model::STATE_NEW &&
$this->acl_check_edit(
'Work_reports_Controller', 'work_report', $work_report->member_id
))
{
$links[] = html::anchor(
url_lang::base().'work_reports/edit/'.$work_report->id,
__('Edit')
);
}
// concept can be viewed only by owner
if (!(!$this->acl_check_view('Work_reports_Controller', 'work_report', $member_id) || (
$work_report->concept &&
$this->user_id != $work_report_model->user_id &&
$this->user_id != $work_report_model->added_by_id
)))
{
$links[] = html::anchor(
url_lang::base().'work_reports/export/'.$work_report->id,
__('Export').' '.help::hint('work_report_export')
);
}
if ($this->acl_check_delete('Users_Controller', 'work', $work_report->member_id) &&
$work_report->state == 0)
if ($work_report->state == Vote_Model::STATE_NEW &&
$this->acl_check_delete(
'Work_reports_Controller', 'work_report', $work_report->member_id
))
{
$links[] = html::anchor(
url_lang::base().'work_reports/delete/'.$work_report->id,
......
if (isset($_POST) && count($_POST))
{
$post_votes = $_POST['vote'];
$vote_model = new Vote_Model();
$comments = $_POST['comment'];
$approval_template_model = new Approval_template_Model();
$approval_template_item_model = new Approval_template_item_Model();
$state = 0;
$amount = 0;
$approved_works_ids = array();
$rejected_works_ids = array();
$pending_works_ids = array();
$work_model = new Job_Model();
foreach ($post_votes as $id => $post_vote)
try
{
$work = $work_model->find($id);
if (!$work || !$work->id)
{
continue;
}
$suggest_amount = $work->suggest_amount;
if ($work->job_report_id)
{
$suggest_amount = $work->job_report->get_suggest_amount();
}
$vote_model = new Vote_Model();
$vote_model->transaction_start();
$work_ids = $_POST['ids'];
$votes = $_POST['vote'];
$comments = $_POST['comment'];
$approval_template_item_model = new Approval_template_item_Model();
// 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,
$this->session->get('user_id'),
$suggest_amount
$aro_group = $approval_template_item_model
->get_aro_group_by_approval_template_id_and_user_id(
$work_report->approval_template_id,
$this->user_id,
$work_report->suggest_amount
);
// user can vote
if ($aro_group && $aro_group->id)
$amount = 0;
$states = array
(
Vote_Model::STATE_NEW => array(),
Vote_Model::STATE_OPEN => array(),
Vote_Model::STATE_REJECTED => array(),
Vote_Model::STATE_APPROVED => array()
);
$votes_count = 0;
// voting user
$user = new User_Model($this->user_id);
$work_model = new Job_Model();
foreach ($work_ids as $work_id)
{
// finding vote of user
$vote = $vote_model->where('user_id', $this->user_id)
->where('fk_id', $id)
->where('type', Vote_Model::WORK)
->find();
// edit/delete vote
if ($vote->id)
// user cannot vote about work
if (!in_array($work_id, $works_to_vote))
continue;
$work = $work_model->where('id', $work_id)->find();
if (!$work || !$work->id)
continue;
// delete old vote
$vote_model->remove_vote(
$this->user_id,
Vote_Model::WORK,
$work->id
);
$vote = $votes[$work->id];
$comment = $comments[$work->id];
// new vote is not empty
if ($vote != '')
{
if ($post_vote == '')
// cannot agree/disagree own work
if ($vote != Vote_Model::ABSTAIN && $work->user_id == $this->user_id)
{
$vote->delete();
throw new Exception('Cannot agree/disagree own work.');
}
else
// add new vote
Vote_Model::insert(
$this->user_id,
Vote_Model::WORK,
$work->id,
$vote,
$comment,
$aro_group->id
);
$votes_count++;
}
// set up state of work
$work->state = Vote_Model::get_state($work);
// work is approved
if ($work->state == Vote_Model::STATE_APPROVED)
$amount += $work->suggest_amount;
$states[$work->state][] = $work->id;
$work->save_throwable();
}
// any vote has been added
if ($votes_count)
{
// send message about adding vote to all watchers
$subject = mail_message::format('work_report_vote_add_subject');
$body = mail_message::format('work_report_vote_add', array
(
$user->name.' '.$user->surname,
$work_report_model->user->name.' '.$work_report_model->user->surname,
url_lang::base().'work_reports/show/'.$work_report_model->id
));
Mail_message_Model::send_system_message_to_item_watchers(
$subject,
$body,
Watcher_Model::WORK_REPORT,
$work_report_model->id
);
}
// no pending works in report
if (!count($states[Vote_Model::STATE_NEW]) &&
!count($states[Vote_Model::STATE_OPEN]))
{
// at least one work from report has been approved
if (count($states[Vote_Model::STATE_APPROVED]))
{
// send money
if (Settings::get('finance_enabled') && $work_report_model->payment_type == Job_report_Model::PAYMENT_BY_CREDIT)
{
$vote->vote = $post_vote;
$vote->comment = $comments[$id];
$vote->time = date('Y-m-d H:i:s');
$vote->save();
$transfer_id = Transfer_Model::insert_transfer_for_work_approve(
$work_report_model->user->member_id, $amount
);
$work_report_model->transfer_id = $transfer_id;
$work_report_model->save_throwable();
foreach ($states[Vote_Model::STATE_APPROVED] as $approved_work_id)
{
$approved_work = new Job_Model($approved_work_id);
$approved_work->transfer_id = $transfer_id;
$approved_work->save_throwable();
}
// reload messages of worker
ORM::factory('member')->reactivate_messages($member_id);
}
$subject = mail_message::format('work_report_approve_subject');
$body = mail_message::format('work_report_approve', array
(
$work_report_model->user->name.' '.$work_report_model->user->surname,
url_lang::base().'work_reports/show/'.$work_report_model->id
));
}
// create vote
// all works from report has been rejected
else
{
$vote->clear();
$vote->user_id = $this->user_id;
$vote->fk_id = $id;
$vote->aro_group_id = $aro_group->id;
$vote->type = Vote_Model::WORK;
$vote->vote = $post_vote;
$vote->time = date('Y-m-d H:i:s');
$vote->comment = $comments[$id];
$vote->save();
}
// set up state of work
$work->state = $work->get_state(Vote_Model::WORK);
$work->save();
switch ($work->state)
{
case 0:
case 1:
$pending_works_ids[] = $work->id;
break;
case 2:
$rejected_works_ids[] = $work->id;
break;
case 3:
$approved_works_ids[] = $work->id;
$amount += $work->suggest_amount;
break;
$subject = mail_message::format('work_report_reject_subject');
$body = mail_message::format('work_report_reject', array
(
$work_report_model->user->name.' '.$work_report_model->user->surname,
url_lang::base().'work_reports/show/'.$work_report_model->id
));
}
// send message to all watchers
Mail_message_Model::send_system_message_to_item_watchers(
$subject,
$body,
Watcher_Model::WORK_REPORT,
$work_report_model->id
);
}
$vote_model->transaction_commit();
status::success('Votes to work reports has been successfully updated.');
}
if (!count($pending_works_ids) &&
count($approved_works_ids) &&
$work_report_model->payment_type == Job_report_Model::PAYMENT_BY_CREDIT)
catch (Exception $e)
{
// creates new transfer
$account_model = new Account_Model();
$operating_id = $account_model->where(
'account_attribute_id', Account_attribute_Model::OPERATING
)->find()->id;
$credit_id = $account_model->where('member_id', $work->user->member_id)
->where('account_attribute_id', Account_attribute_Model::CREDIT)
->find()
->id;
$transfer_id = Transfer_Model::insert_transfer(
$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'),
round($amount, 2)
);
$work_report_model->transfer_id = $transfer_id;
$work_report_model->save();
foreach ($approved_works_ids as $approved_work_id)
{
$approved_work = new Job_Model($approved_work_id);
$approved_work->transfer_id = $transfer_id;
$approved_work->save();
}
$vote_model->transaction_rollback();
status::error('Error - Cannot update votes to work reports.', $e);
Log::add_exception($e);
}
// redirect
url::redirect(url::base(TRUE).url::current(TRUE));
}
......
$view->content->work_report_model = $work_report_model;
$view->content->transfer = $work_report_model->transfer;
$view->content->links = $links;
$view->content->state_text = $state_text;
$view->content->state_text = Vote_Model::get_state_name($work_report->state);
$view->content->works_grid = $works_grid;
$view->render(TRUE);
}
......
* @param integer $user_id
*/
public function add($user_id = NULL)
{
{
if ($user_id)
{
if (!is_numeric($user_id))
......
if (!$user->id)
Controller::error(RECORD);
if (!$this->acl_check_new('Users_Controller', 'work', $user->member_id))
if (!$this->acl_check_new('Work_reports_Controller', 'work_report', $user->member_id))
Controller::error(ACCESS);
$selected = $user->id;
$arr_users[$user->id] = $user->get_full_name() . ' - ' . $user->login;
$member_id = $user->member_id;
}
else
{
if (!$this->acl_check_new('Users_Controller', 'work'))
if (!$this->acl_check_new('Work_reports_Controller', 'work_report'))
Controller::error(ACCESS);
$selected = $this->session->get('user_id');
......
COALESCE(login, '')
)";
$arr_users = ORM::factory('user')->select_list('id', $concat);
$arr_users = ORM::factory('user')
->select_list('id', $concat);
$member_id = NULL;
}
// approval templates
$arr_approval_templates = array();
if ($this->acl_check_view('approval', 'templates'))
if ($this->acl_check_edit('Work_reports_Controller', 'approval_template', $member_id))
{
$arr_approval_templates = ORM::factory('approval_template')->select_list();
}
......
}
// approval template
if (isset($form_data['approval_template_id']) &&
$this->acl_check_view('approval', 'templates'))
if ($this->acl_check_edit('Work_reports_Controller', 'approval_template', $member_id))
{
$at_id = intval($form_data['approval_template_id']);
}
......
$work_report->save_throwable();
$work_report_suggest_amount = 0;
// add works
if (isset($form_data['work_description']) &&
......
$suggest_amount = $work_report->price_per_hour * $hours;
$suggest_amount += $work_report->price_per_km * $km;
$work_report_suggest_amount += $suggest_amount;
$date = explode('-', $form_data['work_date'][$i]);
......
}
}
// finds all aro ids assigned to vote about this work
$approval_template_item_model = new Approval_template_item_Model();
$aro_ids = arr::from_objects(
$approval_template_item_model->get_aro_ids_by_approval_template_id(
$work_report->approval_template_id, $work_report_suggest_amount
), 'id');
$watchers = array_unique(
array($work_report->user_id, $this->user_id)
+ $aro_ids
);
$watcher_model = new Watcher_Model();
// add default watchers
$watcher_model->add_watchers_to_object(
$watchers,
Watcher_Model::WORK_REPORT,
$work_report->id
);
// end adding
$work_report->transaction_commit();
status::success('Work report has been successfully added');
url::redirect('work_reports/show/' . $work_report->id);
if ($user_id)
$this->redirect('users/show_work_report/', $work_report->id);
else
$this->redirect('work_reports/show/', $work_report->id);
}
catch (Exception $e)
{
$work_report->transaction_rollback();
Log::add_exception($e);
status::error('Error - cant add new work report.');
status::error('Error - cant add new work report.', $e);
}
}
// view
$breadcrumbs = breadcrumbs::add();
$breadcrumbs = breadcrumbs::add()
->link('work_reports', 'Work reports',
$this->acl_check_view('Users_Controller','work'))
->text('Add new work report');
if ($user_id)
{
// breadcrumbs navigation
$breadcrumbs->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/'.$user->member->id,
'ID ' . $user->member->id . ' - ' . $user->member->name,
$this->acl_check_view(
'Members_Controller', 'members',
$user->member->id
)
)->enable_translation()
->link('users/show_by_member/' . $user->member_id,
'Users',
$this->acl_check_view(
'Users_Controller', 'users',
$user->member_id
)
)->disable_translation()
->link('users/show/'.$user->id,
$user->name . ' ' . $user->surname .
' (' . $user->login . ')',
$this->acl_check_view(
'Users_Controller','users',
$user->member_id
)
)->enable_translation()
->link('work_reports/show_by_user/'.$user->id, 'Work reports',
$this->acl_check_view(
'Work_reports_Controller', 'work_report',
$user->member_id
)
);
}
else
{
$breadcrumbs->link('work_reports', 'Work reports',
$this->acl_check_view('Work_reports_Controller','work_report'));
}
$breadcrumbs->text('Add new');
$view = new View('main');
$view->title = __('Add new work report');
......
$view->content->arr_users = $arr_users;
$view->content->selected_user = $selected;
$view->content->arr_approval_templates = $arr_approval_templates;
$view->content->member_id = $member_id;
$view->render(TRUE);
}
......
// concept can be edited only by owner
if (!$this->acl_check_edit(
'Users_Controller', 'work', $work_report->user->member_id
'Work_reports_Controller', 'work_report', $work_report->user->member_id
) || (
$work_report->concept &&
$this->user_id != $work_report->user_id &&
......
{
Controller::error(ACCESS);
}
// test if path is from user profile
$is_from_user = (Path::instance()->uri(TRUE)->previous(0, 1) == 'users'
|| Path::instance()->uri(TRUE)->previous(1, 1) == 'show_by_user');
// grouped works
if (empty($work_report->type))
......
// approval templates
$arr_approval_templates = array();
if ($this->acl_check_view('approval', 'templates'))
if ($this->acl_check_view('Work_reports_Controller', 'approval_template', $work_report->user->member_id))
{
$arr_approval_templates = ORM::factory('approval_template')->select_list();
}
......
//// save report
if (isset($form_data['approval_template_id']) &&
$this->acl_check_view('approval', 'templates'))
$old_approval_template_id = $work_report->approval_template_id;
if ($this->acl_check_view('Work_reports_Controller', 'approval_template', $work_report->user->member_id))
{
$at_id = intval($form_data['approval_template_id']);
$work_report->approval_template_id = $at_id;
$work_report->approval_template_id = intval($form_data['approval_template_id']);
}
$work_report->description = $form_data['description'];
......
$work_report->payment_type = intval($form_data['payment_type']);
$work_report->save_throwable();
// update state of approval template
Approval_template_Model::update_state(
$work_report->approval_template_id
);
//// delete works
// delete all works in report
......
$work_report->delete_works($preserved_ids);
}
$work_report_suggest_amount = 0;
//// add/update works
if (isset($form_data['work_description']))
......
$suggest_amount = $work_report->price_per_hour * $hours;
$suggest_amount += $work_report->price_per_km * $km;
$work_report_suggest_amount += $suggest_amount;
$date = explode('-', $date);
......
}
}
// approval template has been changed
if ($work_report->approval_template_id != $old_approval_template_id)
{
// update state of old approval template
Approval_template_Model::update_state(
$old_approval_template_id
);
$watcher_model = new Watcher_Model();
// remove old watchers
$watcher_model->delete_watchers_by_object(
Watcher_Model::WORK_REPORT,
$work_report->id
);
// finds all aro ids assigned to vote about this work report
$approval_template_item_model = new Approval_template_item_Model();
$aro_ids = arr::from_objects(
$approval_template_item_model->get_aro_ids_by_approval_template_id(
$work_report->approval_template_id, $work_report_suggest_amount
), 'id');
$watchers = array_unique(
array($work_report->user_id, $this->user_id)
+ $aro_ids
);
// add new watchers
$watcher_model->add_watchers_to_object(
$watchers,
Watcher_Model::WORK_REPORT,
$work_report->id
);
}
//// sent information
if (!$work_report->concept)
{
$subject = mail_message::format('work_report_update_subject');
$body = mail_message::format('work_report_update', array
(
$work_report->user->name . ' ' . $work_report->user->surname,
url_lang::base().'work_reports/show/'.$work_report->id
));
// send message about work report update to all watchers
Mail_message_Model::send_system_message_to_item_watchers(
$subject,
$body,
Vote_Model::WORK_REPORT,
$work_report->id
);
}
//// finish
$work_report->transaction_commit();
status::success('Work report has been successfully updated');
url::redirect('work_reports/show/'.$work_report->id);
}
catch (Exception $e)
{
$work_report->transaction_rollback();
Log::add_exception($e);
status::error('Error - cant edit work report.');
status::error('Error - cant edit work report.', $e);
}
if ($is_from_user)
$this->redirect('users/show_work_report/', $work_report->id);
else
$this->redirect('work_reports/show/', $work_report->id);
}
// breadcrumbs
// breadcrumbs and links back
$breadcrumbs = breadcrumbs::add();
$breadcrumbs = breadcrumbs::add()
->link('work_reports', 'Work reports',
$this->acl_check_view('Users_Controller', 'work'));
switch ($work_report->get_state())
{
case 0:
case 1:
$breadcrumbs->link('work_reports/pending', 'Pending');
break;
case 2:
$breadcrumbs->link('work_reports/rejected', 'Rejected');
break;
case 3:
$breadcrumbs->link('work_reports/approved', 'Approved');
break;
}
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff