public function actionSearchResults($id, $list = NULL) { $model = $this->findModel($id); $searchModel = new SearchPerson(); $confirmation = NULL; $role = Yii::$app->request->post('role'); // Check if add boxes are submitted if ($selection = Yii::$app->request->post('selection')) { $i = 0; foreach ($selection as $person) { // Check if user is already in list $row = PersonProject::find()->where(['user_id' => $person, 'project_id' => $id, 'list' => $list])->one(); // IF not in list, add to list if (!$row) { $person_project = new PersonProject(); $person_project->user_id = $person; $person_project->project_id = $id; $person_project->list = $list; if ($role) { $person_project->role = $role; } $person_project->save(); $i++; } } //end foreach if ($i > 1) { $confirmation = $i . ' People added to list'; } else { $confirmation = $i . ' Person added to list'; } } if ($searchModel->load(Yii::$app->request->post()) && $searchModel->validate()) { } $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('searchresults', ['model' => $model, 'list' => $list, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'confirmation' => $confirmation]); }
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]); }