sbo__relationship.inc 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. <?php
  2. class sbo__relationship extends ChadoField {
  3. // --------------------------------------------------------------------------
  4. // EDITABLE STATIC CONSTANTS
  5. //
  6. // The following constants SHOULD be set for each descendent class. They are
  7. // used by the static functions to provide information to Drupal about
  8. // the field and it's default widget and formatter.
  9. // --------------------------------------------------------------------------
  10. // The default lable for this field.
  11. public static $default_label = 'Relationship';
  12. // The default description for this field.
  13. public static $description = 'Relationships between records.';
  14. // Provide a list of instance specific settings. These can be access within
  15. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  16. // then Drupal with automatically change these settings for the instnace.
  17. // It is recommended to put settings at the instance level whenever possible.
  18. // If you override this variable in a child class be sure to replicate the
  19. // term_name, term_vocab, term_accession and term_fixed keys as these are
  20. // required for all TripalFields.
  21. public static $default_instance_settings = array(
  22. // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
  23. 'term_vocabulary' => 'SBO',
  24. // The name of the term.
  25. 'term_name' => 'Relationship',
  26. // The unique ID (i.e. accession) of the term.
  27. 'term_accession' => '0000374',
  28. // Set to TRUE if the site admin is allowed to change the term
  29. // type. This will create form elements when editing the field instance
  30. // to allow the site admin to change the term settings above.
  31. 'term_fixed' => FALSE,
  32. // Inidates if this field should be automatically attached to display
  33. // or web services or if this field should be loaded separately. This
  34. // is convenient for speed. Fields that are slow should for loading
  35. // should ahve auto_attach set to FALSE so tha their values can be
  36. // attached asyncronously.
  37. 'auto_attach' => FALSE,
  38. // Settings to help the site admin control how relationship types and
  39. // valid subject/objects can be selected by the user.
  40. 'relationships' => array(
  41. 'option1_vocabs' => '',
  42. 'option2_vocab' => '',
  43. 'option2_parent' => '',
  44. 'relationship_types' => '',
  45. ),
  46. // The number of items to show on a page.
  47. 'items_per_page' => 10,
  48. );
  49. // The default widget for this field.
  50. public static $default_widget = 'sbo__relationship_widget';
  51. // The default formatter for this field.
  52. public static $default_formatter = 'sbo__relationship_formatter';
  53. // --------------------------------------------------------------------------
  54. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  55. // --------------------------------------------------------------------------
  56. // An array containing details about the field. The format of this array
  57. // is the same as that returned by field_info_fields()
  58. protected $field;
  59. // An array containing details about an instance of the field. A field does
  60. // not have to have an instance. But if dealing with an instance (such as
  61. // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
  62. protected $instance;
  63. // An array of columns to use as the "name" of the subject and object.
  64. // For example, for the feature table, this will be the name,
  65. // whereas, for the organism table this will be the genus & species.
  66. protected $base_name_columns;
  67. // One of 'type_id', or 'table_name'. Not all base tables have a type_id so
  68. // this setting allows us to better handle these cases.
  69. protected $base_type_column;
  70. // This field depends heavily on the schema of the relationship and base
  71. // table. The following variables cache the schema to greatly speed up
  72. // this field.
  73. // Note: both are ChadoSchema objects.
  74. protected $schema;
  75. protected $base_schema;
  76. // The column which indicated the subject/object_id in the current
  77. // relationship table. This allows us to support exceptions in the common
  78. // chado naming conventions.
  79. protected $subject_id_column;
  80. protected $object_id_column;
  81. /**
  82. * @see TripalField::elements()
  83. */
  84. public function elementInfo() {
  85. $field_term = $this->getFieldTermID();
  86. return array(
  87. $field_term => array(
  88. 'operations' => array('eq', 'contains', 'starts'),
  89. 'sortable' => FALSE,
  90. 'searchable' => FALSE,
  91. 'type' => 'xs:complexType',
  92. 'readonly' => FALSE,
  93. 'elements' => array(
  94. 'SIO:000493' => array(
  95. 'searchable' => FALSE,
  96. 'name' => 'relationship_clause',
  97. 'label' => 'Relationship Clause',
  98. 'help' => 'An English phrase describing the relationships.',
  99. 'sortable' => FALSE,
  100. 'type' => 'xs:string',
  101. 'readonly' => TRUE,
  102. 'required' => FALSE,
  103. ),
  104. 'local:relationship_subject' => array(
  105. 'searchable' => FALSE,
  106. 'name' => 'relationship_subject',
  107. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  108. 'sortable' => FALSE,
  109. 'type' => 'xs:complexType',
  110. 'readonly' => FALSE,
  111. 'required' => TRUE,
  112. 'elements' => array(
  113. 'rdfs:type' => array(
  114. 'name' => 'type',
  115. 'searchable' => TRUE,
  116. 'label' => 'Relationship Subject Type',
  117. 'help' => 'The subject\'s data type in a relationship clause',
  118. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  119. 'sortable' => TRUE,
  120. 'type' => 'xs:string',
  121. 'readonly' => FALSE,
  122. 'required' => TRUE,
  123. ),
  124. 'schema:name' => array(
  125. 'name' => 'name',
  126. 'searchable' => TRUE,
  127. 'label' => 'Relationship Subject Name',
  128. 'help' => 'The subject\'s name in a relationship clause',
  129. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  130. 'sortable' => TRUE,
  131. 'type' => 'xs:string',
  132. 'readonly' => FALSE,
  133. 'required' => TRUE,
  134. ),
  135. 'entity' => array(
  136. 'searchable' => FALSE,
  137. 'sortable' => FALSE,
  138. )
  139. ),
  140. ),
  141. 'local:relationship_type' => array(
  142. 'searchable' => TRUE,
  143. 'name' => 'relationship_type',
  144. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  145. 'sortable' => TRUE,
  146. 'type' => 'xs:string',
  147. 'readonly' => FALSE,
  148. 'required' => TRUE,
  149. ),
  150. 'local:relationship_object' => array(
  151. 'searchable' => FALSE,
  152. 'name' => 'relationship_object',
  153. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  154. 'sortable' => FALSE,
  155. 'type' => 'xs:complexType',
  156. 'readonly' => FALSE,
  157. 'required' => TRUE,
  158. 'elements' => array(
  159. 'rdfs:type' => array(
  160. 'searchable' => TRUE,
  161. 'name' => 'object_type',
  162. 'label' => 'Relationship Object Type',
  163. 'help' => 'The objects\'s data type in a relationship clause',
  164. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  165. 'sortable' => TRUE,
  166. 'type' => 'xs:string',
  167. 'readonly' => FALSE,
  168. 'required' => TRUE,
  169. ),
  170. 'schema:name' => array(
  171. 'searchable' => TRUE,
  172. 'name' => 'object_name',
  173. 'label' => 'Relationship Object Name',
  174. 'help' => 'The objects\'s name in a relationship clause',
  175. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  176. 'sortable' => TRUE,
  177. 'type' => 'xs:string',
  178. 'readonly' => FALSE,
  179. 'required' => TRUE,
  180. ),
  181. 'entity' => array(
  182. 'searchable' => FALSE,
  183. 'sortable' => FALSE,
  184. )
  185. ),
  186. ),
  187. ),
  188. )
  189. );
  190. }
  191. /**
  192. * Extends TripalField::__construct().
  193. */
  194. public function __construct($field, $instance) {
  195. parent::__construct($field, $instance);
  196. $reltable = $instance['settings']['chado_table'];
  197. $base_table = $instance['settings']['base_table'];
  198. // First, initialize the schema's.
  199. $this->schema = new ChadoSchema();
  200. $this->schema = $this->schema->getTableSchema($reltable);
  201. $this->base_schema = new ChadoSchema();
  202. $this->base_schema = $this->base_schema->getTableSchema($base_table);
  203. // Determine the subject_id/object_id column names.
  204. foreach ($this->schema['foreign keys'][$base_table]['columns'] AS $lcolum => $rcolum) {
  205. if (preg_match('/^subject_.*id/', $lcolum)) {
  206. $this->subject_id_column = $lcolum;
  207. }
  208. else if (preg_match('/^object_.*id/', $lcolum)) {
  209. $this->object_id_column = $lcolum;
  210. }
  211. }
  212. // Determine the name and type columns.
  213. $this->base_name_columns = [];
  214. $this->base_type_column = 'table_name';
  215. switch ($instance['settings']['chado_table']) {
  216. case 'acquisition_relationship':
  217. case 'analysis_relationship':
  218. case 'biomaterial_relationship':
  219. case 'cell_line_relationship':
  220. case 'quantification_relationship':
  221. $this->base_type_column = 'table_name';
  222. break;
  223. case 'element_relationship':
  224. // RELATIONSHIP->subject_id_key->feature_id->name;
  225. $this->base_name_columns = ['name'];
  226. $this->base_type_column = 'table_name';
  227. break;
  228. case 'organism_relationship':
  229. $this->base_name_columns = ['genus','species'];
  230. $this->base_type_column = 'table_name';
  231. break;
  232. case 'project_relationship':
  233. $this->base_name_columns = ['name'];
  234. $this->base_type_column = 'table_name';
  235. break;
  236. case 'phylonode_relationship':
  237. $this->base_name_columns = ['label'];
  238. $this->base_type_column = 'table_name';
  239. break;
  240. case 'pub_relationship':
  241. $this->base_name_columns = ['name'];
  242. $this->base_type_column = 'table_name';
  243. break;
  244. case 'contact':
  245. $this->base_name_columns = ['name'];
  246. $this->base_type_column = 'type_id';
  247. break;
  248. default:
  249. // @todo update this to use the schema.
  250. $this->base_name_columns = ['name'];
  251. $this->base_type_column = 'type_id';
  252. }
  253. }
  254. /**
  255. * Retrive the subject from the current relationship.
  256. *
  257. * @param $relationship
  258. * A single expanded relationship from a variable generated by chado_generate_var().
  259. * At a minimum, if will have a subject, object and type which should be expanded to
  260. * the appropriate type of record depending on the content type this widget
  261. * is attached to.
  262. * @return
  263. * An array of information for the subject of the $relationship.
  264. */
  265. private function getRelationshipSubject($relationship) {
  266. $name = [];
  267. foreach ($this->base_name_columns as $column) {
  268. $name[] = $relationship->{$this->subject_id_column}->{$column};
  269. }
  270. // Retrieve the type.
  271. $type = $this->instance['settings']['base_table'];
  272. if (($this->base_type_column != 'table_name') AND isset($relationship->{$this->subject_id_column}->{$this->base_type_column})) {
  273. $type_object = $relationship->{$this->subject_id_column}->{$this->base_type_column};
  274. if (isset($type_object->name)) {
  275. $type = $type_object->name;
  276. }
  277. elseif (isset($type_object->uniquename)) {
  278. $type = $type_object->uniquename;
  279. }
  280. }
  281. $record = [
  282. 'rdfs:type' => $type,
  283. 'schema:name' => implode(' ', $name),
  284. ];
  285. // If the object has a uniquename then add that in for refernce.
  286. if (property_exists($relationship->{$this->subject_id_column}, 'uniquename')) {
  287. $record['data:0842'] = $relationship->{$this->subject_id_column}->uniquename;
  288. }
  289. // If the object has an organism then add that in for reference.
  290. if (property_exists($relationship->{$this->subject_id_column}, 'organism_id')
  291. AND is_object($relationship->{$this->subject_id_column}->organism_id)) {
  292. $record['OBI:0100026'] = $relationship->{$this->subject_id_column}->organism_id->genus . ' ' . $relationship->{$this->subject_id_column}->organism_id->species;
  293. }
  294. // Add in the TripalEntity ids if the object is published.
  295. if (property_exists($relationship->{$this->subject_id_column}, 'entity_id')) {
  296. $entity_id = $relationship->{$this->subject_id_column}->entity_id;
  297. $record['entity'] = 'TripalEntity:' . $entity_id;
  298. }
  299. return $record;
  300. }
  301. /**
  302. * Retrieve the object from the current relationship.
  303. *
  304. * @param $relationship
  305. * A single expanded relationship from a variable generated by chado_generate_var().
  306. * At a minimum, if will have a subject, object and type which should be expanded to
  307. * the appropriate type of record depending on the content type this widget
  308. * is attached to.
  309. * @return
  310. * An array of information for the object of the $relationship.
  311. */
  312. private function getRelationshipObject($relationship) {
  313. $name = [];
  314. // Retrieve the name (may be multiple parts).
  315. foreach ($this->base_name_columns as $column) {
  316. $name[] = $relationship->{$this->object_id_column}->{$column};
  317. }
  318. // Retrieve the Type.
  319. $type = $this->instance['settings']['base_table'];
  320. if (($this->base_type_column != 'table_name') AND isset($relationship->{$this->object_id_column}->{$this->base_type_column})) {
  321. $type_object = $relationship->{$this->object_id_column}->{$this->base_type_column};
  322. if (isset($type_object->name)) {
  323. $type = $type_object->name;
  324. }
  325. elseif (isset($type_object->uniquename)) {
  326. $type = $type_object->uniquename;
  327. }
  328. }
  329. $record = [
  330. 'rdfs:type' => $type,
  331. 'schema:name' => implode(' ', $name),
  332. ];
  333. // If the object has a unqiuename then add that in for reference.
  334. if (property_exists($relationship->{$this->object_id_column}, 'uniquename')) {
  335. $record['data:0842'] = $relationship->{$this->object_id_column}->uniquename;
  336. }
  337. // If the object has an organism then add that in for reference.
  338. if (property_exists($relationship->{$this->object_id_column}, 'organism_id')
  339. AND is_object($relationship->{$this->object_id_column}->organism_id)) {
  340. $record['OBI:0100026'] = $relationship->{$this->object_id_column}->organism_id->genus . ' ' . $relationship->{$this->object_id_column}->organism_id->species;
  341. }
  342. // Add in the TripalEntity ids if the object is published.
  343. if (property_exists($relationship->{$this->object_id_column}, 'entity_id')) {
  344. $entity_id = $relationship->{$this->object_id_column}->entity_id;
  345. $record['entity'] = 'TripalEntity:' . $entity_id;
  346. }
  347. return $record;
  348. }
  349. /**
  350. * Load a specific relationship as indicated by $delta.
  351. * This function is called by the load method below.
  352. *
  353. * Note: The relationship is loaded by adding it the the entitiy values.
  354. *
  355. * @param $relationship
  356. * A single expanded relationship from a variable generated by chado_generate_var().
  357. * At a minimum, if will have a subject, object and type which should be expanded to
  358. * the appropriate type of record depending on the content type this widget
  359. * is attached to.
  360. * @param $entity
  361. * The entity the widget is attached to.
  362. * @param $delta
  363. * An integer indicating the specific relationship to load. This is usually the rank
  364. * from the relationship table (if there is one).
  365. */
  366. private function loadRelationship($relationship, &$entity, $delta) {
  367. $field_name = $this->field['field_name'];
  368. $field_table = $this->instance['settings']['chado_table'];
  369. $base_table = $this->instance['settings']['base_table'];
  370. $rel_acc = $relationship->type_id->dbxref_id->db_id->name . ':' . $relationship->type_id->dbxref_id->accession;
  371. $rel_type = $relationship->type_id->name;
  372. $verb = $this->get_rel_verb($rel_type);
  373. $pkey = $this->schema['primary key'][0];
  374. $subject_id_key = $this->subject_id_column;
  375. $object_id_key = $this->object_id_column;
  376. // @todo grab these separately like it was before.
  377. $subject_pkey = $object_pkey = $this->base_schema['primary key'][0];
  378. $entity->{$field_name}['und'][$delta]['value'] = array(
  379. 'local:relationship_subject' => $this->getRelationshipSubject($relationship),
  380. 'local:relationship_type' => $relationship->type_id->name,
  381. 'local:relationship_object' => $this->getRelationshipObject($relationship),
  382. );
  383. // Add the clause to the values array. The clause is a written version
  384. // of the relationships.
  385. $rel_type_clean = lcfirst(preg_replace('/_/', ' ', $rel_type));
  386. $subject_type = $entity->{$field_name}['und'][$delta]['value']['local:relationship_subject']['rdfs:type'];
  387. $subject_name = $entity->{$field_name}['und'][$delta]['value']['local:relationship_subject']['schema:name'];
  388. $object_type = $entity->{$field_name}['und'][$delta]['value']['local:relationship_object']['rdfs:type'];
  389. $object_name = $entity->{$field_name}['und'][$delta]['value']['local:relationship_object']['schema:name'];
  390. // Remember the current entity could be either the subject or object!
  391. // Example: The genetic_marker, MARKER1 , derives from the sequence_variant, VARIANT1.
  392. // The above relationship will be shown both on marker and variant pages
  393. // and as such both subject and object names need to be shown.
  394. $clause = 'The ' . $subject_type . ', ' .
  395. $subject_name . ', ' . $verb . ' ' . $rel_type_clean . ' ' .
  396. $object_type . ', ' . $object_name . '.';
  397. $entity->{$field_name}['und'][$delta]['value']['SIO:000493'] = $clause;
  398. // Adding a label allows us to provide a single text value for the
  399. // entire field. It is this text value that can be used in tab/csv
  400. // downloaders.
  401. $entity->{$field_name}['und'][$delta]['value']['rdfs:label'] = $clause;
  402. $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__' . $pkey] = $relationship->$pkey;
  403. $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__' . $subject_id_key] = $relationship->$subject_id_key->$subject_pkey;
  404. $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__type_id'] = $relationship->type_id->cvterm_id;
  405. $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__' . $object_id_key] = $relationship->$object_id_key->$object_pkey;
  406. // For the widget to work properly we will preform values.
  407. $entity->{$field_name}['und'][$delta]['type_name'] = $relationship->type_id->name;
  408. $entity->{$field_name}['und'][$delta]['subject_name'] = $subject_name . ' [id: ' . $relationship->$subject_id_key->$subject_pkey . ']';
  409. $entity->{$field_name}['und'][$delta]['object_name'] = $object_name . ' [id: ' . $relationship->$object_id_key->$object_pkey . ']';
  410. if (array_key_exists('value', $this->schema['fields'])) {
  411. $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__value'] = $relationship->value;
  412. }
  413. if (array_key_exists('rank', $this->schema['fields'])) {
  414. $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__rank'] = $relationship->rank;
  415. }
  416. }
  417. /**
  418. *
  419. * @see TripalField::load()
  420. */
  421. public function load($entity) {
  422. $settings = $this->field['settings'];
  423. $record = $entity->chado_record;
  424. $field_name = $this->field['field_name'];
  425. $field_type = $this->field['type'];
  426. $field_table = $this->instance['settings']['chado_table'];
  427. $field_column = $this->instance['settings']['chado_column'];
  428. $base_table = $this->instance['settings']['base_table'];
  429. $rel_table = $field_table;
  430. // Get the PKey for this table
  431. $pkey = $this->schema['primary key'][0];
  432. // Not all tables have the columns named 'subject_id' and 'object_id'.
  433. // some have variations on that name and we need to determine what they are.
  434. $subject_id_key = $this->subject_id_column;
  435. $object_id_key = $this->object_id_column;
  436. // If we don't have a chado record return before creating a stub for this field!
  437. if (!$record) {
  438. return;
  439. }
  440. // Set some defaults for the empty record.
  441. $entity->{$field_name}['und'][0] = array(
  442. 'value' => '',
  443. 'chado-' . $field_table . '__' . $pkey => '',
  444. 'chado-' . $field_table . '__' . $subject_id_key => '',
  445. 'chado-' . $field_table . '__' . $object_id_key => '',
  446. 'chado-' . $field_table . '__type_id' => '',
  447. // These elements don't need to follow the naming scheme above
  448. // because we don't need the chado_field_storage to try and
  449. // save these values.
  450. 'object_name' => '',
  451. 'subject_name' => '',
  452. 'type_name' => '',
  453. );
  454. // If the table has rank and value fields then add those to the default
  455. // value array.
  456. if (array_key_exists('value', $this->schema['fields'])) {
  457. $entity->{$field_name}['und'][0]['chado-' . $field_table . '__value'] = '';
  458. }
  459. if (array_key_exists('rank', $this->schema['fields'])) {
  460. $entity->{$field_name}['und'][0]['chado-' . $field_table . '__rank'] = '';
  461. }
  462. // Expand the object to include the relationships.
  463. $options = array(
  464. 'return_array' => 1,
  465. // we don't want to fully recurse we only need information about the
  466. // relationship type and the object and subject
  467. 'include_fk' => array(
  468. 'type_id' => 1,
  469. $object_id_key => array(
  470. 'type_id' => 1,
  471. 'organism_id' => 1,
  472. ),
  473. $subject_id_key => array(
  474. 'type_id' => 1,
  475. 'organism_id' => 1,
  476. ),
  477. ),
  478. );
  479. if (array_key_exists('rank', $this->schema['fields'])) {
  480. $options['order_by'] = array('rank' => 'ASC');
  481. }
  482. $record = chado_expand_var($record, 'table', $rel_table, $options);
  483. if (!$record->$rel_table) {
  484. return;
  485. }
  486. // Load the subject relationships
  487. $i = 0;
  488. if (isset($record->$rel_table->$subject_id_key)) {
  489. $srelationships = $record->$rel_table->$subject_id_key;
  490. foreach ($srelationships as $relationship) {
  491. $this->loadRelationship($relationship, $entity, $i);
  492. $i++;
  493. }
  494. }
  495. // Load the object relationships
  496. if (isset($record->$rel_table->$object_id_key)) {
  497. $orelationships = $record->$rel_table->$object_id_key;
  498. foreach ($orelationships as $relationship) {
  499. $this->loadRelationship($relationship, $entity, $i);
  500. $i++;
  501. }
  502. }
  503. }
  504. /**
  505. * @see ChadoField::query()
  506. */
  507. public function query($query, $condition) {
  508. $alias = $this->field['field_name'];
  509. $chado_table = $this->instance['settings']['chado_table'];
  510. $base_table = $this->instance['settings']['base_table'];
  511. $bschema = chado_get_schema($base_table);
  512. $bpkey = $bschema['primary key'][0];
  513. $operator = $condition['operator'];
  514. // Bulid the list of expected elements that will be provided.
  515. $field_term_id = $this->getFieldTermID();
  516. $rel_subject = $field_term_id . ',local:relationship_subject';
  517. $rel_subject_type = $rel_subject . ',' . 'rdfs:type';
  518. $rel_subject_name = $rel_subject . ',' . 'schema:name';
  519. $rel_subject_identifier = $rel_subject . ',' . 'data:0842';
  520. $rel_type = $field_term_id . ',local:relationship_type';
  521. $rel_object = $field_term_id . ',local:relationship_object';
  522. $rel_object_type = $rel_object . ',' . 'rdfs:type';
  523. $rel_object_name = $rel_object . ',' . 'schema:name';
  524. $rel_object_identifier = $rel_object . ',' . 'data:0842';
  525. // Filter by the name of the subject or object.
  526. if ($condition['column'] == $rel_subject_name) {
  527. $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.object_id");
  528. $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.subject_id");
  529. $query->condition("base2.name", $condition['value'], $operator);
  530. }
  531. if ($condition['column'] == $rel_object_name) {
  532. $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.subject_id");
  533. $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.object_id");
  534. $query->condition("base2.name", $condition['value'], $operator);
  535. }
  536. // Filter by unique name of the subject or object.
  537. // If this table has a uniquename!
  538. if (isset($this->schema['fields']['uniquename'])) {
  539. if ($condition['column'] == $rel_subject_identifier) {
  540. $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.object_id");
  541. $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.subject_id");
  542. $query->condition("base2.uniquename", $condition['value'], $operator);
  543. }
  544. if ($condition['column'] == $rel_object_identifier) {
  545. $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.subject_id");
  546. $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.object_id");
  547. $query->condition("base2.uniquename", $condition['value'], $operator);
  548. }
  549. }
  550. // Filter by the type of the subject or object
  551. if ($condition['column'] == $rel_subject_type) {
  552. $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.object_id");
  553. $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.subject_id");
  554. $this->queryJoinOnce($query, 'cvterm', 'SubjectCVT', "SubjectCVT.cvterm_id = base2.type_id");
  555. $this->queryJoinOnce($query, "SubjectCVT.name", $condition['value'], $operator);
  556. }
  557. if ($condition['column'] == $rel_object_type) {
  558. $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.subject_id");
  559. $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.object_id");
  560. $this->queryJoinOnce($query, 'cvterm', 'ObjectCVT', "ObjectCVT.cvterm_id = base2.type_id");
  561. $query->condition("ObjectCVT.name", $condition['value'], $operator);
  562. }
  563. // Filter by relationship type
  564. if ($condition['column'] == 'relationship.relationship_type') {
  565. // This filter commented out because it's way to slow...
  566. // $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.subject_id OR base.$bpkey = $alias.object_id");
  567. // $this->queryJoinOnce($query, 'cvterm', 'RelTypeCVT', "RelTypeCVT.cvterm_id = $alias.type_id");
  568. // $query->condition("RelTypeCVT.name", $condition['value'], $operator);
  569. }
  570. }
  571. /**
  572. * A helper function to define English verbs for relationship types.
  573. *
  574. * @param $rel_type
  575. * The vocabulary term name for the relationship.
  576. *
  577. * @return
  578. * The verb to use when creating a sentence of the relationship.
  579. */
  580. private function get_rel_verb($rel_type) {
  581. $rel_type_clean = lcfirst(preg_replace('/_/', ' ', $rel_type));
  582. $verb = '';
  583. switch ($rel_type_clean) {
  584. case 'integral part of':
  585. case 'instance of':
  586. $verb = 'is an';
  587. break;
  588. case 'proper part of':
  589. case 'transformation of':
  590. case 'genome of':
  591. case 'part of':
  592. $verb = 'is a';
  593. case 'position of':
  594. case 'sequence of':
  595. case 'variant of':
  596. $verb = 'is a';
  597. break;
  598. case 'derives from':
  599. case 'connects on':
  600. case 'contains':
  601. case 'finishes':
  602. case 'guides':
  603. case 'has origin':
  604. case 'has part':
  605. case 'has quality':
  606. case 'is a':
  607. case 'is a maternal parent of':
  608. case 'is a paternal parent of':
  609. case 'is consecutive sequence of':
  610. case 'maximally overlaps':
  611. case 'overlaps':
  612. case 'starts':
  613. break;
  614. default:
  615. $verb = 'is';
  616. }
  617. return $verb;
  618. }
  619. /**
  620. *
  621. * @see TripalField::settingsForm()
  622. */
  623. public function instanceSettingsForm() {
  624. $element = parent::instanceSettingsForm();
  625. $element['items_per_page'] = array(
  626. '#type' => 'textfield',
  627. '#title' => 'Items per Page',
  628. '#description' => t('The number of items that should appear on each page. A pager is provided if more than this number of items exist.'),
  629. '#default_value' => $this->instance['settings']['items_per_page'],
  630. );
  631. //$element = parent::instanceSettingsForm();
  632. $element['relationships'] = array(
  633. '#type' => 'fieldset',
  634. '#title' => 'Allowed Relationship Types',
  635. '#description' => t('There are three ways that relationship types
  636. can be limited for users who have permission to add new relationships.
  637. Please select the most appropriate for you use case. By default
  638. all vocabularies are provided to the user which allows use of any
  639. term for the relationship type.'),
  640. '#collapsed' => TRUE,
  641. '#collapsible' => TRUE,
  642. );
  643. // $element['instructions'] = array(
  644. // '#type' => 'item',
  645. // '#markup' => 'You may provide a list of terms that will be available in a select box
  646. // as the relationship types. This select box will replace the vocabulary select box if the
  647. // following value is set.'
  648. // );
  649. $vocs = chado_get_cv_select_options();
  650. $element['relationships']['option1'] = array(
  651. '#type' => 'item',
  652. '#title' => 'Option #1',
  653. '#description' => t('Use this option to limit the vocabularies that a user .
  654. could use to specify relationship types. With this option any term in .
  655. the vocabulary can be used for the relationship type. You may select
  656. more than one vocabulary.'),
  657. );
  658. $element['relationships']['option1_vocabs'] = array(
  659. '#type' => 'select',
  660. '#multiple' => TRUE,
  661. '#options' => $vocs,
  662. '#size' => 6,
  663. '#default_value' => $this->instance['settings']['relationships']['option1_vocabs'],
  664. // TODO add ajax here so that the relationship autocomplete below works
  665. );
  666. $element['relationships']['option2'] = array(
  667. '#type' => 'item',
  668. '#title' => '<b>Option #2</b>',
  669. '#description' => 'Some vocabularies are heirarchichal (an ontology). Within this
  670. heirarchy groups of related terms typically fall under a common parent. If you
  671. wish to limit the list of terms that a user can use for the relationship type,
  672. you can provide the parent term here. Then, only that term\'s children will
  673. be avilable for use as a relationship type.',
  674. );
  675. $element['relationships']['option2_vocab'] = array(
  676. '#type' => 'select',
  677. '#description' => 'Specify Default Vocabulary',
  678. '#multiple' => FALSE,
  679. '#options' => $vocs,
  680. '#default_value' => $this->instance['settings']['relationships']['option2_vocab'],
  681. '#ajax' => array(
  682. 'callback' => "sbo__relationship_instance_settings_form_ajax_callback",
  683. 'wrapper' => 'relationships-option2-parent',
  684. 'effect' => 'fade',
  685. 'method' => 'replace'
  686. ),
  687. );
  688. $element['relationships']['option2_parent'] = array(
  689. '#type' => 'textfield',
  690. '#description' => 'Specify a Heirarchical Parent Term',
  691. '#default_value' => $this->instance['settings']['relationships']['option2_parent'],
  692. '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
  693. '#prefix' => '<div id=relationships-option2-parent>',
  694. '#suffix' => '</div>'
  695. );
  696. $element['relationships']['option3'] = array(
  697. '#type' => 'item',
  698. '#title' => 'Option #3',
  699. '#description' => 'Provide terms separated by a new line. The term provided should be
  700. unique and distinguishable by the name. You can use a bar | to separate a vocabulary
  701. and a term to allow more specific assignment.',
  702. );
  703. $element['relationships']['relationship_types'] = array(
  704. '#type' => 'textarea',
  705. '#default_value' => $this->instance['settings']['relationships']['relationship_types'],
  706. );
  707. return $element;
  708. }
  709. /**
  710. *
  711. * @param unknown $form
  712. * @param unknown $form_state
  713. */
  714. public function instanceSettingsFormValidate($form, &$form_state) {
  715. // Get relationships settings
  716. $settings = $form_state['values']['instance']['settings']['relationships'];
  717. $form_state['values']['instance']['settings']['relationships']['relationship_types']= trim($settings['relationship_types']);
  718. // Make sure only one option is selected
  719. $option1test = $settings['option1_vocabs'];
  720. $option1 = isset($settings['option1_vocabs']) && array_pop($option1test);
  721. $option2 = (isset($settings['option2_vocab']) && $settings['option2_vocab']) || $settings['option2_parent'];
  722. $option3 = isset($settings['relationship_types']) && trim($settings['relationship_types']);
  723. if ($option1 && ($option2 || $option3) == 1 ||
  724. $option2 && ($option1 || $option3) == 1 ||
  725. $option3 && ($option1 || $option2) == 1) {
  726. form_set_error("instance][settings][relationships", t("Only one option is allowed to limit the relationship types."));
  727. return;
  728. }
  729. // For option3, make sure the supplied types are valid cvterms
  730. if ($option3) {
  731. $rel_types = explode(PHP_EOL, $settings['relationship_types']);
  732. foreach($rel_types AS $type) {
  733. $type = trim($type);
  734. // Ignore empty lines
  735. if ($type == '') {
  736. continue;
  737. }
  738. // Find the matching cvterm
  739. $sql = "SELECT cvterm_id FROM {cvterm} WHERE name = :name";
  740. $results = chado_query($sql, array(':name' => $type));
  741. $terms = array();
  742. while ($obj = $results->fetchObject()) {
  743. $terms[] = $obj;
  744. }
  745. // Don't save the form if a term can not be found or it matches more than one cvterm
  746. $cv = '';
  747. if (count($terms) == 0) {
  748. // If a term can not be found, maybe the type contains '|', parse it as 'vocabulary|cvterm'
  749. if (strpos($type, '|')) {
  750. $tmp = explode('|', $type, 2);
  751. $type = trim($tmp[1]);
  752. $cv = chado_get_cv(array('name' => trim($tmp[0])));
  753. if($cv) {
  754. $sql = "SELECT cvterm_id FROM {cvterm} WHERE name = :name AND cv_id = :cv_id";
  755. $results = chado_query($sql, array(':name' => $type, ':cv_id' => $cv->cv_id));
  756. while ($obj = $results->fetchObject()) {
  757. $terms[] = $obj;
  758. }
  759. }
  760. else {
  761. $cv = $tmp[0];
  762. }
  763. }
  764. if (count($terms) != 1) {
  765. $message = "The term '@type' can not be found.";
  766. $token = array('@type' => $type);
  767. if ($cv) {
  768. $message = "The term '@type' can not be found within the vocabulary '@vocab'.";
  769. $token['@vocab'] = $cv;
  770. }
  771. form_set_error("instance][settings][relationships][relationship_types",
  772. t($message, $token));
  773. }
  774. }
  775. else if (count($terms) > 1) {
  776. // If a type matches more than one term, parse it as 'vocabulary|cvterm' and try again
  777. if (strpos($type, '|')) {
  778. $tmp = explode('|', $type, 2);
  779. $type = trim($tmp[1]);
  780. $cv = chado_get_cv(array('name' => trim($tmp[0])));
  781. if ($cv) {
  782. $sql = "SELECT cvterm_id FROM {cvterm} WHERE name = :name AND cv_id = :cv_id";
  783. $results = chado_query($sql, array(':name' => $type, ':cv_id' => $cv->cv_id));
  784. while ($obj = $results->fetchObject()) {
  785. $terms[] = $obj;
  786. }
  787. }
  788. }
  789. if(count($terms) != 1) {
  790. form_set_error("instance][settings][relationships][relationship_types",
  791. t("The term '@type' matches more than one term. Please specify its vocabulary in the format of 'vocabulary|@type'.", array('@type' => $type)));
  792. }
  793. }
  794. }
  795. }
  796. // For option2: Make sure the parent term is a valid cvterm
  797. if ($option2) {
  798. $cv_id = $settings['option2_vocab'];
  799. $supertype = $settings['option2_parent'];
  800. $term = chado_get_cvterm(array(
  801. 'name' => trim($supertype),
  802. 'cv_id' => $cv_id,
  803. ));
  804. // Tripal cv autocomplete also allow cvterm synonyms, if the parent term doesn't match
  805. // a cvterm, try cvtermsynonym
  806. if (!$term) {
  807. $synonym = chado_get_cvterm(
  808. array(
  809. 'synonym' => array(
  810. 'name' => trim($supertype),
  811. )
  812. )
  813. );
  814. if ($synonym && $synonym->cv_id->cv_id == $cv_id) {
  815. $term = $synonym;
  816. }
  817. }
  818. if (!isset($term->cvterm_id)) {
  819. form_set_error("instance][settings][relationships][option2_parent",
  820. t("The term '@type' is not a valid term for the vocabulary selected.", array('@type' => $supertype)));
  821. }
  822. }
  823. }
  824. /**
  825. * @see TripalField::validate()
  826. */
  827. public function validate($entity_type, $entity, $langcode, $items, &$errors) {
  828. // If we don't have an entity then we don't want to validate. The case
  829. // where this could happen is when a user is editing the field settings
  830. // and trying to set a default value. In that case there's no entity and
  831. // we don't want to validate. There will always be an entity for creation
  832. // and update operations of a content type.
  833. if (!$entity) {
  834. return;
  835. }
  836. $field_name = $this->field['field_name'];
  837. $field_type = $this->field['type'];
  838. $field_table = $this->instance['settings']['chado_table'];
  839. $field_column = $this->instance['settings']['chado_column'];
  840. $base_table = $this->instance['settings']['base_table'];
  841. // Grab the chado record_id for this entity.
  842. $chado_record_id = NULL;
  843. if ($entity AND isset($entity->chado_record_id)) {
  844. $chado_record_id = $entity->chado_record_id;
  845. }
  846. // Validate each releationship.
  847. foreach ($items as $delta => $item) {
  848. $item_errors = $this->validateItem($item, $chado_record_id);
  849. if (!empty($item_errors)) {
  850. $errors[$field_name][$delta][$langcode] = $item_errors;
  851. }
  852. }
  853. }
  854. /**
  855. * Validate a Single relationship.
  856. *
  857. * @param $item
  858. * A single item from the $items array passed to TripalField::validate().
  859. * @return
  860. * An array of errors where each has a:
  861. * - error: this is an error code which is the name of the field.
  862. * - message: A message to show the user describing the problem.
  863. */
  864. public function validateItem($item, $chado_record_id = NULL) {
  865. $errors = array();
  866. $field_name = $this->field['field_name'];
  867. $field_type = $this->field['type'];
  868. $field_table = $this->instance['settings']['chado_table'];
  869. $field_column = $this->instance['settings']['chado_column'];
  870. $base_table = $this->instance['settings']['base_table'];
  871. // 'nd_reagent_relationship' and 'project_relationship' have different column names from
  872. // subject_id/object_id. Do a pattern matching to get the column names.
  873. $subject_id_key = $this->subject_id_column;
  874. $object_id_key = $this->object_id_column;
  875. $subject_id = $item['chado-' . $field_table . '__' . $subject_id_key];
  876. $object_id = $item['chado-' . $field_table . '__' . $object_id_key];
  877. $type_id = $item['chado-' . $field_table . '__type_id'];
  878. $type_id = isset($item['type_id']) ? $item['chado-' . $field_table . '__type_id'] : $type_id;
  879. $type_name = isset($item['type_name']) ? $item['type_name'] : '';
  880. $voc_id = isset($item['vocabulary']) ? $item['vocabulary'] : '';
  881. $subject_name = isset($item['subject_name']) ? $item['subject_name'] : '';
  882. $object_name = isset($item['object_name']) ? $item['object_name'] : '';
  883. // If the row is empty then just continue, there's nothing to validate.
  884. if (!$type_id and !$type_name and !$subject_name and !$object_name) {
  885. return;
  886. }
  887. // Check: Make sure we have values for all of the fields.
  888. if (!$type_name && !$type_id) {
  889. $errors[] = array(
  890. 'error' => 'sbo__relationship',
  891. 'message' => t("Please provide the type of relationship."),
  892. 'element' => 'type',
  893. );
  894. }
  895. if (!$subject_name) {
  896. $errors[] = array(
  897. 'error' => 'sbo__relationship',
  898. 'message' => t("Please provide the subject of the relationship."),
  899. 'element' => 'subject',
  900. );
  901. }
  902. if (!$object_name) {
  903. $errors[] = array(
  904. 'error' => 'sbo__relationship',
  905. 'message' => t("Please provide the object of the relationship."),
  906. 'element' => 'object',
  907. );
  908. }
  909. // Check: Cvterm exists.
  910. if (!$type_id AND !$type_name) {
  911. $errors[] = array(
  912. 'error' => 'sbo__relationship',
  913. 'message' => t("We were unable to find the type you specified. Please check spelling and that the term already exists."),
  914. 'element' => 'type',
  915. );
  916. }
  917. elseif ($type_name AND $voc_id) {
  918. $val = array(
  919. 'cv_id' => $voc_id,
  920. 'name' => $type_name
  921. );
  922. $cvterm = chado_generate_var('cvterm', $val);
  923. if (!isset($cvterm->cvterm_id)) {
  924. $errors[] = array(
  925. 'error' => 'sbo__relationship',
  926. 'message' => t("We were unable to find the type you specified. Please check spelling and that the term already exists."),
  927. 'element' => 'type',
  928. );
  929. }
  930. }
  931. // Before submitting this form we need to make sure that our subject_id and
  932. // object_ids are real records. There are two ways to get the record, either
  933. // just with the text value or with an [id: \d+] string embedded. If the
  934. // later we will pull it out.
  935. $subject_id = '';
  936. $fkey_rcolumn = $this->schema['foreign keys'][$base_table]['columns'][$subject_id_key];
  937. $matches = array();
  938. if(preg_match('/\[id: (\d+)\]/', $subject_name, $matches)) {
  939. $subject_id = $matches[1];
  940. $values = array($fkey_rcolumn => $subject_id);
  941. $subject = chado_select_record($base_table, array($fkey_rcolumn), $values);
  942. if (count($subject) == 0) {
  943. $errors[] = array(
  944. 'error' => 'sbo__relationship',
  945. 'message' => t("The subject record cannot be found using the specified id (e.g. [id: xx])."),
  946. 'element' => 'subject',
  947. );
  948. }
  949. }
  950. else {
  951. // Otherwise we need to look it up using the name field determined in the
  952. // constructor for the current field. There may be more then one name field
  953. // (e.g. organism: genus + species) so we want to check both.
  954. $sql = 'SELECT ' . $fkey_rcolumn . ' FROM {' . $base_table . '} WHERE ' . implode('||', $this->base_name_columns) . '=:keyword';
  955. $subject = chado_query($sql, [':keyword' => $subject_name])->fetchAll();
  956. if (count($subject) == 0 AND $chado_record_id) {
  957. $errors[] = array(
  958. 'error' => 'sbo__relationship',
  959. 'message' => t("The subject record cannot be found. Please check spelling."),
  960. 'element' => 'subject',
  961. );
  962. }
  963. elseif (count($subject) > 1) {
  964. $errors[] = array(
  965. 'error' => 'sbo__relationship',
  966. 'message' => t("The subject is not unique and therefore the relationship cannot be made."),
  967. 'element' => 'subject',
  968. );
  969. }
  970. }
  971. // Now check for a matching object.
  972. $object_id = '';
  973. $fkey_rcolumn = $this->schema['foreign keys'][$base_table]['columns'][$object_id_key];
  974. $matches = array();
  975. if (preg_match('/\[id: (\d+)\]/', $object_name, $matches)) {
  976. $object_id = $matches[1];
  977. $values = array($fkey_rcolumn => $object_id);
  978. $object = chado_select_record($base_table, array($fkey_rcolumn), $values);
  979. if (count($subject) == 0 AND $chado_record_id) {
  980. $errors[] = array(
  981. 'error' => 'sbo__relationship',
  982. 'message' => t("The object record cannot be found using the specified id (e.g. [id: xx])."),
  983. 'element' => 'object',
  984. );
  985. }
  986. }
  987. else {
  988. // Otherwise we need to look it up using the name field determined in the
  989. // constructor for the current field. There may be more then one name field
  990. // (e.g. organism: genus + species) so we want to check both.
  991. $sql = 'SELECT ' . $fkey_rcolumn . ' FROM {' . $base_table . '} WHERE ' . implode('||', $this->base_name_columns) . '=:keyword';
  992. $object = chado_query($sql, [':keyword' => $object_name]);
  993. if (count($object) == 0) {
  994. $errors[] = array(
  995. 'error' => 'sbo__relationship',
  996. 'message' => t("The object record cannot be found. Please check spelling."),
  997. 'element' => 'object',
  998. );
  999. }
  1000. elseif (count($object) > 1) {
  1001. $errors[] = array(
  1002. 'error' => 'sbo__relationship',
  1003. 'message' => t("The object is not unique and therefore the relationship cannot be made."),
  1004. 'element' => 'object',
  1005. );
  1006. }
  1007. }
  1008. // Make sure that either our object or our subject refers to the base record.
  1009. if ($object_id AND $subject_id) {
  1010. if ($object_id != $chado_record_id and $subject_id != $chado_record_id) {
  1011. $errors[] = array(
  1012. 'error' => 'sbo__relationship',
  1013. 'message' => t("Either the subject or the object in the relationship must refer to this record."),
  1014. 'element' => 'row',
  1015. );
  1016. }
  1017. }
  1018. // Make sure that the object and subject are not both the same thing.
  1019. if ($object_id AND $subject_id) {
  1020. if ($object_id == $subject_id) {
  1021. $errors[] = array(
  1022. 'error' => 'sbo__relationship',
  1023. 'message' => t("The subject and the object in the relationship cannot both refer to the same record."),
  1024. 'element' => 'row',
  1025. );
  1026. }
  1027. }
  1028. return $errors;
  1029. }
  1030. /**
  1031. * @see ChadoField::queryOrder()
  1032. */
  1033. public function queryOrder($query, $order) {
  1034. }
  1035. /**
  1036. * Retrieve the schema's
  1037. */
  1038. public function getRelTableSchema() {
  1039. return $this->schema;
  1040. }
  1041. public function getBaseTableSchema() {
  1042. return $this->base_schema;
  1043. }
  1044. /**
  1045. * Retrieve the subject/object key columns.
  1046. */
  1047. public function getSubjectIdColumn() {
  1048. return $this->subject_id_column;
  1049. }
  1050. public function getObjectIdColumn() {
  1051. return $this->object_id_column;
  1052. }
  1053. /**
  1054. * Retrieve the base name columns.
  1055. */
  1056. public function getBaseNameColumns() {
  1057. return $this->base_name_columns;
  1058. }
  1059. /**
  1060. * Retrieve the base type column.
  1061. */
  1062. public function getBaseTypeColumn() {
  1063. return $this->base_type_column;
  1064. }
  1065. }