sbo__relationship.inc 46 KB

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