sbo__relationship.inc 45 KB

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