<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.6">
    <classes>
        <class id="Problem" _delta="define">
            <parent>Ticket</parent>
            <properties>
                <comment><![CDATA[/**
 * Persistent classes for a CMDB
 *
 * @copyright   Copyright (C) 2010-2012 Combodo SARL
 * @license     http://opensource.org/licenses/AGPL-3.0
 */]]></comment>
                <category>bizmodel,searchable,problemmgmt</category>
                <abstract>false</abstract>
                <key_type>autoincrement</key_type>
                <db_table>ticket_problem</db_table>
                <db_key_field>id</db_key_field>
                <db_final_class_field/>
                <naming>
                    <attributes>
                        <attribute id="ref"/>
                    </attributes>
                </naming>
                <display_template/>
                <icon>images/problem.png</icon>
                <reconciliation>
                    <attributes>
                        <attribute id="ref"/>
                    </attributes>
                </reconciliation>
                <order>
                    <columns>
                        <column id="ref" ascending="false"/>
                    </columns>
                </order>
            </properties>
            <fields>
                <field id="status" xsi:type="AttributeEnum">
                    <values>
                        <value id="new">new</value>
                        <value id="assigned">assigned</value>
                        <value id="resolved">resolved</value>
                        <value id="closed">closed</value>
                    </values>
                    <sql>status</sql>
                    <default_value>new</default_value>
                    <is_null_allowed>false</is_null_allowed>
                    <display_style>list</display_style>
                </field>
                <field id="service_id" xsi:type="AttributeExternalKey">
                    <filter>SELECT Service</filter>
                    <dependencies>
                        <attribute id="org_id"/>
                    </dependencies>
                    <sql>service_id</sql>
                    <target_class>Service</target_class>
                    <is_null_allowed>true</is_null_allowed>
                    <on_target_delete>DEL_MANUAL</on_target_delete>
                    <allow_target_creation>false</allow_target_creation>
                </field>
                <field id="service_name" xsi:type="AttributeExternalField">
                    <extkey_attcode>service_id</extkey_attcode>
                    <target_attcode>name</target_attcode>
                </field>
                <field id="servicesubcategory_id" xsi:type="AttributeExternalKey">
                    <filter><![CDATA[SELECT ServiceSubcategory WHERE service_id = :this->service_id]]></filter>
                    <dependencies>
                        <attribute id="service_id"/>
                    </dependencies>
                    <sql>servicesubcategory_id</sql>
                    <target_class>ServiceSubcategory</target_class>
                    <is_null_allowed>true</is_null_allowed>
                    <on_target_delete>DEL_MANUAL</on_target_delete>
                    <allow_target_creation>false</allow_target_creation>
                </field>
                <field id="servicesubcategory_name" xsi:type="AttributeExternalField">
                    <extkey_attcode>servicesubcategory_id</extkey_attcode>
                    <target_attcode>name</target_attcode>
                </field>
                <field id="product" xsi:type="AttributeString">
                    <sql>product</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="impact" xsi:type="AttributeEnum">
                    <values>
                        <value id="1">1</value>
                        <value id="2">2</value>
                        <value id="3">3</value>
                    </values>
                    <sql>impact</sql>
                    <default_value>1</default_value>
                    <is_null_allowed>false</is_null_allowed>
                    <display_style>list</display_style>
                </field>
                <field id="urgency" xsi:type="AttributeEnum">
                    <values>
                        <value id="1">1</value>
                        <value id="2">2</value>
                        <value id="3">3</value>
                        <value id="4">4</value>
                    </values>
                    <sql>urgency</sql>
                    <default_value>1</default_value>
                    <is_null_allowed>false</is_null_allowed>
                    <display_style>list</display_style>
                </field>
                <field id="priority" xsi:type="AttributeEnum">
                    <values>
                        <value id="1">1</value>
                        <value id="2">2</value>
                        <value id="3">3</value>
                        <value id="4">4</value>
                    </values>
                    <sql>priority</sql>
                    <default_value>1</default_value>
                    <is_null_allowed>false</is_null_allowed>
                    <display_style>list</display_style>
                </field>
                <field id="related_change_id" xsi:type="AttributeExternalKey">
                    <filter><![CDATA[SELECT Change WHERE status != "closed"]]></filter>
                    <sql>related_change_id</sql>
                    <target_class>Change</target_class>
                    <is_null_allowed>true</is_null_allowed>
                    <on_target_delete>DEL_MANUAL</on_target_delete>
                </field>
                <field id="related_change_ref" xsi:type="AttributeExternalField">
                    <extkey_attcode>related_change_id</extkey_attcode>
                    <target_attcode>ref</target_attcode>
                </field>
                <field id="assignment_date" xsi:type="AttributeDateTime">
                    <sql>assignment_date</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="resolution_date" xsi:type="AttributeDateTime">
                    <sql>resolution_date</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="knownerrors_list" xsi:type="AttributeLinkedSet">
                    <linked_class>KnownError</linked_class>
                    <ext_key_to_me>problem_id</ext_key_to_me>
                    <edit_mode>add_only</edit_mode>
                    <count_min>0</count_min>
                    <count_max>0</count_max>
                </field>
                <field id="related_request_list" xsi:type="AttributeLinkedSet">
                    <linked_class>UserRequest</linked_class>
                    <ext_key_to_me>parent_problem_id</ext_key_to_me>
                    <edit_mode>add_remove</edit_mode>
                    <count_min>0</count_min>
                    <count_max>0</count_max>
                </field>
                <field id="related_incident_list" xsi:type="AttributeLinkedSet">
                    <linked_class>Incident</linked_class>
                    <ext_key_to_me>parent_problem_id</ext_key_to_me>
                    <edit_mode>add_remove</edit_mode>
                    <count_min>0</count_min>
                    <count_max>0</count_max>
                </field>
            </fields>
            <lifecycle>
                <attribute>status</attribute>
                <stimuli>
                    <stimulus id="ev_assign" xsi:type="StimulusUserAction"/>
                    <stimulus id="ev_reassign" xsi:type="StimulusUserAction"/>
                    <stimulus id="ev_resolve" xsi:type="StimulusUserAction"/>
                    <stimulus id="ev_close" xsi:type="StimulusUserAction"/>
                </stimuli>
                <states>
                    <state id="new">
                        <flags>
                            <attribute id="ref">
                                <read_only/>
                            </attribute>
                            <attribute id="org_id">
                                <must_prompt/>
                            </attribute>
                            <attribute id="team_id">
                                <hidden/>
                            </attribute>
                            <attribute id="agent_id">
                                <hidden/>
                            </attribute>
                            <attribute id="description">
                                <must_prompt/>
                            </attribute>
                            <attribute id="start_date">
                                <read_only/>
                            </attribute>
                            <attribute id="last_update">
                                <read_only/>
                            </attribute>
                            <attribute id="close_date">
                                <hidden/>
                            </attribute>
                            <attribute id="service_id">
                                <normal/>
                            </attribute>
                            <attribute id="servicesubcategory_id">
                                <normal/>
                            </attribute>
                            <attribute id="product">
                                <normal/>
                            </attribute>
                            <attribute id="impact">
                                <must_prompt/>
                            </attribute>
                            <attribute id="urgency">
                                <must_prompt/>
                            </attribute>
                            <attribute id="priority">
                                <read_only/>
                            </attribute>
                            <attribute id="related_change_id">
                                <normal/>
                            </attribute>
                            <attribute id="assignment_date">
                                <hidden/>
                            </attribute>
                            <attribute id="resolution_date">
                                <hidden/>
                            </attribute>
                        </flags>
                        <transitions>
                            <transition id="ev_assign">
                                <target>assigned</target>
                                <actions>
                                    <action>
                                        <verb>SetCurrentDate</verb>
                                        <params>
                                            <param xsi:type="attcode">assignment_date</param>
                                        </params>
                                    </action>
                                </actions>
                            </transition>
                        </transitions>
                    </state>
                    <state id="assigned">
                        <inherit_flags_from>new</inherit_flags_from>
                        <flags>
                            <attribute id="title"/>
                            <attribute id="team_id">
                                <mandatory/>
                                <must_prompt/>
                            </attribute>
                            <attribute id="agent_id">
                                <mandatory/>
                                <must_prompt/>
                            </attribute>
                            <attribute id="assignment_date">
                                <read_only/>
                            </attribute>
                            <attribute id="service_id"/>
                            <attribute id="servicesubcategory_id"/>
                            <attribute id="product"/>
                            <attribute id="impact"/>
                            <attribute id="urgency"/>
                            <attribute id="related_change_id"/>
                        </flags>
                        <transitions>
                            <transition id="ev_reassign">
                                <target>assigned</target>
                                <actions/>
                            </transition>
                            <transition id="ev_resolve">
                                <target>resolved</target>
                                <actions>
                                    <action>
                                        <verb>SetCurrentDate</verb>
                                        <params>
                                            <param xsi:type="attcode">resolution_date</param>
                                        </params>
                                    </action>
                                </actions>
                            </transition>
                        </transitions>
                    </state>
                    <state id="resolved">
                        <inherit_flags_from>assigned</inherit_flags_from>
                        <flags>
                            <attribute id="caller_id">
                                <read_only/>
                            </attribute>
                            <attribute id="service_id">
                                <mandatory/>
                            </attribute>
                            <attribute id="servicesubcategory_id">
                                <must_prompt/>
                            </attribute>
                            <attribute id="product">
                                <must_prompt/>
                            </attribute>
                            <attribute id="impact">
                                <read_only/>
                            </attribute>
                            <attribute id="urgency">
                                <read_only/>
                            </attribute>
                            <attribute id="org_id">
                                <read_only/>
                            </attribute>
                            <attribute id="team_id">
                                <read_only/>
                            </attribute>
                            <attribute id="agent_id">
                                <read_only/>
                            </attribute>
                            <attribute id="title">
                                <read_only/>
                            </attribute>
                            <attribute id="description">
                                <read_only/>
                            </attribute>
                            <attribute id="resolution_date">
                                <read_only/>
                            </attribute>
                        </flags>
                        <transitions>
                            <transition id="ev_reassign">
                                <target>assigned</target>
                                <actions/>
                            </transition>
                            <transition id="ev_close">
                                <target>closed</target>
                                <actions>
                                    <action>
                                        <verb>SetCurrentDate</verb>
                                        <params>
                                            <param xsi:type="attcode">close_date</param>
                                        </params>
                                    </action>
                                </actions>
                            </transition>
                        </transitions>
                    </state>
                    <state id="closed">
                        <inherit_flags_from>resolved</inherit_flags_from>
                        <flags>
                            <attribute id="private_log">
                                <read_only/>
                            </attribute>
                            <attribute id="related_change_id">
                                <read_only/>
                            </attribute>
                            <attribute id="close_date">
                                <read_only/>
                            </attribute>
                            <attribute id="service_id">
                                <read_only/>
                            </attribute>
                            <attribute id="servicesubcategory_id">
                                <read_only/>
                            </attribute>
                            <attribute id="product">
                                <read_only/>
                            </attribute>
                        </flags>
                        <transitions/>
                    </state>
                </states>
            </lifecycle>
            <methods>
                <method id="SetAssignedDate">
                    <comment><![CDATA[/**
	 * To be deprecated: use SetCurrentDate() instead
	 * @return void
	 */]]></comment>
                    <static>false</static>
                    <access>public</access>
                    <type>LifecycleAction</type>
                    <code><![CDATA[        public function SetAssignedDate($sStimulusCode)
        {
                $this->Set('assignment_date', time());
                return true;
        }]]></code>
                </method>
                <method id="SetResolveDate">
                    <comment><![CDATA[/**
	 * To be deprecated: use SetCurrentDate() instead
	 * @return void
	 */]]></comment>
                    <static>false</static>
                    <access>public</access>
                    <type>LifecycleAction</type>
                    <code><![CDATA[        public function SetResolveDate($sStimulusCode)
        {
                $this->Set('resolution_date', time());
                return true;
        }]]></code>
                </method>
                <method id="SetClosureDate">
                    <comment><![CDATA[/**
	 * To be deprecated: use SetCurrentDate() instead
	 * @return void
	 */]]></comment>
                    <static>false</static>
                    <access>public</access>
                    <type>LifecycleAction</type>
                    <code><![CDATA[        public function SetClosureDate($sStimulusCode)
        {
                $this->Set('close_date', time());
                return true;
        }]]></code>
                </method>
                <method id="ComputePriority">
                    <comment>/** Compute the priority of the ticket based on its impact and urgency&#13;
                        * @return integer The priority of the ticket 1(high) .. 3(low)&#13;
                        */
                    </comment>
                    <static>false</static>
                    <access>public</access>
                    <type>LifecycleAction</type>
                    <code><![CDATA[        public function ComputePriority()
        {
                // priority[impact][urgency]
                $aPriorities = array(
                        // single person
                        1 => array(
                                        1 => 1,
                                        2 => 1,
                                        3 => 2,
                                        4 => 4,
                        ),
                        // a group
                        2 => array(
                                1 => 1,
                                2 => 2,
                                3 => 3,
                                4 => 4,
                        ),
                        // a departement!
                        3 => array(
                                        1 => 2,
                                        2 => 3,
                                        3 => 3,
                                        4 => 4,
                        ),
                );
                $iPriority = 1;
                if (isset($aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')]))
                {
                        $iPriority = $aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')];
                }
                return $iPriority;              
        }]]></code>
                </method>
                <method id="ComputeValues">
                    <static>false</static>
                    <access>public</access>
                    <type>Overload-DBObject</type>
                    <code><![CDATA[	public function ComputeValues()
	{
		// Compute the priority of the ticket
		$this->Set('priority', $this->ComputePriority());
	}]]></code>
                </method>
                <method id="OnInsert">
                    <static>false</static>
                    <access>protected</access>
                    <type>Overload-DBObject</type>
                    <code><![CDATA[	protected function OnInsert()
	{
		$this->SetIfNull('start_date', time());
		$this->SetIfNull('last_update', time());
	}]]></code>
                </method>
                <method id="OnUpdate">
                    <static>false</static>
                    <access>protected</access>
                    <type>Overload-DBObject</type>
                    <code><![CDATA[	protected function OnUpdate()
	{
		$this->Set('last_update', time());
	}]]></code>
                </method>
            </methods>
            <presentation>
                <details>
                    <items>
                        <item id="functionalcis_list">
                            <rank>10</rank>
                        </item>
                        <item id="contacts_list">
                            <rank>20</rank>
                        </item>
                        <item id="knownerrors_list">
                            <rank>30</rank>
                        </item>
                        <item id="workorders_list">
                            <rank>40</rank>
                        </item>
                        <item id="related_request_list">
                            <rank>50</rank>
                        </item>
                        <item id="related_incident_list">
                            <rank>50</rank>
                        </item>
                        <item id="col:col1">
                            <rank>60</rank>
                            <items>
                                <item id="fieldset:Ticket:baseinfo">
                                    <rank>10</rank>
                                    <items>
                                        <item id="ref">
                                            <rank>10</rank>
                                        </item>
                                        <item id="title">
                                            <rank>20</rank>
                                        </item>
                                        <item id="org_id">
                                            <rank>30</rank>
                                        </item>
                                        <item id="status">
                                            <rank>40</rank>
                                        </item>
                                        <item id="priority">
                                            <rank>50</rank>
                                        </item>
                                        <item id="service_id">
                                            <rank>60</rank>
                                        </item>
                                        <item id="servicesubcategory_id">
                                            <rank>70</rank>
                                        </item>
                                        <item id="product">
                                            <rank>80</rank>
                                        </item>
                                    </items>
                                </item>
                                <item id="fieldset:Ticket:moreinfo">
                                    <rank>20</rank>
                                    <items>
                                        <item id="impact">
                                            <rank>10</rank>
                                        </item>
                                        <item id="urgency">
                                            <rank>20</rank>
                                        </item>
                                        <item id="description">
                                            <rank>30</rank>
                                        </item>
                                    </items>
                                </item>
                            </items>
                        </item>
                        <item id="col:col2">
                            <rank>70</rank>
                            <items>
                                <item id="fieldset:Ticket:date">
                                    <rank>10</rank>
                                    <items>
                                        <item id="start_date">
                                            <rank>10</rank>
                                        </item>
                                        <item id="last_update">
                                            <rank>20</rank>
                                        </item>
                                        <item id="assignment_date">
                                            <rank>30</rank>
                                        </item>
                                        <item id="resolution_date">
                                            <rank>40</rank>
                                        </item>
                                        <item id="close_date">
                                            <rank>50</rank>
                                        </item>
                                    </items>
                                </item>
                                <item id="fieldset:Ticket:contact">
                                    <rank>20</rank>
                                    <items>
                                        <item id="caller_id">
                                            <rank>10</rank>
                                        </item>
                                        <item id="team_id">
                                            <rank>20</rank>
                                        </item>
                                        <item id="agent_id">
                                            <rank>30</rank>
                                        </item>
                                    </items>
                                </item>
                                <item id="fieldset:Ticket:relation">
                                    <rank>30</rank>
                                    <items>
                                        <item id="related_change_id">
                                            <rank>10</rank>
                                        </item>
                                    </items>
                                </item>
                            </items>
                        </item>
                    </items>
                </details>
                <search>
                    <items>
                        <item id="ref">
                            <rank>10</rank>
                        </item>
                        <item id="title">
                            <rank>20</rank>
                        </item>
                        <item id="org_id">
                            <rank>30</rank>
                        </item>
                        <item id="start_date">
                            <rank>40</rank>
                        </item>
                        <item id="status">
                            <rank>50</rank>
                        </item>
                        <item id="operational_status">
                            <rank>55</rank>
                        </item>
                        <item id="service_id">
                            <rank>60</rank>
                        </item>
                        <item id="servicesubcategory_id">
                            <rank>70</rank>
                        </item>
                        <item id="product">
                            <rank>80</rank>
                        </item>
                        <item id="impact">
                            <rank>90</rank>
                        </item>
                        <item id="urgency">
                            <rank>100</rank>
                        </item>
                        <item id="priority">
                            <rank>110</rank>
                        </item>
                        <item id="caller_id">
                            <rank>120</rank>
                        </item>
                        <item id="team_id">
                            <rank>130</rank>
                        </item>
                        <item id="agent_id">
                            <rank>140</rank>
                        </item>
                        <item id="close_date">
                            <rank>150</rank>
                        </item>
                    </items>
                </search>
                <list>
                    <items>
                        <item id="title">
                            <rank>10</rank>
                        </item>
                        <item id="org_id">
                            <rank>20</rank>
                        </item>
                        <item id="start_date">
                            <rank>30</rank>
                        </item>
                        <item id="status">
                            <rank>40</rank>
                        </item>
                        <item id="service_id">
                            <rank>50</rank>
                        </item>
                        <item id="priority">
                            <rank>60</rank>
                        </item>
                    </items>
                </list>
            </presentation>
        </class>
    </classes>
    <menus>
        <menu id="ProblemManagement" xsi:type="MenuGroup" _delta="define_if_not_exists">
            <rank>42</rank>
        </menu>
        <menu id="Problem:Shortcuts" xsi:type="TemplateMenuNode" _delta="define_if_not_exists">
            <rank>5</rank>
            <parent>ProblemManagement</parent>
            <template_file/>
        </menu>
        <menu id="Problem:Overview" xsi:type="DashboardMenuNode" _delta="define">
            <rank>0</rank>
            <parent>ProblemManagement</parent>
            <definition>
                <layout>DashboardLayoutTwoCols</layout>
                <title>UI:ProblemMgmtMenuOverview:Title</title>
                <cells>
                    <cell id="0">
                        <rank>0</rank>
                        <dashlets>
                            <dashlet id="1" xsi:type="DashletGroupByBars">
                                <rank>0</rank>
                                <title>UI-ProblemManagementOverview-ProblemByService</title>
                                <query>SELECT Problem</query>
                                <group_by>service_id</group_by>
                                <style>bars</style>
                            </dashlet>
                        </dashlets>
                    </cell>
                    <cell id="1">
                        <rank>1</rank>
                        <dashlets>
                            <dashlet id="2" xsi:type="DashletGroupByPie">
                                <rank>0</rank>
                                <title>UI-ProblemManagementOverview-ProblemByPriority</title>
                                <query>SELECT Problem</query>
                                <group_by>priority</group_by>
                                <style>pie</style>
                            </dashlet>
                        </dashlets>
                    </cell>
                    <cell id="2">
                        <rank>2</rank>
                        <dashlets>
                            <dashlet id="3" xsi:type="DashletObjectList">
                                <rank>0</rank>
                                <title>UI-ProblemManagementOverview-ProblemUnassigned</title>
                                <query>SELECT Problem WHERE status IN ("new")</query>
                                <menu>false</menu>
                            </dashlet>
                        </dashlets>
                    </cell>
                </cells>
            </definition>
        </menu>
        <menu id="NewProblem" xsi:type="NewObjectMenuNode" _delta="define">
            <rank>1</rank>
            <parent>ProblemManagement</parent>
            <class>Problem</class>
        </menu>
        <menu id="SearchProblems" xsi:type="SearchMenuNode" _delta="define">
            <rank>2</rank>
            <parent>ProblemManagement</parent>
            <class>Problem</class>
        </menu>
        <menu id="Problem:MyProblems" xsi:type="OQLMenuNode" _delta="define">
            <rank>1</rank>
            <parent>Problem:Shortcuts</parent>
            <oql>
                <![CDATA[SELECT Problem WHERE agent_id = :current_contact_id AND status NOT IN ("closed", "resolved")]]></oql>
            <do_search/>
        </menu>
        <menu id="Problem:OpenProblems" xsi:type="OQLMenuNode" _delta="define">
            <rank>2</rank>
            <parent>Problem:Shortcuts</parent>
            <oql><![CDATA[SELECT Problem WHERE status IN ("new", "assigned", "resolved")]]></oql>
            <do_search>1</do_search>
        </menu>
    </menus>
</itop_design>
