コード例 #1
0
ファイル: BbiiSession.php プロジェクト: sourcetoad/bbii2
 /**
  * Retrieves a list of models based on the current search/filter conditions.
  * 
  * @param  [type] $params [description]
  * @return ActiveDataProvider The data provider that can return the models based on the search/filter conditions.
  */
 public function search($params = null)
 {
     $query = BbiiSession::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->addCondition('id', $this->id, true);
     $this->addCondition('last_visit', $this->last_visit, true);
     return $dataProvider;
 }
コード例 #2
0
ファイル: _footer.php プロジェクト: sourcetoad/bbii2
?>
</div>
                    </li>
                    <li class="list-group-item">
                        <?php 
echo Yii::t('BbiiModule.bbii', 'Newest member');
?>
                        <div class="pull-right">
                          <?php 
if ($newest->member_name != NULL) {
    echo Html::a($newest->member_name, array('member/view', 'id' => $newest->id));
}
?>
                        </div>
                    </li>
                    <li class="list-group-item">
                        <?php 
echo Yii::t('BbiiModule.bbii', 'Visitors today');
?>
                        <div class="badge pull-right"><?php 
echo BbiiSession::find()->count();
?>
</div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>

コード例 #3
0
ファイル: BbiiModule.php プロジェクト: sourcetoad/bbii2
 /**
  * this method is called before any module controller action is performed
  * you may place customized code here
  *
  * @version  2.2.0
  * @param  [type] $controller [description]
  * @param  [type] $action     [description]
  * @return [type]             [description]
  */
 public function beforeAction($controller, $action = null)
 {
     if (parent::beforeAction($controller, $action)) {
         // register last visit by member
         if (\Yii::$app->user->identity->id) {
             //$model = BbiiMember::find(\Yii::$app->user->identity->id );
             $model = BbiiMember::find()->where(['id' => \Yii::$app->user->identity->id])->one();
             if ($model !== null) {
                 $model->setAttribute('last_visit', date('Y-m-d H:i:s'));
                 $model->save();
             } else {
                 $userClass = new User();
                 $user = $userClass::find()->where([$this->userIdColumn => \Yii::$app->user->identity->id])->one();
                 $username = $user->getAttribute($this->userNameColumn);
                 $model = new BbiiMember();
                 $model->setAttribute('first_visit', date('Y-m-d H:i:s'));
                 $model->setAttribute('id', \Yii::$app->user->identity->id);
                 $model->setAttribute('last_visit', date('Y-m-d H:i:s'));
                 $model->setAttribute('member_name', $username);
                 $model->save();
             }
         }
         // register visits
         if (isset($_SERVER['HTTP_USER_AGENT'])) {
             // web spider visit
             $spider = BbiiSpider::find()->where(['user_agent' => $_SERVER['HTTP_USER_AGENT']])->one();
             if ($spider !== null) {
                 $spider->setScenario('visit');
                 $spider->hits++;
                 $spider->last_visit = null;
                 if (!$spider->validate() || !$spider->save()) {
                     // todo Some kind of logging when the spider model does not validate or save - DJE : 2015-07-20
                 }
                 // guest visit
             } else {
                 $model = BbiiSession::find()->where(['id' => \Yii::$app->session->getId()])->one();
                 $model = $model ?: new BbiiSession();
                 $model->id = \Yii::$app->session->getId();
                 if (!$model->validate() || !$model->save()) {
                     // todo Some kind of logging when the user model does not validate or save - DJE : 2015-07-20
                 }
             }
         }
         // delete older session entries
         BbiiSession::deleteAll('last_visit < \'' . date('Y-m-d H:i:s', time() - 24 * 3600) . '\'');
         return true;
     }
     return false;
 }