freenetis-github/application/controllers/comments.php @ b8a40ec0
8baed187 | Michal Kliment | <?php defined('SYSPATH') or die('No direct script access.');
|
|
/*
|
|||
* This file is part of open source system FreenetIS
|
|||
* and it is released under GPLv3 licence.
|
|||
*
|
|||
* More info about licence can be found:
|
|||
* http://www.gnu.org/licenses/gpl-3.0.html
|
|||
*
|
|||
* More info about project can be found:
|
|||
* http://www.freenetis.org/
|
|||
*
|
|||
*/
|
|||
/**
|
|||
* Controller handles comments. Comment is message with info character.
|
|||
* Comment can be related to any part of system data using commnet threads.
|
|||
*
|
|||
* @author Michal Kliment
|
|||
* @package Controller
|
|||
*/
|
|||
class Comments_Controller extends Controller
|
|||
{
|
|||
/**
|
|||
* Adds new comments to comment thread
|
|||
*
|
|||
* @author Michal Kliment
|
|||
* @param integer $comments_thread_id
|
|||
*/
|
|||
public function add($comments_thread_id = NULL)
|
|||
c1bdc1c4 | Michal Kliment | {
|
|
8baed187 | Michal Kliment | // bad parameter
|
|
if (!$comments_thread_id || !is_numeric($comments_thread_id))
|
|||
Controller::warning(PARAMETER);
|
|||
$comments_thread = new Comments_thread_Model($comments_thread_id);
|
|||
// comment thread doesn't exist
|
|||
if (!$comments_thread->id)
|
|||
Controller::error(RECORD);
|
|||
// finds parent of comment thread
|
|||
$parent = $comments_thread->get_parent();
|
|||
$breadcrumbs = breadcrumbs::add();
|
|||
$title = '';
|
|||
c1bdc1c4 | Michal Kliment | // user who add comment
|
|
$user = new User_Model($this->user_id);
|
|||
8baed187 | Michal Kliment | switch ($comments_thread->type)
|
|
{
|
|||
// thread belongs to account
|
|||
case 'account':
|
|||
// access control
|
|||
c1bdc1c4 | Michal Kliment | if (!Settings::get('finance_enabled') ||
|
|
!$this->acl_check_view('Members_Controller', 'comment', $parent->member_id))
|
|||
8baed187 | Michal Kliment | Controller::error(ACCESS);
|
|
$link_back_url = Path::instance()->previous();
|
|||
$breadcrumbs->link('members/show_all', 'Members')
|
|||
->disable_translation()
|
|||
->link('members/show/' . $parent->member_id,
|
|||
'ID ' . $parent->member->id . ' - ' . $parent->member->name)
|
|||
->enable_translation()
|
|||
->link($link_back_url, 'Transfers')
|
|||
->text('Add comment to financial state of member');
|
|||
$title = __('Add comment to financial state of member');
|
|||
break;
|
|||
c1bdc1c4 | Michal Kliment | // thread belongs to connection_requests
|
|
case 'connection_request':
|
|||
// access control
|
|||
if (!module::e('connection_request') ||
|
|||
!$this->acl_check_edit('Connection_Requests_Controller', 'request'))
|
|||
Controller::error(ACCESS);
|
|||
$link_back_url = Path::instance()->previous();
|
|||
$title = __('Add comment to connection request');
|
|||
$breadcrumbs->link('connection_requests/show_all', 'Connection requests',
|
|||
$this->acl_check_view('Connection_requests_Controller', 'request'))
|
|||
->disable_translation()
|
|||
->link('connection_requests/show/' . $parent->id,
|
|||
$parent->ip_address . ' (' . $parent->mac_address . ')',
|
|||
$this->acl_check_view('Connection_requests_Controller', 'request', $parent->member_id))
|
|||
->text($title);
|
|||
break;
|
|||
8baed187 | Michal Kliment | case 'job':
|
|
// access control
|
|||
c1bdc1c4 | Michal Kliment | if (!Settings::get('works_enabled') ||
|
|
!$this->acl_check_new('Comments_Controller', 'works', $parent->user->member_id))
|
|||
8baed187 | Michal Kliment | Controller::error(ACCESS);
|
|
c1bdc1c4 | Michal Kliment | if (Path::instance()->uri(TRUE)->previous(0,1) == 'users')
|
|
8baed187 | Michal Kliment | {
|
|
$breadcrumbs->link('members/show_all', 'Members',
|
|||
$this->acl_check_view('Members_Controller', 'members'))
|
|||
->disable_translation()
|
|||
->link('members/show/' . $parent->user->member->id,
|
|||
'ID ' . $parent->user->member->id . ' - ' . $parent->user->member->name,
|
|||
$this->acl_check_view('Members_Controller', 'members', $parent->user->member->id))
|
|||
->enable_translation()
|
|||
->link('users/show_by_member/' . $parent->user->member_id, 'Users',
|
|||
$this->acl_check_view('Users_Controller', 'users', $parent->user->member_id))
|
|||
->link('users/show/' . $parent->user->id,
|
|||
$parent->user->name . " " . $parent->user->surname . " (" . $parent->user->login . ")",
|
|||
$this->acl_check_view('Users_Controller', 'users', $parent->user->member_id))
|
|||
->link('works/show_by_user/' . $parent->user->id, 'Works',
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Works_Controller', 'work', $parent->user->member_id))
|
|
8baed187 | Michal Kliment | ->disable_translation()
|
|
->link('users/show_work/' . $parent->id, __('ID') . ' ' . $parent->id,
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Works_Controller', 'work', $parent->user->member_id))
|
|
8baed187 | Michal Kliment | ->enable_translation();
|
|
}
|
|||
else
|
|||
{
|
|||
c1bdc1c4 | Michal Kliment | $breadcrumbs
|
|
->link('works/pending', 'Works',
|
|||
$this->acl_check_view('Works_Controller', 'work'))
|
|||
->disable_translation()
|
|||
8baed187 | Michal Kliment | ->link('works/show/' . $parent->id,
|
|
__('ID') . ' ' . $parent->id,
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Works_Controller', 'work', $parent->user->member_id))
|
|
8baed187 | Michal Kliment | ->enable_translation();
|
|
}
|
|||
c1bdc1c4 | Michal Kliment | ||
$breadcrumbs->text('Add comment');
|
|||
8baed187 | Michal Kliment | $title = __('Add comment to work');
|
|
c1bdc1c4 | Michal Kliment | ||
$link_back_url = Path::instance()->previous();
|
|||
$type = Watcher_Model::WORK;
|
|||
$subject = mail_message::format('work_comment_add_subject');
|
|||
$body = mail_message::format('work_comment_add', array
|
|||
(
|
|||
$user->name.' '.$user->surname,
|
|||
$parent->user->name.' '.$parent->user->surname,
|
|||
url_lang::base().'works/show/'.$parent->id
|
|||
));
|
|||
break;
|
|||
// thread belongs to log queues
|
|||
case 'log_queue':
|
|||
// access control
|
|||
if (!$this->acl_check_new('Log_queues_Controller', 'comments'))
|
|||
Controller::error(ACCESS);
|
|||
$link_back_url = Path::instance()->previous();
|
|||
$title = __('Add comment to log');
|
|||
$tname = Log_queue_Model::get_type_name($parent->type);
|
|||
$breadcrumbs->link('log_queues/show_all', 'Errors and logs')
|
|||
->disable_translation()
|
|||
->link('log_queues/show/' . $parent->id, $tname . ' (' . $parent->id . ')')
|
|||
->text($title);
|
|||
break;
|
|||
case 'request':
|
|||
// access control
|
|||
if (!Settings::get('approval_enabled') ||
|
|||
!$this->acl_check_edit('Comments_Controller', 'requests'))
|
|||
Controller::error(ACCESS);
|
|||
$title = __('Add comment to request');
|
|||
if (Path::instance()->uri(TRUE)->previous(0,1) == 'users')
|
|||
{
|
|||
$breadcrumbs
|
|||
->link('members/show_all', 'Members',
|
|||
$this->acl_check_view('Members_Controller', 'members'))
|
|||
->disable_translation()
|
|||
->link('members/show/'.$parent->user->member->id,
|
|||
'ID ' . $parent->user->member->id . ' - ' .
|
|||
$parent->user->member->name,
|
|||
$this->acl_check_view(
|
|||
'Members_Controller', 'members',
|
|||
$parent->user->member->id
|
|||
)
|
|||
)->enable_translation()
|
|||
->link('users/show_by_member/' . $parent->user->member_id,
|
|||
'Users',
|
|||
$this->acl_check_view(
|
|||
'Users_Controller', 'users',
|
|||
$parent->user->member_id
|
|||
)
|
|||
)->disable_translation()
|
|||
->link('users/show/'.$parent->user->id,
|
|||
$parent->user->name . ' ' . $parent->user->surname .
|
|||
' (' . $parent->user->login . ')',
|
|||
$this->acl_check_view(
|
|||
'Users_Controller','users',
|
|||
$parent->user->member_id
|
|||
)
|
|||
)->enable_translation()
|
|||
->link('requests/show_by_user/'.$parent->user->id, 'Requests',
|
|||
$this->acl_check_view(
|
|||
'Requests_Controller', 'request',
|
|||
$parent->user->member_id
|
|||
)
|
|||
)->link('users/show_request/'.$parent->id, 'ID '.$parent->id,
|
|||
$this->acl_check_view(
|
|||
'Requests_Controller', 'request',
|
|||
$parent->user->member_id
|
|||
));
|
|||
}
|
|||
else
|
|||
{
|
|||
$breadcrumbs
|
|||
->link('requests/show_all', 'Requests',
|
|||
$this->acl_check_view('Requests_Controller', 'request'))
|
|||
->link('requests/show/'.$parent->id, 'ID '.$parent->id,
|
|||
$this->acl_check_view(
|
|||
'Comments_Controller', 'requests',
|
|||
$parent->user->member_id
|
|||
));
|
|||
}
|
|||
$breadcrumbs->text('Add comment');
|
|||
$link_back_url = Path::instance()->previous();
|
|||
$type = Watcher_Model::REQUEST;
|
|||
$subject = mail_message::format('request_comment_add_subject');
|
|||
$body = mail_message::format('request_comment_add', array
|
|||
(
|
|||
$user->name.' '.$user->surname,
|
|||
$parent->user->name.' '.$parent->user->surname,
|
|||
url_lang::base().'requests/show/'.$parent->id
|
|||
));
|
|||
8baed187 | Michal Kliment | break;
|
|
default:
|
|||
Controller::error(RECORD);
|
|||
break;
|
|||
}
|
|||
c1bdc1c4 | Michal Kliment | $form = new Forge();
|
|
8baed187 | Michal Kliment | ||
$form->textarea('text')
|
|||
->rules('required');
|
|||
$form->submit('Save');
|
|||
// form is validate
|
|||
if ($form->validate())
|
|||
{
|
|||
c1bdc1c4 | Michal Kliment | $form_data = $form->as_array(FALSE);
|
|
8baed187 | Michal Kliment | $comment = new Comment_Model();
|
|
c1bdc1c4 | Michal Kliment | ||
try
|
|||
8baed187 | Michal Kliment | {
|
|
c1bdc1c4 | Michal Kliment | $comment->transaction_start();
|
|
$comment->comments_thread_id = $comments_thread_id;
|
|||
$comment->user_id = $this->user_id;
|
|||
$comment->datetime = date('Y-m-d h:i:s');
|
|||
$comment->text = $form_data['text'];
|
|||
$comment->save_throwable();
|
|||
if (isset($type))
|
|||
{
|
|||
// send message about comment adding to all watchers
|
|||
Mail_message_Model::send_system_message_to_item_watchers(
|
|||
$subject,
|
|||
$body,
|
|||
$type,
|
|||
$parent->id
|
|||
);
|
|||
}
|
|||
$comment->transaction_commit();
|
|||
8baed187 | Michal Kliment | status::success('Comment has been successfully added');
|
|
}
|
|||
c1bdc1c4 | Michal Kliment | catch (Exception $e)
|
|
{
|
|||
$comment->transaction_rollback();
|
|||
status::error('Error - Cannot add comment', $e);
|
|||
Log::add_exception($e);
|
|||
}
|
|||
8baed187 | Michal Kliment | ||
$this->redirect($link_back_url);
|
|||
}
|
|||
else
|
|||
{
|
|||
$view = new View('main');
|
|||
$view->title = $title;
|
|||
$view->breadcrumbs = $breadcrumbs->html();
|
|||
$view->content = new View('form');
|
|||
$view->content->headline = $title;
|
|||
$view->content->form = $form->html();
|
|||
$view->render(TRUE);
|
|||
}
|
|||
}
|
|||
7dafd607 | Michal Kliment | /**
|
|
* Handles relation between comment and other table in database, which has
|
|||
* to contains column comments_thread_id.
|
|||
*
|
|||
* Adds new comment thread to type and foreign key.
|
|||
*
|
|||
* @author Michal Kliment
|
|||
* @param string $type
|
|||
* @param integer $fk_id
|
|||
*/
|
|||
public function add_thread($type = NULL, $fk_id = NULL)
|
|||
{
|
|||
// bad parameter
|
|||
if (!$type || !$fk_id || !is_numeric($fk_id))
|
|||
Controller::warning(PARAMETER);
|
|||
// creates model name
|
|||
$model = ucfirst($type) . '_Model';
|
|||
// this model doesn't exist
|
|||
if (!class_exists($model))
|
|||
Controller::error(RECORD);
|
|||
$object = new $model($fk_id);
|
|||
// record doesn't exist or doesn't support comment thread
|
|||
if (!$object->id || !$object->property_exists('comments_thread_id'))
|
|||
Controller::error(RECORD);
|
|||
// comment thread doesn't exist
|
|||
if (!$object->comments_thread_id)
|
|||
{
|
|||
$comments_thread = new Comments_thread_Model();
|
|||
$comments_thread->type = $type;
|
|||
$comments_thread->save();
|
|||
$object->comments_thread_id = $comments_thread->id;
|
|||
$object->save();
|
|||
}
|
|||
$this->add($object->comments_thread_id);
|
|||
}
|
|||
8baed187 | Michal Kliment | /**
|
|
* Edits comment
|
|||
*
|
|||
* @author Michal Kliment
|
|||
* @param integer $comment_id
|
|||
*/
|
|||
public function edit($comment_id = NULL)
|
|||
{
|
|||
// bad parameter
|
|||
if (!$comment_id || !is_numeric($comment_id))
|
|||
Controller::warning(PARAMETER);
|
|||
$comment = new Comment_Model($comment_id);
|
|||
// comment doesn't exist
|
|||
if (!$comment->id)
|
|||
Controller::error(RECORD);
|
|||
// finds parent of comment thread
|
|||
$parent = $comment->comments_thread->get_parent();
|
|||
$breadcrumbs = breadcrumbs::add();
|
|||
c1bdc1c4 | Michal Kliment | // user who add comment
|
|
$user = new User_Model($this->user_id);
|
|||
8baed187 | Michal Kliment | switch ($comment->comments_thread->type)
|
|
{
|
|||
// thread belongs to account
|
|||
case 'account':
|
|||
// access control
|
|||
c1bdc1c4 | Michal Kliment | if (!Settings::get('finance_enabled') ||
|
|
!$this->acl_check_view('Members_Controller', 'comment', $parent->member_id))
|
|||
8baed187 | Michal Kliment | Controller::error(ACCESS);
|
|
$link_back_url = 'transfers/show_by_account/' . $parent->id;
|
|||
$breadcrumbs->link('members/show_all', 'Members')
|
|||
->disable_translation()
|
|||
->link('members/show/' . $parent->member_id,
|
|||
'ID ' . $parent->member->id . ' - ' . $parent->member->name)
|
|||
->enable_translation()
|
|||
->link($link_back_url, 'Transfers')
|
|||
->text('Edit comment');
|
|||
break;
|
|||
c1bdc1c4 | Michal Kliment | ||
// thread belongs to connection_requests
|
|||
case 'connection_request':
|
|||
// access control
|
|||
if (!module::e('connection_request') ||
|
|||
!$this->acl_check_edit('Connection_Requests_Controller', 'request'))
|
|||
Controller::error(ACCESS);
|
|||
$link_back_url = Path::instance()->previous();
|
|||
$title = __('Edit comment');
|
|||
$breadcrumbs->link('connection_requests/show_all', 'Connection requests',
|
|||
$this->acl_check_view('Connection_requests_Controller', 'request'))
|
|||
->disable_translation()
|
|||
->link('connection_requests/show/' . $parent->id,
|
|||
$parent->ip_address . ' (' . $parent->mac_address . ')',
|
|||
$this->acl_check_view('Connection_requests_Controller', 'request', $parent->member_id))
|
|||
->text($title);
|
|||
break;
|
|||
// thread belongs to log queues
|
|||
case 'log_queue':
|
|||
// access control
|
|||
if (!$this->acl_check_edit('Log_queues_Controller', 'comments'))
|
|||
Controller::error(ACCESS);
|
|||
$link_back_url = Path::instance()->previous();
|
|||
$title = __('Edit comment');
|
|||
$tname = Log_queue_Model::get_type_name($parent->type);
|
|||
$breadcrumbs->link('log_queues/show_all', 'Errors and logs')
|
|||
->disable_translation()
|
|||
->link('log_queues/show/' . $parent->id, $tname . ' (' . $parent->id . ')')
|
|||
->text($title);
|
|||
break;
|
|||
8baed187 | Michal Kliment | ||
case 'job':
|
|||
// access control
|
|||
c1bdc1c4 | Michal Kliment | if (!Settings::get('works_enabled') ||
|
|
!$this->acl_check_edit('Comments_Controller', 'works', $comment->user->member_id))
|
|||
8baed187 | Michal Kliment | Controller::error(ACCESS);
|
|
c1bdc1c4 | Michal Kliment | if (Path::instance()->uri(TRUE)->previous(0,1) == 'users')
|
|
8baed187 | Michal Kliment | {
|
|
$breadcrumbs->link('members/show_all', 'Members',
|
|||
$this->acl_check_view('Members_Controller', 'members'))
|
|||
->disable_translation()
|
|||
->link('members/show/' . $parent->user->member->id,
|
|||
'ID ' . $parent->user->member->id . ' - ' . $parent->user->member->name,
|
|||
$this->acl_check_view('Members_Controller', 'members', $parent->user->member->id))
|
|||
->enable_translation()
|
|||
->link('users/show_by_member/' . $parent->user->member_id, 'Users',
|
|||
$this->acl_check_view('Users_Controller', 'users', $parent->user->member_id))
|
|||
->link('users/show/' . $parent->user->id,
|
|||
$parent->user->name . " " . $parent->user->surname . " (" . $parent->user->login . ")",
|
|||
$this->acl_check_view('Users_Controller', 'users', $parent->user->member_id))
|
|||
->link('works/show_by_user/' . $parent->user->id, 'Works',
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Works_Controller', 'work', $parent->user->member_id))
|
|
8baed187 | Michal Kliment | ->disable_translation()
|
|
->link('users/show_work/' . $parent->id, __('ID') . ' ' . $parent->id,
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Works_Controller', 'work', $parent->user->member_id))
|
|
8baed187 | Michal Kliment | ->enable_translation();
|
|
}
|
|||
else
|
|||
{
|
|||
c1bdc1c4 | Michal Kliment | $breadcrumbs
|
|
->link('works/pending', 'Works',
|
|||
$this->acl_check_view('Works_Controller', 'work'))
|
|||
->disable_translation()
|
|||
8baed187 | Michal Kliment | ->link('works/show/' . $parent->id,
|
|
__('ID') . ' ' . $parent->id,
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Works_Controller', 'work', $parent->user->member_id))
|
|
8baed187 | Michal Kliment | ->enable_translation();
|
|
}
|
|||
$breadcrumbs->text('Edit comment');
|
|||
c1bdc1c4 | Michal Kliment | $link_back_url = Path::instance()->previous();
|
|
$type = Watcher_Model::WORK;
|
|||
$subject = mail_message::format('work_comment_update_subject');
|
|||
$body = mail_message::format('work_comment_update', array
|
|||
(
|
|||
$user->name.' '.$user->surname,
|
|||
$parent->user->name.' '.$parent->user->surname,
|
|||
url_lang::base().'works/show/'.$parent->id
|
|||
));
|
|||
break;
|
|||
case 'request':
|
|||
// access control
|
|||
if (!Settings::get('approval_enabled') || !$this->acl_check_edit('Comments_Controller', 'requests'))
|
|||
Controller::error(ACCESS);
|
|||
$title = __('Add comment to request');
|
|||
if (Path::instance()->uri(TRUE)->previous(0,1) == 'users')
|
|||
{
|
|||
$breadcrumbs
|
|||
->link('members/show_all', 'Members',
|
|||
$this->acl_check_view('Members_Controller', 'members'))
|
|||
->disable_translation()
|
|||
->link('members/show/'.$parent->user->member->id,
|
|||
'ID ' . $parent->user->member->id . ' - ' .
|
|||
$parent->user->member->name,
|
|||
$this->acl_check_view(
|
|||
'Members_Controller', 'members',
|
|||
$parent->user->member->id
|
|||
)
|
|||
)->enable_translation()
|
|||
->link('users/show_by_member/' . $parent->user->member_id,
|
|||
'Users',
|
|||
$this->acl_check_view(
|
|||
'Users_Controller', 'users',
|
|||
$parent->user->member_id
|
|||
)
|
|||
)->disable_translation()
|
|||
->link('users/show/'.$parent->user->id,
|
|||
$parent->user->name . ' ' . $parent->user->surname .
|
|||
' (' . $parent->user->login . ')',
|
|||
$this->acl_check_view(
|
|||
'Users_Controller','users',
|
|||
$parent->user->member_id
|
|||
)
|
|||
)->enable_translation()
|
|||
->link('requests/show_by_user/'.$parent->user->id, 'Requests',
|
|||
$this->acl_check_view(
|
|||
'Requests_Controller', 'request',
|
|||
$parent->user->member_id
|
|||
)
|
|||
)->link('users/show_request/'.$parent->id, 'ID '.$parent->id,
|
|||
$this->acl_check_view(
|
|||
'Requests_Controller', 'request',
|
|||
$parent->user->member_id
|
|||
));
|
|||
}
|
|||
else
|
|||
{
|
|||
$breadcrumbs
|
|||
->link('requests/show_all', 'Requests',
|
|||
$this->acl_check_view('Requests_Controller', 'request'))
|
|||
->link('requests/show/'.$parent->id, 'ID '.$parent->id,
|
|||
$this->acl_check_view(
|
|||
'Comments_Controller', 'requests',
|
|||
$parent->user->member_id
|
|||
));
|
|||
}
|
|||
$breadcrumbs->text('Add comment');
|
|||
$link_back_url = Path::instance()->previous();
|
|||
$type = Watcher_Model::REQUEST;
|
|||
$subject = mail_message::format('request_comment_update_subject');
|
|||
$body = mail_message::format('request_comment_update', array
|
|||
(
|
|||
$user->name.' '.$user->surname,
|
|||
$parent->user->name.' '.$parent->user->surname,
|
|||
url_lang::base().'requests/show/'.$parent->id
|
|||
));
|
|||
8baed187 | Michal Kliment | break;
|
|
default:
|
|||
Controller::error(RECORD);
|
|||
break;
|
|||
}
|
|||
$form = new Forge(url::base(TRUE) . url::current(TRUE));
|
|||
$form->textarea('text')
|
|||
->rules('required')
|
|||
->value($comment->text);
|
|||
$form->submit('Save');
|
|||
// form is validate
|
|||
if ($form->validate())
|
|||
{
|
|||
c1bdc1c4 | Michal Kliment | $form_data = $form->as_array(FALSE);
|
|
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | try
|
|
8baed187 | Michal Kliment | {
|
|
c1bdc1c4 | Michal Kliment | $comment->transaction_start();
|
|
$comment->datetime = date('Y-m-d h:i:s');
|
|||
$comment->text = $form_data['text'];
|
|||
$comment->save_throwable();
|
|||
if (isset($type))
|
|||
{
|
|||
// send message about comment updating to all watchers
|
|||
Mail_message_Model::send_system_message_to_item_watchers(
|
|||
$subject,
|
|||
$body,
|
|||
$type,
|
|||
$parent->id
|
|||
);
|
|||
}
|
|||
$comment->transaction_commit();
|
|||
8baed187 | Michal Kliment | status::success('Comment has been successfully updated');
|
|
}
|
|||
c1bdc1c4 | Michal Kliment | catch(Exception $e)
|
|
{
|
|||
$comment->transaction_rollback();
|
|||
status::error('Error - Cannot update comment', $e);
|
|||
Log::add_exception($e);
|
|||
}
|
|||
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $this->redirect($link_back_url);
|
|
8baed187 | Michal Kliment | }
|
|
$title = __('Edit comment');
|
|||
$view = new View('main');
|
|||
$view->title = $title;
|
|||
$view->breadcrumbs = $breadcrumbs->html();
|
|||
$view->content = new View('form');
|
|||
$view->content->headline = $title;
|
|||
$view->content->form = $form->html();
|
|||
$view->render(TRUE);
|
|||
}
|
|||
/**
|
|||
* Deletes comment
|
|||
*
|
|||
* @author Michal Kliment
|
|||
* @param integer $comment_id
|
|||
*/
|
|||
public function delete($comment_id = NULL)
|
|||
{
|
|||
// bad parameter
|
|||
if (!$comment_id || !is_numeric($comment_id))
|
|||
Controller::warning(PARAMETER);
|
|||
$comment = new Comment_Model($comment_id);
|
|||
// comment doesn't exist
|
|||
if (!$comment->id)
|
|||
Controller::error(RECORD);
|
|||
c1bdc1c4 | Michal Kliment | ||
8baed187 | Michal Kliment | // finds parent of comment thread
|
|
$parent = $comment->comments_thread->get_parent();
|
|||
c1bdc1c4 | Michal Kliment | ||
// user who add comment
|
|||
$user = new User_Model($this->user_id);
|
|||
8baed187 | Michal Kliment | ||
switch ($comment->comments_thread->type)
|
|||
{
|
|||
// thread belongs to account
|
|||
case 'account':
|
|||
// access control
|
|||
c1bdc1c4 | Michal Kliment | if (!Settings::get('finance_enabled') ||
|
|
!$this->acl_check_view('Members_Controller', 'comment', $parent->member_id))
|
|||
8baed187 | Michal Kliment | Controller::error(ACCESS);
|
|
$link_back_url = 'transfers/show_by_account/' . $parent->id;
|
|||
c1bdc1c4 | Michal Kliment | ||
8baed187 | Michal Kliment | break;
|
|
c1bdc1c4 | Michal Kliment | ||
// thread belongs to connection_requests
|
|||
case 'connection_request':
|
|||
// access control
|
|||
if (!module::e('connection_request') ||
|
|||
!$this->acl_check_edit('Connection_Requests_Controller', 'request'))
|
|||
Controller::error(ACCESS);
|
|||
$link_back_url = Path::instance()->previous();
|
|||
break;
|
|||
// thread belongs to log queues
|
|||
case 'log_queue':
|
|||
// access control
|
|||
if (!$this->acl_check_delete('Log_queues_Controller', 'comments'))
|
|||
Controller::error(ACCESS);
|
|||
$link_back_url = Path::instance()->previous();
|
|||
break;
|
|||
8baed187 | Michal Kliment | case 'job':
|
|
// access control
|
|||
c1bdc1c4 | Michal Kliment | if (!Settings::get('works_enabled') ||
|
|
!$this->acl_check_delete('Comments_Controller', 'works', $comment->user->member_id))
|
|||
8baed187 | Michal Kliment | Controller::error(ACCESS);
|
|
c1bdc1c4 | Michal Kliment | ||
$link_back_url = Path::instance()->previous();
|
|||
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $type = Watcher_Model::WORK;
|
|
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $subject = mail_message::format('work_comment_delete_subject');
|
|
$body = mail_message::format('work_comment_delete', array
|
|||
(
|
|||
$user->name.' '.$user->surname,
|
|||
$parent->user->name.' '.$parent->user->surname,
|
|||
url_lang::base().'works/show/'.$parent->id
|
|||
));
|
|||
8baed187 | Michal Kliment | break;
|
|
c1bdc1c4 | Michal Kliment | case 'request':
|
|
// access control
|
|||
if (!Settings::get('approval_enabled') ||
|
|||
!$this->acl_check_edit('Comments_Controller', 'requests'))
|
|||
Controller::error(ACCESS);
|
|||
$link_back_url = Path::instance()->previous();
|
|||
$type = Watcher_Model::REQUEST;
|
|||
$subject = mail_message::format('request_comment_delete_subject');
|
|||
$body = mail_message::format('request_comment_delete', array
|
|||
(
|
|||
$user->name.' '.$user->surname,
|
|||
$parent->user->name.' '.$parent->user->surname,
|
|||
url_lang::base().'requests/show/'.$parent->id
|
|||
));
|
|||
break;
|
|||
8baed187 | Michal Kliment | default:
|
|
Controller::error(RECORD);
|
|||
break;
|
|||
}
|
|||
c1bdc1c4 | Michal Kliment | ||
try
|
|||
8baed187 | Michal Kliment | {
|
|
c1bdc1c4 | Michal Kliment | $comment->transaction_start();
|
|
$comment->delete_throwable();
|
|||
if (isset($type))
|
|||
{
|
|||
// send message about comment adding to all watchers
|
|||
Mail_message_Model::send_system_message_to_item_watchers(
|
|||
$subject,
|
|||
$body,
|
|||
$type,
|
|||
$parent->id
|
|||
);
|
|||
}
|
|||
$comment->transaction_commit();
|
|||
8baed187 | Michal Kliment | status::success('Comment has been successfully deleted');
|
|
}
|
|||
c1bdc1c4 | Michal Kliment | catch(Exception $e)
|
|
{
|
|||
$comment->transaction_rollback();
|
|||
status::error('Error - Cannot delete comment', $e);
|
|||
Log::add_exception($e);
|
|||
}
|
|||
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $this->redirect($link_back_url);
|
|
8baed187 | Michal Kliment | }
|
|
}
|