當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Activity::findOne方法代碼示例

本文整理匯總了PHP中app\models\Activity::findOne方法的典型用法代碼示例。如果您正苦於以下問題:PHP Activity::findOne方法的具體用法?PHP Activity::findOne怎麽用?PHP Activity::findOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\Activity的用法示例。


在下文中一共展示了Activity::findOne方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: findModel

 /**
  * Finds the Activity model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Activity the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Activity::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
開發者ID:hoangngk,項目名稱:adminpanel,代碼行數:15,代碼來源:ActivitiesController.php

示例2: actionIndex

 function actionIndex($actid = 1)
 {
     $typeid = Yii::$app->request->get("typeid");
     $actid = Yii::$app->request->get("actid");
     $message = "";
     $errormsg = "";
     $model = new SignUpForm();
     $activity = Activity::findOne($actid);
     $model->actid = $actid;
     $model->typeid = $typeid;
     $activityTypes = SignupTypeForm::find()->select(['subject', 'id'])->where(['actid' => $actid])->asArray()->all();
     $types = array();
     foreach ($activityTypes as $activityType) {
         $types[$activityType['id']] = $activityType['subject'];
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->save();
         $message = "保存成功";
     } else {
         $errormsg = $model->getErrors();
     }
     return $this->render("index", ['model' => $model, 'activity' => $activity, 'types' => $types, 'message' => $message, 'errormsg' => $errormsg]);
 }
開發者ID:JeremiahW,項目名稱:membermgt,代碼行數:23,代碼來源:SignupController.php

示例3: actionView

 public function actionView()
 {
     $activityId = Yii::$app->request->get('id');
     $activityModel = Activity::findOne(['id' => $activityId]);
     $activityTeachersModel = ActivityTeachers::getAllTeachersByActivityId($activityModel['id']);
     $activityUsers = [];
     if ($activityModel['recruit_count'] > 0) {
         for ($i = 1; $i <= $activityModel['recruit_count']; $i++) {
             $activityUsersInfo = ActivityUsers::findOne(['activity_id' => $activityModel['id'], 'orders' => $i]);
             if (empty($activityUsersInfo)) {
                 $activityUsers[$i]['status'] = '未報名';
                 $activityUsers[$i]['class'] = 'red';
                 $activityUsers[$i]['userId'] = '';
             } else {
                 $activityUsers[$i]['status'] = ActivityUsers::$statusList[$activityUsersInfo['status']];
                 $activityUsers[$i]['userId'] = $activityUsersInfo['user_id'];
                 if ($activityUsersInfo['status'] == ActivityUsers::NO_APPROVED) {
                     $activityUsers[$i]['class'] = 'blue';
                 } else {
                     $activityUsers[$i]['class'] = '';
                 }
             }
         }
     }
     $data = ['activityModel' => $activityModel, 'activityTeachersModel' => $activityTeachersModel, 'activityUsers' => $activityUsers];
     return $this->render('/activity/view', ['data' => $data]);
 }
開發者ID:hanxiao84322,項目名稱:coach_system,代碼行數:27,代碼來源:ActivityController.php

示例4: actionActivityApply

 public function actionActivityApply()
 {
     $activityId = Yii::$app->request->get('id');
     $activityInfo = Activity::findOne(['id' => $activityId]);
     $levelId = $activityInfo['level_id'];
     if ($activityInfo['status'] != Activity::BEGIN_SIGN_UP) {
         throw new ServerErrorHttpException('該活動的狀態不是開始報名,謝謝。');
     }
     if (Yii::$app->user->isGuest) {
         return $this->redirect('/login/login');
     } else {
         $userId = Yii::$app->user->id;
         if (Yii::$app->user->identity->status != '1') {
             throw new ServerErrorHttpException('係統錯誤,原因:您目前的狀態是未審核,不能報名活動,謝謝。');
         }
         $activityLevelInfo = Level::findOne(['id' => $activityInfo['level_id']]);
         if ($activityLevelInfo['order'] != Yii::$app->user->identity->level_order) {
             throw new ServerErrorHttpException('係統錯誤,原因:您目前沒有權限報名該級別下的活動,謝謝。');
         }
         //檢查用戶參與的活動,狀態不是取消的都算是已經參與了報名
         $isExist = ActivityUsers::getUserIsExistActivityStatus($userId, $activityInfo['level_id']);
         if (!empty($isExist)) {
             throw new ServerErrorHttpException('係統錯誤,原因:您已經參與了該級別下的活動,請耐心等待活動結果,謝謝。');
         }
         //報名成功,給出用戶的序號
         $activityUsersOrder = ActivityUsers::getActivityUsersOrder($userId, $activityId);
         if (empty($activityUsersOrder)) {
             $activityUsersOrder = 1;
         }
         $transaction = Yii::$app->db->beginTransaction();
         $data = ['activity_id' => $activityId, 'user_id' => $userId, 'status' => ActivityUsers::APPROVED, 'level_id' => $levelId, 'orders' => $activityUsersOrder];
         $model = new ActivityUsers();
         $model->setAttributes($data);
         if ($model->save()) {
             $activityUserId = $model->id;
             $activityUser = ActivityUsers::findOne(['id' => $activityUserId]);
             $activityName = Activity::getOneActivityNameById($activityUser['activity_id']);
             $data = ['orders' => $activityUser['orders'], 'activityName' => $activityName];
             //新增一條用戶和級別對應的信息
             $result = UsersLevel::updateAll(['activity_id' => $activityId], ['user_id' => $userId, 'level_id' => $levelId]);
             if (!$result) {
                 $transaction->rollBack();
                 throw new ServerErrorHttpException('更新狀態錯誤,原因:更新數據庫錯誤!');
             } else {
                 $transaction->commit();
             }
             return $this->render('/activity/apply-success', ['data' => $data]);
         } else {
             throw new ServerErrorHttpException('係統錯誤,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE));
         }
     }
 }
開發者ID:hanxiao84322,項目名稱:coach_system,代碼行數:52,代碼來源:UserCenterController.php

示例5: actionUpdate

 /**
  * Updates an existing ActivityUsers model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $activityInfo = Activity::findOne(['id', $model->activity_id]);
     $userInfo = Users::findOne($model->user_id);
     $model->userName = $userInfo['username'];
     $model->activityName = $activityInfo->name;
     if (Yii::$app->request->isPost) {
         $updateParams = Yii::$app->request->post();
         $transaction = Yii::$app->db->beginTransaction();
         if ($updateParams['ActivityUsers']['practice_score'] > 100 || $updateParams['ActivityUsers']['theory_score'] > 100 || $updateParams['ActivityUsers']['rule_score'] > 100) {
             throw new ServerErrorHttpException('評分更新錯誤,原因:每項評分都不能超過100分!');
         }
         if ($model->load($updateParams) && $model->save()) {
             if ($updateParams['ActivityUsers']['status'] == ActivityUsers::END) {
                 //如果結束狀態,必須評分
                 if ($updateParams['ActivityUsers']['practice_score'] <= 0 || $updateParams['ActivityUsers']['theory_score'] <= 0 || $updateParams['ActivityUsers']['rule_score'] <= 0) {
                     throw new ServerErrorHttpException('評分更新錯誤,原因:每項評分都必須大於零!');
                 }
                 //根據3個單項評分計算全部評價內容包括考勤
                 $result = $this->getSource($model->activity_id, $model->user_id, $model->practice_score, $model->theory_score, $model->rule_score);
                 $model->score_appraise = $result['scoreAppraise'];
                 $model->appraise_result = $result['performance'];
                 $model->attendance_appraise = $result['attendanceComment'];
                 $model->practice_comment = $result['practiceComment'];
                 $model->theory_comment = $result['theoryComment'];
                 $model->rule_comment = $result['rulesComment'];
                 $model->total_comment = $result['commentAppraise'];
                 $model->result_comment = $result['scoreAppraise'];
                 $model->status = $result['status'];
                 if ($model->save()) {
                     //如果通過更新晉級信息
                     if ($model->status == ActivityUsers::PASS) {
                         //                            $messagesInfo = Messages::findOne(['id' => 29]);
                         //                            $message = $messagesInfo['content'];
                         //                            $data = [
                         //                                'messages_id' => 29,
                         //                                'users_id' => $model->user_id,
                         //                            ];
                         //                            MessagesUsers::addInfo($data);
                         $content = "尊敬的學員,您已經被成功完成活動,請到個人中心查看具體信息,謝謝。【教練係統】";
                         //                            $smsModel = Sms::getInstance(Yii::$app->params['smsUserName'],Yii::$app->params['smsPassword']);
                         //                            $result = $smsModel->pushMt($userInfo['phone'], time(), $content, 0);
                         //                            if ($result != '0') {
                         //                                throw new ServerErrorHttpException('更新狀態錯誤,原因:' . $result . '!');
                         //                            }
                         $transaction->commit();
                         return $this->redirect(['view', 'id' => $model->id]);
                     }
                     $transaction->commit();
                     Yii::$app->getSession()->setFlash('success', '更新成功!');
                 } else {
                     $transaction->rollBack();
                     throw new ServerErrorHttpException('評分更新錯誤,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE) . '!');
                 }
             } else {
                 if ($updateParams['ActivityUsers']['status'] == ActivityUsers::ENROLL) {
                     //如果錄取,給出用戶的序號
                     $activityUsersOrder = ActivityUsers::getActivityUsersOrder($model->user_id, $model->activity_id);
                     if (empty($activityUsersOrder)) {
                         $activityUsersOrder = 1;
                     }
                     $model->orders = $activityUsersOrder;
                     $model->status = ActivityUsers::ENROLL;
                     if ($model->save()) {
                         $transaction->commit();
                         //                        $messagesInfo = Messages::findOne(['id' => 30]);
                         //                        $message = $messagesInfo['content'];
                         //                        $data = [
                         //                            'messages_id' => 30,
                         //                            'users_id' => $model->user_id,
                         //                        ];
                         //                        MessagesUsers::addInfo($data);
                         //                        $content = $message . "【教練係統】";
                         //錄取發短信
                         //                        $content = "尊敬的學員,您已經被成功錄取,序號為" . $activityUsersOrder . ",謝謝!【教練係統】";
                         //                        $smsModel = Sms::getInstance(Yii::$app->params['smsUserName'],Yii::$app->params['smsPassword']);
                         //                        $result = $smsModel->pushMt($userInfo['phone'], time(), $content, 0);
                         //                        if ($result != '0') {
                         //                            throw new ServerErrorHttpException('更新狀態錯誤,原因:' . $result . '!');
                         //                        }
                         return $this->redirect(['view', 'id' => $model->id]);
                     } else {
                         $transaction->rollBack();
                         //                    Yii::$app->getSession()->setFlash('error', '更新狀態錯誤,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE) . '!');
                         throw new ServerErrorHttpException('更新狀態錯誤,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE) . '!');
                     }
                 } else {
                     $transaction->commit();
                     Yii::$app->getSession()->setFlash('success', '更新成功!');
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             }
         } else {
//.........這裏部分代碼省略.........
開發者ID:hanxiao84322,項目名稱:coach_system,代碼行數:101,代碼來源:ActivityUsersController.php


注:本文中的app\models\Activity::findOne方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。