model.itop-request-mgmt.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Persistent classes for a CMDB
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. class UserRequest extends ResponseTicket
  25. {
  26. public static function Init()
  27. {
  28. $aParams = array
  29. (
  30. "category" => "bizmodel,searchable,requestmgmt",
  31. "key_type" => "autoincrement",
  32. "name_attcode" => "ref",
  33. "state_attcode" => "status",
  34. "reconc_keys" => array("ref"),
  35. "db_table" => "ticket_request",
  36. "db_key_field" => "id",
  37. "db_finalclass_field" => "",
  38. "display_template" => "",
  39. "icon" => "../modules/itop-request-mgmt-1.0.0/images/user-request.png",
  40. );
  41. MetaModel::Init_Params($aParams);
  42. MetaModel::Init_InheritAttributes();
  43. MetaModel::Init_InheritLifecycle();
  44. MetaModel::Init_AddAttribute(new AttributeEnum("request_type", array("allowed_values"=>new ValueSetEnum('service request,issue,information'), "sql"=>"request_type", "default_value"=>"service request", "is_null_allowed"=>false, "depends_on"=>array())));
  45. MetaModel::Init_AddAttribute(new AttributeString("freeze_reason", array("allowed_values"=>null, "sql"=>"freeze_reason", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  46. MetaModel::Init_SetZListItems('details', array('document_list', 'ci_list', 'contact_list','incident_list',
  47. 'col:col1' => array(
  48. 'fieldset:Ticket:baseinfo' => array('ref','title','org_id','status','priority','request_type','service_id','servicesubcategory_id','product' ),
  49. 'fieldset:Ticket:moreinfo' => array('impact','urgency','description','resolution_code', 'solution', 'user_satisfaction', 'user_commment','freeze_reason'),
  50. ),
  51. 'col:col2' => array(
  52. 'fieldset:Ticket:date' => array('start_date','last_update','assignment_date','tto_escalation_deadline', 'ttr_escalation_deadline', 'close_date', 'closure_deadline',),
  53. 'fieldset:Ticket:contact' => array('caller_id','workgroup_id','agent_id',),
  54. 'fieldset:Ticket:relation' => array('related_problem_id', 'related_change_id'),
  55. )
  56. ));
  57. // MetaModel::Init_SetZListItems('details', array('ref', 'title', 'org_id', 'description', 'request_type','ticket_log', 'start_date', 'tto_escalation_deadline', 'ttr_escalation_deadline', 'document_list', 'ci_list', 'contact_list','incident_list', 'status', 'caller_id', 'service_id', 'servicesubcategory_id', 'product', 'impact', 'urgency', 'priority', 'workgroup_id', 'agent_id', 'agent_email', 'related_problem_id', 'related_change_id', 'close_date', 'last_update', 'assignment_date', 'closure_deadline', 'resolution_code', 'solution', 'user_satisfaction', 'user_commment', 'freeze_reason'));
  58. MetaModel::Init_SetZListItems('advanced_search', array('ref', 'title', 'org_id', 'start_date', 'status', 'caller_id', 'service_id', 'servicesubcategory_id', 'product', 'impact', 'urgency', 'priority', 'workgroup_id', 'agent_id', 'agent_email', 'related_problem_id', 'related_change_id', 'close_date', 'resolution_code', 'solution', 'user_satisfaction', 'user_commment'));
  59. MetaModel::Init_SetZListItems('standard_search', array('ref', 'title', 'org_id', 'request_type','start_date', 'status', 'caller_id', 'service_id', 'servicesubcategory_id', 'product', 'impact', 'urgency', 'priority', 'workgroup_id', 'agent_id', 'agent_email', 'close_date', 'resolution_code', 'solution', 'user_satisfaction', 'user_commment'));
  60. MetaModel::Init_SetZListItems('list', array('title', 'org_id', 'start_date', 'status', 'service_id', 'priority', 'workgroup_id', 'agent_id'));
  61. MetaModel::Init_OverloadStateAttribute('frozen', 'freeze_reason', OPT_ATT_MANDATORY);
  62. // The freeze reason remains hidden in all other states
  63. MetaModel::Init_OverloadStateAttribute('new', 'request_type', OPT_ATT_MANDATORY);
  64. MetaModel::Init_OverloadStateAttribute('new', 'freeze_reason', OPT_ATT_HIDDEN);
  65. MetaModel::Init_OverloadStateAttribute('assigned', 'request_type', OPT_ATT_MANDATORY);
  66. MetaModel::Init_OverloadStateAttribute('assigned', 'freeze_reason', OPT_ATT_HIDDEN);
  67. MetaModel::Init_OverloadStateAttribute('frozen', 'request_type', OPT_ATT_MANDATORY);
  68. MetaModel::Init_OverloadStateAttribute('frozen', 'freeze_reason', OPT_ATT_MANDATORY | OPT_ATT_MUSTPROMPT);
  69. MetaModel::Init_OverloadStateAttribute('escalated_tto', 'request_type', OPT_ATT_MANDATORY);
  70. MetaModel::Init_OverloadStateAttribute('escalated_tto', 'freeze_reason', OPT_ATT_HIDDEN);
  71. MetaModel::Init_OverloadStateAttribute('escalated_ttr', 'request_type', OPT_ATT_MANDATORY);
  72. MetaModel::Init_OverloadStateAttribute('escalated_ttr', 'freeze_reason', OPT_ATT_HIDDEN);
  73. MetaModel::Init_OverloadStateAttribute('resolved', 'request_type', OPT_ATT_MANDATORY);
  74. MetaModel::Init_OverloadStateAttribute('resolved', 'freeze_reason', OPT_ATT_HIDDEN);
  75. MetaModel::Init_OverloadStateAttribute('closed', 'request_type', OPT_ATT_READONLY);
  76. MetaModel::Init_OverloadStateAttribute('closed', 'freeze_reason', OPT_ATT_HIDDEN);
  77. MetaModel::Init_DefineStimulus(new StimulusUserAction("ev_freeze", array()));
  78. MetaModel::Init_DefineTransition("assigned", "ev_freeze", array("target_state"=>"frozen", "actions"=>array(), "user_restriction"=>null));
  79. MetaModel::Init_DefineTransition("frozen", "ev_timeout", array("target_state"=>"escalated_ttr", "actions"=>array(), "user_restriction"=>null));
  80. MetaModel::Init_DefineTransition("frozen", "ev_assign", array("target_state"=>"assigned", "actions"=>array(), "user_restriction"=>null));
  81. MetaModel::Init_DefineTransition("frozen", "ev_resolve", array("target_state"=>"resolved", "actions"=>array(), "user_restriction"=>null));
  82. }
  83. public function ComputeValues()
  84. {
  85. $sCurrRef = $this->Get('ref');
  86. if (strlen($sCurrRef) == 0)
  87. {
  88. $iKey = $this->GetKey();
  89. if ($iKey < 0)
  90. {
  91. // Object not yet in the Database
  92. $iKey = MetaModel::GetNextKey(get_class($this));
  93. }
  94. $sName = sprintf('R-%06d', $iKey);
  95. $this->Set('ref', $sName);
  96. }
  97. return parent::ComputeValues();
  98. }
  99. /**
  100. * Get the icon representing this object
  101. * @param boolean $bImgTag If true the result is a full IMG tag (or an emtpy string if no icon is defined)
  102. * @return string Either the full IMG tag ($bImgTag == true) or just the path to the icon file
  103. */
  104. public function GetIcon($bImgTag = true)
  105. {
  106. $sStatus = $this->Get('status');
  107. switch($this->GetState())
  108. {
  109. case 'escalated_tto':
  110. case 'escalated_ttr':
  111. $sIcon = self::MakeIconFromName('user-request-escalated.png');
  112. break;
  113. case 'resolved':
  114. case 'closed':
  115. $sIcon = self::MakeIconFromName('user-request-closed.png');
  116. break;
  117. case 'new':
  118. $sIcon = self::MakeIconFromName('user-request.png');
  119. $oEscalationDeadline = $this->Get('tto_escalation_deadline');
  120. if ($oEscalationDeadline != null)
  121. {
  122. // A SLA is running
  123. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  124. $iEscalationDeadline = AttributeDateTime::GetAsUnixSeconds($oEscalationDeadline);
  125. $ratio = ($iEscalationDeadline - time())/($iEscalationDeadline - $iStartDate);
  126. if ($ratio <= 0)
  127. {
  128. $sIcon = self::MakeIconFromName('user-request-escalated.png');
  129. }
  130. else if ($ratio <= 0.25)
  131. {
  132. $sIcon = self::MakeIconFromName('user-request-deadline.png');
  133. }
  134. }
  135. break;
  136. case 'assigned':
  137. $sIcon = self::MakeIconFromName('user-request.png');
  138. $oEscalationDeadline = $this->Get('ttr_escalation_deadline');
  139. if ($oEscalationDeadline != null)
  140. {
  141. // A SLA is running
  142. $iStartDate = AttributeDateTime::GetAsUnixSeconds($this->Get('start_date'));
  143. $iEscalationDeadline = AttributeDateTime::GetAsUnixSeconds($oEscalationDeadline);
  144. $ratio = ($iEscalationDeadline - time())/($iEscalationDeadline - $iStartDate);
  145. if ($ratio <= 0)
  146. {
  147. $sIcon = self::MakeIconFromName('user-request-escalated.png');
  148. }
  149. else if ($ratio <= 0.25)
  150. {
  151. $sIcon = self::MakeIconFromName('user-request-deadline.png');
  152. }
  153. }
  154. break;
  155. default:
  156. $sIcon = MetaModel::GetClassIcon(get_class($this), $bImgTag);
  157. }
  158. return $sIcon;
  159. }
  160. protected static function MakeIconFromName($sIconName, $bImgTag = true)
  161. {
  162. $sIcon = '';
  163. if ($sIconName != '')
  164. {
  165. $sPath = '../modules/itop-request-mgmt-1.0.0/images/'.$sIconName;
  166. if ($bImgTag)
  167. {
  168. $sIcon = "<img src=\"$sPath\" style=\"vertical-align:middle;\"/>";
  169. }
  170. else
  171. {
  172. $sIcon = $sPath;
  173. }
  174. }
  175. return $sIcon;
  176. }
  177. }
  178. $oMyMenuGroup = new MenuGroup('RequestManagement', 30 /* fRank */);
  179. new TemplateMenuNode('UserRequest:Overview', '../modules/itop-request-mgmt-1.0.0/overview.html', $oMyMenuGroup->GetIndex() /* oParent */, 0 /* fRank */);
  180. new NewObjectMenuNode('NewUserRequest', 'UserRequest', $oMyMenuGroup->GetIndex(), 1 /* fRank */);
  181. new SearchMenuNode('SearchUserRequests', 'UserRequest', $oMyMenuGroup->GetIndex(), 2 /* fRank */);
  182. $oShortcutNode = new TemplateMenuNode('UserRequest:Shortcuts', '', $oMyMenuGroup->GetIndex(), 3 /* fRank */);
  183. $oNode = new OQLMenuNode('UserRequest:MyRequests', 'SELECT UserRequest WHERE agent_id = :current_contact_id AND status NOT IN ("closed","resolved")', $oShortcutNode->GetIndex(), 1 /* fRank */);
  184. $oNode->SetParameters(array('auto_reload' => 'fast'));
  185. $oNode = new OQLMenuNode('UserRequest:EscalatedRequests', 'SELECT UserRequest WHERE status IN ("escalated_tto", "escalated_ttr")', $oShortcutNode->GetIndex(), 2 /* fRank */);
  186. $oNode->SetParameters(array('auto_reload' => 'fast'));
  187. $oNode = new OQLMenuNode('UserRequest:OpenRequests', 'SELECT UserRequest WHERE status IN ("new", "assigned", "escalated_tto", "escalated_ttr", "frozen", "resolved")', $oShortcutNode->GetIndex(), 3 /* fRank */);
  188. $oNode->SetParameters(array('auto_reload' => 'fast'));
  189. ?>