Esempio n. 1
0
 public static function &get_instance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Esempio n. 2
0
 public function handle_request_internal()
 {
     $req = APF::get_instance()->get_request();
     $res = APF::get_instance()->get_response();
     $ticket_id = $req->get_parameter('ticket_id');
     $error = $req->get_parameter('error');
     $user_id = $req->get_user_id();
     $user_role = Bll_RoleBiz::get_instance()->get_user_role($user_id);
     $ticket = Bll_TicketBiz::get_instance()->get_detail($ticket_id);
     if (empty($ticket)) {
         $location = Home_IndexController::build_uri();
         $res->redirect($location);
     }
     //custom_detail
     $custom_detail = Bll_TicketColumnDetailBiz::get_instance()->get_ticket_custom($ticket_id);
     $custom_all = Bll_TicketColumnDetailBiz::get_instance()->get_all_custom($ticket_id);
     $ticket_before_md5 = md5(json_encode($ticket));
     $ticket->reporter = Bll_UserBiz::get_instance()->get_wholename_by_username($ticket->reporter);
     $ticket->owner = Bll_UserBiz::get_instance()->get_wholename_by_username($ticket->owner);
     $ticket->assigned_qa = Bll_UserBiz::get_instance()->get_wholename_by_username($ticket->assigned_qa);
     $ticket_log = Bll_TicketLogBiz::get_instance()->get_log($ticket_id);
     $ticket_cc_arr = Bll_TicketCcBiz::get_instance()->get_ticket_cc($ticket_id);
     $cc_tmp = array();
     foreach ($ticket_cc_arr as $key => $ticket_cc) {
         if (Util_StringUtils::is_email($ticket_cc->cc_to)) {
             $cc_tmp[] = $ticket_cc->cc_to;
         } else {
             $cc_tmp[] = Bll_UserBiz::get_instance()->get_wholename_by_username($ticket_cc->cc_to);
         }
     }
     $ticket_cc_str = implode(";", $cc_tmp);
     $current_time = date("Y-m-d H:i:s");
     $ticket_log_process = array();
     foreach ($ticket_log as $key => $log) {
         if ($ticket_log[$key]->field == "component") {
             if (ctype_digit($ticket_log[$key]->oldvalue)) {
                 $ticket_log[$key]->oldvalue = Bll_TicketBiz::get_instance()->get_component_name($ticket_log[$key]->oldvalue);
             }
             if (ctype_digit($ticket_log[$key]->newvalue)) {
                 $ticket_log[$key]->newvalue = Bll_TicketBiz::get_instance()->get_component_name($ticket_log[$key]->newvalue);
             }
         } else {
             if ($ticket_log[$key]->field == "department") {
                 if (ctype_digit($ticket_log[$key]->oldvalue)) {
                     $ticket_log[$key]->oldvalue = Bll_TicketBiz::get_instance()->get_common_name($ticket_log[$key]->oldvalue);
                 }
                 if (ctype_digit($ticket_log[$key]->newvalue)) {
                     $ticket_log[$key]->newvalue = Bll_TicketBiz::get_instance()->get_common_name($ticket_log[$key]->newvalue);
                 }
             } else {
                 if ($ticket_log[$key]->field == "ticket" && $ticket_log[$key]->oldvalue == "null") {
                     $ticket_log[$key]->newvalue = "new";
                 }
             }
         }
         $ticket_log_process[$log->created_at][] = $log;
     }
     $log_time = array();
     foreach ($ticket_log_process as $key => $log) {
         /*
          * within 24h show xxx hours ago
          * mt 24h lt 7days show xx days ago
          * mt 7days lt 30days show xx weeks ago
          * mt 30days show xx months ago
          * floor((strtotime($current_time)-strtotime($log->created_at))/86400)
          */
         $second = floor(strtotime($current_time) - strtotime($key));
         $minute = floor((strtotime($current_time) - strtotime($key)) / 60);
         $hour = floor((strtotime($current_time) - strtotime($key)) / 3600);
         $day = floor((strtotime($current_time) - strtotime($key)) / 86400);
         $week = floor((strtotime($current_time) - strtotime($key)) / 604800);
         $month = floor((strtotime($current_time) - strtotime($key)) / 2592000);
         if ($second < 60) {
             $log_time[$key] = $second . ' seconds ago ';
         } else {
             if ($minute < 60) {
                 $log_time[$key] = $minute . ' minutes ago ';
             } else {
                 if ($hour < 24) {
                     $log_time[$key] = $hour . ' hours ago ';
                 } else {
                     if ($hour >= 24 && $hour < 168) {
                         $log_time[$key] = $day . ' days ago ';
                     } else {
                         if ($hour >= 168 && $hour < 720) {
                             $log_time[$key] = $week . ' weeks ago ';
                         } else {
                             if ($hour >= 720) {
                                 $log_time[$key] = $month . ' months ago ';
                             }
                         }
                     }
                 }
             }
         }
     }
     $parent = Bll_TicketRelationBiz::get_instance()->find_root_by_parent($ticket_id);
     if ($parent) {
         $parent_id = $parent->parent_ticket_id;
     } else {
         $parent_id = "0";
     }
     $son = Bll_TicketRelationBiz::get_instance()->find_son_bugs_of_parent($ticket_id);
     if (empty($son)) {
         $son_id = "0";
     } else {
         $son_id = $son[0]->ticket_id;
     }
     $ticket_status = Ticket_Status::get_status($ticket);
     $actions = $ticket_status->get_available_actions($user_role, $ticket->environment);
     $resolutions = Bll_DdCommonBiz::get_instance()->get_resolutions();
     //start.....
     $all_users = Bll_UserBiz::get_instance()->get_all_valid_users();
     $tmp_all = array();
     foreach ($all_users as $key => $value) {
         $tmp_all[$key] = $value->whole_name;
     }
     $all_users = json_encode($tmp_all);
     $dev_users = Bll_UserBiz::get_instance()->get_dev_users();
     $tmp_dev = array();
     foreach ($dev_users as $key => $value) {
         $tmp_dev[$key] = $value->whole_name;
     }
     $dev_users = json_encode($tmp_dev);
     $qa_users = Bll_UserBiz::get_instance()->get_qa_users();
     $admin_users = Bll_UserBiz::get_instance()->get_admins();
     $qa_admin_users = array_merge($qa_users, $admin_users);
     $tmp_qa = array();
     foreach ($qa_admin_users as $key => $value) {
         $tmp_qa[$key] = $value->whole_name;
     }
     $qa_admin_users = json_encode($tmp_qa);
     //end.....
     $reasons = Bll_DdCommonBiz::get_instance()->get_reasons();
     $files = Bll_AttachmentBiz::get_instance()->get_file_by_ticket_id($ticket_id);
     if ($files) {
         foreach ($files as $file) {
             $file_link = Bll_AttachmentBiz::get_instance()->get_file_link_by_hash($file->fetch_hash);
             $file->fetch_hash = $file_link;
         }
     }
     $prioritys = Bll_DdCommonBiz::get_instance()->get_prioritys();
     $emergencies = Bll_DdCommonBiz::get_instance()->get_emergencies();
     $environments = Bll_DdCommonBiz::get_instance()->get_environments();
     $departments = Bll_DdCommonBiz::get_instance()->get_departments_new();
     $department_id = Bll_DdCommonBiz::get_instance()->get_department_id_by_name($ticket->department);
     $rel_components = Bll_DdComponentBiz::get_instance()->get_components($department_id->id);
     $req->set_attribute('user_id', $user_id);
     $req->set_attribute('files', $files);
     $req->set_attribute('prioritys', $prioritys);
     $req->set_attribute('emergencies', $emergencies);
     $req->set_attribute('departments', $departments);
     $req->set_attribute('rel_components', $rel_components);
     $req->set_attribute('environments', $environments);
     $req->set_attribute('reasons', $reasons);
     $req->set_attribute('resolutions', $resolutions);
     $req->set_attribute('ticket', $ticket);
     $req->set_attribute('ticket_cc_str', $ticket_cc_str);
     $req->set_attribute('ticket_logs', $ticket_log_process);
     $req->set_attribute('log_time', $log_time);
     $req->set_attribute('actions', $actions);
     $req->set_attribute('all_users', $all_users);
     $req->set_attribute('dev_users', $dev_users);
     $req->set_attribute('qa_admin_users', $qa_admin_users);
     $req->set_attribute('ticket_before_md5', $ticket_before_md5);
     $req->set_attribute('parent_id', $parent_id);
     $req->set_attribute('son_id', $son_id);
     $req->set_attribute('custom_detail', $custom_detail);
     $req->set_attribute('custom_all', $custom_all);
     if ($error) {
         $req->set_attribute('error', $error);
     }
     return 'Ticket_Detail';
 }
Esempio n. 3
0
 /**
  *	处理ticket数据 
  */
 public function deal_ticket_data($results)
 {
     $docs = $results['docs'];
     $ids = array();
     foreach ($docs as $doc) {
         $ids[] = $doc['fields']['id'];
         $tickets = Bll_TicketBiz::get_instance()->get_tickets_by_id_arr($ids);
         $tickets = $this->process_tickets($tickets, $results['docs']);
         $historys = Bll_TicketStatusHistoryBiz::get_instance()->get_history_by_ids($ids);
         $his_pro = array();
         foreach ($historys as $row) {
             if ($row->status == 'accepted') {
                 if (isset($his_pro[$row->ticket_id][$row->status]) && strtotime($row->created_at) < strtotime($his_pro[$row->ticket_id][$row->status]) || !isset($his_pro[$row->ticket_id][$row->status])) {
                     $his_pro[$row->ticket_id][$row->status] = $row->created_at;
                 }
             } else {
                 if (isset($his_pro[$row->ticket_id][$row->status]) && strtotime($row->created_at) > strtotime($his_pro[$row->ticket_id][$row->status]) || !isset($his_pro[$row->ticket_id][$row->status])) {
                     $his_pro[$row->ticket_id][$row->status] = $row->created_at;
                 }
             }
         }
         foreach ($tickets as $key => $ticket) {
             foreach ($tickets[$key] as $k => $v) {
                 $tickets[$key][$k]->additional = Bll_TicketColumnDetailBiz::get_instance()->get_all_custom($v->id);
                 //QA时间
                 if (isset($his_pro[$v->id]['accepted'])) {
                     $tickets[$key][$k]->qa_at = $his_pro[$v->id]['accepted'];
                     $tickets[$key][$k]->qa_time = $this->format_time_v1($this->convert_time($v->created_at, $tickets[$key][$k]->qa_at));
                 } else {
                     $tickets[$key][$k]->qa_at = '0';
                     $tickets[$key][$k]->qa_time = '-';
                 }
                 //开发时间
                 if (isset($his_pro[$v->id]['verified']) && !in_array($v->status, array('opened', 'accepted'))) {
                     $tickets[$key][$k]->dev_at = $his_pro[$v->id]['verified'];
                     $tickets[$key][$k]->dev_time = $this->format_time($this->convert_time($v->created_at, $tickets[$key][$k]->dev_at));
                 } else {
                     $tickets[$key][$k]->dev_at = '0';
                     $tickets[$key][$k]->dev_time = '-';
                 }
                 //完整处理时间
                 if (isset($his_pro[$v->id]['closed'])) {
                     $tickets[$key][$k]->all_at = $his_pro[$v->id]['closed'];
                     $tickets[$key][$k]->all_time = $this->format_time($this->convert_time($v->created_at, $tickets[$key][$k]->all_at));
                     $tickets[$key][$k]->all_time_2 = $this->format_time_v2($this->convert_time($v->created_at, $tickets[$key][$k]->all_at));
                 } else {
                     $tickets[$key][$k]->all_at = '0';
                     $tickets[$key][$k]->all_time = '-';
                 }
                 //reopened
                 $parent = Bll_TicketRelationBiz::get_instance()->find_root_by_parent($v->id);
                 if ($parent) {
                     $tickets[$key][$k]->pid = $parent->parent_ticket_id;
                 } else {
                     $tickets[$key][$k]->pid = '';
                 }
                 if (isset($v->description)) {
                     $tickets[$key][$k]->description = preg_replace('/<img.*>/siU', '', $v->description);
                 }
             }
         }
     }
     return $tickets;
 }
Esempio n. 4
0
 public function handle_request_internal()
 {
     $req = APF::get_instance()->get_request();
     $params = $req->get_parameters();
     //var_dump($params);die();
     //var_dump($params['description']);die();
     if ($params && $params['summary'] && $params['editor1'] && $params['owner'] && $params['reporter']) {
         $input_arr = array('summary' => $params['summary'], 'reporter' => $params['reporter'], 'description' => Ticket_AttachAddController::convert_imageurl($params['editor1']), 'priority' => $params['priority'], 'emergency' => $params['emergency'], 'environment' => $params['environment'], 'department' => $params['department'], 'component' => $params['component'], 'owner' => $params['owner'], 'cc_user' => $params['cc_user'], 'assigned_qa' => $params['assigned_qa'], 'pmt_id' => $params['pmt_id'], 'version' => $params['version'], 'is_regression' => $params['is_regression'], 'status' => 'opened', 'version' => $params['version'], 'is_occasional' => $params['is_occasional'], 'person_liable' => $params['person_liable']);
         if (in_array($input_arr['department'], array('47', '48'))) {
             $input_arr['pmt_id'] = 0;
         }
         $input_arr['owner'] = strpos($input_arr['owner'], ";") ? substr($input_arr['owner'], 0, strpos($input_arr['owner'], ";")) : $input_arr['owner'];
         $input_arr['owner'] = Bll_UserBiz::get_instance()->get_username_by_wholename($input_arr['owner']);
         $input_arr['assigned_qa'] = strpos($input_arr['assigned_qa'], ";") ? substr($input_arr['assigned_qa'], 0, strpos($input_arr['assigned_qa'], ";")) : $input_arr['assigned_qa'];
         $input_arr['assigned_qa'] = Bll_UserBiz::get_instance()->get_username_by_wholename($input_arr['assigned_qa']);
         //$input_arr['person_liable'] = strpos($input_arr['person_liable'],";")?substr($input_arr['person_liable'], 0, strpos($input_arr['person_liable'],";")):$input_arr['person_liable'];
         //$input_arr['person_liable'] = Bll_UserBiz::get_instance()->get_username_by_wholename($input_arr['person_liable']);
         $ticket_id = Bll_TicketBiz::get_instance()->ticket_add($input_arr);
         //request icase api
         if (isset($params['case_id'])) {
             $cycle = 3;
             $url = "http://icase.corp.anjuke.com/api/save/case2bug?";
             $p = array();
             $p['bug_id'] = $ticket_id;
             $p['case_id'] = $params['case_id'];
             $url = $url . "bug_id=" . $p['bug_id'] . "&case_id=" . $p['case_id'] . "&key=nmzszxsl";
             $culr = curl_init();
             curl_setopt($culr, CURLOPT_URL, $url);
             curl_setopt($culr, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($culr, CURLOPT_FOLLOWLOCATION, 1);
             $data = curl_exec($culr);
             $data = json_decode($data, true);
             while ($cycle > 0) {
                 if ($data['status'] == "ok") {
                     break;
                 }
                 $data = curl_exec($culr);
                 $cycle--;
             }
             curl_close($culr);
         }
         //request imonitor api
         if (isset($params['task_fail_id']) && $params['task_fail_id'] != "") {
             $cycle = 3;
             $url = "10.10.9.53:8888/api/ibug/";
             $p = array();
             $p['bug_id'] = $ticket_id;
             $p['task_fail_id'] = $params['task_fail_id'];
             $culr = curl_init();
             curl_setopt($culr, CURLOPT_URL, $url);
             curl_setopt($culr, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($culr, CURLOPT_HEADER, 0);
             curl_setopt($culr, CURLOPT_POST, 1);
             curl_setopt($culr, CURLOPT_POSTFIELDS, $p);
             $data = curl_exec($culr);
             while ($cycle > 0) {
                 if ($data == "ok") {
                     break;
                 }
                 $data = curl_exec($culr);
                 $cycle--;
             }
             curl_close($culr);
         }
         //custom column
         $custom_columns = Bll_TicketCustomColumnBiz::get_instance()->get_custom_columns();
         foreach ($custom_columns as $column) {
             if (!empty($params[$column->column_name])) {
                 $custom_arr[$column->column_name] = $params[$column->column_name];
             }
         }
         if (!empty($custom_arr)) {
             $res = Bll_TicketColumnDetailBiz::get_instance()->ticket_custom_add($ticket_id, $custom_arr);
         }
         //save files using curl
         $file_hidden = $params['file_hidden'];
         if (!empty($file_hidden)) {
             foreach ($file_hidden as $file_id) {
                 $file_info = Bll_AttachmentBiz::get_instance()->get_file_info_by_id($file_id);
                 $local_filepath = $file_info->local_filepath;
                 $finfo = finfo_open(FILEINFO_MIME_TYPE);
                 $file_type = finfo_file($finfo, $local_filepath);
                 $post_params = array("file" => "@" . $local_filepath . ";type=" . $file_type);
                 $request_url = APF::get_instance()->get_config('file_upload_url');
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $request_url);
                 curl_setopt($ch, CURLOPT_POST, 1);
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 $ret = curl_exec($ch);
                 $info = curl_getinfo($ch);
                 $ret_value = json_decode($ret);
                 if (!$ret_value->error) {
                     $fetch_hash = $ret_value->saved_file[0]->hash;
                 }
                 //更新数据库
                 $res = Bll_AttachmentBiz::get_instance()->modify_file_info($file_id, $ticket_id, $fetch_hash);
             }
         }
         $current_time = date("Y-m-d H:i:s");
         if ($ticket_id) {
             //mail add
             $id = Bll_MailBiz::get_instance()->mail_add($ticket_id, $current_time);
         }
         if ($ticket_id) {
             //new ticket log add
             $input_arr = array('ticket_id' => $ticket_id, 'created_by' => $req->get_username(), 'field' => 'ticket', 'oldvalue' => 'null', 'newvalue' => $input_arr['description'], 'created_at' => $current_time);
             $log_id = Bll_TicketLogBiz::get_instance()->log_add($input_arr);
         }
         $location = Ticket_DetailController::build_uri() . '?ticket_id=' . $ticket_id;
         APF::get_instance()->get_response()->redirect($location);
     } else {
         if ($params['post'] == 'posted') {
             $req->set_attribute('error', '请检查,summary,description,owner为必填项!');
         }
     }
     $all_users = Bll_UserBiz::get_instance()->get_all_valid_users();
     $tmp_all = array();
     foreach ($all_users as $key => $value) {
         $tmp_all[$key] = $value->whole_name;
     }
     $all_users = json_encode($tmp_all);
     $dev_users = Bll_UserBiz::get_instance()->get_dev_users();
     $tmp_dev = array();
     foreach ($dev_users as $key => $value) {
         $tmp_dev[$key] = $value->whole_name;
     }
     $dev_users = json_encode($tmp_dev);
     $qa_users = Bll_UserBiz::get_instance()->get_qa_users();
     $admin_users = Bll_UserBiz::get_instance()->get_admins();
     $qa_admin_users = array_merge($qa_users, $admin_users);
     $tmp_qa = array();
     foreach ($qa_admin_users as $key => $value) {
         $tmp_qa[$key] = $value->whole_name;
     }
     $qa_admin_users = json_encode($tmp_qa);
     $prioritys = Bll_DdCommonBiz::get_instance()->get_prioritys();
     $emergencies = Bll_DdCommonBiz::get_instance()->get_emergencies();
     $reasons = Bll_DdCommonBiz::get_instance()->get_reasons();
     $environments = Bll_DdCommonBiz::get_instance()->get_environments();
     $departments = Bll_DdCommonBiz::get_instance()->get_departments_new();
     $custom_columns = Bll_TicketCustomColumnBiz::get_instance()->get_custom_columns();
     $req->set_attribute('prioritys', $prioritys);
     $req->set_attribute('emergencies', $emergencies);
     $req->set_attribute('reasons', $reasons);
     $req->set_attribute('environments', $environments);
     $req->set_attribute('departments', $departments);
     $req->set_attribute('reporter', $req->get_username());
     $req->set_attribute('all_users', $all_users);
     $req->set_attribute('dev_users', $dev_users);
     $req->set_attribute('qa_admin_users', $qa_admin_users);
     $req->set_attribute('custom_columns', $custom_columns);
     $req->set_attribute('paramas', $params);
     return 'Ticket_Add';
 }