I am very familiar with using exposed filters in views but have finally decided it's time to write my own module as the exposed filters aren't offering exactly what I require.

I have a list of storied and want to create a form to filter them. This form will contain the following filters: Year created (checkbox) Tags (checkboxes) Keyword (textfield)

I'll also need a pager but plan to implement this later (one step at a time).

So far I've created a basic form (i've only show the year checkbox to save space)

$form['search_form_year'] = array (
    '#type' => 'checkboxes',
    '#options' => $years,
    '#title' => t('Year filter'),
  );


  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
   );

  $form['#submit'][] = 'blog_search_process_form';

I'm not totally sure how to query the database but from reading around i've decided that Entity field query is the best (please correct me if i'm wrong).

So in my callback function i've written:

function blog_search_process_form($form,  &$form_state) {

  //get the dates selected and convert into first and last min of year

if (isset($form_state['values']['search_form_year'])){
    foreach($form_state['values']['search_form_year'] as $k => $year) {
       if ($k == $year) {
        $first_minute_of_year = mktime(0, 0, 0, 1, 1, $year);
        $last_minute_of_year = mktime(23, 59, 59, 12, 31, $year);
      }
    }
 }
  $conditions = array();

  $efq = new EntityFieldQuery();
  $efq->entityCondition('entity_type', 'node');
  $efq->entityCondition('bundle', 'article');
  $efq->propertyCondition('created', array($first_minute_of_year, $last_minute_of_year), 'BETWEEN');

  $result = $efq->execute();  
}

This is where i'm running into problems. I want to tick a date box for nodes published in 2015 and have had to use the propertyCondition looking for dates between the first minute of the year and last minute of the year.

But if i select two years: 2015 and 2013 How do I build the efq query bit by bit, one for each year. I was going to put the foreach loop between the lines below like so:

$efq->entityCondition('bundle', 'article');    
 foreach($form_state['values']['search_form_year'] as $k => $year) {
       if ($k == $year) {
        $first_minute_of_year = mktime(0, 0, 0, 1, 1, $year);
        $last_minute_of_year = mktime(23, 59, 59, 12, 31, $year);
        $efq->propertyCondition('created', array($first_minute_of_year, $last_minute_of_year), 'BETWEEN');
      }
    }

$result = $efq->execute();

but this just kills the script.

Can anybody perhaps offer a better way to do this, or do it correctly the way i've chosen?

Sorry for the long post.