Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @description api react for issue log
- * @author Ilya Khalizov, Ilia Kovalenko
- */
- class issueLogController extends apiController
- {
- /**
- * equels issue id
- */
- private $_page_id;
- public function __construct()
- {
- parent::__construct();
- require_once ROOT_DIR . '/plugins/function.imageurl.php';
- if ($this->_input['data']) {
- $data = json_decode($this->_input['data']);
- $this->_page_id = (int)$data->page_id;
- } else {
- $this->_page_id = (int)$this->_input['page_id'];
- }
- }
- /**
- * @description get issue's log
- * @return object
- */
- public function listAction()
- {
- if ($this->_input['page_id'] > 0) {
- $this->_result = IssueLog::findById($this->_input['page_id']);
- } else {
- $this->_result = IssueLog::findByFilterParams($this->_input);
- }
- $this->_result['allow_change_filds'] = IssueLog::checkEditAccess($this->_input['page_id']);
- $this->_result['allow_change_filds_creator'] = IssueLog::getAllowedToChangeIssueStatusIds(
- $this->_loggedUser->get('username')
- );
- $this->_result['admin'] = $this->_loggedUser->get('admin');
- $this->output();
- }
- /**
- * @description get issue's log on short format
- * @return object
- */
- public function shortListAction()
- {
- $this->_result = IssueLog::findByFilterParamsShort($this->_input);
- $this->_result['allow_change_filds'] = IssueLog::checkEditAccess($this->_input['page_id']);
- $this->_result['allow_change_filds_creator'] = IssueLog::getAllowedToChangeIssueStatusIds(
- $this->_loggedUser->get('username')
- );
- $this->_result['admin'] = $this->_loggedUser->get('admin');
- $this->output();
- }
- /**
- * @description change responsible person
- * @return json
- *
- * @var $this
- * @var $query
- * @var $page_id
- * @var $resp_person
- * @var $user
- *
- */
- public function changeResponsibleAction()
- {
- $status = false;
- if ($this->_input['resp_person']) {
- $resp_person = mysql_real_escape_string($this->_input['resp_person']);
- $issue = new IssueLog($this->_page_id);
- $issue->set('resp_username', $resp_person);
- $issue->update();
- $user = $this->_dbr->getAssoc("SELECT username, `name` FROM users WHERE username = '$resp_person'");
- $this->_result['resp_username'] = $user;
- $this->_result['issuelog_id'] = $this->_page_id;
- $this->sendAndLogEmail('responsible');
- $status = true;
- }
- $this->_result['success'] = $status;
- $this->output();
- }
- /**
- * @description change solving responsible person
- * @return json
- *
- * @var $this
- * @var $query
- * @var $page_id
- * @var $resp_person
- * @var $user
- *
- */
- public function changeSolvingResponsibleAction()
- {
- $status = false;
- if (IssueLog::checkEditAccess($this->_input['page_id'])) {
- if ($this->_input['solving_resp_person']) {
- $solving_resp_person = mysql_real_escape_string($this->_input['solving_resp_person']);
- $issue = new IssueLog($this->_page_id);
- $issue->set('solving_resp_username', $solving_resp_person);
- $issue->update();
- $user = $this->_dbr->getAssoc("SELECT username, `name` FROM users WHERE username = '$solving_resp_person'");
- $this->_result['resp_username'] = $user;
- $this->_result['issuelog_id'] = $this->_page_id;
- $this->sendAndLogEmail('solving');
- $status = true;
- }
- }
- $this->_result['success'] = $status;
- $this->output();
- }
- /**
- * @description change department
- * @return json
- *
- * @var $this
- * @var $query
- * @var $departament
- *
- */
- public function changeDepartmentAction()
- {
- $status = false;
- if (IssueLog::checkEditAccess($this->_input['page_id']))
- {
- if (isset($this->_input['department']))
- {
- $departments = $this->_input['department'];
- $issue = new IssueLog($this->_page_id);
- $this->_result['department_ids'] = $issue->saveDepartments($departments);
- $status = true;
- }
- }
- $this->_result['success'] = $status;
- $this->output();
- }
- /**
- * @description change issue description
- * @return json
- *
- * @var $this
- * @var $query
- * @var $issueDescription
- *
- */
- public function changeIssueDescriptionAction()
- {
- $status = false;
- if (IssueLog::checkEditAccess($this->_input['page_id'])) {
- $issueDescription = mysql_real_escape_string($this->_input['change_issue_description']);
- $issue = new IssueLog($this->_page_id);
- $issue->set('issue', $issueDescription);
- $issue->update();
- $status = true;
- }
- $this->_result['success'] = $status;
- $this->output();
- }
- /**
- * set due date
- * @var $due_date
- * @var $this
- */
- public function setDueDateAction()
- {
- $due_date = mysql_real_escape_string($this->_input['due_date']);
- $issue = new IssueLog($this->_page_id);
- $issue->set('due_date', $due_date);
- $issue->update();
- $this->_result['success'] = true;
- $this->output();
- }
- /**
- * delete due date
- * @var $this
- */
- public function deleteDueDateAction()
- {
- $issue = new IssueLog($this->_page_id);
- $issue->set('due_date', null);
- $issue->update();
- $this->_result['success'] = true;
- $this->output();
- }
- /**
- * @description change type
- * @return json
- *
- * @var $this
- * @var $query
- * @var $issue_type_id
- *
- */
- public function changeIssueTypeAction()
- {
- //checkEditAccess - https://trello.com/c/cfqp58X0/4716-natalia-g-issue-list-small-change
- //if (IssueLog::checkEditAccess($this->_input['page_id'])) {
- $issue_type_id = $this->_input['issue_type_id'];
- $issue = new IssueLog($this->_page_id);
- $issue->replaceIssueTypes($issue_type_id);
- $this->_result['success'] = true;
- $this->output();
- //}
- }
- /**
- * @description save the issue images, files and videos
- * @var $images
- * @var $imgs_qty
- * @var $file_name
- * @var $file_extension
- * @var $type
- * @var $pic
- * @var $md5
- * @var $file
- * @var $mime_type
- */
- public function saveImagesAction()
- {
- $images = $_FILES['imgs'] ? $_FILES['imgs'] : [];
- if ($images) {
- $imgs_qty = count($images['tmp_name'])-1;
- if ($imgs_qty >= 0) {
- for(; $imgs_qty >= 0; $imgs_qty--) {
- $tmp_name = $images['tmp_name'][$imgs_qty];
- $file_name = $images['name'][$imgs_qty];
- $mime_type = $images['type'][$imgs_qty];
- $issue = new IssueLog($this->_page_id);
- $issue->addFile($file_name, $tmp_name, $mime_type);
- }
- }
- }
- $this->getIssueImagesAction();
- }
- /**
- * @description delete the issue images and files
- */
- public function deleteImagesAction()
- {
- $images = $this->_input['images_delete'] ? $this->_input['images_delete'] : [];
- foreach ($images as $image) {
- $image_hash = $this->_dbr->getOne("SELECT `hash` FROM issue_pic WHERE id = $image");
- (new UploadFiles())->delete($image_hash);
- // $image_path = set_file_path($image_hash);
- // if (is_file($image_path)) {
- // unlink($image_path);
- // }
- $this->_db->query("DELETE FROM issue_pic WHERE id = $image");
- }
- $this->getIssueImagesAction();
- }
- /**
- * @description get issue images
- */
- public function getIssueImagesAction()
- {
- $issue = new IssueLog($this->_page_id);
- $this->_result['images'] = $issue->getFiles('pic');
- $this->_result['files'] = $issue->getFiles('doc');
- $this->_result['videos'] = $issue->getFiles('video');
- $this->output();
- }
- /**
- * get issue types
- */
- public function getIssueTypesAction() {
- $query = "SELECT `name`, inactive, id FROM issue_type";
- $result = $this->_dbr->getAll($query);
- $this->_result['issue_types'] = $result;
- $default_issue_type = \Config::get('default_issue_type');
- $this->_result['default_issue_type'] = $default_issue_type;
- $this->output();
- }
- /**
- * set issue types
- * @return object
- */
- public function setIssueTypesAction() {
- if ($this->_input['name'] && !$this->_input['type_id']) {
- $name = mysql_real_escape_string($this->_input['name']);
- $this->_db->query("INSERT INTO issue_type (`name`) VALUES ('" . $name . "')");
- }
- if ($this->_input['name'] && $this->_input['type_id']) {
- $name = mysql_real_escape_string($this->_input['name']);
- $this->_db->query("UPDATE issue_type SET `name` = '$name' WHERE id = " . $this->_input['type_id']);
- }
- if ($this->_input['default']) {
- \Config::set('default_issue_type', (int)$this->_input['default']);
- }
- if ($this->_input['inactive'] >= 0 && $this->_input['type_id']) {
- $this->_db->query("UPDATE issue_type SET inactive = " . (int)$this->_input['inactive'] . " WHERE id = " . $this->_input['type_id']);
- }
- if ($this->_input['inspection'] >= 0 && $this->_input['type_id']) {
- $this->_db->query("UPDATE issue_type SET inspection = " . (int)$this->_input['inspection'] . " WHERE id = " . $this->_input['type_id']);
- }
- $this->_result['success'] = true;
- $this->getIssueTypesAction();
- }
- /**
- * @description send email and log it when choose new responsible person
- */
- private function sendAndLogEmail($type)
- {
- if ($type == 'responsible') {
- $person = $this->_input['resp_person'];
- $field = 'resp_username';
- }
- if ($type == 'solving') {
- $person = $this->_input['solving_resp_person'];
- $field = 'solving_resp_username';
- }
- global $siteURL;
- $current_respuser= $this->_db->getOne("select " . $field . " from issuelog where id=" . $this->_page_id);
- $newuser_email = $this->_db->getOne("select email from users where username='" . $person . "'");
- if ($current_respuser != $resp_person) {
- if (strlen($person)) {
- $ret = new stdClass;
- $ret->from = $this->_loggedUser->get('email');
- $ret->from_name = $this->_loggedUser->get('name');
- $user = new User($this->_db, $this->_dbr, $person);
- $ret->email_invoice = $newuser_email;
- $ret->saved_id = $this->_page_id;
- $ret->auction_number = $this->_page_id;
- $ret->txnid = 'issuelog';
- $ret->url = $siteURL . "react/logs/issue_logs/$this->_page_id/";
- standardEmail($this->_db, $this->_dbr, $ret, 'new_responsible_issue');
- }
- }
- }
- /**
- * print checked issues
- * @var $issue_ids
- * @var $this
- * @var $dompdf
- * @var $smarty
- * @var $content
- * @var $html
- */
- public function issuesPrintAction()
- {
- global $smarty;
- $issue_ids = $this->_input['issue_ids'];
- $issue_ids = implode(',', $issue_ids);
- $issues = $this->_dbr->getAll("
- SELECT
- GROUP_CONCAT(issue_type.`name` separator '<br>') issue_type
- , issuelog.issue
- , (
- SELECT Updated
- FROM total_log
- WHERE
- TableID = issuelog.id
- AND " . get_table_name('issuelog') . "
- AND " . get_field_name('id') . "
- ) AS added_time
- , (
- SELECT users.`name`
- FROM total_log
- JOIN users ON users.id = total_log.username_id
- WHERE
- TableID = issuelog.id
- AND " . get_table_name('issuelog') . "
- AND " . get_field_name('id') . "
- ) AS added_person
- , users.`name` solving_person
- , empd.`name` departament
- , issuelog.obj,
- CASE obj
- WHEN 'supplier' THEN CONCAT('Supplier: ', issuelog.obj_id)
- WHEN 'auction' THEN CONCAT('Auftrag: ',
- IF(auction.auction_number, auction.auction_number, issuelog.obj_id),
- IF(auction.txnid, CONCAT('/',auction.txnid), ''))
- WHEN 'rma' THEN CONCAT('Ticket: ', issuelog.obj_id)
- WHEN 'ww_order' THEN CONCAT('WWO: ', issuelog.obj_id)
- WHEN 'op_order' THEN CONCAT('OP Order: ', issuelog.obj_id)
- WHEN 'route' THEN CONCAT('Route: ', issuelog.obj_id)
- WHEN 'manual' THEN 'Manual'
- WHEN 'rating' CONCAT(THEN 'Rating: ', issuelog.obj_id)
- WHEN 'insurance' THEN CONCAT('Insurance: ', issuelog.obj_id)
- WHEN 'shippingInvoiceResults' THEN CONCAT('Shipping invoice: ', issuelog.obj_id)
- WHEN 'monitoredShippingPrices' THEN CONCAT('Monitored shipping price: ', issuelog.obj_id)
- END AS where_did
- FROM issuelog
- LEFT JOIN emp_department empd ON empd.id = issuelog.department_id
- LEFT JOIN users ON users.username = issuelog.resp_username
- LEFT JOIN users users_solving ON users_solving.username = issuelog.solving_resp_username
- LEFT JOIN issue_type ON issue_type.id = issuelog.type_id
- LEFT JOIN auction ON auction.id = issuelog.obj_id AND issuelog.obj = 'auction'
- LEFT JOIN rma ON rma.rma_id = issuelog.obj_id AND issuelog.obj = 'rma'
- LEFT JOIN auction auction_rma ON rma.auction_number = auction_rma.auction_number AND rma.txnid = auction_rma.txnid
- LEFT JOIN orders ON auction.auction_number = orders.auction_number and auction.txnid = orders.txnid
- LEFT JOIN orders orders_rma ON rma.auction_number = orders_rma.auction_number and rma.txnid = orders_rma.txnid
- LEFT JOIN auction_par_varchar ON auction.auction_number = auction_par_varchar.auction_number AND auction.txnid = auction_par_varchar.txnid AND auction_par_varchar.`key` = 'country_shipping'
- LEFT JOIN auction_par_varchar apv_rma ON rma.auction_number = apv_rma.auction_number AND rma.txnid = apv_rma.txnid AND apv_rma.`key` = 'country_shipping'
- LEFT JOIN total_log tl ON
- tl.TableID = issuelog.id
- AND " . get_table_name('issuelog', 'tl') . "
- AND " . get_field_name('id', 'tl') . "
- LEFT JOIN issuelog_type ON issuelog_type.issuelog_id = issuelog.id
- WHERE issuelog.id IN ($issue_ids)
- GROUP BY added_time
- ORDER BY added_time DESC
- ");
- if ($issues) {
- $smarty->assign('issues', $issues);
- $html = $smarty->fetch('issues.tpl');
- require_once("dompdf/dompdf_config.inc.php");
- $dompdf = new DOMPDF();
- $dompdf->set_paper('A4', 'landscape');
- $dompdf->load_html($html);
- $dompdf->render();
- $content = $dompdf->output();
- header("Content-type: application/pdf");
- header("Content-disposition: inline; filename=issues.pdf");
- echo $content;
- }
- }
- /**
- * @description Saving filter settings
- */
- public function saveFilterSettingsAction()
- {
- $filter = [];
- $success = false;
- $id = 0;
- $options = [];
- $filter_id = intval($this->_input['filter_id']);
- if (isset($this->_input['settingName']))
- {
- $title = mysql_real_escape_string(trim($this->_input['settingName']));
- //$title_exists = $this->_db->getOne("SELECT title FROM saved_filters WHERE title = '".$title."'");
- $filter_fields = [ 'seller',
- 'source_seller',
- 'shipping_country',
- 'shipping_method',
- 'warehouse_shipped_from',
- 'by_comment',
- 'date_from',
- 'date_to',
- 'show_with_inactive',
- 'status',
- 'where_did',
- 'issue_type',
- 'added_person',
- 'department_id',
- 'resp_username',
- 'solving_resp_username',
- 'recurring',
- 'supplier_id',
- ];
- $input_fields = $this->_input['filters'];
- foreach ( $filter_fields as $filter_field ) {
- if (isset($input_fields[$filter_field])) {
- $filter[$filter_field] = mysql_real_escape_string($input_fields[$filter_field]);
- }
- }
- $filter_json = json_encode($filter);
- $id = IssueLog::saveFilterSettings($filter_id, $title, $filter_json);
- /*
- if ($filter_id > 0) {
- // update filter
- $this->_db->query("UPDATE saved_filters
- SET `title` = '" . $title . "', `filter_set` = '" . $filter_json . "', `page` = 'issue_logs'
- WHERE id = " . $filter_id . "
- ");
- } else {
- // save new filter
- $this->_db->query("INSERT INTO saved_filters (`title`, `filter_set`, `page` )
- VALUES ('" . $title . "', '" . $filter_json . "', 'issue_logs')");
- }
- $id = $this->_db->getOne('SELECT LAST_INSERT_ID()');
- */
- if ($id > 0) {
- $q = "SELECT saved_filters.id, saved_filters.title, saved_filters.filter_set
- FROM saved_filters
- WHERE saved_filters.id = " . $id;
- $result = $this->_dbr->getAssoc($q);
- foreach ($result as &$item) {
- $item['filter_set'] = json_decode($item['filter_set']);
- }
- $success = true;
- }
- }
- if ($success && $id > 0) {
- $this->_result['options']['issue_filter_settings'] = $result;
- }
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Deleting filter settings
- */
- public function deleteFilterSettingsAction()
- {
- $success = false;
- $user_id = $this->_loggedUser->get('id');
- $filter_id = intval($this->_input['filter_id']);
- if ($filter_id > 0 && $user_id > 0) {
- $q = "
- DELETE saved_filters
- FROM saved_filters
- JOIN total_log ON " . get_table_name('saved_filters') . " AND
- `total_log`.username_id = " . $user_id . " AND
- `total_log`.TableID = saved_filters.id
- WHERE saved_filters.id = " . $filter_id . "
- ";
- $this->_db->query($q);
- $success = true;
- }
- $this->_result['filter_id'] = $filter_id;
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Adding/editing checkpoint
- *
- * @var $checkpoint_id
- * @var $issue_id
- * @var $description
- * @var $ordering
- * @var $done
- */
- public function saveCheckpointAction()
- {
- $success = false;
- $checkpoint_info = [];
- $issue_id = intval($this->_input['issue_id']);
- if ($issue_id > 0)
- {
- $issue = new IssueLog($issue_id);
- $checkpoint_id = $issue->saveCheckpoint([
- 'id' => intval($this->_input['checkpoint_id']),
- 'issuelog_id' => $issue_id,
- 'description' => mysql_real_escape_string($this->_input['description']),
- 'ordering' => ($this->_input['ordering']) ? intval($this->_input['ordering']) : 0,
- 'done' => ($this->_input['done'] > 0) ? 1 : 0
- ]);
- if ($checkpoint_id > 0)
- {
- $checkpoint_info = $issue->getCheckpoint($checkpoint_id);
- $success = true;
- }
- }
- $this->_result['checkpoint'] = $checkpoint_info;
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Adding/editing checkpoints
- */
- public function saveCheckpointsAction()
- {
- $success = false;
- $checkpoints_info = [];
- $issue_id = intval($this->_input['issue_id']);
- $checkpoints = $this->_input['checkpoints'];
- if (is_array($checkpoints) && $issue_id > 0)
- {
- $issue = new IssueLog($issue_id);
- foreach ($checkpoints as $checkpoint)
- {
- $checkpoint_id = $issue->saveCheckpoint([
- 'id' => intval($checkpoint['checkpoint_id']),
- 'issuelog_id' => $issue_id,
- 'description' => mysql_real_escape_string($checkpoint['description']),
- 'ordering' => (isset($checkpoint['ordering'])) ? intval($checkpoint['ordering']) : 0,
- 'done' => ($checkpoint['done'] > 0) ? 1 : 0
- ]);
- if ($checkpoint_id > 0)
- {
- $checkpoints_info[] = $issue->getCheckpoint($checkpoint_id);
- $success = true;
- }
- }
- }
- $this->_result['checkpoints'] = $checkpoints_info;
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Removing checkpoint
- *
- * @var $checkpoint_id
- * @var $issue_id
- *
- */
- public function removeCheckpointAction()
- {
- $issue_id = intval($this->_input['issue_id']);
- $checkpoint_id = intval($this->_input['checkpoint_id']);
- if ($issue_id > 0 && $checkpoint_id > 0)
- {
- $q = "DELETE FROM issue_checkpoint WHERE
- issue_checkpoint.id = " . $checkpoint_id . " AND
- issue_checkpoint.issuelog_id = " . $issue_id;
- $this->_db->query($q);
- }
- $this->checklistAction();
- }
- /**
- * @description Getting checklist
- *
- * @var $issue_id
- */
- public function checklistAction()
- {
- $success = false;
- $issue_id = intval($this->_input['issue_id']);
- $checklist = array();
- if ($issue_id > 0) {
- $checklist = IssueLog::getChecklist($issue_id);
- $success = true;
- }
- $this->_result['checklist'] = IssueLog::checklistReorder($issue_id, $checklist);
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Adding/editing issue type fields
- *
- * @var $issue_type_fields - array of issue type fields
- * with data (issue_field_id, name, issue_type_id, show_in_popup)
- */
- public function saveIssueTypeFieldAction()
- {
- $success = false;
- $results = [];
- $issue_type_fields = $this->_input['issue_type_fields'];
- /*
- // test
- $issue_type_fields = [
- ['issue_field_id' => 2, 'name' => 'qwe10', 'issue_type_id' => 1, 'show_in_popup' => 0],
- ['issue_field_id' => 5, 'name' => 'qwe11', 'issue_type_id' => 1, 'show_in_popup' => 0],
- ['name' => 'qwe12', 'issue_type_id' => 1, 'show_in_popup' => 0]
- ];
- */
- if (is_array($issue_type_fields) && count($issue_type_fields) > 0) {
- foreach ($issue_type_fields as $issue_type_field) {
- /*
- * Add or update issue type field
- */
- $result = IssueLog::saveIssueTypeField(
- intval($issue_type_field['field_id']),
- mysql_real_escape_string($issue_type_field['field_name']),
- intval($issue_type_field['issue_type_id']),
- ($issue_type_field['show_in_popup'] > 0) ? 1 : 0,
- ($issue_type_field['inactive'] > 0) ? 1 : 0
- );
- if ($result) {
- $success = true;
- $results[] = $result;
- } else {
- $success = false;
- }
- }
- }
- $this->_result['issue_type_fields'] = $results;
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Getting issue type fieldlist
- * @var $issue_type_id
- */
- public function issueTypeFieldlistAction()
- {
- $issue_type_id = intval($this->_input['issue_type_id']);
- $show_in_popup = (isset($this->_input['show_in_popup'])) ? intval($this->_input['show_in_popup']) : -1;
- $inactive = (isset($this->_input['inactive'])) ? intval($this->_input['inactive']) : -1;
- if ($issue_type_id > 0) {
- $fieldlist = IssueLog::getIssueTypeFieldList([$issue_type_id], $show_in_popup, $inactive);
- } else {
- $fieldlist = IssueLog::getIssueTypeFieldList([], $show_in_popup, $inactive);
- }
- $this->_result['fieldlist'] = $fieldlist;
- $this->_result['success'] = ($fieldlist) ? true : false;
- $this->output();
- }
- /**
- * @description Save checklist ordering
- *
- * @var $issue_id
- * @var $ordering - array of checkpoint ids and orderings
- */
- public function saveChecklistOrderingAction()
- {
- $success = false;
- $ordering = $this->_input['ordering'];
- $issue_id = intval($this->_input['issue_id']);
- if (is_array($ordering) && count($ordering) > 0) {
- foreach ($ordering as $item) {
- if (isset($item['checkpoint_id']) && isset($item['ordering'])) {
- $q = "UPDATE issue_checkpoint
- SET ordering = " . intval($item['ordering']) . "
- WHERE issuelog_id = " . $issue_id . "
- AND id = " . $item['checkpoint_id'];
- $this->_db->query($q);
- }
- }
- $this->_result['ordering'] = $ordering;
- $success = true;
- }
- $checklist = array();
- if ($issue_id > 0) {
- $q = "SELECT * FROM issue_checkpoint WHERE issuelog_id = " . $issue_id . " ORDER BY ordering, id ASC";
- $checklist = $this->_dbr->getAll($q);
- }
- $this->_result['checklist'] = $checklist;
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Set days for ping after no activity
- * @var $days - after X days send email
- * via cron if no activity in issue
- * @var $issue_id
- */
- public function setPingAfterNoActivityAction()
- {
- $success = false;
- $days = $this->_input['days'];
- $issue_id = $this->_input['issue_id'];
- $user_id = $user_id = $this->_loggedUser->get('id');
- if ($days >= 0 && $issue_id > 0 && $user_id > 0) {
- IssueLog::savePingDays($issue_id, $user_id, $days);
- $this->_result['ping_days'] = $days;
- $success = true;
- }
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Getting additional description fields
- * @var $issue_id
- */
- public function additionalDescriptionFieldsAction()
- {
- $success = false;
- $issue_id = $this->_input['issue_id'];
- if ($issue_id > 0) {
- $issue = new IssueLog($issue_id);
- $this->_result['fields'] = $issue->getAdditionalFields();
- $success = true;
- }
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Getting additional description fields
- * @var $issue_id
- */
- public function saveAdditionalFieldsAction()
- {
- $success = false;
- $issue_id = $this->_input['issue_id'];
- $fields = $this->_input['additional_fields'];
- //test
- /*
- $fields['additional_fields'] = array(
- 0 => array('field_id' => 27, 'value' => 'new field test value 1'),
- 1 => array('field_id' => 25, 'value' => 'new field test value 2'),
- 2 => array('field_id' => 26, 'value' => 'new field test value 3')
- );
- print_r($fields); die();
- */
- if ($issue_id > 0 && count($fields) > 0) {
- $issue = new IssueLog($issue_id);
- foreach ($fields as $field) {
- $issue->saveAdditionalField( intval($field['field_id']), $field['value']);
- }
- $success = true;
- $this->_result['fields'] = $issue->getAdditionalFields();
- }
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Getting all checklist titles
- */
- public function getChecklistTitlesAction()
- {
- $q = "SELECT
- DISTINCT issue_checkpoint.issuelog_id as issue_id,
- COUNT(issue_checkpoint.id) as `checkpoints`,
- issuelog.checklist_title
- FROM issue_checkpoint
- LEFT JOIN issuelog ON issuelog.id = issue_checkpoint.issuelog_id
- WHERE 1
- GROUP BY issue_checkpoint.issuelog_id";
- $this->_result['titles'] = $this->_dbr->getAll($q);
- $this->_result['success'] = true;
- $this->output();
- }
- /**
- * @description Getting all checklist titles
- */
- public function importChecklistAction()
- {
- $success = false;
- $issue_id_from = $this->_input['issue_id_from'];
- $issue_id_to = $this->_input['issue_id_to'];
- if ($issue_id_from > 0 && $issue_id_to > 0 && $issue_id_to != $issue_id_from) {
- IssueLog::importChecklist($issue_id_from, $issue_id_to);
- $success = true;
- }
- $checklist = IssueLog::getChecklist($issue_id_to);
- $this->_result['checklist'] = IssueLog::checklistReorder($issue_id_to, $checklist);
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Saving checklist title
- * @var $title - checklist title
- * @var $issue_id
- */
- public function saveChecklistTitleAction()
- {
- $success = false;
- $issue_id = intval($this->_input['issue_id']);
- $title = $this->_input['checklist_title'];
- if ($issue_id > 0)
- {
- $issue = new IssueLog($issue_id);
- $issue->set('checklist_title', $title);
- $issue->update();
- $success = true;
- }
- $this->_result['title'] = $title;
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Duplicating the issue
- */
- public function duplicateIssueAction()
- {
- $success = false;
- $issue_id = intval($this->_input['issue_id']);
- if ($issue_id > 0)
- {
- $new_issue_id = IssueLog::duplicateIssue($issue_id, [
- // What will we duplicate?
- 'tags' => (isset($this->_input['tags'])) ? intval($this->_input['tags']) : 1,
- 'details' => (isset($this->_input['details'])) ? intval($this->_input['details']) : 1,
- 'description' => (isset($this->_input['description'])) ? intval($this->_input['description']) : 1,
- 'comments' => (isset($this->_input['comments'])) ? intval($this->_input['comments']) : 1,
- 'checklist' => (isset($this->_input['checklist'])) ? intval($this->_input['checklist']) : 1,
- 'images' => (isset($this->_input['images'])) ? intval($this->_input['images']) : 1,
- 'files' => (isset($this->_input['files'])) ? intval($this->_input['files']) : 1,
- 'videos' => (isset($this->_input['videos'])) ? intval($this->_input['videos']) : 1
- ]);
- $this->_result['new_issue_id'] = $new_issue_id;
- $res = IssueLog::findByFilterParams(array('page_id' => $new_issue_id));
- $this->_result['issue'] = $res['issue_list'][0];
- $success = true;
- }
- $this->_result['success'] = $success;
- $this->output();
- }
- /**
- * @description Set close_notif option
- */
- public function closeNotifAction()
- {
- $success = false;
- $issue_id = intval($this->_input['issue_id']);
- $username = $this->_loggedUser->get('username');
- if ($issue_id > 0 && $username)
- {
- $data = IssueLog::closeNotifToogle($issue_id, $username);
- $this->_result['close_notif'] = $data;
- $success = true;
- }
- $this->_result['success'] = $success;
- $this->output();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement