datamodel.itop-attachments.xml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  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. * @author Erwan Taloc <erwan.taloc@combodo.com>
  16. * @author Romain Quetiez <romain.quetiez@combodo.com>
  17. * @author Denis Flaven <denis.flaven@combodo.com>
  18. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  19. */]]></comment>
  20. <category>addon,bizmodel</category>
  21. <abstract>false</abstract>
  22. <key_type>autoincrement</key_type>
  23. <db_table>attachment</db_table>
  24. <db_key_field>id</db_key_field>
  25. <db_final_class_field></db_final_class_field>
  26. <naming>
  27. <format>%1$s %2$s</format>
  28. <attributes>
  29. <attribute id="item_class"/>
  30. <attribute id="temp_id"/>
  31. </attributes>
  32. </naming>
  33. <display_template></display_template>
  34. <icon></icon>
  35. <reconciliation>
  36. <attributes>
  37. <attribute id=""/>
  38. </attributes>
  39. </reconciliation>
  40. </properties>
  41. <fields>
  42. <field id="expire" xsi:type="AttributeDateTime">
  43. <sql>expire</sql>
  44. <default_value></default_value>
  45. <is_null_allowed>false</is_null_allowed>
  46. </field>
  47. <field id="temp_id" xsi:type="AttributeString">
  48. <sql>temp_id</sql>
  49. <default_value></default_value>
  50. <is_null_allowed>true</is_null_allowed>
  51. </field>
  52. <field id="item_class" xsi:type="AttributeString">
  53. <sql>item_class</sql>
  54. <default_value></default_value>
  55. <is_null_allowed>false</is_null_allowed>
  56. </field>
  57. <field id="item_id" xsi:type="AttributeString">
  58. <sql>item_id</sql>
  59. <default_value></default_value>
  60. <is_null_allowed>true</is_null_allowed>
  61. </field>
  62. <field id="item_org_id" xsi:type="AttributeInteger">
  63. <sql>item_org_id</sql>
  64. <default_value>0</default_value>
  65. <is_null_allowed>true</is_null_allowed>
  66. </field>
  67. <field id="contents" xsi:type="AttributeBlob"/>
  68. </fields>
  69. <methods>
  70. <method id="MapContextParam">
  71. <comment><![CDATA[/**
  72. * Maps the given context parameter name to the appropriate filter/search code for this class
  73. * @param string $sContextParam Name of the context parameter, e.g. 'org_id'
  74. * @return string Filter code, e.g. 'customer_id'
  75. */]]></comment>
  76. <static>true</static>
  77. <access>public</access>
  78. <type>Overload-ExNihilo</type>
  79. <code><![CDATA[ public static function MapContextParam($sContextParam)
  80. {
  81. if ($sContextParam == 'org_id')
  82. {
  83. return 'item_org_id';
  84. }
  85. else
  86. {
  87. return null;
  88. }
  89. }]]></code>
  90. </method>
  91. <method id="SetItem">
  92. <comment><![CDATA[/**
  93. * Set/Update all of the '_item' fields
  94. * @param object $oItem Container item
  95. * @return void
  96. */]]></comment>
  97. <static>false</static>
  98. <access>public</access>
  99. <type>Overload-ExNihilo</type>
  100. <code><![CDATA[ public function SetItem($oItem, $bUpdateOnChange = false)
  101. {
  102. $sClass = get_class($oItem);
  103. $iItemId = $oItem->GetKey();
  104. $this->Set('item_class', $sClass);
  105. $this->Set('item_id', $iItemId);
  106. $aCallSpec = array($sClass, 'MapContextParam');
  107. if (is_callable($aCallSpec))
  108. {
  109. $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter
  110. if (MetaModel::IsValidAttCode($sClass, $sAttCode))
  111. {
  112. $iOrgId = $oItem->Get($sAttCode);
  113. if ($iOrgId > 0)
  114. {
  115. if ($iOrgId != $this->Get('item_org_id'))
  116. {
  117. $this->Set('item_org_id', $iOrgId);
  118. if ($bUpdateOnChange)
  119. {
  120. $this->DBUpdate();
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }]]></code>
  127. </method>
  128. <method id="SetDefaultOrgId">
  129. <comment>/**
  130. * Give a default value for item_org_id (if relevant...)
  131. * @return void
  132. */</comment>
  133. <static>false</static>
  134. <access>public</access>
  135. <type>Overload-ExNihilo</type>
  136. <code><![CDATA[ public function SetDefaultOrgId()
  137. {
  138. // First check that the organization CAN be fetched from the target class
  139. //
  140. $sClass = $this->Get('item_class');
  141. $aCallSpec = array($sClass, 'MapContextParam');
  142. if (is_callable($aCallSpec))
  143. {
  144. $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter
  145. if (MetaModel::IsValidAttCode($sClass, $sAttCode))
  146. {
  147. // Second: check that the organization CAN be fetched from the current user
  148. //
  149. if (MetaModel::IsValidClass('Person'))
  150. {
  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. // OK - try it
  158. //
  159. $oCurrentPerson = MetaModel::GetObject('Person', UserRights::GetContactId(), false);
  160. if ($oCurrentPerson)
  161. {
  162. $this->Set('item_org_id', $oCurrentPerson->Get($sAttCode));
  163. }
  164. }
  165. }
  166. }
  167. }
  168. }
  169. }]]></code>
  170. </method>
  171. </methods>
  172. <presentation>
  173. <details>
  174. <items>
  175. <item>temp_id</item>
  176. <item>item_class</item>
  177. <item>item_id</item>
  178. <item>item_org_id</item>
  179. </items>
  180. </details>
  181. <search>
  182. <items>
  183. <item>temp_id</item>
  184. <item>item_class</item>
  185. <item>item_id</item>
  186. </items>
  187. </search>
  188. <list>
  189. <items>
  190. <item>temp_id</item>
  191. <item>item_class</item>
  192. <item>item_id</item>
  193. </items>
  194. </list>
  195. </presentation>
  196. </class>
  197. </classes>
  198. </itop_design>