public function actionSipData() { if (!isset(Yii::app()->request->urlReferrer)) { throw new CHttpException(500, "Invalid request"); } else { header("Content-Type: application/json"); $criteria = new CDbCriteria(); // $criteria->order = "is_active ASC , balance DESC"; $criteria->order = "vici_user ASC"; $allremoteData = RemoteDataCache::model()->findAll($criteria); $updatedData = array(); /*format some data*/ foreach ($allremoteData as $curObj) { /** * @var $curObj ORemoteDataCache */ $curObj->date_updated = $this->simpleAgoHelper(strtotime($curObj->date_updated)); $criteria = new CDbCriteria(); $criteria->compare("account_id", $curObj->id); $criteria->order = "date_created DESC"; $last_credit_update = AccountChargeLog::model()->find($criteria); //get just one from the bottom , the latest $curObj->last_credit_update = ''; // if ($last_credit_update) { $curObj->last_credit_update = date("F j, Y, g:i a", strtotime($last_credit_update->date_created)); } $updatedData[] = CMap::mergeArray($curObj->attributes, ["last_credit_update" => $curObj->last_credit_update]); } echo CJSON::encode($updatedData); Yii::app()->end(); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return AccountChargeLog the loaded model * @throws CHttpException */ public function loadModel($id) { $model = AccountChargeLog::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }