本文整理汇总了PHP中TicketValidation::can方法的典型用法代码示例。如果您正苦于以下问题:PHP TicketValidation::can方法的具体用法?PHP TicketValidation::can怎么用?PHP TicketValidation::can使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TicketValidation
的用法示例。
在下文中一共展示了TicketValidation::can方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: geTimelineItems
static function geTimelineItems(Ticket $ticket, $rand)
{
global $DB, $CFG_GLPI;
$timeline = array();
$user = new User();
$group = new Group();
$followup_obj = new TicketFollowup();
$task_obj = new TicketTask();
$document_item_obj = new Document_Item();
$ticket_valitation_obj = new TicketValidation();
//checks rights
$showpublic = Session::haveRightsOr("followup", array(TicketFollowup::SEEPUBLIC, TicketFollowup::SEEPRIVATE)) && Session::haveRightsOr("task", array(TicketTask::SEEPUBLIC, TicketTask::SEEPRIVATE));
$restrict_fup = $restrict_task = "";
if (!Session::haveRight("ticket", TicketFollowup::SEEPRIVATE)) {
$restrict_fup = " AND (`is_private` = '0'\n OR `users_id` ='" . Session::getLoginUserID() . "') ";
}
if (!Session::haveRight("ticket", TicketTask::SEEPRIVATE)) {
$restrict_task = " AND (`is_private` = '0'\n OR `users_id` ='" . Session::getLoginUserID() . "') ";
}
if (!$showpublic) {
$restrict = " AND 1 = 0";
}
//add ticket followups to timeline
$followups = $followup_obj->find("tickets_id = " . $ticket->getID() . " {$restrict_fup}", 'date DESC');
foreach ($followups as $followups_id => $followup) {
$followup_obj->getFromDB($followups_id);
$can_edit = $followup_obj->canUpdateItem();
$followup['can_edit'] = $can_edit;
$timeline[$followup['date'] . "_followup_" . $followups_id] = array('type' => 'TicketFollowup', 'item' => $followup);
}
//add ticket tasks to timeline
$tasks = $task_obj->find("tickets_id = " . $ticket->getID() . " {$restrict_task}", 'date DESC');
foreach ($tasks as $tasks_id => $task) {
$task_obj->getFromDB($tasks_id);
$can_edit = $task_obj->canUpdateItem();
$task['can_edit'] = $can_edit;
$timeline[$task['date'] . "_task_" . $tasks_id] = array('type' => 'TicketTask', 'item' => $task);
}
//add ticket documents to timeline
$document_obj = new Document();
$document_items = $document_item_obj->find("itemtype = 'Ticket' AND items_id = " . $ticket->getID());
foreach ($document_items as $document_item) {
$document_obj->getFromDB($document_item['documents_id']);
$timeline[$document_obj->fields['date_mod'] . "_document_" . $document_item['documents_id']] = array('type' => 'Document_Item', 'item' => $document_obj->fields);
}
//add assign changes
/*$log_obj = new Log;
$gassign_items = $log_obj->find("itemtype = 'Ticket' AND items_id = ".$ticket->getID()."
AND itemtype_link = 'Group' AND linked_action = '15'");
foreach ($gassign_items as $logs_id => $gassign) {
//find group
$group_name = preg_replace("#(.*)\s\([0-9]*\)#", "$1", $gassign['new_value']);
$groups = $group->find("name = '$group_name'");
$first_group = array_shift($groups);
$group->getFromDB($first_group['id']);
$content = __("Assigned to")." : ".
"<img src='".$CFG_GLPI['root_doc']."/plugins/talk/pics/group.png' class='group_assign' />".
" <strong>".$group->getLink()."</strong>";
//find user
$user_name = preg_replace("#(.*)\s\([0-9]*\)#", "$1", $gassign['user_name']);
$users = $user->find("CONCAT(firstname, ' ', realname) = '$user_name'");
$first_user = array_shift($users);
if ($first_user == NULL) {
$first_user['id'] = false;
}
$timeline[$gassign['date_mod']."_assign_".$logs_id] = array('type' => 'Assign',
'item' => array(
'date' => $gassign['date_mod'],
'content' => $content,
'can_edit' => false,
'users_id' => $first_user['id']
));
}*/
//add existing solution
if (!empty($ticket->fields['solution'])) {
$users_id = 0;
$solution_date = $ticket->fields['solvedate'];
//search date and user of last solution in glpi_logs
if ($res_solution = $DB->query("SELECT date_mod AS solution_date, user_name FROM glpi_logs\n WHERE itemtype = 'Ticket' \n AND items_id = " . $ticket->getID() . "\n AND id_search_option = 24\n ORDER BY id DESC\n LIMIT 1")) {
$data_solution = $DB->fetch_assoc($res_solution);
if (!empty($data_solution['solution_date'])) {
$solution_date = $data_solution['solution_date'];
}
// find user
if (!empty($data_solution['user_name'])) {
$users_id = addslashes(trim(preg_replace("/.*\\(([0-9]+)\\)/", "\$1", $data_solution['user_name'])));
}
}
// fix trouble with html_entity_decode who skip accented characters (on windows browser)
$solution_content = preg_replace_callback("/(&#[0-9]+;)/", function ($m) {
return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
}, $ticket->fields['solution']);
$timeline[$solution_date . "_solution"] = array('type' => 'Solution', 'item' => array('id' => 0, 'content' => Html::clean(html_entity_decode($solution_content)), 'date' => $solution_date, 'users_id' => $users_id, 'solutiontypes_id' => $ticket->fields['solutiontypes_id'], 'can_edit' => Ticket::canUpdate() && $ticket->canSolve()));
}
// add ticket validation to timeline
if ($ticket->fields['type'] == Ticket::DEMAND_TYPE && (Session::haveRight('ticketvalidation', TicketValidation::VALIDATEREQUEST) || Session::haveRight('ticketvalidation', TicketValidation::CREATEREQUEST)) || $ticket->fields['type'] == Ticket::INCIDENT_TYPE && (Session::haveRight('ticketvalidation', TicketValidation::VALIDATEINCIDENT) || Session::haveRight('ticketvalidation', TicketValidation::CREATEINCIDENT))) {
$ticket_validations = $ticket_valitation_obj->find('tickets_id = ' . $ticket->getID());
//.........这里部分代码省略.........
示例2: getTimelineItems
/**
* @since version 0.90
*
**/
function getTimelineItems()
{
global $DB, $CFG_GLPI;
$timeline = array();
$user = new User();
$group = new Group();
$followup_obj = new TicketFollowup();
$task_obj = new TicketTask();
$document_item_obj = new Document_Item();
$ticket_valitation_obj = new TicketValidation();
//checks rights
$showpublic = Session::haveRightsOr("followup", array(TicketFollowup::SEEPUBLIC, TicketFollowup::SEEPRIVATE)) || Session::haveRightsOr("task", array(TicketTask::SEEPUBLIC, TicketTask::SEEPRIVATE));
$restrict_fup = $restrict_task = "";
if (!Session::haveRight("followup", TicketFollowup::SEEPRIVATE)) {
$restrict_fup = " AND (`is_private` = '0'\n OR `users_id` ='" . Session::getLoginUserID() . "') ";
}
if (!Session::haveRight("task", TicketTask::SEEPRIVATE)) {
$restrict_task = " AND (`is_private` = '0'\n OR `users_id` ='" . Session::getLoginUserID() . "') ";
}
if (!$showpublic) {
$restrict = " AND 1 = 0";
}
//add ticket followups to timeline
if ($followup_obj->canview()) {
$followups = $followup_obj->find("tickets_id = " . $this->getID() . " {$restrict_fup}", 'date DESC');
foreach ($followups as $followups_id => $followup) {
$followup_obj->getFromDB($followups_id);
$followup['can_edit'] = $followup_obj->canUpdateItem();
$timeline[$followup['date'] . "_followup_" . $followups_id] = array('type' => 'TicketFollowup', 'item' => $followup);
}
}
//add ticket tasks to timeline
if ($task_obj->canview()) {
$tasks = $task_obj->find("tickets_id = " . $this->getID() . " {$restrict_task}", 'date DESC');
foreach ($tasks as $tasks_id => $task) {
$task_obj->getFromDB($tasks_id);
$task['can_edit'] = $task_obj->canUpdateItem();
$timeline[$task['date'] . "_task_" . $tasks_id] = array('type' => 'TicketTask', 'item' => $task);
}
}
//add ticket documents to timeline
$document_obj = new Document();
$document_items = $document_item_obj->find("itemtype = 'Ticket' AND items_id = " . $this->getID());
foreach ($document_items as $document_item) {
$document_obj->getFromDB($document_item['documents_id']);
$timeline[$document_obj->fields['date_mod'] . "_document_" . $document_item['documents_id']] = array('type' => 'Document_Item', 'item' => $document_obj->fields);
}
//add existing solution
if (!empty($this->fields['solution']) || !empty($this->fields['solutiontypes_id'])) {
$users_id = 0;
$solution_date = $this->fields['solvedate'];
//search date and user of last solution in glpi_logs
if ($res_solution = $DB->query("SELECT `date_mod` AS solution_date, `user_name`, `id`\n FROM `glpi_logs`\n WHERE `itemtype` = 'Ticket'\n AND `items_id` = " . $this->getID() . "\n AND `id_search_option` = 24\n ORDER BY `id` DESC\n LIMIT 1")) {
$data_solution = $DB->fetch_assoc($res_solution);
if (!empty($data_solution['solution_date'])) {
$solution_date = $data_solution['solution_date'];
}
// find user
if (!empty($data_solution['user_name'])) {
$users_id = addslashes(trim(preg_replace("/.*\\(([0-9]+)\\)/", "\$1", $data_solution['user_name'])));
}
}
// fix trouble with html_entity_decode who skip accented characters (on windows browser)
$solution_content = preg_replace_callback("/(&#[0-9]+;)/", function ($m) {
return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
}, $this->fields['solution']);
$timeline[$solution_date . "_solution"] = array('type' => 'Solution', 'item' => array('id' => 0, 'content' => Toolbox::unclean_cross_side_scripting_deep($solution_content), 'date' => $solution_date, 'users_id' => $users_id, 'solutiontypes_id' => $this->fields['solutiontypes_id'], 'can_edit' => Ticket::canUpdate() && $this->canSolve()));
}
// add ticket validation to timeline
if ($this->fields['type'] == Ticket::DEMAND_TYPE && (Session::haveRight('ticketvalidation', TicketValidation::VALIDATEREQUEST) || Session::haveRight('ticketvalidation', TicketValidation::CREATEREQUEST)) || $this->fields['type'] == Ticket::INCIDENT_TYPE && (Session::haveRight('ticketvalidation', TicketValidation::VALIDATEINCIDENT) || Session::haveRight('ticketvalidation', TicketValidation::CREATEINCIDENT))) {
$ticket_validations = $ticket_valitation_obj->find('tickets_id = ' . $this->getID());
foreach ($ticket_validations as $validations_id => $validation) {
$canedit = $ticket_valitation_obj->can($validations_id, UPDATE);
$user->getFromDB($validation['users_id_validate']);
$timeline[$validation['submission_date'] . "_validation_" . $validations_id] = array('type' => 'TicketValidation', 'item' => array('id' => $validations_id, 'date' => $validation['submission_date'], 'content' => __('Validation request') . " => " . $user->getlink() . "<br>" . $validation['comment_submission'], 'users_id' => $validation['users_id'], 'can_edit' => $canedit));
if (!empty($validation['validation_date'])) {
$timeline[$validation['validation_date'] . "_validation_" . $validations_id] = array('type' => 'TicketValidation', 'item' => array('id' => $validations_id, 'date' => $validation['validation_date'], 'content' => __('Validation request answer') . " : " . _sx('status', ucfirst(TicketValidation::getStatus($validation['status']))) . "<br>" . $validation['comment_validation'], 'users_id' => $validation['users_id_validate'], 'status' => "status_" . $validation['status'], 'can_edit' => $canedit));
}
}
}
//reverse sort timeline items by key (date)
krsort($timeline);
return $timeline;
}
示例3: doSpecificMassiveActions
/**
* @see CommonDBTM::doSpecificMassiveActions()
**/
function doSpecificMassiveActions($input = array())
{
$res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
switch ($input['action']) {
case "link_ticket":
if (isset($input['link']) && isset($input['tickets_id_1'])) {
if ($this->getFromDB($input['tickets_id_1'])) {
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
$input2 = array();
$input2['id'] = $input['tickets_id_1'];
$input2['_link']['tickets_id_1'] = $input['tickets_id_1'];
$input2['_link']['link'] = $input['link'];
$input2['_link']['tickets_id_2'] = $key;
if ($this->can($input['tickets_id_1'], 'w')) {
if ($this->update($input2)) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
}
}
}
break;
case "submit_validation":
$valid = new TicketValidation();
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
$input2 = array('tickets_id' => $key, 'users_id_validate' => $input['users_id_validate'], 'comment_submission' => $input['comment_submission']);
if ($valid->can(-1, 'w', $input2)) {
if ($valid->add($input2)) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
}
break;
case "add_followup":
$fup = new TicketFollowup();
foreach ($input["item"] as $key => $val) {
if ($val == 1) {
$input2 = array('tickets_id' => $key, 'is_private' => $input['is_private'], 'requesttypes_id' => $input['requesttypes_id'], 'content' => $input['content']);
if ($fup->can(-1, 'w', $input2)) {
if ($fup->add($input2)) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
$res['noright']++;
}
}
}
break;
default:
return parent::doSpecificMassiveActions($input);
}
return $res;
}
示例4: methodsetTicketValidation
/**
* Answer to a ticket validation request
* for an authenticated user
*
* @param $params array of options (ticket, id2name)
* @param $protocol the communication protocol used
*
* @return array of hashtable as glpi.getTicket
**/
static function methodsetTicketValidation($params, $protocol)
{
global $DB, $CFG_GLPI;
if (isset($params['help'])) {
return array('approval' => 'integer,mandatory', 'id2name' => 'bool,optional', 'status' => 'text,mandatory', 'comment' => 'text,optional', 'help' => 'bool,optional');
}
if (!Session::getLoginUserID()) {
return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
}
$ticket = new Ticket();
if (!isset($params['approval'])) {
return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'approval');
}
if (!isset($params['status'])) {
return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'status');
}
$tabstatus = TicketValidation::getAllStatusArray();
if (!isset($tabstatus[$params['status']])) {
return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'status=' . $params['status']);
}
if ($params['status'] == 'rejected' && !isset($params['comment'])) {
return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'comment');
}
$valid = new TicketValidation();
if (!$valid->getFromDB($params['approval'])) {
return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND, '', 'approval');
}
$input = array('id' => $valid->getField('id'), 'status' => $params['status']);
if (isset($params['comment'])) {
$input['comment_validation'] = addslashes($params['comment']);
}
if (!$valid->can($params['approval'], 'w')) {
return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
}
if ($valid->update($input)) {
unset($params['approval'], $params['status'], $params['comment']);
$params['ticket'] = $valid->getField('tickets_id');
return self::methodGetTicket($params, $protocol);
}
return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
}
示例5: TicketFollowup
$fup = new TicketFollowup();
foreach ($_POST["item"] as $key => $val) {
if ($val == 1) {
$input = array('tickets_id' => $key, 'is_private' => $_POST['is_private'], 'requesttypes_id' => $_POST['requesttypes_id'], 'content' => $_POST['content']);
if ($fup->can(-1, 'w', $input)) {
$fup->add($input);
}
}
}
break;
case "submit_validation":
$valid = new TicketValidation();
foreach ($_POST["item"] as $key => $val) {
if ($val == 1) {
$input = array('tickets_id' => $key, 'users_id_validate' => $_POST['users_id_validate'], 'comment_submission' => $_POST['comment_submission']);
if ($valid->can(-1, 'w', $input)) {
$valid->add($input);
}
}
}
break;
case "add_task":
$task = new TicketTask();
foreach ($_POST["item"] as $key => $val) {
if ($val == 1) {
$input = array('tickets_id' => $key, 'taskcategories_id' => $_POST['taskcategories_id'], 'content' => $_POST['content']);
if ($task->can(-1, 'w', $input)) {
$task->add($input);
}
}
}
示例6: manageValidationAdd
//.........这里部分代码省略.........
$users = Group_User::getGroupUsers($input['_groups_id_requester'], "is_manager='1'");
foreach ($users as $data) {
$validations_to_send[] = $data['id'];
}
}
// Add to already set groups
foreach ($this->getGroups(CommonITILActor::REQUESTER) as $d) {
$users = Group_User::getGroupUsers($d['groups_id'], "is_manager='1'");
foreach ($users as $data) {
$validations_to_send[] = $data['id'];
}
}
break;
case 'assign_supervisor':
if (isset($input['_groups_id_assign']) && $input['_groups_id_assign']) {
$users = Group_User::getGroupUsers($input['_groups_id_assign'], "is_manager='1'");
foreach ($users as $data) {
$validations_to_send[] = $data['id'];
}
}
foreach ($this->getGroups(CommonITILActor::ASSIGN) as $d) {
$users = Group_User::getGroupUsers($d['groups_id'], "is_manager='1'");
foreach ($users as $data) {
$validations_to_send[] = $data['id'];
}
}
break;
default:
// Group case from rules
if ($key === 'group') {
foreach ($validation as $groups_id) {
$validation_right = 'validate_incident';
if (isset($input['type']) && $input['type'] == Ticket::DEMAND_TYPE) {
$validation_right = 'validate_request';
}
$opt = array('groups_id' => $groups_id, 'right' => $validation_right, 'entity' => $entid);
$data_users = TicketValidation::getGroupUserHaveRights($opt);
foreach ($data_users as $user) {
$validations_to_send[] = $user['id'];
}
}
} else {
$validations_to_send[] = $validation;
}
}
}
// Validation user added on ticket form
if (isset($input['users_id_validate'])) {
if (array_key_exists('groups_id', $input['users_id_validate'])) {
foreach ($input['users_id_validate'] as $key => $validation_to_add) {
if (is_numeric($key)) {
$validations_to_send[] = $validation_to_add;
}
}
} else {
foreach ($input['users_id_validate'] as $key => $validation_to_add) {
if (is_numeric($key)) {
$validations_to_send[] = $validation_to_add;
}
}
}
}
// Keep only one
$validations_to_send = array_unique($validations_to_send);
$validation = new TicketValidation();
if (count($validations_to_send)) {
$values = array();
$values['tickets_id'] = $this->fields['id'];
if ($input['id'] != $this->fields['id']) {
$values['_ticket_add'] = true;
}
// to know update by rules
if (isset($input["_rule_process"])) {
$values['_rule_process'] = $input["_rule_process"];
}
// if auto_import, tranfert it for validation
if (isset($input['_auto_import'])) {
$values['_auto_import'] = $input['_auto_import'];
}
// Cron or rule process of hability to do
if (Session::isCron() || isset($input["_auto_import"]) || isset($input["_rule_process"]) || $validation->can(-1, CREATE, $values)) {
// cron or allowed user
$add_done = false;
foreach ($validations_to_send as $user) {
// Do not auto add twice same validation
if (!TicketValidation::alreadyExists($values['tickets_id'], $user)) {
$values["users_id_validate"] = $user;
if ($validation->add($values)) {
$add_done = true;
}
}
}
if ($add_done) {
Event::log($this->fields['id'], "ticket", 4, "tracking", sprintf(__('%1$s updates the item %2$s'), $_SESSION["glpiname"], $this->fields['id']));
}
}
}
}
return true;
}