/** * Displays a single Shift model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $dp = new ActiveDataProvider(['query' => Participant::find()->where(['shift_id' => $id])]); $form = new AddParticipantForm(); $form->shift_id = $id; if ($form->load(Yii::$app->request->post())) { $form->addUser(); } return $this->render('view', ['model' => $model, 'form' => $form, 'dp' => $dp]); }
/** * @return array|bool|null|\yii\db\ActiveRecord */ public function actionGetpostdata() { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; $id = intval(Yii::$app->request->post('id')); $participant = Participant::find()->select(['date', 'name', 'text'])->where(['id' => $id])->one(); if ($participant) { $participant->date = Date::DateMonth($participant->date); return $participant; } } return false; }
public function init() { // $presents = (new Present())->presents; $presents = (new Present())->getPresentsList(); $activity = Activity::find()->orderBy('RAND()')->one(); $query = Participant::find()->orderBy(['id' => SORT_DESC]); $countQuery = clone $query; $p_pages = new Pagination(['totalCount' => $countQuery->count()]); $p_pages->pageSize = 10; $models = $query->offset($p_pages->offset)->limit($p_pages->limit)->all(); $winners = Participant::find()->where(['winner' => 1])->all(); $this->getView()->params = ['participants' => $models, 'participants_pages' => $p_pages, 'presents' => $presents, 'activity' => $activity, 'winners' => $winners]; parent::init(); // TODO: Change the autogenerated stub }
public function generateReport() { $output = []; $participants = Participant::find()->joinWith(['shift', 'shift.team'])->where(['team.event_id' => $this->id])->orderBy(['participant.timestamp' => SORT_ASC])->all(); $date_containers = []; $date_totals = []; $user_totals = []; $multi_shift_totals = []; $team_names = ["Total Event" => 0]; $max_needed = ["Total Event" => $this->maxTotalShifts]; //Get list of teams, plus event total, and their max total shifts foreach ($this->teams as $team) { $team_names[$team->name] = 0; $max_needed[$team->name] = $team->maxTotalShifts; } //Loop through every participant signup, group by date (week) foreach ($participants as $participant) { $dt = new MDateTime($participant->timestamp); $dt->subToStart('W'); $timestamp = $dt->timestamp; $team_name = $participant->shift->team->name; if (!isset($date_containers[$timestamp])) { $date_containers[$timestamp] = $team_names; $date_totals[$timestamp] = 0; $user_totals[$timestamp] = 0; } if (!isset($date_containers[$timestamp][$team_name])) { $date_containers[$timestamp][$team_name] = 0; } $date_containers[$timestamp][$team_name]++; $date_containers[$timestamp]["Total Event"]++; $date_totals[$timestamp]++; } //Add missing dates to $date_containers $first_date = new MDateTime(array_keys($date_containers)[0]); $last_date = new MDateTime(array_pop(array_keys($date_containers))); $last_date->add(new DateInterval('P1W')); $period = new DatePeriod($first_date, new DateInterval('P1W'), $last_date); foreach ($period as $dt) { if (!isset($date_containers[$dt->getTimestamp()])) { $date_containers[$dt->getTimestamp()] = $team_names; $date_totals[$dt->getTimestamp()] = 0; $user_totals[$dt->getTimestamp()] = 0; } //Calculate unique user totals from the start to each different time period $unique_ids = []; foreach ($participants as $participant) { $end_of_week = new MDateTime($dt->getTimestamp()); $end_of_week->addToEnd('W'); if ($participant->timestamp <= $end_of_week->timestamp) { } $unique_ids[$participant->user_id] = 1; } $user_totals[$dt->getTimestamp()] = count($unique_ids); } ksort($date_containers); ksort($date_totals); ksort($user_totals); //Add previous dates totals to the next date past that one //to show progression over time $current_vals = []; foreach ($date_containers as $timestamp => $data) { foreach ($data as $team_name => $total) { if (isset($current_vals[$team_name])) { $date_containers[$timestamp][$team_name] += $current_vals[$team_name]; } } $current_vals = $date_containers[$timestamp]; } $headers = ['Team']; foreach ($period as $date) { $headers[] = $date->format('n/j'); } $raw_output = []; $percent_output = []; foreach ($team_names as $name => $v) { $team_raw_output = [$name]; $team_percent_output = [$name]; foreach ($period as $date) { $team_raw_output[] = $date_containers[$date->getTimestamp()][$name]; $team_percent_output[] = sprintf("%.1f%%", $date_containers[$date->getTimestamp()][$name] / $max_needed[$name] * 100); } $raw_output[] = $team_raw_output; $percent_output[] = $team_percent_output; } //Total shifts per participant foreach ($participants as $participant) { if (!isset($multi_shift_totals[$participant->user_id])) { $multi_shift_totals[$participant->user_id] = 0; } $multi_shift_totals[$participant->user_id]++; } $multi_shift_breakdown = []; foreach ($multi_shift_totals as $p_total) { $label = $p_total == 1 ? "1 Shift" : "{$p_total} Shifts"; if (!isset($multi_shift_breakdown[$p_total])) { $multi_shift_breakdown[$p_total] = [$label, 0]; } $multi_shift_breakdown[$p_total][1]++; } ksort($multi_shift_breakdown); //Sort by team name $sort_func = function ($a, $b) { if ($a[0] === "Total Event") { return -1; } if ($b[0] === "Total Event") { return 1; } return $a[0] > $b[0]; }; usort($raw_output, $sort_func); usort($percent_output, $sort_func); $output[] = $headers; $output[] = ["Percent Totals"]; $output = array_merge($output, $percent_output); $output[] = [""]; $output[] = ["Raw Totals"]; $output = array_merge($output, $raw_output); $output[] = [""]; $output[] = ["Weekly Total"]; $output[] = [""] + $date_totals; $output[] = [""]; $output[] = ["Total Unique Users"]; $output[] = [""] + $user_totals; $output[] = [""]; $output[] = ["Number of Shifts per Volunteer"]; $output = array_merge($output, $multi_shift_breakdown); return $output; }
/** * Lists all Participant models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Participant::find()->orderBy(['id' => SORT_DESC])]); return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * Lists all Participant models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Participant::find()->where(['winner' => 1])]); return $this->render('index', ['dataProvider' => $dataProvider]); }