datamodel.itop-attachments.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2">
  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. <attributes>
  26. <attribute id="item_class"/>
  27. <attribute id="temp_id"/>
  28. </attributes>
  29. </naming>
  30. <display_template/>
  31. <icon/>
  32. <reconciliation>
  33. <attributes>
  34. <attribute id=""/>
  35. </attributes>
  36. </reconciliation>
  37. <indexes>
  38. <index id="1">
  39. <attributes>
  40. <attribute id="temp_id"/>
  41. </attributes>
  42. </index>
  43. <index id="2">
  44. <attributes>
  45. <attribute id="item_class"/>
  46. <attribute id="item_id"/>
  47. </attributes>
  48. </index>
  49. <index id="3">
  50. <attributes>
  51. <attribute id="item_org_id"/>
  52. </attributes>
  53. </index>
  54. </indexes>
  55. </properties>
  56. <fields>
  57. <field id="expire" xsi:type="AttributeDateTime">
  58. <sql>expire</sql>
  59. <default_value/>
  60. <is_null_allowed>false</is_null_allowed>
  61. </field>
  62. <field id="temp_id" xsi:type="AttributeString">
  63. <sql>temp_id</sql>
  64. <default_value/>
  65. <is_null_allowed>true</is_null_allowed>
  66. </field>
  67. <field id="item_class" xsi:type="AttributeString">
  68. <sql>item_class</sql>
  69. <default_value/>
  70. <is_null_allowed>false</is_null_allowed>
  71. </field>
  72. <field id="item_id" xsi:type="AttributeObjectKey">
  73. <sql>item_id</sql>
  74. <is_null_allowed>true</is_null_allowed>
  75. <class_attcode>item_class</class_attcode>
  76. </field>
  77. <field id="item_org_id" xsi:type="AttributeInteger">
  78. <sql>item_org_id</sql>
  79. <default_value>0</default_value>
  80. <is_null_allowed>true</is_null_allowed>
  81. </field>
  82. <field id="contents" xsi:type="AttributeBlob"/>
  83. </fields>
  84. <methods>
  85. <method id="MapContextParam">
  86. <comment><![CDATA[/**
  87. * Maps the given context parameter name to the appropriate filter/search code for this class
  88. * @param string $sContextParam Name of the context parameter, e.g. 'org_id'
  89. * @return string Filter code, e.g. 'customer_id'
  90. */]]></comment>
  91. <static>true</static>
  92. <access>public</access>
  93. <type>Overload-ExNihilo</type>
  94. <code><![CDATA[ public static function MapContextParam($sContextParam)
  95. {
  96. if ($sContextParam == 'org_id')
  97. {
  98. return 'item_org_id';
  99. }
  100. else
  101. {
  102. return null;
  103. }
  104. }]]></code>
  105. </method>
  106. <method id="SetItem">
  107. <comment><![CDATA[/**
  108. * Set/Update all of the '_item' fields
  109. * @param object $oItem Container item
  110. * @return void
  111. */]]></comment>
  112. <static>false</static>
  113. <access>public</access>
  114. <type>Overload-ExNihilo</type>
  115. <code><![CDATA[ public function SetItem($oItem, $bUpdateOnChange = false)
  116. {
  117. $sClass = get_class($oItem);
  118. $iItemId = $oItem->GetKey();
  119. $this->Set('item_class', $sClass);
  120. $this->Set('item_id', $iItemId);
  121. $aCallSpec = array($sClass, 'MapContextParam');
  122. if (is_callable($aCallSpec))
  123. {
  124. $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter
  125. if (MetaModel::IsValidAttCode($sClass, $sAttCode))
  126. {
  127. $iOrgId = $oItem->Get($sAttCode);
  128. if ($iOrgId > 0)
  129. {
  130. if ($iOrgId != $this->Get('item_org_id'))
  131. {
  132. $this->Set('item_org_id', $iOrgId);
  133. if ($bUpdateOnChange)
  134. {
  135. $this->DBUpdate();
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }]]></code>
  142. </method>
  143. <method id="SetDefaultOrgId">
  144. <comment>/**
  145. * Give a default value for item_org_id (if relevant...)
  146. * @return void
  147. */</comment>
  148. <static>false</static>
  149. <access>public</access>
  150. <type>Overload-ExNihilo</type>
  151. <code><![CDATA[ public function SetDefaultOrgId()
  152. {
  153. // First check that the organization CAN be fetched from the target class
  154. //
  155. $sClass = $this->Get('item_class');
  156. $aCallSpec = array($sClass, 'MapContextParam');
  157. if (is_callable($aCallSpec))
  158. {
  159. $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter
  160. if (MetaModel::IsValidAttCode($sClass, $sAttCode))
  161. {
  162. // Second: check that the organization CAN be fetched from the current user
  163. //
  164. if (MetaModel::IsValidClass('Person'))
  165. {
  166. $aCallSpec = array($sClass, 'MapContextParam');
  167. if (is_callable($aCallSpec))
  168. {
  169. $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter
  170. if (MetaModel::IsValidAttCode($sClass, $sAttCode))
  171. {
  172. // OK - try it
  173. //
  174. $oCurrentPerson = MetaModel::GetObject('Person', UserRights::GetContactId(), false);
  175. if ($oCurrentPerson)
  176. {
  177. $this->Set('item_org_id', $oCurrentPerson->Get($sAttCode));
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }]]></code>
  185. </method>
  186. </methods>
  187. <presentation>
  188. <details>
  189. <items>
  190. <item id="temp_id">
  191. <rank>10</rank>
  192. </item>
  193. <item id="item_class">
  194. <rank>20</rank>
  195. </item>
  196. <item id="item_id">
  197. <rank>30</rank>
  198. </item>
  199. <item id="item_org_id">
  200. <rank>40</rank>
  201. </item>
  202. </items>
  203. </details>
  204. <search>
  205. <items>
  206. <item id="temp_id">
  207. <rank>10</rank>
  208. </item>
  209. <item id="item_class">
  210. <rank>20</rank>
  211. </item>
  212. <item id="item_id">
  213. <rank>30</rank>
  214. </item>
  215. </items>
  216. </search>
  217. <list>
  218. <items>
  219. <item id="temp_id">
  220. <rank>10</rank>
  221. </item>
  222. <item id="item_class">
  223. <rank>20</rank>
  224. </item>
  225. <item id="item_id">
  226. <rank>30</rank>
  227. </item>
  228. </items>
  229. </list>
  230. </presentation>
  231. </class>
  232. </classes>
  233. </itop_design>