tripal-2.0_pre-release.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <?php
  2. /**
  3. * @file
  4. * Wrappers for functions created for Tripal 2 whose names were changed before release
  5. */
  6. /**
  7. * This function is a wrapper for adding fields to an existing form for managing properties.
  8. * Many of the chado tables have a corresponding 'prop' table (e.g. analysisprop, contactprop,
  9. * organismprop, etc) and those prop tables all have the same schema. Use this function
  10. * to add all the necessary components to a form for allowing the user to add/edit properties to
  11. * a given record. To retreive properties in hook_insert or hook_update of a node form use
  12. * use the function tripal_core_properties_form_retreive().
  13. *
  14. * @param $form
  15. * The Drupal form array into which the properties elements will be added
  16. * @param $form_state
  17. * The corresponding form_state array for the form
  18. * @param $prop_table
  19. * The name of the property table (e.g. anlaysisprop, contactprop)
  20. * @param $id_field
  21. * The name of the ID field in the property table (e.g. analysis_id, contact_id)
  22. * @param $cv_name
  23. * The name of the controlled vocabulary that these properties are derived from
  24. * @param $available_props
  25. * An array of properties to inclde in the properties drop down. This array should
  26. * have cvterm_id's as the key and the cvterm name as the value
  27. * @param $id
  28. * The current base table ID. For example, if the property table is analysisprop then the
  29. * value should be that of the analysis_id. If the property table is contactprop then the
  30. * value should be that of the contact_id. This is the record from which currently assigned
  31. * properties will be retrieved.
  32. * @param $exclude
  33. * An optional array of cvterms to exclude when retreiving terms already saved in the database.
  34. * Use this array when properties are present but should be handled elsewhere.
  35. * For example, for contacts, the description field is stored as a property because
  36. * the actual field is only 255 characters. The 'contact_description' therefore should
  37. * not be shown in the list of properties, even if present, because it is handled by
  38. * a different form element.
  39. * @param $include
  40. * An optional array of terms to pre-populate in the form. This argument can be used to
  41. * add a default set of pre-populated properties regardless if they exist in the database
  42. * or not. The array should be of the following form:
  43. * array(
  44. * array('cvterm' => $obj1, 'value' => $val1),
  45. * array('cvterm' => $obj2, 'value' => $val2),
  46. * ... etc
  47. * );
  48. * The 'cvterm' key should have as a value an object with these properties: 'name', 'cvterm_id', 'definition'.
  49. * @param $instructions
  50. * An optional additional set of instructions for the form properties.
  51. * @param $fset_title
  52. * A title for the property field set. The default is 'Additional Details'.
  53. * @ingroup tripal_properties_api
  54. */
  55. function tripal_core_properties_form(&$form, &$form_state, $prop_table, $id_field, $cv_name,
  56. $available_props, $id = NULL, $exclude = array(), $include = array(), $instructions = '',
  57. $fset_title = 'Additional Details') {
  58. // $available_props is now created by the form based on the cv
  59. // $exclude and $include are not yet supported
  60. $details = array(
  61. 'property_table' => $prop_table,
  62. 'base_foreign_key' => $id_field,
  63. 'base_key_value' => $id,
  64. 'cv_name' => $cv_name,
  65. 'fieldset_title' => $fset_title,
  66. 'additional_instructions' => $instructions
  67. );
  68. tripal_api_chado_node_properties_form($form, $form_state, $details);
  69. }
  70. /**
  71. * This function is used in a hook_insert, hook_update for a node form
  72. * when the properties form has been added to the form. It retrieves all of the properties
  73. * and returns them in an array of the format:
  74. *
  75. * $properties[<property name>][<rank>] = <value>
  76. *
  77. * This array can then be used for inserting or updating properties using the API call
  78. * tripal_hook_insert_property()
  79. *
  80. * @param $node
  81. * @param $cvname
  82. * The name of the controlled vocabulary that the properties belong to
  83. *
  84. * @return
  85. * A properties array
  86. *
  87. * @ingroup tripal_properties_api
  88. */
  89. function tripal_core_properties_form_retreive($node, $cv_name) {
  90. return tripal_api_chado_node_properties_form_retreive($node);
  91. }
  92. /**
  93. * Retrieve a property for a given base table record
  94. *
  95. * @param $basetable
  96. * The base table for which the property should be retrieved. Thus to retrieve a property
  97. * for a feature the basetable=feature and property is retrieved from featureprop
  98. * @param $record_id
  99. * The foriegn key field of the base table. This should be in integer.
  100. * @param $property
  101. * The cvterm name describing the type of properties to be retrieved
  102. * @param $cv_name
  103. * The name of the cv that the above cvterm is part of
  104. *
  105. * @return
  106. * An array in the same format as that generated by the function
  107. * tripal_core_generate_chado_var(). If only one record is returned it
  108. * is a single object. If more than one record is returned then it is an array
  109. * of objects
  110. *
  111. * @ingroup tripal_properties_api
  112. */
  113. function tripal_core_get_property($basetable, $record_id, $property, $cv_name) {
  114. return tripal_api_chado_get_property($basetable, $record_id, $property, $cv_name);
  115. }
  116. /**
  117. * Insert a property for a given base table. By default if the property already
  118. * exists a new property is added with the next available rank. If
  119. * $update_if_present argument is specified then the record will be updated if it
  120. * exists rather than adding a new property.
  121. *
  122. * @param $basetable
  123. * The base table for which the property should be inserted. Thus to insert a property
  124. * for a feature the basetable=feature and property is inserted into featureprop
  125. * @param $record_id
  126. * The foriegn key value of the base table. This should be in integer.
  127. * @param $property
  128. * The cvterm name describing the type of properties to be inserted
  129. * @param $cv_name
  130. * The name of the cv that the above cvterm is part of
  131. * @param $value
  132. * The value of the property to be inserted (can be empty)
  133. * @param $update_if_present
  134. * A boolean indicating whether an existing record should be updated. If the
  135. * property already exists and this value is not specified or is zero then
  136. * a new property will be added with the next largest rank.
  137. *
  138. * @return
  139. * Return True on Insert/Update and False otherwise
  140. *
  141. * @ingroup tripal_properties_api
  142. */
  143. function tripal_core_insert_property($basetable, $record_id, $property,
  144. $cv_name, $value, $update_if_present = 0) {
  145. return tripal_api_chado_insert_property($basetable, $record_id, $property,
  146. $cv_name, $value, $update_if_present);
  147. }
  148. /**
  149. * Update a property for a given base table record and property name. This
  150. * function should be used only if one record of the property will be present.
  151. * If the property name can have multiple entries (with increasing rank) then
  152. * use the function named tripal_core_update_property_by_id
  153. *
  154. * @param $basetable
  155. * The base table for which the property should be updated. The property table
  156. * is constructed using a combination of the base table name and the suffix
  157. * 'prop' (e.g. basetable = feature then property tabie is featureprop).
  158. * @param $record_id
  159. * The foreign key of the basetable to update a property for. This should be in integer.
  160. * For example, if the basetable is 'feature' then the $record_id should be the feature_id
  161. * @param $property
  162. * The cvterm name of property to be updated
  163. * @param $cv_name
  164. * The name of the cv that the above cvterm is part of
  165. * @param $value
  166. * The value of the property to be inserted (can be empty)
  167. * @param $insert_if_missing
  168. * A boolean indicating whether a record should be inserted if one doesn't exist to update
  169. *
  170. * Note: The property to be updated is select via the unique combination of $record_id and
  171. * $property and then it is updated with the supplied value
  172. *
  173. * @return
  174. * Return True on Update/Insert and False otherwise
  175. *
  176. * @ingroup tripal_properties_api
  177. */
  178. function tripal_core_update_property($basetable, $record_id, $property,
  179. $cv_name, $value, $insert_if_missing = 0) {
  180. return tripal_api_chado_update_property($basetable, $record_id, $property,
  181. $cv_name, $value, $insert_if_missing);
  182. }
  183. /**
  184. * Update a property for a given base table record. This function should be
  185. * used if multiple records of the same property will be present. Also, use this
  186. * function to change the property name of an existing property.
  187. *
  188. * @param $basetable
  189. * The base table for which the property should be updated. The property table
  190. * is constructed using a combination of the base table name and the suffix
  191. * 'prop' (e.g. basetable = feature then property tabie is featureprop).
  192. * @param $record_id
  193. * The primary key of the base table. This should be in integer.
  194. * For example, if the basetable is 'feature' then the $record_id should be the featureprop_id
  195. * @param $property
  196. * The cvterm name of property to be updated
  197. * @param $cv_name
  198. * The name of the cv that the above cvterm is part of
  199. * @param $value
  200. * The value of the property to be inserted (can be empty)
  201. *
  202. * @return
  203. * Return True on Update/Insert and False otherwise
  204. *
  205. * @ingroup tripal_properties_api
  206. */
  207. function tripal_core_update_property_by_id($basetable, $record_id, $property,
  208. $cv_name, $value) {
  209. return tripal_api_chado_update_property_by_id($basetable, $record_id, $property,
  210. $cv_name, $value);
  211. }
  212. /**
  213. * Deletes a property for a given base table record using the property name
  214. *
  215. * @param $basetable
  216. * The base table for which the property should be deleted. Thus to deleted a property
  217. * for a feature the basetable=feature and property is deleted from featureprop
  218. * @param $record_id
  219. * The primary key of the basetable to delete a property for. This should be in integer.
  220. * @param $property
  221. * The cvterm name describing the type of property to be deleted
  222. * @param $cv_name
  223. * The name of the cv that the above cvterm is part of
  224. *
  225. * Note: The property to be deleted is select via the unique combination of $record_id and $property
  226. *
  227. * @return
  228. * Return True on Delete and False otherwise
  229. *
  230. * @ingroup tripal_properties_api
  231. */
  232. function tripal_core_delete_property($basetable, $record_id, $property, $cv_name) {
  233. return tripal_api_chado_delete_property($basetable, $record_id, $property, $cv_name);
  234. }
  235. /**
  236. * Deletes a property using the property ID
  237. *
  238. * @param $basetable
  239. * The base table for which the property should be deleted. Thus to deleted a property
  240. * for a feature the basetable=feature and property is deleted from featureprop
  241. * @param $record_id
  242. * The primary key of the basetable to delete a property for. This should be in integer.
  243. *
  244. * @return
  245. * Return True on Delete and False otherwise
  246. *
  247. * @ingroup tripal_properties_api
  248. */
  249. function tripal_core_delete_property_by_id($basetable, $record_id) {
  250. return tripal_api_chado_delete_property_by_id($basetable, $record_id);
  251. }
  252. /**
  253. * @section Database References API
  254. */
  255. /**
  256. * Provides a form for adding to BASE_dbxref and dbxref tables
  257. *
  258. * @param $form
  259. * The Drupal form array into which the dbxref elements will be added
  260. * @param $form_state
  261. * The corresponding form_state array for the form
  262. * @param $details
  263. * An array defining details needed by this form. Required Keys are:
  264. * - linking_table: the name of the dbxref linking table (ie: feature_dbxref)
  265. * - base_foreign_key: the name of the foreign key linking this table to the non-dbxref table (ie: feature_id)
  266. * - base_key_value: the value of the base_foreign_key for the current form (ie: 999 if the feature_id=999)
  267. * Optional keys include:
  268. * - fieldset_title: the non-translated title for this fieldset
  269. * - additional_instructions: a non-translated string providing additional instructions
  270. */
  271. function tripal_core_additional_dbxrefs_form(&$form, &$form_state, $details) {
  272. tripal_api_chado_node_additional_dbxrefs_form($form, $form_state, $details);
  273. }
  274. /**
  275. * Function to theme the add/remove dbxrefs form into a table
  276. */
  277. function theme_tripal_core_additional_dbxrefs_form_table($variables) {
  278. return theme_tripal_api_chado_node_additional_dbxrefs_form_table($variables);
  279. }
  280. /**
  281. * This function is used in a hook_insert, hook_update for a node form
  282. * when the additional_dbxrefs form has been added to the form. It retrieves all of the dbxrefs
  283. * and returns them in an array of the format:
  284. *
  285. * $dbxefs[<db_id>][<version>][<dbxref_id>] = <accession>
  286. *
  287. * This array can then be used for inserting or updating dbxrefs using the API call
  288. * tripal_hook_insert_dbxref()
  289. *
  290. * @param $node
  291. *
  292. * @return
  293. * A dbxref array
  294. *
  295. * @ingroup tripal_databaserefernce_api
  296. */
  297. function tripal_core_additional_dbxrefs_form_retreive($node) {
  298. return tripal_api_chado_node_additional_dbxrefs_form_retreive($node);
  299. }
  300. /**
  301. * This function is used in hook_insert or hook_update and handles inserting of any new
  302. * dbxrefs and creation of links between those dbxrefs and node content
  303. *
  304. * @param $node
  305. * The node passed into hook_insert & hook_update
  306. * @param $linking_table
  307. * The name of the _dbxref linking table (ie: feature_dbxref)
  308. * @param $foreignkey_name
  309. * The name of the foreign key used to link to the node content (ie: feature_id)
  310. * @param $foreignkey_value
  311. * The value of the foreign key (ie: 445, if there exists a feature where feature_id=445)
  312. */
  313. function tripal_core_additional_dbxrefs_form_update_dbxrefs($node, $linking_table, $foreignkey_name, $foreignkey_value) {
  314. tripal_api_chado_node_additional_dbxrefs_form_update_dbxrefs($node, $linking_table, $foreignkey_name, $foreignkey_value);
  315. }
  316. /**
  317. * @section Relationships API
  318. */
  319. /**
  320. * Provides a form for adding to BASE_relationship and relationship tables
  321. *
  322. * @param $form
  323. * The Drupal form array into which the relationship elements will be added
  324. * @param $form_state
  325. * The corresponding form_state array for the form
  326. * @param $details
  327. * An array defining details needed by this form. Required Keys are:
  328. * - relationship_table: the name of the relationship table (ie: feature_relationship)
  329. * - base_table: the name of the base table (ie: feature)
  330. * - base_foreign_key: the name of the foreign key linking this table to the non-relationship table (ie: feature_id)
  331. * - base_key_value: the value of the base_foreign_key for the current form (ie: 999 if the feature_id=999)
  332. * - nodetype: the non-translated singular title of this node type
  333. * One of the following:
  334. * - cv_id: the id of the ontology to supply terms for the type dropdown
  335. * - cv_name: the name of the ontology to supply terms for the type dropdown
  336. * Optional keys include:
  337. * - fieldset_title: the non-translated title for this fieldset
  338. * - additional_instructions: a non-translated string providing additional instructions
  339. * - nodetype_plural: the non-translated plural title of this node type
  340. *
  341. * @ingroup tripal_relationships_api
  342. */
  343. function tripal_core_relationships_form(&$form, &$form_state, $details) {
  344. tripal_api_chado_node_relationships_form($form, $form_state, $details);
  345. }
  346. /**
  347. * Function to theme the add/remove relationships form into a table
  348. *
  349. * @ingroup tripal_relationships_api
  350. */
  351. function theme_tripal_core_relationships_form_table($variables) {
  352. return theme_tripal_api_chado_node_relationships_form_table($variables);
  353. }
  354. /**
  355. * This function is used in a hook_insert, hook_update for a node form
  356. * when the relationships form has been added to the form. It retrieves all of the relationships
  357. * and returns them in an array of the format:
  358. *
  359. * $relationships[<type_id>][<rank>] = array(
  360. * 'subject_id' => <subject_id>,
  361. * 'object_id' => <object_id>,
  362. * );
  363. *
  364. * This array can then be used for inserting or updating relationships manually
  365. *
  366. * @param $node
  367. *
  368. * @return
  369. * A relationship array
  370. *
  371. * @ingroup tripal_relationships_api
  372. */
  373. function tripal_core_relationships_form_retreive($node) {
  374. tripal_api_chado_node_relationships_form_retreive($node);
  375. }
  376. /**
  377. * This function is used in hook_insert or hook_update and handles inserting of
  378. * relationships between the current nodetype and other memebers of the same nodetype
  379. *
  380. * @param $node
  381. * The node passed into hook_insert & hook_update
  382. * @param $relationship_table
  383. * The name of the _relationship linking table (ie: feature_relationship)
  384. * @param $current_id
  385. * The value of the foreign key (ie: 445, if there exists a feature where feature_id=445)
  386. *
  387. * @ingroup tripal_relationships_api
  388. */
  389. function tripal_core_relationships_form_update_relationships($node, $relationship_table, $current_id) {
  390. tripal_api_chado_node_relationships_form_update_relationships($node, $relationship_table, $current_id);
  391. }