tripal_entities.module 9.1 KB

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