datamodel.itop-attachments.xml 6.8 KB

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