/** * This method will get the IDS of the GSMs we want to filter by * * This should cause no problems with doubling up on relaitonships as it creates its own db object, * then just does a check against paper_id with out requiring a new relationship * * @param array $values an array of selected gsms 'ranges' that come in the form of '100-150' */ public function gsms($values) { // create a new db object so we dont screw with the relationship on the search. $db = new Database(); $db->select('paper_id')->from('collections')->join('pigments', 'collections.id', 'pigments.collection_id')->join('sheets', 'pigments.id', 'sheets.pigment_id')->join('gsms', 'sheets.id', 'gsms.sheet_id')->groupby('paper_id'); // loop through each of the values (100-150), break them apart into a min/max and then do a between foreach ($values as $value) { $value = explode('-', $value); if (isset($value[0]) && isset($value[1]) && $value[0] < $value[1]) { $db->orwhere('gsms.name BETWEEN', "'" . $value[0] . "' AND '" . $value[1] . "'", false); } } $result = $db->get(); $results = $result->result_array(false); // loop through each of the resultsm put the paper_ids into a cleaned array then add it to the searches params $papers = array(); foreach ($results as $result) { $papers[] = $result['paper_id']; } if (count($papers)) { $this->db->in('papers.id', $papers); // note how this is $this->db :: ie hits the searches object to filter the papers by } else { $this->db->where('papers.id', '0'); /// if there are no paper with that gsm, force the main query to return no results. } }