/** * method to execute remove of billing lines (only credit and active) * it's called automatically by the api main controller */ public function execute() { Billrun_Factory::log()->log("Execute api remove", Zend_Log::INFO); $request = $this->getRequest()->getRequest(); // supports GET / POST requests Billrun_Factory::log()->log("Input: " . print_R($request, 1), Zend_Log::INFO); $stamps = array(); foreach ($request['stamps'] as $line_stamp) { $clear_stamp = Billrun_Util::filter_var($line_stamp, FILTER_SANITIZE_STRING, FILTER_FLAG_ALLOW_HEX); if (!empty($clear_stamp)) { $stamps[] = $clear_stamp; } } if (empty($stamps)) { Billrun_Factory::log()->log("remove action failed; no correct stamps", Zend_Log::INFO); $this->getController()->setOutput(array(array('status' => false, 'desc' => 'failed - invalid stamps input', 'input' => $request))); return true; } $model = new LinesModel(); $query = array('source' => 'api', 'stamp' => array('$in' => $stamps), '$or' => array(array('billrun' => array('$gte' => Billrun_Billrun::getActiveBillrun())), array('billrun' => array('$exists' => false)))); $ret = $model->remove($query); if (!isset($ret['ok']) || !$ret['ok'] || !isset($ret['n'])) { Billrun_Factory::log()->log("remove action failed pr miscomplete", Zend_Log::INFO); $this->getController()->setOutput(array(array('status' => false, 'desc' => 'remove failed', 'input' => $request))); return true; } Billrun_Factory::log()->log("remove success", Zend_Log::INFO); $this->getController()->setOutput(array(array('status' => $ret['n'], 'desc' => 'success', 'input' => $request))); }
/** * method to execute the query * it's called automatically by the api main controller */ public function execute() { Billrun_Factory::log()->log("Execute api query", Zend_Log::INFO); $request = $this->getRequest()->getRequest(); // supports GET / POST requests Billrun_Factory::log()->log("Input: " . print_R($request, 1), Zend_Log::INFO); if (!isset($request['aid']) && !isset($request['sid'])) { $this->setError('Require to supply aid or sid', $request); return true; } $find = array(); $max_list = 1000; if (isset($request['aid'])) { $aids = Billrun_Util::verify_array($request['aid'], 'int'); if (count($aids) > $max_list) { $this->setError('Maximum of aid is ' . $max_list, $request); return true; } $find['aid'] = array('$in' => $aids); } if (isset($request['sid'])) { $sids = Billrun_Util::verify_array($request['sid'], 'int'); if (count($sids) > $max_list) { $this->setError('Maximum of sid is ' . $max_list, $request); return true; } $find['sid'] = array('$in' => $sids); } if (isset($request['billrun'])) { $find['billrun'] = $this->getBillrunQuery($request['billrun']); } if (isset($request['query'])) { $query = $this->getArrayParam($request['query']); $find = array_merge($find, (array) $query); } $options = array('sort' => array('urt'), 'page' => isset($request['page']) && $request['page'] > 0 ? (int) $request['page'] : 0, 'size' => isset($request['size']) && $request['size'] > 0 ? (int) $request['size'] : 1000); $model = new LinesModel($options); if (isset($request['distinct'])) { $lines = $model->getDistinctField((string) $request['distinct'], $find); } else { $lines = $model->getData($find); foreach ($lines as &$line) { $line = $line->getRawData(); } } Billrun_Factory::log()->log("query success", Zend_Log::INFO); $ret = array(array('status' => 1, 'desc' => 'success', 'input' => $request, 'details' => $lines)); $this->getController()->setOutput($ret); }
public function execute() { Billrun_Factory::log()->log("Execute activity call", Zend_Log::INFO); $request = $this->getRequest(); $sid = (int) $request->get('sid', 0); if (empty($sid)) { return $this->setError('Subscriber not exists', $request); } $include_incoming = (int) $request->get('include_incoming', 0); $include_outgoing = (int) $request->get('include_outgoing', 0); $include_sms = (int) $request->get('include_sms', 0); $from_date = $request->get('from_date', time() - 30 * 3600); $to_date = $request->get('to_date', time()); if (!is_numeric($from_date)) { $from_date = strtotime($from_date); } if (!is_numeric($to_date)) { $to_date = strtotime($to_date); } $model = new LinesModel(); $results = $model->getActivity($sid, $from_date, $to_date, $include_outgoing, $include_incoming, $include_sms); $this->getController()->setOutput(array(array('status' => 1, 'desc' => 'success', 'details' => $results, 'input' => $request))); }
/** * basic fetch data method used by the cache * * @param array $params parameters to fetch the data * * @return boolean */ protected function fetchData($params) { $model = new LinesModel($params['options']); $lines = $model->getDataAggregated(array('$match' => $params['find']), array('$group' => $params['group'])); if (isset($params['groupby']['_id'])) { $groupby_keys = array_reverse(array_keys($params['groupby']['_id'])); } else { $groupby_keys = array(); } $results = array(); foreach ($lines as $line) { $row = $line->getRawData(); foreach ($groupby_keys as $key) { $row[$key] = $row['_id'][$key]; } unset($row['_id']); $results[] = array_reverse($row, true); } return $results; }