EPSCoR / ERCore

ERcore content management system to assist with NSF EPSCoR reporting
4 stars 7 forks source link

Patent changes #63

Open khuffman opened 8 years ago

khuffman commented 8 years ago

I was working on Table E issues and started looking on the first item: Patents, which on our site had the following problem described here: https://github.com/EPSCoR/ERCore/issues/15#issuecomment-101070138 so if a patent has the date fields Provisional Date, Award Date and License Date all filled, it would show up in all three rows in Table E, which is not correct. The correct is it should show up in "Awarded" and "Licensed" rows only (if those date fields have values in them). Here are the changes we are doing to our Patent content type and our outputs.inc file to solve this issue:

` private function generate_patent_data($count, $period){ $data = array();

    foreach (array("Awarded"=>'field_er_patent_award_date', "Pending"=>'field_er_filing_date', "Licensed"=>'field_er_patent_date') as $label=>$date_field){
        $query = db_select('node', 'node');
        $query->condition("node.type", 'er_patent', '=');
        $query->innerJoin("field_data_{$date_field}", 'date', 'node.nid = date.entity_id');
        $this->applyDateRange($query, $date_field, $period);

          if ($label == "Pending") {   //go through Pending and strip out nid's that also in Awarded or Licenced
            //Query for nid of patents that are awarded
            $queryaward = db_select('node', 'node');
            $queryaward->addField('node', 'nid');
            $queryaward->condition("node.type", 'er_patent', '=');
            $queryaward->innerJoin("field_data_field_er_patent_award_date", 'date', 'node.nid = date.entity_id');
            $this->applyDateRange($queryaward, 'field_er_patent_award_date', $period);

            //Query for nid of patents that are licensed
            $querylicensed = db_select('node', 'node');
            $querylicensed->addField('node', 'nid');
            $querylicensed->condition("node.type", 'er_patent', '=');
            $querylicensed->innerJoin("field_data_field_er_patent_date", 'date', 'node.nid = date.entity_id');
            $this->applyDateRange($querylicensed, 'field_er_patent_date', $period);

            //Do a union of above: this will return all patents that are either awarded or licensed
            $mergedquery = $queryaward->union($querylicensed);
            $result = $mergedquery->execute();
            while ($tempvar = $result->fetchAssoc()){
                $nidawardlicense[] = $tempvar; 
            }
            if (!empty($nidawardlicense)){
            //Now append a "NOT IN" to the query, so under section "Pending" only show patents that are not awarded or licensed
            $query->condition('node.nid', $nidawardlicense , 'NOT IN');
            }
         }

      $data[$label] = $this->generate_node_output($count, $query);
    }

    return $data;

}

`

khuffman commented 8 years ago

Sorry, the code lines didn't go inside the code box, so the code starts with:

private function generate_patent_data($count, $period){

and ends with: }

ercore commented 8 years ago

@khuffman I am going to leave this issue open so I can investigate the content type, the output, and the reporting requirements a little further.

Thank you for posting this and sharing your solution.