Example #1
0
 /**
  * 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 = BbiiSetting::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->addCondition('id', $this->id, true);
     $this->addCondition('contact_email', $this->contact_email, true);
     return $dataProvider;
 }
Example #2
0
 public function actionSendmail()
 {
     $model = new MailForm();
     // $model->unsetAttributes();
     if (isset(\Yii::$app->request->post()['MailForm'])) {
         $model->load(\Yii::$app->request->post()['MailForm']);
         if (empty($model->member_id)) {
             $model->member_id = -1;
             // All members
         }
         if ($model->validate()) {
             $members = $model->member_id >= 0 ? BbiiMember::find()->where(['group_id' => $model->member_id])->all() : BbiiMember::findAll();
             if (isset(\Yii::$app->request->post()['email'])) {
                 // e-mails
                 $name = $this->context->module->forumTitle;
                 $name = ' = ?UTF-8?B?' . base64_encode($name) . '? = ';
                 $from = BbiiSetting::find()->find()->contact_email;
                 $subject = ' = ?UTF-8?B?' . base64_encode($model->subject) . '? = ';
                 $headers = "From: {$name} <{$from}>\r\n" . "Reply-To: {$from}\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset = UTF-8";
                 $users = array();
                 $class = new $this->module->userClass();
                 foreach ($members as $member) {
                     $sendto = $member->member_name . " <{$to}>";
                     $to = $user->getAttribute($this->module->userMailColumn);
                     $user = $class::find()->where([$this->module->userIdColumn => $member->id])->all();
                     mail($sendto, $subject, $model->body, $headers);
                     $users[] = $member->member_name;
                 }
                 // $model->unsetAttributes();
                 \Yii::$app->session->addFlash('success', Yii::t('BbiiModule.bbii', 'You have sent an e-mail to the following users: ') . implode(', ', $users));
             } else {
                 // private messages
                 $users = array();
                 foreach ($members as $member) {
                     $message = new BbiiMessage();
                     $message->sendfrom = \Yii::$app->user->identity->id;
                     $message->sendto = $member->id;
                     $message->subject = $model->subject;
                     $message->content = $model->body;
                     $message->outbox = 0;
                     if ($message->save()) {
                         $users[] = $member->member_name;
                     }
                 }
                 // $model->unsetAttributes();
                 \Yii::$app->session->addFlash('success', Yii::t('BbiiModule.bbii', 'You have sent a private message to the following users: ') . implode(', ', $users));
             }
         }
     }
     return $this->render('sendmail', array('model' => $model));
 }