123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- function tripal_pub_preprocess_tripal_pub_relationships(&$variables) {
-
- $pub = $variables['node']->pub;
-
-
-
-
- $sql = "
- SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type
- FROM {pub_relationship} PR
- INNER JOIN {pub} P ON PR.object_id = P.pub_id
- INNER JOIN {cvterm} CVT ON PR.type_id = CVT.cvterm_id
- LEFT JOIN public.chado_pub CP ON P.pub_id = CP.pub_id
- WHERE PR.subject_id = :subject_id
- ";
- $as_subject = chado_query($sql, array(':subject_id' => $pub->pub_id));
- $sql = "
- SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type
- FROM {pub_relationship} PR
- INNER JOIN {pub} P ON PR.subject_id = P.pub_id
- INNER JOIN {cvterm} CVT ON PR.type_id = CVT.cvterm_id
- LEFT JOIN public.chado_pub CP ON P.pub_id = CP.pub_id
- WHERE PR.object_id = :object_id
- ";
- $as_object = chado_query($sql, array(':object_id' => $pub->pub_id));
-
- $relationships = array();
- $relationships['object'] = array();
- $relationships['subject'] = array();
-
- while ($relationship = $as_object->fetchObject()) {
-
- $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
- $sub_type = t(preg_replace('/_/', " ", $relationship->sub_type));
- if (!array_key_exists($rel_type, $relationships['object'])) {
- $relationships['object'][$rel_type] = array();
- }
- if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) {
- $relationships['object'][$rel_type][$sub_type] = array();
- }
- $relationships['object'][$rel_type][$sub_type][] = $relationship;
- }
-
- while ($relationship = $as_subject->fetchObject()) {
-
- $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
- $obj_type = t(preg_replace('/_/', " ", $relationship->obj_type));
- if (!array_key_exists($rel_type, $relationships['subject'])) {
- $relationships['subject'][$rel_type] = array();
- }
- if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) {
- $relationships['subject'][$rel_type][$obj_type] = array();
- }
- $relationships['subject'][$rel_type][$obj_type][] = $relationship;
- }
- $pub->all_relationships = $relationships;
- }
|