/**
  * Get all customers.
  *
  * @return array Array of customers.
  */
 private function getRealCustomers($onlySubscribed)
 {
     $where = array("c.cAktiv = 'Y'");
     $join = '';
     $query = "SELECT c.kKunde,\n\t\t\t\t\t\t c.kKundengruppe as kKundengruppe,\n\t\t\t\t\t\t c.kSprache,\n\t\t\t\t\t\t c.cKundenNr,\n\t\t\t\t\t\t CASE c.cAnrede\n\t\t\t\t\t\t\tWHEN 'w' THEN 'f'\n\t\t\t\t\t\t\tWHEN 'm' THEN 'm'\n\t\t\t\t\t\t END as cAnrede,\n\t\t\t\t\t\t c.cTitel,\n\t\t\t\t\t\t c.cVorname,\n\t\t\t\t\t\t c.cNachname,\n\t\t\t\t\t\t c.cFirma,\n\t\t\t\t\t\t c.cZusatz,\n\t\t\t\t\t\t c.cStrasse,\n\t\t\t\t\t\t c.cHausnummer,\n\t\t\t\t\t\t c.cAdressZusatz,\n\t\t\t\t\t\t c.cPLZ,\n\t\t\t\t\t\t c.cOrt,\n\t\t\t\t\t\t c.cBundesland,\n\t\t\t\t\t\t c.cLand,\n\t\t\t\t\t\t c.cTel,\n\t\t\t\t\t\t c.cMobil,\n\t\t\t\t\t\t c.cFax,\n\t\t\t\t\t\t c.cMail,\n\t\t\t\t\t\t c.cUSTID,\n\t\t\t\t\t\t c.cWWW,\n\t\t\t\t\t\t c.cSperre,\n\t\t\t\t\t\t c.fGuthaben,\n\t\t\t\t\t\t if(ns.nAktiv, 1, 0) as cNewsletter,\n\t\t\t\t\t\t c.dGeburtstag,\n\t\t\t\t\t\t c.fRabatt,\n\t\t\t\t\t\t c.cHerkunft,\n\t\t\t\t\t\t c.dErstellt,\n\t\t\t\t\t\t c.dVeraendert,\n\t\t\t\t\t\t c.cAktiv,\n\t\t\t\t\t\t c.cAbgeholt,\n\t\t\t\t\t\t c.nRegistriert\n                         FROM " . self::CUSTOMERS_TABLE . ' c
                      LEFT JOIN ' . self::NEWSLETTER_SUBSCRIBER_TABLE . ' ns ON c.kKunde = ns.kKunde';
     $hours = filter_input(INPUT_POST, 'hours');
     // Get only customer modified in $hours hours.
     if (empty($hours) === false) {
         $where[] = "(c.dVeraendert >= DATE_SUB(NOW(), INTERVAL {$hours} HOUR) OR c.dVeraendert = '0000-00-00 00:00:00')";
     }
     $group = filter_input(INPUT_POST, 'group');
     // Get only customers from requested group.
     if (empty($group) === false) {
         $where[] = "c.kKundengruppe = {$group}";
     }
     $emails = json_decode(filter_input(INPUT_POST, 'emails'));
     // Get only customers for requested emails.
     if ($emails !== null && count($emails) > 0) {
         $where[] = "c.cMail IN ('" . implode("','", $emails) . "')";
     }
     // Filter by subscribed only.
     if ($onlySubscribed === true) {
         $where[] = 'ns.nAktiv = 1';
     }
     // Add where if customers should be filtered.
     if (empty($where) === false) {
         $query .= $join . ' WHERE ' . implode(' AND ', $where);
     }
     $limit = filter_input(INPUT_POST, 'limit', FILTER_VALIDATE_INT);
     $offset = filter_input(INPUT_POST, 'offset', FILTER_VALIDATE_INT);
     if ($limit) {
         $offset = $offset ? $offset : 0;
         $query .= " LIMIT {$offset}, {$limit} ";
     }
     $customers = $GLOBALS['DB']->executeQuery($query, 9);
     $customersToReturn = array();
     if (empty($customers)) {
         return $customersToReturn;
     }
     foreach ($customers as $customer) {
         $customer = $this->decryptData($customer);
         $customerToReturn = array();
         // Create customer using the field definition.
         foreach (self::getFieldDefinitions() as $fieldDefinition) {
             // Name of the field in db.
             $fieldName = $fieldDefinition['id'];
             // If field is not requested, don't add it.
             if (self::isFieldRequested($fieldName) === false) {
                 continue;
             }
             // Determine whether the field exists in table and has a value.
             $fieldValid = array_key_exists($fieldName, $customer) && empty($customer[$fieldName]) === false;
             // If current field is customer group, get a name of group and go to the next field.
             if ($fieldValid === true && $fieldName === 'kKundengruppe') {
                 $customerGroup = new Kundengruppe($customer[$fieldName]);
                 $customerToReturn[$fieldName] = $customerGroup->getName();
                 continue;
             }
             // Read field value.
             $customerToReturn[$fieldName] = $fieldValid === true ? $customer[$fieldName] : '';
         }
         // Add customer to the return list.
         $customersToReturn[] = $customerToReturn;
     }
     return $customersToReturn;
 }
 private function getKundenAttribute($kKunde)
 {
     $kunde = new Kunde($kKunde);
     $kundengruppe = new Kundengruppe($kunde->kKundengruppe);
     return array("mail" => $kunde->cMail, "vorname" => $kunde->cVorname, "nachname" => $kunde->cNachname, "anrede" => $kunde->cAnrede, "kundengruppe" => $kundengruppe->getName(), "strasse" => $kunde->cStrasse, "firma" => $kunde->cFirma, "titel" => $kunde->cTitel, "plz" => $kunde->cPLZ, "ort" => $kunde->cOrt, "bundesland" => $kunde->cBundesland, "land" => $kunde->cLand, "tel" => $kunde->cTel, "mobil" => $kunde->cMobil, "geburtstag" => $kunde->dGeburtstag, "kundennummer" => $kunde->cKundenNr, "istkunde" => "Y");
 }