/**
  * Check if the array has an non empty item which has $language as a key
  * 
  * @param string $language
  * @return bool
  */
 public function has_value($language)
 {
     if (!isset($this->arr[$language])) {
         $cache = MslsSqlCacher::init(__CLASS__)->set_params($this->args);
         $this->arr[$language] = $cache->get_var($cache->prepare("SELECT count(ID) FROM {$cache->posts} WHERE YEAR(post_date) = %d AND post_status = 'publish'", $this->get_arg(0, 0)));
     }
     return (bool) $this->arr[$language];
 }
 /**
  * Check if the array has an non empty item which has $language as a key
  *
  * @param string $language
  * @return bool
  */
 public function has_value($language)
 {
     if (!isset($this->arr[$language])) {
         $date = new DateTime();
         $cache = MslsSqlCacher::init(__CLASS__)->set_params($this->args);
         $this->arr[$language] = $cache->get_var($cache->prepare("SELECT count(ID) FROM {$cache->posts} WHERE DATE(post_date) = %s AND post_status = 'publish'", $date->setDate($this->get_arg(0, 0), $this->get_arg(1, 0), $this->get_arg(2, 0))->format('Y-m-d')));
     }
     return (bool) $this->arr[$language];
 }
 /**
  * Execute filter. Exclude translated posts from WP_Query
  * @param WP_Query $query
  * @return false or WP_Query object
  */
 public function execute_filter(WP_Query $query)
 {
     $blogs = MslsBlogCollection::instance()->get();
     if (!filter_has_var(INPUT_GET, 'msls_filter')) {
         return false;
     }
     $id = filter_input(INPUT_GET, 'msls_filter', FILTER_SANITIZE_NUMBER_INT);
     if (isset($blogs[$id])) {
         $cache = MslsSqlCacher::init(__CLASS__)->set_params(__METHOD__);
         // load post we need to exclude (already have translation) from search query
         $posts = $cache->get_results($cache->prepare("SELECT option_id, option_name FROM {$cache->options} WHERE option_name LIKE %s AND option_value LIKE %s", 'msls_%', '%"' . $blogs[$id]->get_language() . '"%'));
         $exclude_ids = array();
         foreach ($posts as $post) {
             $exclude_ids[] = substr($post->option_name, 5);
         }
         $query->query_vars['post__not_in'] = $exclude_ids;
         return $query;
     }
     return false;
 }
 /**
  * Cleanup the options
  *
  * Removes all values of the current blogs which are stored in the
  * options-table and returns true if it was successful.
  * @return boolean
  */
 public static function cleanup()
 {
     if (delete_option('msls')) {
         $cache = MslsSqlCacher::init(__CLASS__)->set_params(__METHOD__);
         $sql = $cache->prepare("DELETE FROM {$cache->options} WHERE option_name LIKE %s", 'msls_%');
         return (bool) $cache->query($sql);
     }
     return false;
 }
 /**
  * Verify the static init-method
  * @covers MslsSqlCacher::init
  * @covers MslsSqlCacher::__construct
  */
 function test_init_method()
 {
     $obj = MslsSqlCacher::init('MslsSqlCacherTest');
     $this->assertInstanceOf('MslsSqlCacher', $obj);
     return $obj;
 }