コード例 #1
0
 public function get3()
 {
     // 留言
     $request = Yii::$app->request;
     $name = $request->get('name');
     $content = $request->get('content');
     $model = new \app\models\Message();
     $isok = $model->insert($name, $content);
     $this->back['isok'] = $isok;
 }
コード例 #2
0
 /**
  * Updates an existing SourceMessage 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);
     if ($model->load(Yii::$app->request->post())) {
         $message = new \app\models\Message();
         if ($message->load(Yii::$app->request->post())) {
             if (!$message->save()) {
                 $error = "";
                 foreach ($message->getErrors() as $er) {
                     $error = $er->attribute;
                 }
                 Yii::$app->session->setFlash("error", Yii::t('app', "Can not save. \n{}"));
             }
         }
         //            return $this->redirect(["index"]);
         return $this->redirect(['view', 'id' => $model->id]);
     }
     $searchModel = new SourceMessageSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('update', ['model' => $model, 'message' => new \app\models\Message(), 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
コード例 #3
0
ファイル: ListCept.php プロジェクト: jsopra/lepetitmessager
<?php

Yii::$app->redis->executeCommand('FLUSHDB');
use Codeception\Util\Debug;
$model = new \app\models\Message();
$model->author_email = '*****@*****.**';
$model->author_name = 'test';
$model->message = str_repeat('A', 140);
$model->save();
$I = new ApiTester($scenario);
$I->wantTo('Ver a lista de mensagens');
$I->sendGET('messages', []);
$I->seeResponseIsJson();
$I->seeResponseJsonMatchesJsonPath('$[0].author_name');
$I->seeResponseJsonMatchesJsonPath('$[0].author_email');
$I->seeResponseJsonMatchesJsonPath('$[0].message');
$I->seeResponseJsonMatchesJsonPath('$[0].id');
$I->seeResponseJsonMatchesJsonPath('$[0].creation_time');
コード例 #4
0
ファイル: messages.php プロジェクト: jcshep/FrontRunner
    foreach ($messages as $message) {
        ?>
										
									<tr <?php 
        if ($message->status == 2) {
            ?>
class="unread"<?php 
        }
        ?>
 onclick="location.href='/message/view/<?php 
        echo $message->id;
        ?>
';">
										<td width="70">											
											<?php 
        echo app\models\Message::messageCodes($message->status);
        ?>
											
										</td>	
																
										<td width="110"><?php 
        echo date('m/j, g:ia', $message->time);
        ?>
</td>

										<td>
											<em><?php 
        echo $message->message;
        ?>
</em>
										</td>	
コード例 #5
0
 public function actionList($id, $list)
 {
     $model = $this->findModel($id);
     // Get segment parameter and apply
     $segment = Yii::$app->request->get('segment');
     // Get role parameter and apply
     $role = Yii::$app->request->get('role');
     // Get related model (people)
     $query = $model->getPeople($list, $segment, $role);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 250]]);
     // Get list text from list id's
     if ($list == 1) {
         $list_type = 'Availability';
     }
     if ($list == 2) {
         $list_type = 'Final';
     }
     //Check if list action was submitted
     if ($selection = Yii::$app->request->post('selection')) {
         // Figure out what needs to be done
         $action = Yii::$app->request->post('action');
         switch ($action) {
             // Move to final list
             case 'list-move':
                 foreach ($selection as $person) {
                     $query = new Query();
                     $query->createCommand()->update('person_project', ['list' => 2], ['user_id' => $person, 'project_id' => $id, 'list' => $list])->execute();
                 }
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
                 // Send Message
             // Send Message
             case 'send-message':
                 // Check if a file was uploaded
                 // Loop through checked users
                 foreach ($selection as $person) {
                     $person_model = Person::findOne($person);
                     $message = new \app\models\Message();
                     $message->user_id = $person_model->id;
                     $message->project_id = $id;
                     $message->message = Yii::$app->request->post('message');
                     $message->attachment = \yii\web\UploadedFile::getInstanceByName('attachment');
                     $message->time = time();
                     $message->status = 1;
                     $message->type = 'email';
                     //Set email to proper address / check if a family member and send there instead
                     $email = $person_model->email;
                     if (!$email && $person_model->family_id) {
                         $family_leader = Person::findOne($person_model->family_id);
                         $email = $family_leader->email;
                     }
                     if ($message->save() && $email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
                         // Create mail item
                         $mail = Yii::$app->mailer->compose('/mail/message', ['message' => $message, 'person' => $person_model])->setTo($email)->setSubject('New Message From FrontRunner Casting');
                         // Set from address
                         if ($model->reply_to) {
                             $mail->setFrom($model->reply_to);
                         } else {
                             $mail->setFrom('*****@*****.**');
                         }
                         // Add mail item to array
                         $messages[] = $mail;
                     }
                 }
                 //endforeach
                 // Try to send messages
                 if (isset($messages)) {
                     try {
                         Yii::$app->mailer->sendMultiple($messages);
                         Yii::$app->session->setFlash('messagesSent');
                     } catch (\Swift_SwiftException $exception) {
                         Yii::$app->session->setFlash('error', 'Messages could not be sent. Please try again.');
                     }
                 }
                 // Redirect back to list
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
                 // Basic text message
             // Basic text message
             case 'send-text-message':
                 Yii::$app->session->setFlash('messagesSent');
                 $message = Yii::$app->request->post('text-message');
                 // Send Message with twilio
                 $model->sendText($selection, $message);
                 // Redirect back to list
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
                 // Send availability check email
             // Send availability check email
             case 'availability-check':
                 foreach ($selection as $person) {
                     // Change status to requested
                     $query = new Query();
                     $query->createCommand()->update('person_project', ['availability' => 2], ['user_id' => $person, 'project_id' => $id, 'list' => $list])->execute();
                     // Get person model
                     $person_model = Person::findOne($person);
                     // Send Availability Check email
                     $message = new \app\models\Message();
                     $message->user_id = $person_model->id;
                     $message->project_id = $id;
                     $message->message = Yii::$app->request->post('availability-message');
                     $message->attachment = \yii\web\UploadedFile::getInstanceByName('attachment');
                     $message->time = time();
                     $message->status = 3;
                     $message->type = 'email';
                     // Insert specific available / unavailable links for user
                     $person_project_id = PersonProject::find()->where(['project_id' => $id, 'user_id' => $person_model->id])->one();
                     $message->message = str_replace('[person_project_id]', $person_project_id->id, $message->message);
                     //Set email to proper address / check if a family member and send there instead
                     $email = $person_model->email;
                     if (!$email && $person_model->family_id) {
                         $family_leader = Person::findOne($person_model->family_id);
                         $email = $family_leader->email;
                     }
                     if ($message->save() && $person_model && $email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
                         // Create mail item
                         $mail = Yii::$app->mailer->compose('/mail/message', ['message' => $message, 'person' => $person_model])->setTo($email)->setSubject('FrontRunner Casting - Availability Request for ' . $person_model->fname . ' ' . $person_model->lname);
                         // Set from address
                         if ($model->reply_to) {
                             $mail->setFrom($model->reply_to);
                         } else {
                             $mail->setFrom('*****@*****.**');
                         }
                         // Add mail item to array
                         $messages[] = $mail;
                     }
                     //end if message is valid and saved
                 }
                 //end for each
                 // Try to send messages
                 if (isset($messages)) {
                     try {
                         Yii::$app->mailer->sendMultiple($messages);
                         Yii::$app->session->setFlash('messagesSent');
                     } catch (\Swift_SwiftException $exception) {
                         Yii::$app->session->setFlash('error', 'Messages could not be sent. Please try again. ' . $exception);
                     }
                 }
                 // Redirect back to list
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
                 // Update database to show requested
             // Update database to show requested
             case 'confirmation-check':
                 foreach ($selection as $person) {
                     $query = new Query();
                     $query->createCommand()->update('person_project', ['confirmed' => 2], ['user_id' => $person, 'project_id' => $id, 'list' => $list])->execute();
                     $person_model = Person::findOne($person);
                     // Send Availability Check email
                     $message = new \app\models\Message();
                     $message->user_id = $person_model->id;
                     $message->project_id = $id;
                     $message->message = Yii::$app->request->post('confirmation-message');
                     $message->attachment = \yii\web\UploadedFile::getInstanceByName('confirmation-attachment');
                     $message->time = time();
                     $message->status = 3;
                     $message->type = 'email';
                     // Insert specific available / unavailable links for user
                     $person_project_id = PersonProject::find()->where(['project_id' => $id, 'user_id' => $person_model->id])->one();
                     $message->message = str_replace('[person_project_id]', $person_project_id->id, $message->message);
                     //Set email to proper address / check if a family member and send there instead
                     $email = $person_model->email;
                     if (!$email && $person_model->family_id) {
                         $family_leader = Person::findOne($person_model->family_id);
                         $email = $family_leader->email;
                     }
                     if ($message->save() && $email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
                         // Create mail item
                         $mail = Yii::$app->mailer->compose('/mail/message', ['message' => $message, 'person' => $person_model])->setTo($email)->setSubject('FrontRunner Casting - Confirmation Request for ' . $person_model->fname . ' ' . $person_model->lname);
                         // Set from address
                         if ($model->reply_to) {
                             $mail->setFrom($model->reply_to);
                         } else {
                             $mail->setFrom('*****@*****.**');
                         }
                         // Add mail item to array
                         $messages[] = $mail;
                     }
                     // Try to send messages
                     if (isset($messages)) {
                         try {
                             Yii::$app->mailer->sendMultiple($messages);
                             Yii::$app->session->setFlash('messagesSent');
                         } catch (\Swift_SwiftException $exception) {
                             Yii::$app->session->setFlash('error', 'Messages could not be sent. Please try again. ' . $exception);
                         }
                     }
                 }
                 // Redirect back to list
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
                 // Text message confirmation check
             // Text message confirmation check
             case 'confirmation-check-text':
                 Yii::$app->session->setFlash('messagesSent');
                 // Send Message with twilio
                 $model->sendText(Yii::$app->request->post('confirmation-text-message'));
                 // Redirect back to list
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
                 // Manually set as available
             // Manually set as available
             case 'availability-available':
                 foreach ($selection as $person) {
                     $query = new Query();
                     $query->createCommand()->update('person_project', ['availability' => 3], ['user_id' => $person, 'project_id' => $id, 'list' => $list])->execute();
                 }
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
                 // Manually set as unavailable
             // Manually set as unavailable
             case 'availability-unavailable':
                 foreach ($selection as $person) {
                     $query = new Query();
                     $query->createCommand()->update('person_project', ['availability' => 4], ['user_id' => $person, 'project_id' => $id, 'list' => $list])->execute();
                 }
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
                 // Manually set as confirmed
             // Manually set as confirmed
             case 'confirmation-confirmed':
                 foreach ($selection as $person) {
                     $query = new Query();
                     $query->createCommand()->update('person_project', ['confirmed' => 1], ['user_id' => $person, 'project_id' => $id, 'list' => $list])->execute();
                 }
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
                 // Manually set as confirmed
             // Manually set as confirmed
             case 'confirmation-unconfirmed':
                 foreach ($selection as $person) {
                     $query = new Query();
                     $query->createCommand()->update('person_project', ['confirmed' => 0], ['user_id' => $person, 'project_id' => $id, 'list' => $list])->execute();
                 }
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
                 // Move to another project
             // Move to another project
             case 'project-move':
                 foreach ($selection as $person) {
                     $person_project = new \app\models\PersonProject();
                     $person_project->user_id = $person;
                     $person_project->project_id = Yii::$app->request->post('sent-to-project');
                     $person_project->list = 1;
                     $person_project->availability = 1;
                     if ($person_project->save()) {
                         Yii::$app->session->setFlash('peopleMoved');
                     }
                 }
                 // Redirect back to list
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 # Send Availability Check email
                 break;
                 // Remove from list
             // Remove from list
             case 'list-remove':
                 foreach ($selection as $person) {
                     $query = new Query();
                     $query->createCommand()->delete('person_project', ['user_id' => $person, 'project_id' => $id, 'list' => $list])->execute();
                 }
                 return $this->redirect(['/project/list', 'id' => $id, 'list' => $list]);
                 break;
         }
     }
     return $this->render('list', ['model' => $model, 'dataProvider' => $dataProvider, 'list_type' => $list_type, 'list_type_id' => $list]);
 }