Esempio n. 1
0
 public function exportMembers()
 {
     $db = JFactory::getDBO();
     foreach ($this->filter as $k => $v) {
         if (empty($v)) {
             $this->filter[$k] = array();
         }
     }
     // Assemble Database call
     if (!in_array('notconfig', $this->filter['status'])) {
         $where = array();
         if (!empty($this->filter['planid'])) {
             $where[] = '`plan` IN (' . implode(',', $this->filter['planid']) . ')';
         }
         $query = 'SELECT a.id, a.userid' . ' FROM #__acctexp_subscr AS a' . ' INNER JOIN #__users AS b ON a.userid = b.id';
         if (!empty($where)) {
             $query .= ' WHERE ( ' . implode(' OR ', $where) . ' )';
         }
         if (!empty($this->filter['status'])) {
             $stati = array();
             foreach ($this->filter['status'] as $status) {
                 $stati[] = 'LOWER( `status` ) = \'' . strtolower($status) . '\'';
             }
             if (!empty($where)) {
                 $query .= ' AND (' . implode(' OR ', $stati) . ')';
             } else {
                 $query .= ' WHERE (' . implode(' OR ', $stati) . ')';
             }
         }
         if (!empty($this->filter['orderby'])) {
             $query .= ' ORDER BY ' . $this->filter['orderby'] . '';
         }
     } else {
         $query = 'SELECT DISTINCT b.id AS `userid`' . ' FROM #__users as b' . ' WHERE b.id NOT IN (' . ' SELECT a.userid' . ' FROM #__acctexp_subscr as a);';
     }
     $db->setQuery($query);
     $descriptions = AECToolbox::rewriteEngineExplain($this->options['rewrite_rule']);
     $descarray = explode(';', $descriptions);
     $this->exphandler->putDescription($descarray);
     // Fetch Userlist
     $userlist = $db->loadObjectList();
     // Plans Array
     $plans = array();
     // Iterate through userlist
     if (!empty($userlist)) {
         foreach ($userlist as $entry) {
             $metaUser = new metaUser($entry->userid);
             if (!empty($entry->id)) {
                 $metaUser->moveFocus($entry->id);
             }
             if ($metaUser->hasSubscription) {
                 $planid = $metaUser->focusSubscription->plan;
                 if (!isset($plans[$planid])) {
                     $plans[$planid] = new SubscriptionPlan();
                     $plans[$planid]->load($planid);
                 }
                 $invoiceid = aecInvoiceHelper::lastClearedInvoiceIDbyUserID($metaUser->userid, $planid);
                 if ($invoiceid) {
                     $invoice = new Invoice();
                     $invoice->load($invoiceid);
                     $line = AECToolbox::rewriteEngine($this->options['rewrite_rule'], $metaUser, $plans[$planid], $invoice);
                 } else {
                     $line = AECToolbox::rewriteEngine($this->options['rewrite_rule'], $metaUser, $plans[$planid]);
                 }
             } else {
                 $line = AECToolbox::rewriteEngine($this->options['rewrite_rule'], $metaUser);
             }
             $larray = explode(';', $line);
             // Remove whitespaces and newlines
             foreach ($larray as $larrid => $larrval) {
                 $larray[$descarray[$larrid]] = trim($larrval);
                 unset($larray[$larrid]);
             }
             $this->exphandler->putln($larray);
         }
     }
 }