public function actionMarkNotificationRead()
 {
     $data = Yii::$app->request->post();
     $id = intval($data['id']);
     $modelId = intval($data['modelId']);
     $type = $data['type'];
     if ($type == 'post') {
         $model = PostReplay::findOne($modelId);
         $model->is_read = 1;
         if ($model->save()) {
             return 0;
         }
     }
     if ($type == 'announcement') {
         $model = AnnouncementHasParticipant::findOne(['Accouncement_id' => $modelId, 'Participant_id' => $id]);
         $model->is_read = 1;
         if ($model->save()) {
             return 0;
         }
     }
     if ($type == 'activity') {
         $model = ParticipantHasActivity::findOne(['Participant_id' => $id, 'Activity_id' => $modelId]);
         $model->is_read = 1;
         if ($model->save()) {
             return 0;
         }
     }
     return -1;
 }
 public function getTotalAttendCountByActivityId($id)
 {
     return ParticipantHasActivity::find()->where(['Activity_id' => $id, 'attendance' => 1])->count();
 }
 public function actionRecord()
 {
     if (Yii::$app->user->can('activityRecord')) {
         $dataProvider = [];
         $activities = Activity::getAllActivities();
         foreach ($activities as $activity) {
             $row['id'] = $activity['id'];
             $row['Activity_name'] = $activity['Activity_name'];
             $row['datetime'] = $activity['startDatetime'];
             $row['total'] = ParticipantHasActivity::getTotalJoinCountByActivityId($activity['id']);
             $row['attend'] = ParticipantHasActivity::getTotalAttendCountByActivityId($activity['id']);
             array_push($dataProvider, $row);
         }
         return $this->render('record', ['dataProvider' => $dataProvider]);
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
 }
 public function actionAttend($id, $activity, $user, $token)
 {
     if (($admin = User::findByUsername($user)) !== null) {
         $auth = \Yii::$app->authManager;
         if (password_verify($token, $admin->password) && $auth->checkAccess($admin->id, 'participantHasActivity')) {
             if (($model = ParticipantHasActivity::findOne(['Participant_id' => $id, 'Activity_id' => $activity])) !== null) {
                 if ($model->attendance != 1) {
                     $model->attendance = 1;
                     $model->attend_datetime = date("Y-m-d H:i:s");
                     \app\models\User::addScore(10, $id);
                     if ($model->save()) {
                         die('success');
                     }
                 } else {
                     die('Attended');
                 }
             }
         }
     }
     die('fail');
 }
Beispiel #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getParticipantHasActivities()
 {
     return $this->hasMany(ParticipantHasActivity::className(), ['Participant_id' => 'id']);
 }
Beispiel #6
0
            <h1><?php 
    echo Html::encode($this->title);
    ?>
</h1>
            <p>
                <?php 
    echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
    ?>
                <?php 
    echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]);
    ?>
                <?php 
    if (!Yii::$app->user->isGuest && strtotime($model->startDatetime) - time() > 0) {
        ?>
                    <?php 
        if (!\app\models\ParticipantHasActivity::checkHasJoin($model->id)) {
            ?>
                        <?php 
            echo Html::a('Add to your Schedule', ['/participant-has-activity/join', 'activityId' => $model->id], ['class' => 'btn btn-default']);
            ?>
                    <?php 
        } else {
            ?>
                        <?php 
            echo Html::a('Remove from your Schedule', ['/participant-has-activity/quit', 'activityId' => $model->id], ['class' => 'btn btn-default']);
            ?>
                    <?php 
        }
        ?>
                <?php 
    }