datamodel.itop-attachments.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
  3. <classes>
  4. <class id="Attachment" _delta="define">
  5. <parent>DBObject</parent>
  6. <properties>
  7. <comment><![CDATA[/**
  8. * Module attachments
  9. *
  10. * A quick and easy way to upload and attach files to *any* (see Configuration below) object in the CMBD in one click
  11. *
  12. * Configuration: the list of classes for which the "Attachments" tab is visible is defined via the module's 'allowed_classes'
  13. * configuration parameter. By default the tab is active for all kind of Tickets.
  14. *
  15. * @copyright Copyright (C) 2010-2012 Combodo SARL
  16. * @license http://opensource.org/licenses/AGPL-3.0
  17. */]]></comment>
  18. <category>addon,bizmodel</category>
  19. <abstract>false</abstract>
  20. <key_type>autoincrement</key_type>
  21. <db_table>attachment</db_table>
  22. <db_key_field>id</db_key_field>
  23. <db_final_class_field/>
  24. <naming>
  25. <format>%1$s %2$s</format>
  26. <attributes>
  27. <attribute id="item_class"/>
  28. <attribute id="temp_id"/>
  29. </attributes>
  30. </naming>
  31. <display_template/>
  32. <icon/>
  33. <reconciliation>
  34. <attributes>
  35. <attribute id=""/>
  36. </attributes>
  37. </reconciliation>
  38. </properties>
  39. <fields>
  40. <field id="expire" xsi:type="AttributeDateTime">
  41. <sql>expire</sql>
  42. <default_value/>
  43. <is_null_allowed>false</is_null_allowed>
  44. </field>
  45. <field id="temp_id" xsi:type="AttributeString">
  46. <sql>temp_id</sql>
  47. <default_value/>
  48. <is_null_allowed>true</is_null_allowed>
  49. </field>
  50. <field id="item_class" xsi:type="AttributeString">
  51. <sql>item_class</sql>
  52. <default_value/>
  53. <is_null_allowed>false</is_null_allowed>
  54. </field>
  55. <field id="item_id" xsi:type="AttributeString">
  56. <sql>item_id</sql>
  57. <default_value/>
  58. <is_null_allowed>true</is_null_allowed>
  59. </field>
  60. <field id="item_org_id" xsi:type="AttributeInteger">
  61. <sql>item_org_id</sql>
  62. <default_value>0</default_value>
  63. <is_null_allowed>true</is_null_allowed>
  64. </field>
  65. <field id="contents" xsi:type="AttributeBlob"/>
  66. </fields>
  67. <methods>
  68. <method id="MapContextParam">
  69. <comment><![CDATA[/**
  70. * Maps the given context parameter name to the appropriate filter/search code for this class
  71. * @param string $sContextParam Name of the context parameter, e.g. 'org_id'
  72. * @return string Filter code, e.g. 'customer_id'
  73. */]]></comment>
  74. <static>true</static>
  75. <access>public</access>
  76. <type>Overload-ExNihilo</type>
  77. <code><![CDATA[ public static function MapContextParam($sContextParam)
  78. {
  79. if ($sContextParam == 'org_id')
  80. {
  81. return 'item_org_id';
  82. }
  83. else
  84. {
  85. return null;
  86. }
  87. }]]></code>
  88. </method>
  89. <method id="SetItem">
  90. <comment><![CDATA[/**
  91. * Set/Update all of the '_item' fields
  92. * @param object $oItem Container item
  93. * @return void
  94. */]]></comment>
  95. <static>false</static>
  96. <access>public</access>
  97. <type>Overload-ExNihilo</type>
  98. <code><![CDATA[ public function SetItem($oItem, $bUpdateOnChange = false)
  99. {
  100. $sClass = get_class($oItem);
  101. $iItemId = $oItem->GetKey();
  102. $this->Set('item_class', $sClass);
  103. $this->Set('item_id', $iItemId);
  104. $aCallSpec = array($sClass, 'MapContextParam');
  105. if (is_callable($aCallSpec))
  106. {
  107. $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter
  108. if (MetaModel::IsValidAttCode($sClass, $sAttCode))
  109. {
  110. $iOrgId = $oItem->Get($sAttCode);
  111. if ($iOrgId > 0)
  112. {
  113. if ($iOrgId != $this->Get('item_org_id'))
  114. {
  115. $this->Set('item_org_id', $iOrgId);
  116. if ($bUpdateOnChange)
  117. {
  118. $this->DBUpdate();
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }]]></code>
  125. </method>
  126. <method id="SetDefaultOrgId">
  127. <comment>/**
  128. * Give a default value for item_org_id (if relevant...)
  129. * @return void
  130. */</comment>
  131. <static>false</static>
  132. <access>public</access>
  133. <type>Overload-ExNihilo</type>
  134. <code><![CDATA[ public function SetDefaultOrgId()
  135. {
  136. // First check that the organization CAN be fetched from the target class
  137. //
  138. $sClass = $this->Get('item_class');
  139. $aCallSpec = array($sClass, 'MapContextParam');
  140. if (is_callable($aCallSpec))
  141. {
  142. $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter
  143. if (MetaModel::IsValidAttCode($sClass, $sAttCode))
  144. {
  145. // Second: check that the organization CAN be fetched from the current user
  146. //
  147. if (MetaModel::IsValidClass('Person'))
  148. {
  149. $aCallSpec = array($sClass, 'MapContextParam');
  150. if (is_callable($aCallSpec))
  151. {
  152. $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter
  153. if (MetaModel::IsValidAttCode($sClass, $sAttCode))
  154. {
  155. // OK - try it
  156. //
  157. $oCurrentPerson = MetaModel::GetObject('Person', UserRights::GetContactId(), false);
  158. if ($oCurrentPerson)
  159. {
  160. $this->Set('item_org_id', $oCurrentPerson->Get($sAttCode));
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }]]></code>
  168. </method>
  169. </methods>
  170. <presentation>
  171. <details>
  172. <items>
  173. <item id="temp_id">
  174. <rank>10</rank>
  175. </item>
  176. <item id="item_class">
  177. <rank>20</rank>
  178. </item>
  179. <item id="item_id">
  180. <rank>30</rank>
  181. </item>
  182. <item id="item_org_id">
  183. <rank>40</rank>
  184. </item>
  185. </items>
  186. </details>
  187. <search>
  188. <items>
  189. <item id="temp_id">
  190. <rank>10</rank>
  191. </item>
  192. <item id="item_class">
  193. <rank>20</rank>
  194. </item>
  195. <item id="item_id">
  196. <rank>30</rank>
  197. </item>
  198. </items>
  199. </search>
  200. <list>
  201. <items>
  202. <item id="temp_id">
  203. <rank>10</rank>
  204. </item>
  205. <item id="item_class">
  206. <rank>20</rank>
  207. </item>
  208. <item id="item_id">
  209. <rank>30</rank>
  210. </item>
  211. </items>
  212. </list>
  213. </presentation>
  214. </class>
  215. </classes>
  216. </itop_design>