<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
  <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" order="0">
              <ascending>false</ascending>
            </column>
          </columns>
        </order>
      </properties>
      <fields>
        <field id="status" xsi:type="AttributeEnum">
          <values>
            <value>new</value>
            <value>assigned</value>
            <value>resolved</value>
            <value>closed</value>
          </values>
          <sql>status</sql>
          <default_value>new</default_value>
          <is_null_allowed>false</is_null_allowed>
        </field>
        <field id="org_id" xsi:type="AttributeExternalKey">
          <sql>org_id</sql>
          <target_class>Organization</target_class>
          <is_null_allowed>false</is_null_allowed>
          <on_target_delete>DEL_AUTO</on_target_delete>
          <jointype/>
        </field>
        <field id="org_name" xsi:type="AttributeExternalField">
          <extkey_attcode>org_id</extkey_attcode>
          <target_attcode>name</target_attcode>
        </field>
        <field id="service_id" xsi:type="AttributeExternalKey">
          <filter><![CDATA[SELECT Service AS s JOIN SLA AS sla ON sla.service_id=s.id JOIN lnkContractToSLA AS ln ON ln.sla_id=sla.id JOIN CustomerContract AS cc ON ln.contract_id=cc.id WHERE cc.org_id =:this->org_id]]></filter>
          <dependencies>
            <attribute id="org_id"/>
          </dependencies>
          <sql>service_id</sql>
          <target_class>Service</target_class>
          <is_null_allowed>false</is_null_allowed>
          <on_target_delete>DEL_MANUAL</on_target_delete>
          <jointype/>
        </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>false</is_null_allowed>
          <on_target_delete>DEL_MANUAL</on_target_delete>
          <jointype/>
        </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>1</value>
            <value>2</value>
            <value>3</value>
          </values>
          <sql>impact</sql>
          <default_value>1</default_value>
          <is_null_allowed>false</is_null_allowed>
        </field>
        <field id="urgency" xsi:type="AttributeEnum">
          <values>
            <value>1</value>
            <value>2</value>
            <value>3</value>
          </values>
          <sql>urgency</sql>
          <default_value>1</default_value>
          <is_null_allowed>false</is_null_allowed>
        </field>
        <field id="priority" xsi:type="AttributeEnum">
          <values>
            <value>1</value>
            <value>2</value>
            <value>3</value>
          </values>
          <sql>priority</sql>
          <default_value>1</default_value>
          <is_null_allowed>false</is_null_allowed>
        </field>
        <field id="workgroup_id" xsi:type="AttributeExternalKey">
          <filter><![CDATA[SELECT Team AS t JOIN CustomerContract AS cc ON cc.support_team_id=t.id JOIN lnkContractToSLA AS ln ON ln.contract_id=cc.id JOIN SLA AS sla ON ln.sla_id=sla.id WHERE sla.service_id = :this->service_id AND cc.org_id = :this->org_id]]></filter>
          <dependencies>
            <attribute id="org_id"/>
            <attribute id="service_id"/>
          </dependencies>
          <sql>workgroup_id</sql>
          <target_class>Team</target_class>
          <is_null_allowed>false</is_null_allowed>
          <on_target_delete>DEL_MANUAL</on_target_delete>
          <jointype/>
        </field>
        <field id="workgroup_name" xsi:type="AttributeExternalField">
          <extkey_attcode>workgroup_id</extkey_attcode>
          <target_attcode>name</target_attcode>
        </field>
        <field id="agent_id" xsi:type="AttributeExternalKey">
          <filter><![CDATA[SELECT Person AS p JOIN lnkTeamToContact AS l ON l.contact_id=p.id JOIN Team AS t ON l.team_id=t.id WHERE t.id = :this->workgroup_id]]></filter>
          <dependencies>
            <attribute id="workgroup_id"/>
          </dependencies>
          <sql>agent_id</sql>
          <target_class>Person</target_class>
          <is_null_allowed>true</is_null_allowed>
          <on_target_delete>DEL_MANUAL</on_target_delete>
          <jointype/>
        </field>
        <field id="agent_name" xsi:type="AttributeExternalField">
          <extkey_attcode>agent_id</extkey_attcode>
          <target_attcode>name</target_attcode>
        </field>
        <field id="agent_email" xsi:type="AttributeExternalField">
          <extkey_attcode>agent_id</extkey_attcode>
          <target_attcode>email</target_attcode>
        </field>
        <field id="related_change_id" xsi:type="AttributeExternalKey">
          <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>
          <jointype/>
        </field>
        <field id="related_change_ref" xsi:type="AttributeExternalField">
          <extkey_attcode>related_change_id</extkey_attcode>
          <target_attcode>ref</target_attcode>
        </field>
        <field id="close_date" xsi:type="AttributeDateTime">
          <sql>close_date</sql>
          <default_value/>
          <is_null_allowed>true</is_null_allowed>
        </field>
        <field id="last_update" xsi:type="AttributeDateTime">
          <sql>last_update</sql>
          <default_value/>
          <is_null_allowed>true</is_null_allowed>
        </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>
          <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="description">
                <must_prompt/>
              </attribute>
              <attribute id="ticket_log">
                <hidden/>
              </attribute>
              <attribute id="start_date">
                <read_only/>
              </attribute>
              <attribute id="org_id">
                <must_prompt/>
              </attribute>
              <attribute id="service_id">
                <must_prompt/>
              </attribute>
              <attribute id="servicesubcategory_id">
                <must_prompt/>
              </attribute>
              <attribute id="product">
                <must_prompt/>
              </attribute>
              <attribute id="impact">
                <must_prompt/>
              </attribute>
              <attribute id="urgency">
                <must_prompt/>
              </attribute>
              <attribute id="priority">
                <read_only/>
              </attribute>
              <attribute id="workgroup_id">
                <must_prompt/>
              </attribute>
              <attribute id="agent_id">
                <hidden/>
              </attribute>
              <attribute id="agent_email">
                <hidden/>
              </attribute>
              <attribute id="related_change_id">
                <hidden/>
              </attribute>
              <attribute id="close_date">
                <hidden/>
              </attribute>
              <attribute id="last_update">
                <read_only/>
              </attribute>
              <attribute id="assignment_date">
                <hidden/>
              </attribute>
              <attribute id="resolution_date">
                <hidden/>
              </attribute>
            </flags>
            <transitions>
              <transition id="ev_assign">
                <stimulus>ev_assign</stimulus>
                <target>assigned</target>
                <actions>
                  <action>
                    <verb>SetAssignedDate</verb>
                  </action>
                </actions>
              </transition>
            </transitions>
          </state>
          <state id="assigned">
            <flags>
              <attribute id="ref">
                <read_only/>
              </attribute>
              <attribute id="title">
                <read_only/>
              </attribute>
              <attribute id="description">
                <read_only/>
              </attribute>
              <attribute id="start_date">
                <read_only/>
              </attribute>
              <attribute id="org_id">
                <read_only/>
              </attribute>
              <attribute id="priority">
                <read_only/>
              </attribute>
              <attribute id="workgroup_id">
                <mandatory/>
                <must_prompt/>
              </attribute>
              <attribute id="agent_id">
                <mandatory/>
                <must_prompt/>
              </attribute>
              <attribute id="agent_email">
                <read_only/>
              </attribute>
              <attribute id="close_date">
                <hidden/>
              </attribute>
              <attribute id="last_update">
                <read_only/>
              </attribute>
              <attribute id="assignment_date">
                <read_only/>
              </attribute>
              <attribute id="resolution_date">
                <hidden/>
              </attribute>
            </flags>
            <transitions>
              <transition id="ev_reassign">
                <stimulus>ev_reassign</stimulus>
                <target>assigned</target>
                <actions/>
              </transition>
              <transition id="ev_resolve">
                <stimulus>ev_resolve</stimulus>
                <target>resolved</target>
                <actions>
                  <action>
                    <verb>SetResolveDate</verb>
                  </action>
                </actions>
              </transition>
            </transitions>
          </state>
          <state id="resolved">
            <flags>
              <attribute id="ref">
                <read_only/>
              </attribute>
              <attribute id="title">
                <read_only/>
              </attribute>
              <attribute id="description">
                <read_only/>
              </attribute>
              <attribute id="start_date">
                <read_only/>
              </attribute>
              <attribute id="org_id">
                <read_only/>
              </attribute>
              <attribute id="service_id">
                <read_only/>
              </attribute>
              <attribute id="servicesubcategory_id">
                <read_only/>
              </attribute>
              <attribute id="product">
                <read_only/>
              </attribute>
              <attribute id="impact">
                <read_only/>
              </attribute>
              <attribute id="urgency">
                <read_only/>
              </attribute>
              <attribute id="priority">
                <read_only/>
              </attribute>
              <attribute id="workgroup_id">
                <read_only/>
              </attribute>
              <attribute id="agent_id">
                <read_only/>
              </attribute>
              <attribute id="agent_email">
                <read_only/>
              </attribute>
              <attribute id="close_date">
                <hidden/>
              </attribute>
              <attribute id="last_update">
                <read_only/>
              </attribute>
              <attribute id="assignment_date">
                <read_only/>
              </attribute>
              <attribute id="resolution_date">
                <hidden/>
              </attribute>
            </flags>
            <transitions>
              <transition id="ev_reassign">
                <stimulus>ev_reassign</stimulus>
                <target>assigned</target>
                <actions/>
              </transition>
              <transition id="ev_close">
                <stimulus>ev_close</stimulus>
                <target>closed</target>
                <actions>
                  <action>
                    <verb>SetClosureDate</verb>
                  </action>
                </actions>
              </transition>
            </transitions>
          </state>
          <state id="closed">
            <flags>
              <attribute id="ref">
                <read_only/>
              </attribute>
              <attribute id="title">
                <read_only/>
              </attribute>
              <attribute id="description">
                <read_only/>
              </attribute>
              <attribute id="ticket_log">
                <read_only/>
              </attribute>
              <attribute id="start_date">
                <read_only/>
              </attribute>
              <attribute id="org_id">
                <read_only/>
              </attribute>
              <attribute id="service_id">
                <read_only/>
              </attribute>
              <attribute id="servicesubcategory_id">
                <read_only/>
              </attribute>
              <attribute id="product">
                <read_only/>
              </attribute>
              <attribute id="impact">
                <read_only/>
              </attribute>
              <attribute id="urgency">
                <read_only/>
              </attribute>
              <attribute id="priority">
                <read_only/>
              </attribute>
              <attribute id="workgroup_id">
                <read_only/>
              </attribute>
              <attribute id="agent_id">
                <read_only/>
              </attribute>
              <attribute id="agent_email">
                <read_only/>
              </attribute>
              <attribute id="close_date">
                <read_only/>
              </attribute>
              <attribute id="last_update">
                <read_only/>
              </attribute>
              <attribute id="assignment_date">
                <read_only/>
              </attribute>
              <attribute id="resolution_date">
                <hidden/>
              </attribute>
            </flags>
            <transitions/>
          </state>
        </states>
      </lifecycle>
      <methods>
        <method id="SetAssignedDate">
          <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">
          <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">
          <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
         * @return integer The priority of the ticket 1(high) .. 3(low)
         */</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,
                        ),
                        // a group
                        2 => array(
                                1 => 1,
                                2 => 2,
                                3 => 3,
                        ),
                        // a departement!
                        3 => array(
                                        1 => 2,
                                        2 => 3,
                                        3 => 3,
                        ),
                );
                $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());

		$sCurrRef = $this->Get('ref');
		if (strlen($sCurrRef) == 0)
		{
			$iKey = $this->GetKey();
			if ($iKey < 0)
			{
				// Object not yet in the Database
				$iKey = MetaModel::GetNextKey(get_class($this));
			}
			$sName = sprintf('P-%06d', $iKey);
			$this->Set('ref', $sName);
		}
	}]]></code>
        </method>
      </methods>
      <presentation>
        <details>
          <items>
            <item id="document_list">
              <rank>10</rank>
            </item>
            <item id="ci_list">
              <rank>20</rank>
            </item>
            <item id="contact_list">
              <rank>30</rank>
            </item>
            <item id="incident_list">
              <rank>40</rank>
            </item>
            <item id="col:col1">
              <rank>50</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>60</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="close_date">
                      <rank>40</rank>
                    </item>
                  </items>
                </item>
                <item id="fieldset:Ticket:contact">
                  <rank>20</rank>
                  <items>
                    <item id="workgroup_id">
                      <rank>10</rank>
                    </item>
                    <item id="agent_id">
                      <rank>20</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="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="workgroup_id">
              <rank>120</rank>
            </item>
            <item id="agent_id">
              <rank>130</rank>
            </item>
            <item id="agent_email">
              <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="Problem:Overview" xsi:type="DashboardMenuNode" _delta="define">
      <rank>0</rank>
      <parent>ProblemManagement</parent>
      <definition>
        <layout>DashboardLayoutTwoCols</layout>
        <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>true</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/>
    </menu>
  </menus>
</itop_design>
