public function generateRoleDropdown($person_id, $project_id) { $role_array = array(); $roles = $this->roles; // Get person project id $person_project = PersonProject::find()->where(['user_id' => $person_id, 'project_id' => $project_id])->one(); // Get project roles if ($roles) { foreach ($roles as $id => $role) { $role_array[$role->id] = $role->title; } } // Generate dropdown list if (count($role_array)) { return Html::DropDownList('role', $person_project->role, $role_array, ['class' => 'form-control input-sm role-select', 'data-id' => $person_project->id, 'prompt' => '']); } return ''; }
public static function isClientApproved($user_id, $project_id) { $model = \app\models\PersonProject::findOne(['user_id' => $user_id, 'project_id' => $project_id]); if ($model->approved == 1) { return 'approved'; } if ($model->approved == 2) { return 'denied'; } return false; }
public function getList() { return $this->hasMany(PersonProject::className(), ['user_id' => 'id']); }
public function actionRenderPdf($id, $list) { $project = Project::findOne($id); $people = PersonProject::find()->where(['project_id' => $id, 'list' => $list])->all(); if ($list == 1) { $list_type = 'Available'; } if ($list == 2) { $list_type = 'Final'; } $content = $this->renderPartial('_pdf', ['people' => $people]); $pdf = new Pdf(['mode' => Pdf::MODE_CORE, 'format' => Pdf::FORMAT_A4, 'orientation' => Pdf::ORIENT_PORTRAIT, 'destination' => Pdf::DEST_BROWSER, 'content' => $content, 'cssInline' => '.kv-heading-1{font-size:18px}, img{max-width:150px}, td{border-bottom:1px solid #CCC !important;}', 'options' => ['title' => $project->title], 'methods' => ['SetHeader' => [$project->title . ' - ' . $list_type . ' List'], 'SetFooter' => ['{PAGENO}']]]); return $pdf->render(); }
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]); }
public function getCount() { return PersonProject::find()->where(['role' => $this->id])->count(); }