/**
  * @param Tx_Typo3Agencies_Domain_Model_Filter $filter
  * @param Tx_Typo3Agencies_Domain_Model_Order $order
  * @return array|\Tx_Extbase_Persistence_QueryResultInterface
  */
 public function findByNameOrCity(Tx_Typo3Agencies_Domain_Model_Filter $filter, Tx_Typo3Agencies_Domain_Model_Order $order)
 {
     $query = $this->createQuery();
     $searchString = '%' . mysql_real_escape_string($filter->getLocation()) . '%';
     if ($order) {
         $ordering = $order->getOrderings();
         $query->setOrderings($ordering);
     }
     $query->matching($query->logicalAnd(array($query->equals('approved', TRUE), $query->logicalOr(array($query->equals('payed_until_date', 0), $query->greaterThanOrEqual('payed_until_date', time()))), $query->logicalOr(array($query->like('name', $searchString), $query->like('city', $searchString))))));
     return $query->execute();
 }
 /**
  * Finds all references by the specified filter
  *
  * @param Tx_Typo3Agencies_Domain_Model_Filter $filter The filter the references must apply to
  * @param unknown_type $offset
  * @param unknown_type $rowsPerPage
  * @param unknown_type $justCount
  * @param unknown_type $includeDeactivated
  * @return array The references
  */
 public function findAllByFilter(Tx_Typo3Agencies_Domain_Model_Filter $filter, $offset = NULL, $rowsPerPage = NULL, $justCount = FALSE, $includeDeactivated = FALSE)
 {
     $query = $this->createQuery();
     $where = array();
     if ($includeDeactivated) {
         $where[] = '1=1';
     } else {
         $where[] = 'tx_typo3agencies_domain_model_reference.deactivated = 0';
     }
     if ($filter->getSearchTerm() != '') {
         $escapedSearchTerm = $GLOBALS['TYPO3_DB']->fullQuoteStr('%' . $filter->getSearchTerm() . '%');
         $where[] = '(tx_typo3agencies_domain_model_reference.about LIKE ' . $escapedSearchTerm . ' OR tx_typo3agencies_domain_model_reference.title LIKE ' . $escapedSearchTerm . ' OR tx_typo3agencies_domain_model_reference.description LIKE ' . $escapedSearchTerm . ' OR tx_typo3agencies_domain_model_reference.tags LIKE ' . $escapedSearchTerm . ' OR tx_typo3agencies_domain_model_reference.conclusion LIKE ' . $escapedSearchTerm . ')';
     }
     if ($filter->getCategory() > 0) {
         $where[] = 'tx_typo3agencies_domain_model_reference.category = ' . intval($filter->getCategory());
     }
     if ($filter->getIndustry() > 0) {
         $where[] = 'tx_typo3agencies_domain_model_reference.industry = ' . intval($filter->getIndustry());
     }
     if ($filter->getRevenue() > 0) {
         $where[] = 'tx_typo3agencies_domain_model_reference.revenue = ' . intval($filter->getRevenue());
     }
     if ($filter->isListed()) {
         $where[] = 'tx_typo3agencies_domain_model_reference.listed = 1';
     }
     $limit = ' LIMIT ' . intval($offset) . ', ' . intval($rowsPerPage);
     if ($justCount || $offset == NULL || $rowsPerPage == NULL) {
         $limit = '';
     }
     $query->statement('SELECT tx_typo3agencies_domain_model_reference.* FROM tx_typo3agencies_domain_model_reference left join tx_typo3agencies_domain_model_agency on tx_typo3agencies_domain_model_reference.agency = tx_typo3agencies_domain_model_agency.uid WHERE ' . implode(' AND ', $where) . $GLOBALS['TSFE']->sys_page->enableFields('tx_typo3agencies_domain_model_reference') . ' ORDER BY tx_typo3agencies_domain_model_agency.member DESC, tx_typo3agencies_domain_model_reference.crdate DESC' . $limit);
     $result = $query->execute();
     if ($justCount) {
         return count($result->toArray());
     }
     return $result;
 }