示例#1
0
 /**
  * @param $duration
  * @param $orderProductId
  *
  * This function required order_product to be succefully created
  */
 private function createCodeBank($duration, $orderProductId, $maxCallOut, $minBalance)
 {
     $cb = new CodeBank();
     $cb->code = self::GenerateCode();
     $cb->expiredBy = self::GenerateExpiredBy($duration);
     $cb->maxCallOut = $maxCallOut;
     $cb->minBalance = $minBalance;
     $cb->order_product_id = $orderProductId;
     $cb->save();
     // Create record for code_member
     $codeMember = new CodeMember();
     $codeMember->loadDefaultValues();
     $codeMember->auth_item_name = 'admin';
     $codeMember->user_id = Yii::$app->user->identity->id;
     $codeMember->link('codeBank', $cb);
     if (Yii::$app->authManager->getAssignment('admin', Yii::$app->user->identity->id) == null) {
         $adminRole = Yii::$app->authManager->getRole('admin');
         Yii::$app->authManager->assign($adminRole, Yii::$app->user->identity->id);
     }
     return true;
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CodeMember::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'auth_item_name', $this->auth_item_name])->andFilterWhere(['like', 'codeBank_code', $this->codeBank_code]);
     return $dataProvider;
 }
示例#3
0
 public function actionAccept()
 {
     $codeMember = new CodeMember();
     $codeMember->user_id = Yii::$app->request->get('user_id');
     $codeMember->codeBank_code = Yii::$app->request->get('code');
     $codeMember->auth_item_name = Yii::$app->request->get('role');
     $message_id = Yii::$app->request->get('message_id');
     $codeMember->save();
     //Check auth_assignment
     if (Yii::$app->authManager->getAssignment($codeMember->auth_item_name, $codeMember->user_id) == null) {
         $role = Yii::$app->authManager->getRole($codeMember->auth_item_name);
         Yii::$app->authManager->assign($role, $codeMember->user_id);
     }
     $username = $codeMember->user->username;
     $message = Messages::findOne(intval($message_id));
     $message->content = Yii::$app->controller->renderPartial('_accepted_message', ['username' => $username, 'role' => $codeMember->auth_item_name, 'code' => $codeMember->codeBank_code]);
     $message->save();
     Yii::$app->session->setFlash('success', 'You have been added to participate for Hybrizy code: ' . $codeMember->codeBank_code);
     return $this->redirect(['/messages/index']);
 }
示例#4
0
 /**
  * Finds the CodeMember model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CodeMember the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CodeMember::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#5
0
文件: CodeBank.php 项目: fnoorman/dev
 public function getCodeMembers()
 {
     return $this->hasMany(CodeMember::className(), ['codeBank_code' => 'code']);
 }