public function actionGetall($subject_id = 0, $comment_id = 0) { global $arr_response; //in case params are sent via POST $subject_id = $_REQUEST['subject_id']; $comment_id = $_REQUEST['comment_id']; $width = $_REQUEST['width']; $height = $_REQUEST['height']; $keepratio = isset($_REQUEST['keepratio']) ? $_REQUEST['keepratio'] : 1; //Default to true //PHP casts any string to 0. so its ok. We need to cast in case we receive a string. $subject_id = (int) $subject_id; $comment_id = (int) $comment_id; $width = (int) $width; $height = (int) $height; $keepratio = $keepratio ? true : false; $arr_response = array_merge($arr_response, Subject::getLiveData($subject_id, $comment_id, $width, $height, $keepratio)); //TODO: Add log/counter statistics for API requests }
/** * Fetch data about a subject. * This action does NOT return a html web page. * This action returns data about a subject in an encoded format for data interchange(JSON,XML,etc.) * It can be used for API implementation. */ public function actionFetch($subject_id = 0, $comment_id = 0) { //in case params are sent via POST if (isset($_POST['subject_id'])) { $subject_id = $_POST['subject_id']; } if (isset($_POST['comment_id'])) { $comment_id = $_POST['comment_id']; } //PHP casts any string to 0. so its ok. We need to cast in case we receive a string. $subject_id = (int) $subject_id; $comment_id = (int) $comment_id; $data = NULL; $data = Subject::getLiveData($subject_id, $comment_id, false); if ($data['new_sub'] == 0) { $this->no_log = true; } //This is just to control the logging functionality(client dont receive this info) if ($data['new_sub'] != 0) { if (isset($_GET['subject_id'])) { //Only if its not comming from site.php js(that script does not sends that param) if ($data['subject_id']) { $this->model = $this->loadModel($data['subject_id']); } //Track each unique view of the subject in homepage as subjects passes by if (!Yii::app()->session['subject_view_live']) { Yii::app()->session['subject_view_live'] = array('1' => 1); } //just in case start it with something if (!in_array($this->model->id, Yii::app()->session['subject_view_live'])) { //buggy we need to reasign a new array as we can not modify an array on the fly in a session var $arr_sv = Yii::app()->session['subject_view_live']; $arr_sv[] = $this->model->id; Yii::app()->session['subject_view_live'] = $arr_sv; $this->model->live_views += 1; $this->model->save(); } } } echo json_encode($data); }