datamodel.itop-attachments.xml 6.8 KB

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