public function loadModel($id) { if (($model = MetrikaUrl::model()->findByPk($id)) === null) { throw new CHttpException(404, Yii::t('MetrikaModule.metrika', 'Requested page was not found!')); } return $model; }
public function run() { $model = MetrikaUrl::model()->findByAttributes(array('url' => $this->url)); if (!is_null($model)) { echo $this->count + $model->views; } }
public function actionIndex() { if (!Yii::app()->getRequest()->getIsAjaxRequest()) { throw new CHttpException('404', Yii::t('MetrikaModule.metrika', 'Page was not found')); } $referrer = explode('?', Yii::app()->getRequest()->urlReferrer); $transaction = Yii::app()->db->beginTransaction(); try { $modelUrl = MetrikaUrl::model()->findByAttributes(array('url' => $referrer[0])); if ($modelUrl === null) { $modelUrl = new MetrikaUrl(); $modelUrl->setAttributes(array('url' => $referrer[0])); } else { $modelUrl->views++; } $modelUrl->save(); $modelTransitions = new MetrikaTransitions(); $modelTransitions->setAttributes(array('url_id' => $modelUrl->id, 'params_get' => isset($referrer[1]) ? $referrer[1] : '')); $modelTransitions->save(); $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); } }