/** * @param array $userIds * @param array $orderIds * @return Gpf_DbEngine_Row_Collection */ public function getAffectedTransactionsList($userIds, $orderIds = array()) { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->addAll(Pap_Db_Table_Transactions::getInstance()); $select->from->add(Pap_Db_Table_Transactions::getName()); $dateRangeFilter = new Gpf_SqlBuilder_Filter(); $dateRange = $dateRangeFilter->decodeDatePreset(Pap_Features_CompressedCommissionPlacementModel_Processor::getRecurrencePreset()); $select->where->add(Pap_Db_Table_Transactions::DATE_INSERTED, '>', $dateRange['dateFrom']); $select->where->add(Pap_Db_Table_Transactions::DATE_INSERTED, '<', $dateRange['dateTo']); $select->where->add(Pap_Db_Table_Transactions::USER_ID, 'IN', $userIds); if (!is_null($orderIds) && count($orderIds) > 0) { $compoundCondition = new Gpf_SqlBuilder_CompoundWhereCondition(); foreach ($orderIds as $orderId) { $compoundCondition->add(Pap_Db_Table_Transactions::ORDER_ID, 'LIKE', '%'.$orderId.'%', 'OR'); } $select->where->addCondition($compoundCondition); } $select->orderBy->add(Pap_Db_Table_Transactions::TIER); $transaction = new Pap_Db_Transaction(); $transactionsRecordSet = $select->getAllRows(); $unpaidTransactions = new Gpf_Data_RecordSet(); $unpaidTransactions->setHeader($transactionsRecordSet->getHeader()); foreach ($transactionsRecordSet as $trans) { if ($trans->get(Pap_Db_Table_Transactions::PAYOUT_STATUS) == Pap_Common_Constants::PSTATUS_UNPAID) { $unpaidTransactions->add($trans); } else { $this->log('Removing paid transaction from affected transactions: ' . $trans->get(Pap_Db_Table_Transactions::TRANSACTION_ID)); } } return $transaction->loadCollectionFromRecordset($unpaidTransactions); }