1 | <?php |
||
2 | use yii\helpers\Html; |
||
3 | use yii\helpers\Url; |
||
4 | use yii\widgets\ActiveForm; |
||
5 | use yii\bootstrap\Button; |
||
6 | use yii\helpers\ArrayHelper as AH; |
||
7 | |||
8 | use common\models\User; |
||
9 | use common\models\Question; |
||
10 | /** |
||
11 | * @var yii\web\View $this |
||
12 | */ |
||
13 | \site\assets\PickadateAsset::register($this); |
||
14 | |||
15 | $this->title = "The Faster Scale App | Previous Check-ins"; |
||
16 | $time = Yii::$container->get('common\interfaces\TimeInterface'); |
||
17 | $this->registerJsFile('/js/checkin/view.js', ['depends' => [\site\assets\AppAsset::class]]); |
||
18 | if($answer_pie) { |
||
19 | $this->registerJsFile('/js/checkin/charts/pie.js', ['depends' => [\site\assets\AppAsset::class]]); |
||
20 | } |
||
21 | |||
22 | function checkboxItemTemplate($index, $label, $name, $checked, $value) { |
||
0 ignored issues
–
show
|
|||
23 | $checked_val = ($checked) ? "btn-primary" : ""; |
||
24 | return "<button class='btn btn-default $checked_val' data-toggle='button' disabled='disabled' name='$name' value='$value'>$label</button>"; |
||
25 | } |
||
26 | |||
27 | $pie_data = []; |
||
28 | if($answer_pie) { |
||
29 | $values = array_map('intval', array_column($answer_pie, "count")); |
||
30 | $labels = array_column($answer_pie, "name"); |
||
31 | $colors = array_column($answer_pie, "color"); |
||
32 | $highlights = array_column($answer_pie, "highlight"); |
||
33 | |||
34 | $pie_data = [ |
||
35 | "labels" => $labels, |
||
36 | "datasets" => [[ |
||
37 | "data" => $values, |
||
38 | "backgroundColor" => $colors, |
||
39 | "hoverBackgroundColor" => $highlights |
||
40 | ]] |
||
41 | ]; |
||
42 | } else { |
||
43 | } |
||
44 | |||
45 | $minus_week = $time->alterLocalDate($actual_date, "-1 week"); |
||
46 | $minus_day = $time->alterLocalDate($actual_date, "-1 day"); |
||
47 | $plus_day = $time->alterLocalDate($actual_date, "+1 day"); |
||
48 | $plus_week = $time->alterLocalDate($actual_date, "+1 week"); |
||
49 | ?> |
||
50 | <div class="checkin-view"> |
||
51 | <h1>View Previous Check-ins</h1> |
||
52 | |||
53 | <?php |
||
54 | switch(true) { |
||
55 | case ($score < 30): |
||
56 | $alert_level = "success"; |
||
57 | $alert_msg = "You're doing well! Keep on doing whatever it is you're doing!"; |
||
58 | break; |
||
59 | |||
60 | case ($score < 40): |
||
61 | $alert_level = "info"; |
||
62 | $alert_msg = "Some warning signs, but nothing too bad. Analyze what you're feeling and be watchful you don't move further down the scale."; |
||
63 | break; |
||
64 | |||
65 | case ($score < 60): |
||
66 | $alert_level = "warning"; |
||
67 | $alert_msg = "Definite warning signs. Sounds like you aren't doing well. Take a break from whatever you're doing and process your thoughts and emotions."; |
||
68 | break; |
||
69 | |||
70 | default: |
||
71 | $alert_level = "danger"; |
||
72 | $alert_msg = "Welcome to the dangerzone. You need to take action right now or you'll continue moving down the scale. Go call someone. Try visiting <a href='http://emergency.nofap.org/'>http://emergency.nofap.org</a> for immediate help."; |
||
73 | } |
||
74 | ?> |
||
75 | |||
76 | <div class='row'> |
||
77 | <div class='col-md-8'> |
||
78 | <div id='past-checkin-nav' role='toolbar' class='btn-toolbar'> |
||
79 | <div class='form-inline'> |
||
80 | <div class='btn-group' role='group'> |
||
81 | <a class="btn btn-default" href="<?= Url::toRoute(['checkin/view', 'date'=>$minus_week]); ?>" title="<?=Html::encode($minus_week)?>" aria-label="Previous Week"><<</a> |
||
82 | <a class="btn btn-default" href="<?= Url::toRoute(['checkin/view', 'date'=>$minus_day]); ?>" title="<?=Html::encode($minus_day)?>" aria-label="Previous Day"><</a> |
||
83 | </div> |
||
84 | <div class='btn-group datepicker-container' role='group'> |
||
85 | <input type="text" id="datepicker" class='form-control btn btn-default' value="<?=$actual_date?>" data-value="<?=$actual_date?>" readOnly="true" /> |
||
86 | </div> |
||
87 | <div class='btn-group' role='group'> |
||
88 | <a class="btn btn-default<?= $isToday ? " disabled" : "" ?>" href="<?= Url::toRoute(['checkin/view', 'date'=>$plus_day]); ?>" title="<?=Html::encode($plus_day)?>" aria-label="Next Day">></a> |
||
89 | <a class="btn btn-default<?= $isToday ? " disabled" : "" ?>" href="<?= Url::toRoute(['checkin/view', 'date'=>$plus_week]); ?>" title="<?=Html::encode($plus_week)?>" aria-label="Next Week">>></a> |
||
90 | </div> |
||
91 | </div> |
||
92 | </div> |
||
93 | <div id="score"> |
||
94 | <h2>Score: <?php print $score; ?></h2> |
||
95 | <div class='alert alert-<?=$alert_level?>'><?=$alert_msg?></div> |
||
96 | </div> |
||
97 | </div> |
||
98 | <div class='col-md-4'> |
||
99 | <div class='card'> |
||
100 | <div class='card-header'><h4>Category Breakdown</h4></div> |
||
101 | <div class='card-block'> |
||
102 | <div class='card-text'> |
||
103 | <?php if ($pie_data): ?> |
||
104 | <canvas id='category-pie-chart'></canvas> |
||
105 | <?php else: ?> |
||
106 | <p>no data</p> |
||
107 | <?php endif; ?> |
||
108 | </div> |
||
109 | </div> |
||
110 | </div> |
||
111 | </div> |
||
112 | </div> |
||
113 | |||
114 | |||
115 | <?php if($questions) { |
||
116 | print "<h3>Processing Questions:</h3>"; |
||
117 | foreach($questions as $behavior_id => $behavior_questions) { |
||
118 | print "<div class='well well-sm'>"; |
||
119 | print "<button type='button' class='btn btn-primary' disabled='disabled'>{$behavior_questions['question']['title']}</button>"; |
||
120 | print "<div class='row'>"; |
||
121 | foreach($behavior_questions['answers'] as $question) { |
||
122 | print "<div class='col-md-4'>"; |
||
123 | print "<p><strong>{$question['title']}</strong></p>"; |
||
124 | print "<p>".Html::encode($question['answer'])."</p>"; |
||
125 | print "</div>"; |
||
126 | } |
||
127 | print "</div></div>"; |
||
128 | } |
||
129 | } |
||
130 | |||
131 | ?> |
||
132 | <h3>Behaviors:</h3> |
||
133 | <?php |
||
134 | $form = ActiveForm::begin([ |
||
135 | 'id' => 'checkin-form', |
||
136 | 'options' => ['class' => 'form-horizontal'], |
||
137 | ]); |
||
138 | |||
139 | foreach($categories as $category) { |
||
140 | $behaviors = AH::map($behaviorsList[$category['id']], 'id', 'name'); |
||
141 | print $form |
||
142 | ->field($model, "behaviors{$category['id']}") |
||
143 | ->checkboxList($behaviors, |
||
144 | ['item' => "checkboxItemTemplate"]); |
||
145 | } |
||
146 | ActiveForm::end(); |
||
147 | |||
148 | $this->registerJson($past_checkin_dates, "past-checkin-dates"); |
||
149 | if($answer_pie) { |
||
150 | $this->registerJson($pie_data, "pie_data"); |
||
151 | } |
||
152 | ?> |
||
153 | </div> |
||
154 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.