SHARE
TWEET

cludder.selex.inc

benjamin_mcf Dec 23rd, 2011 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * @file
  5.  *
  6.  * Functions that return data used in the subject field.
  7.  */
  8. function grab_subjects() {
  9.   $squery = db_select('taxonomy_term_data', 't');
  10.   $squery
  11.         ->fields('t', array('vid', 'name', 'tid', 'weight'))
  12.         ->condition('t.vid', 2, '=')
  13.         ->orderBy('t.weight', 'ASC');
  14.   $sresult = $squery->execute();
  15.   $soptions = array();
  16.   foreach ($sresult as $srow) {
  17.         $soptions[$srow->tid] = $srow->name;
  18.   };
  19.   return $soptions;
  20. }
  21.  
  22.  
  23. function grab_grades() {
  24.   $gquery = db_select('taxonomy_term_data', 't');
  25.   $gquery
  26.         ->fields('t', array('vid', 'name', 'tid', 'weight'))
  27.         ->condition('t.vid', 3, '=')
  28.         ->orderBy('t.weight', 'ASC');
  29.   $gresult = $gquery->execute();
  30.   $goptions = array();
  31.   foreach ($gresult as $grow) {
  32.         $goptions[$grow->tid] = $grow->name;
  33.   };
  34.   return $goptions;
  35. }
  36.  
  37. function grab_strands($subjids, $gradids) {    
  38.      
  39.   $strquery = db_select('taxonomy_term_data', 'str');
  40.   $strquery->join('field_data_field_strand_subject', 's', 'str.tid = s.entity_id');
  41.   $strquery->join(' field_data_field_strand_grade', 'g', 'str.tid = g.entity_id');
  42.   $strquery->fields('str', array('vid', 'name', 'tid'));
  43.   $strquery->fields('s', array('field_strand_subject_tid'));
  44.   $strquery->fields('g', array('field_strand_grade_tid'));
  45.   $db_or = db_or();
  46.   foreach ($subjids as $subjid) {
  47.       $db_or->condition('s.field_strand_subject_tid', $subjid, '=');    
  48.       $strquery->condition($db_or);
  49.   }
  50.   $db_more = db_or();
  51.   foreach ($gradids as $gradid) {
  52.       $db_more->condition('g.field_strand_grade_tid', $gradid, '=');    
  53.       $strquery->condition($db_more);
  54.   }
  55.   $strresult = $strquery->execute();
  56.   $stroptions = array();
  57.   foreach ($strresult as $strrow) {
  58.         $stroptions[$strrow->tid] = $strrow->name;
  59.   };
  60.   return $stroptions;
  61. }
  62.  
  63. function grab_topics($subjids, $gradids, $strandids) {
  64.      
  65.      
  66.   $topquery = db_select('taxonomy_term_data', 't');
  67.   $topquery->join('field_data_field_topic_subject', 's', 't.tid = s.entity_id');
  68.   $topquery->join('field_data_field_topic_grade', 'g', 't.tid = g.entity_id');
  69.   if (!empty($strandids) && (in_array(15, $gradids) || in_array(16, $gradids))) {
  70.       $topquery->join('field_data_field_topic_strand', 'str', 't.tid = str.entity_id');
  71.   }
  72.   $topquery->fields('t', array('vid', 'name', 'tid'));
  73.   $topquery->fields('s', array('field_topic_subject_tid'));
  74.   $topquery->fields('g', array('field_topic_grade_tid'));
  75.   if (!empty($strandids) && (in_array(15, $gradids) || in_array(16, $gradids))) {
  76.       $topquery->fields('str', array('field_topic_strand_tid'));
  77.   }
  78.   $topquery->condition('t.vid', 5, '=');
  79.   $db_or = db_or();
  80.   foreach ($subjids as $subjid) {
  81.       $db_or->condition('s.field_topic_subject_tid', $subjid, '=');    
  82.       $topquery->condition($db_or);
  83.   }
  84.   $db_more = db_or();
  85.   foreach ($gradids as $gradid) {
  86.       $db_more->condition('g.field_topic_grade_tid', $gradid, '=');    
  87.       $topquery->condition($db_more);
  88.   }
  89.   $topresult = $topquery->execute();
  90.   $topoptions = array();
  91.   $strandids[] = 539;
  92.   foreach ($topresult as $toprow) {
  93.       if (!(isset($toprow->field_topic_strand_tid))) {
  94.         $topoptions[$toprow->tid] = $toprow->name;
  95.       }
  96.       if ((isset($toprow->field_topic_strand_tid)) && (in_array($toprow->field_topic_strand_tid, $strandids))) {
  97.         $topoptions[$toprow->tid] = $toprow->name;
  98.       }
  99.   };
  100.   return $topoptions;
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top