/packages/acs-content-repository/tcl/content-type-procs.tcl

https://github.com/iuri/PWTI · TCL · 399 lines · 350 code · 48 blank · 1 comment · 14 complexity · 87819dbe85adfa3dd0ecc39b5d1250f7 MD5 · raw file

  1. #
  2. ad_library {
  3. Procedures for content types
  4. @author Dave Bauer (dave@thedesignexperience.org)
  5. @creation-date 2004-06-09
  6. @arch-tag: 4a8a3652-fd5d-49aa-86fc-fade683f06ce
  7. @cvs-id $Id: content-type-procs.tcl,v 1.11 2007/09/18 20:04:21 gustafn Exp $
  8. }
  9. namespace eval ::content::type {}
  10. namespace eval ::content::type::attribute {}
  11. ad_proc -public content::type::new {
  12. -content_type:required
  13. {-supertype "content_revision"}
  14. -pretty_name:required
  15. -pretty_plural:required
  16. -table_name:required
  17. -id_column:required
  18. {-name_method ""}
  19. } {
  20. @param content_type
  21. @param supertype
  22. @param pretty_name
  23. @param pretty_plural
  24. @param table_name
  25. @param id_column
  26. @param name_method
  27. @return type_id
  28. } {
  29. return [package_exec_plsql -var_list [list \
  30. [list content_type $content_type ] \
  31. [list supertype $supertype ] \
  32. [list pretty_name $pretty_name ] \
  33. [list pretty_plural $pretty_plural ] \
  34. [list table_name $table_name ] \
  35. [list id_column $id_column ] \
  36. [list name_method $name_method ] \
  37. ] content_type create_type]
  38. }
  39. ad_proc -public content::type::delete {
  40. -content_type:required
  41. {-drop_children_p ""}
  42. {-drop_table_p ""}
  43. {-drop_objects_p "f"}
  44. } {
  45. @param content_type
  46. @param drop_children_p
  47. @param drop_table_p
  48. @param drop_objets_p Drop the objects of this content type along with all entries in cr_items and cr_revisions. Will not be done by default.
  49. } {
  50. if {$drop_objects_p eq "f"} {
  51. return [package_exec_plsql -var_list [list \
  52. [list content_type $content_type ] \
  53. [list drop_children_p $drop_children_p ] \
  54. [list drop_table_p $drop_table_p ] \
  55. ] content_type drop_type]
  56. } else {
  57. return [package_exec_plsql -var_list [list \
  58. [list content_type $content_type ] \
  59. [list drop_children_p $drop_children_p ] \
  60. [list drop_table_p $drop_table_p ] \
  61. [list drop_objects_p $drop_objects_p ] \
  62. ] content_type drop_type]
  63. }
  64. }
  65. ad_proc -public content::type::attribute::new {
  66. -content_type:required
  67. -attribute_name:required
  68. -datatype:required
  69. -pretty_name:required
  70. {-pretty_plural ""}
  71. {-sort_order ""}
  72. {-default_value ""}
  73. {-column_spec ""}
  74. } {
  75. @param content_type
  76. @param attribute_name
  77. @param datatype
  78. @param pretty_name
  79. @param pretty_plural
  80. @param sort_order
  81. @param default_value
  82. @param column_spec Specification for column to pass to the
  83. database. Not optional if the column does not already exist in the table.
  84. @return attribute_id for created attribute
  85. } {
  86. if {[db_type] eq "oracle"} {
  87. switch -- $column_spec {
  88. text { set column_spec clob }
  89. boolean { set column_spec "char(1)" }
  90. }
  91. } else {
  92. switch -- $column_spec {
  93. clob { set column_spec text }
  94. }
  95. }
  96. return [package_exec_plsql -var_list [list \
  97. [list content_type $content_type ] \
  98. [list attribute_name $attribute_name ] \
  99. [list datatype $datatype ] \
  100. [list pretty_name $pretty_name ] \
  101. [list pretty_plural $pretty_plural ] \
  102. [list sort_order $sort_order ] \
  103. [list default_value $default_value ] \
  104. [list column_spec $column_spec ] \
  105. ] content_type create_attribute]
  106. }
  107. ad_proc -public content::type::attribute::delete {
  108. -content_type:required
  109. -attribute_name:required
  110. {-drop_column ""}
  111. } {
  112. @param content_type
  113. @param attribute_name
  114. @param drop_column
  115. } {
  116. return [package_exec_plsql -var_list [list \
  117. [list content_type $content_type ] \
  118. [list attribute_name $attribute_name ] \
  119. [list drop_column $drop_column ] \
  120. ] content_type drop_attribute]
  121. }
  122. ad_proc -public content::type::get_template {
  123. -content_type:required
  124. {-use_context "public"}
  125. } {
  126. @param content_type
  127. @param use_context
  128. @return template_id
  129. } {
  130. return [package_exec_plsql -var_list [list \
  131. [list content_type $content_type ] \
  132. [list use_context $use_context ] \
  133. ] content_type get_template]
  134. }
  135. ad_proc -public content::type::is_content_type {
  136. -object_type:required
  137. } {
  138. @param object_type
  139. @return t or f
  140. } {
  141. return [package_exec_plsql -var_list [list \
  142. [list object_type $object_type ] \
  143. ] content_type is_content_type]
  144. }
  145. ad_proc -public content::type::refresh_view {
  146. -content_type:required
  147. } {
  148. @param content_type
  149. Creates or replaces the view associated with the supplied content type. By convention,
  150. this view is called TYPEx .
  151. } {
  152. return [package_exec_plsql -var_list [list \
  153. [list content_type $content_type ] \
  154. ] content_type refresh_view]
  155. }
  156. ad_proc -public content::type::register_child_type {
  157. -parent_type:required
  158. -child_type:required
  159. {-relation_tag ""}
  160. {-min_n ""}
  161. {-max_n ""}
  162. } {
  163. @param parent_type
  164. @param child_type
  165. @param relation_tag
  166. @param min_n
  167. @param max_n
  168. @return 0
  169. } {
  170. return [package_exec_plsql -var_list [list \
  171. [list parent_type $parent_type ] \
  172. [list child_type $child_type ] \
  173. [list relation_tag $relation_tag ] \
  174. [list min_n $min_n ] \
  175. [list max_n $max_n ] \
  176. ] content_type register_child_type]
  177. }
  178. ad_proc -public content::type::register_mime_type {
  179. -content_type:required
  180. -mime_type:required
  181. } {
  182. Associate a content_type with a mime_type (both params are strings, e.g. folder , application/pdf )
  183. @param content_type
  184. @param mime_type
  185. @return 0
  186. } {
  187. return [package_exec_plsql -var_list [list \
  188. [list content_type $content_type ] \
  189. [list mime_type $mime_type ] \
  190. ] content_type register_mime_type]
  191. }
  192. ad_proc -public content::type::register_relation_type {
  193. -content_type:required
  194. -target_type:required
  195. {-relation_tag ""}
  196. {-min_n ""}
  197. {-max_n ""}
  198. } {
  199. @param content_type
  200. @param target_type
  201. @param relation_tag
  202. @param min_n
  203. @param max_n
  204. @return 0
  205. } {
  206. return [package_exec_plsql -var_list [list \
  207. [list content_type $content_type ] \
  208. [list target_type $target_type ] \
  209. [list relation_tag $relation_tag ] \
  210. [list min_n $min_n ] \
  211. [list max_n $max_n ] \
  212. ] content_type register_relation_type]
  213. }
  214. ad_proc -public content::type::register_template {
  215. -content_type:required
  216. -template_id:required
  217. {-use_context "public"}
  218. {-is_default ""}
  219. } {
  220. @param content_type
  221. @param template_id
  222. @param use_context
  223. @param is_default
  224. } {
  225. return [package_exec_plsql -var_list [list \
  226. [list content_type $content_type ] \
  227. [list template_id $template_id ] \
  228. [list use_context $use_context ] \
  229. [list is_default $is_default ] \
  230. ] content_type register_template]
  231. }
  232. ad_proc -public content::type::rotate_template {
  233. -template_id:required
  234. -content_type:required
  235. {-use_context "public"}
  236. } {
  237. Force all items of content_type to use a new template. This will also cause items of this content
  238. type with no template assigned to use the new template. Finally, sets new template as default for
  239. this type. (IS THIS RIGHT ???? ----------------- ??????? )
  240. @param template_id
  241. @param content_type
  242. @param use_context
  243. } {
  244. return [package_exec_plsql -var_list [list \
  245. [list template_id $template_id ] \
  246. [list content_type $v_content_type ] \
  247. [list use_context $use_context ] \
  248. ] content_type rotate_template]
  249. }
  250. ad_proc -public content::type::set_default_template {
  251. -content_type:required
  252. -template_id:required
  253. {use_context: "public"}
  254. } {
  255. @param content_type
  256. @param template_id
  257. @param use_context
  258. @return 0
  259. } {
  260. return [package_exec_plsql -var_list [list \
  261. [list content_type $content_type ] \
  262. [list template_id $template_id ] \
  263. [list use_context $use_context ] \
  264. ] content_type set_default_template]
  265. }
  266. ad_proc -public content::type::unregister_child_type {
  267. -parent_type:required
  268. -child_type:required
  269. {-relation_tag ""}
  270. } {
  271. @param parent_type
  272. @param child_type
  273. @param relation_tag
  274. @see content::type::register_child_type
  275. @return 0
  276. } {
  277. return [package_exec_plsql -var_list [list \
  278. [list parent_type $parent_type ] \
  279. [list child_type $child_type ] \
  280. [list relation_tag $relation_tag ] \
  281. ] content_type unregister_child_type]
  282. }
  283. ad_proc -public content::type::unregister_mime_type {
  284. -content_type:required
  285. -mime_type:required
  286. } {
  287. @param content_type
  288. @param mime_type
  289. @see content::type::register_mime_type
  290. @return 0
  291. } {
  292. return [package_exec_plsql -var_list [list \
  293. [list content_type $content_type ] \
  294. [list mime_type $mime_type ] \
  295. ] content_type unregister_mime_type]
  296. }
  297. ad_proc -public content::type::unregister_relation_type {
  298. -content_type:required
  299. -target_type:required
  300. {-relation_tag ""}
  301. } {
  302. @param content_type
  303. @param target_type
  304. @param relation_tag
  305. @see content::type::register_relation_type
  306. @return 0
  307. } {
  308. return [package_exec_plsql -var_list [list \
  309. [list content_type $content_type ] \
  310. [list target_type $target_type ] \
  311. [list relation_tag $relation_tag ] \
  312. ] content_type unregister_relation_type]
  313. }
  314. ad_proc -public content::type::unregister_template {
  315. {-content_type ""}
  316. -template_id:required
  317. {-use_context ""}
  318. } {
  319. @param content_type
  320. @param template_id
  321. @param use_context
  322. @see content::type::register_template
  323. @return 0
  324. } {
  325. return [package_exec_plsql -var_list [list \
  326. [list content_type $content_type ] \
  327. [list template_id $template_id ] \
  328. [list use_context $use_context ] \
  329. ] content_type unregister_template]
  330. }
  331. ad_proc -public content::type::content_type_p {
  332. -content_type:required
  333. -mime_type:required
  334. } {
  335. Checks if the mime_type is of the content_type, e.g if application/pdf is of content_type "image" (which it should not...)
  336. Cached
  337. @param content_type content type to check against
  338. @param mime_type mime type to check for
  339. } {
  340. return [util_memoize [list content::type::content_type_p_not_cached -mime_type $mime_type -content_type $content_type]]
  341. }
  342. ad_proc -public content::type::content_type_p_not_cached {
  343. -content_type:required
  344. -mime_type:required
  345. } {
  346. Checks if the mime_type is of the content_type, e.g if application/pdf is of content_type "image" (which it should not...)
  347. @param content_type content type to check against
  348. @param mime_type mime type to check for
  349. } {
  350. return [db_string content_type_p "" -default 0]
  351. }