tripal_entities.module 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. require_once "includes/tripal_entities.field_storage.inc";
  3. require_once "includes/tripal_entities.fields.inc";
  4. require_once "includes/ChadoData.inc";
  5. require_once "includes/ChadoDataController.inc";
  6. require_once "includes/ChadoDataUIController.inc";
  7. require_once "includes/ChadoDataType.inc";
  8. require_once "includes/ChadoDataTypeController.inc";
  9. require_once "includes/ChadoDataTypeUIController.inc";
  10. /**
  11. * Implements hook_menu().
  12. */
  13. function tripal_entities_menu() {
  14. /* // This provides a place for Field API to hang its own
  15. // interface and has to be the same as what was defined
  16. // in basic_entity_info() above.
  17. $items['admin/structure/chado_data/manage'] = array(
  18. 'title' => 'Chado Data',
  19. 'description' => t('Manage chado records, including default status, fields, settings, etc.'),
  20. 'page callback' => 'tripal_entities_list_entities',
  21. 'access arguments' => array('administer chado_data'),
  22. );
  23. // Add entities.
  24. $items['admin/structure/chado_data/manage/add'] = array(
  25. 'title' => 'Add Chado Data',
  26. 'page callback' => 'drupal_get_form',
  27. 'page arguments' => array('chado_data_form'),
  28. 'access arguments' => array('create chado_data entities'),
  29. 'type' => MENU_LOCAL_ACTION,
  30. );
  31. // List of all chado_data entities.
  32. $items['admin/structure/chado_data/manage/list'] = array(
  33. 'title' => 'List',
  34. 'type' => MENU_DEFAULT_LOCAL_TASK,
  35. ); */
  36. // The page to view our entities - needs to follow what
  37. // is defined in basic_uri and will use load_basic to retrieve
  38. // the necessary entity info.
  39. // $items['chado_data/%chado_data'] = array(
  40. // 'title callback' => 'chado_data_title',
  41. // 'title arguments' => array(1),
  42. // 'page callback' => 'chado_data_view',
  43. // 'page arguments' => array(1),
  44. // 'access arguments' => array('view chado_data'),
  45. // 'type' => MENU_CALLBACK,
  46. // );
  47. // // 'View' tab for an individual entity page.
  48. // $items['chado_data/%chado_data/view'] = array(
  49. // 'title' => 'View',
  50. // 'type' => MENU_DEFAULT_LOCAL_TASK,
  51. // 'weight' => -10,
  52. // );
  53. // // 'Edit' tab for an individual entity page.
  54. // $items['chado_data/%chado_data/edit'] = array(
  55. // 'title' => 'Edit',
  56. // 'page callback' => 'drupal_get_form',
  57. // 'page arguments' => array('chado_data_form', 1),
  58. // 'access arguments' => array('edit any chado_data entity'),
  59. // 'type' => MENU_LOCAL_TASK,
  60. // );
  61. return $items;
  62. }
  63. /**
  64. * Implements hook_permission().
  65. */
  66. function tripal_entities_permission() {
  67. // We set up permisssions to manage entity types, manage all entities and the
  68. // permissions for each individual entity
  69. $permissions = array(
  70. 'administer chado data types' => array(
  71. 'title' => t('Administer Chado data types'),
  72. 'description' => t('Create and delete fields for Chado data types, and set their permissions.'),
  73. ),
  74. 'administer chado data' => array(
  75. 'title' => t('Administer Chado data'),
  76. 'description' => t('Edit and delete all chado data'),
  77. ),
  78. );
  79. // Generate permissions per each data type.
  80. foreach (chado_data_get_types() as $type) {
  81. $type_name = check_plain($type->type);
  82. $permissions += array(
  83. "edit any $type_name data" => array(
  84. 'title' => t('%type_name: Edit any', array('%type_name' => $type->label)),
  85. ),
  86. "view any $type_name data" => array(
  87. 'title' => t('%type_name: View any', array('%type_name' => $type->label)),
  88. ),
  89. );
  90. }
  91. return $permissions;
  92. }
  93. /**
  94. * Implements hook_theme().
  95. */
  96. function tripal_entities_theme($existing, $type, $theme, $path) {
  97. return array(
  98. 'chado_data_add_list' => array(
  99. 'variables' => array('content' => array()),
  100. ),
  101. 'chado_data' => array(
  102. 'render element' => 'elements',
  103. 'template' => 'chado_data',
  104. ),
  105. );
  106. }
  107. /**
  108. * https://api.drupal.org/api/drupal/modules!rdf!rdf.module/group/rdf/7
  109. */
  110. function tripal_entities_rdf_mapping() {
  111. return array();
  112. /* return array(
  113. 'type' => 'chado_data',
  114. 'bundle' => 'gene',
  115. 'mapping' => array(
  116. 'rdftype' => array('sioc:Item', 'foaf:Document'),
  117. 'title' => array(
  118. 'predicates' => array('dc:title'),
  119. ),
  120. 'uid' => array(
  121. 'predicates' => array('sioc:has_creator'),
  122. 'type' => 'rel',
  123. ),
  124. 'name' => array(
  125. 'predicates' => array('foaf:name'),
  126. ),
  127. 'uniquename' => array(
  128. 'predicates' => array('foaf:name'),
  129. ),
  130. 'organism_id' => array(
  131. 'predicates' => array('sioc:has_parent'),
  132. 'type' => 'rel'
  133. )
  134. ),
  135. ); */
  136. }
  137. // http://www.bluespark.com/blog/drupal-entities-part-3-programming-hello-drupal-entity
  138. // http://dikini.net/31.08.2010/entities_bundles_fields_and_field_instances
  139. /**
  140. * Implement hook_entity_info().
  141. */
  142. function tripal_entities_entity_info() {
  143. $entities = array();
  144. $entities['chado_data'] = array(
  145. // A human readable label to identify our entity.
  146. 'label' => t('Chado Data'),
  147. 'plural label' => t('Vocabulary Terms'),
  148. // The entity class and controller class extend the classes provided by the
  149. // Entity API.
  150. 'entity class' => 'ChadoData',
  151. 'controller class' => 'ChadoDataController',
  152. // The table for this entity defined in hook_schema()
  153. 'base table' => 'chado_data',
  154. // Returns the uri elements of an entity.
  155. 'uri callback' => 'tripal_entities_vocbulary_term_uri',
  156. // IF fieldable == FALSE, we can't attach fields.
  157. 'fieldable' => TRUE,
  158. // entity_keys tells the controller what database fields are used for key
  159. // functions. It is not required if we don't have bundles or revisions.
  160. // Here we do not support a revision, so that entity key is omitted.
  161. 'entity keys' => array(
  162. 'id' => 'entity_id',
  163. 'bundle' => 'type',
  164. ),
  165. 'bundle keys' => array(
  166. 'bundle' => 'type',
  167. ),
  168. // Callback function for access to this entity.
  169. 'access callback' => 'chado_data_access',
  170. // FALSE disables caching. Caching functionality is handled by Drupal core.
  171. 'static cache' => FALSE,
  172. // Bundles are defined below.
  173. 'bundles' => array(),
  174. // The information below is used by the ChadoDataUIController
  175. // (which extends the EntityDefaultUIController). The admin_ui
  176. // key here is mean to appear on the 'Find Content' page of the
  177. // administrative menu.
  178. 'admin ui' => array(
  179. 'path' => 'admin/content/chado_data',
  180. 'file' => 'includes/tripal_entities.admin.inc',
  181. 'controller class' => 'ChadoDataUIController',
  182. 'menu wildcard' => '%chado_data',
  183. ),
  184. );
  185. // Bundles are alternative groups of fields or configuration
  186. // associated with a base entity type.
  187. // We want to dynamically add the bundles (or term types) to the entity.
  188. $values = array(
  189. 'cv_id' => array(
  190. 'name' => 'sequence'
  191. ),
  192. 'name' => 'gene',
  193. );
  194. $cvterm = chado_generate_var('cvterm', $values);
  195. $label = preg_replace('/_/', ' ', ucwords($cvterm->name));
  196. $bundle_id = $cvterm->dbxref_id->db_id->name . '_' . $cvterm->dbxref_id->accession;
  197. $entities['trp_vocabulary_term']['bundles'][$bundle_id] = array(
  198. 'label' => $label,
  199. 'admin' => array(
  200. 'path' => 'admin/structure/chado_data/manage',
  201. 'access arguments' => array('administer chado_data entities'),
  202. ),
  203. 'entity keys' => array(
  204. 'id' => 'entity_id',
  205. 'bundle' => 'bundle',
  206. ),
  207. );
  208. // The entity that holds information about the entity types
  209. $entities['chado_data_type'] = array(
  210. 'label' => t('Chado Data Type'),
  211. 'entity class' => 'ChadoDataType',
  212. 'controller class' => 'ChadoDataTypeController',
  213. 'base table' => 'chado_data_type',
  214. 'fieldable' => FALSE,
  215. 'bundle of' => 'chado_data',
  216. 'exportable' => TRUE,
  217. 'entity keys' => array(
  218. 'id' => 'id',
  219. 'name' => 'type',
  220. 'label' => 'label',
  221. ),
  222. 'access callback' => 'chado_data_type_access',
  223. 'module' => 'tripal_entities',
  224. // Enable the entity API's admin UI.
  225. 'admin ui' => array(
  226. 'path' => 'admin/structure/chado_data_types',
  227. 'file' => 'includes/tripal_entities.admin.inc',
  228. 'controller class' => 'ChadoDataTypeUIController',
  229. ),
  230. );
  231. return $entities;
  232. }
  233. /**
  234. * Returns a render array with all chado_data entities.
  235. *
  236. * @see pager_example.module
  237. */
  238. function tripal_entities_list_entities() {
  239. $content = array();
  240. // Load all of our entities.
  241. $entities = chado_data_load_multiple();
  242. if (!empty($entities)) {
  243. foreach ($entities as $entity) {
  244. // Create tabular rows for our entities.
  245. $rows[] = array(
  246. 'data' => array(
  247. 'id' => $entity->entity_id,
  248. 'title' => l($entity->title, 'chado_data/' . $entity->entity_id),
  249. 'type' => $entity->type,
  250. ),
  251. );
  252. }
  253. // Put our entities into a themed table. See theme_table() for details.
  254. $content['entity_table'] = array(
  255. '#theme' => 'table',
  256. '#rows' => $rows,
  257. '#header' => array(t('ID'), t('Item Description'), t('Bundle')),
  258. );
  259. }
  260. else {
  261. // There were no entities. Tell the user.
  262. $content[] = array(
  263. '#type' => 'item',
  264. '#markup' => t('No chado data entities currently exist.'),
  265. );
  266. }
  267. return $content;
  268. }