public function postInsert($event) { $oStatistics = new Statistics(); $oStatistics->setCategoryId($this->getId()); try { $iPeriod = Period::getCurrentPeriod(); } catch (sfException $e) { return; } if (false !== $iPeriod) { $oStatistics->setPeriodId($iPeriod); $oStatistics->save(); } }
/** * Returns row by input data * * @param integer $iPeriodId * @param integer $iCategoryId: null * @return Statistics */ public function getFullStatistics($iPeriodId, $iCategoryId = null) { $q = Doctrine_Query::create()->select('s.*')->from('Statistics s')->where('s.period_id=?', $iPeriodId)->limit(1); if (null !== $iCategoryId) { $q->andWhere('s.category_id=?', $iCategoryId); } else { $q->andWhere('s.category_id IS NULL'); } $stat = $q->fetchOne(); if (!is_object($stat)) { $stat = new Statistics(); $stat->setPeriodId($iPeriodId); if (null !== $iCategoryId) { $stat->setCategoryId($iCategoryId); } $stat->save(); } return $stat; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Statistics(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Statistics'])) { $model->attributes = $_POST['Statistics']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * 用户开始进入某页面,添加相关信息 * @param unknown_type $id */ public function visitStart($id, $refer) { try { $ip = ip2long(UtilNet::getClientIp()); $model = Statistics::model()->find(array('condition' => 'ip = :ip AND aid = :aid AND refer = :refer AND UNIX_TIMESTAMP( )-starttime<:interval', 'order' => 'id DESC', 'params' => array(':ip' => $ip, ':aid' => $id, ':refer' => $refer, ':interval' => 180))); UtilHelper::writeToFile($model->attributes); if ($model) { $model->endtime = time(); // UtilHelper::writeToFile(array_merge(array('提示'=>'更新'), $model->attributes), 'a+'); if ($model->save()) { echo $model->id; } } else { $model = new Statistics(); $model->aid = $id; $model->ip = $ip; $model->starttime = time(); if (!Yii::app()->user->isGuest) { $model->uid = Yii::app()->user->id; } $model->terminal = $_SERVER['HTTP_USER_AGENT']; $model->refer = $refer; // UtilHelper::writeToFile(array_merge(array('提示'=>'新加入数据'), $model->attributes), 'a+'); if ($model->save()) { echo $model->id; } } UtilHelper::writeToFile(CHtml::errorSummary($model), 'a+'); } catch (Exception $e) { echo $e->getMessage(); } }