Proyectos de Subversion Moodle

Rev

Rev 621 | Rev 925 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 621 Rev 622
Línea 1... Línea 1...
1
<?php
1
<?php
Línea 2... Línea 2...
2
 
2
 
3
class block_cesa_course_rating extends block_base
3
class block_cesa_course_rating extends block_base
-
 
4
{
-
 
5
 
4
{
6
 
5
  public function init()
7
  public function init()
6
  {
8
  {
7
    $this->title = get_string('pluginname', 'block_cesa_course_rating');
9
    $this->title = get_string('pluginname', 'block_cesa_course_rating');
Línea 8... Línea 10...
8
  }
10
  }
9
 
11
 
-
 
12
  public function applicable_formats()
10
  public function applicable_formats()
13
  {
11
  {
14
 
12
    return [
15
    return [
13
      'all' => false,
16
      'all' => false,
14
      'my' => false,
17
      'my' => false,
Línea 40... Línea 43...
40
 
43
 
41
  public function html_attributes()
44
  public function html_attributes()
42
  {
45
  {
43
    global $CFG;
46
    global $CFG;
-
 
47
    $attributes = parent::html_attributes();
-
 
48
 
-
 
49
    /*
-
 
50
      $ccn_mt = '';
-
 
51
      $ccn_mb = '';
-
 
52
      $ccn_pt = '';
-
 
53
      $ccn_pb = '';
-
 
54
      $ccn_css_class = '';
-
 
55
      
-
 
56
      if(!empty($this->config->ccn_margin_top)){
-
 
57
          if($this->config->ccn_margin_top == '0') {
-
 
58
              $ccn_mt = '';
-
 
59
          } elseif($this->config->ccn_margin_top == 'zero') {
-
 
60
              $ccn_mt = 'margin-top:0px;';
-
 
61
          } else {
-
 
62
              $ccn_mt = 'margin-top:'.$this->config->ccn_margin_top.'px;';
-
 
63
          }
-
 
64
      }
-
 
65
      if(!empty($this->config->ccn_margin_bottom)){
-
 
66
          $ccn_mb = 'margin-bottom:'.$this->config->ccn_margin_bottom.'px;';
-
 
67
      } else {
-
 
68
          $ccn_mb = '';
-
 
69
      }
-
 
70
      if(!empty($this->config->ccn_padding_top)){
-
 
71
          $ccn_pt = 'padding-top:'.$this->config->ccn_padding_top.'px;';
-
 
72
      } else {
-
 
73
          $ccn_pt = '';
-
 
74
      }
-
 
75
      if(!empty($this->config->ccn_padding_bottom)){
-
 
76
          $ccn_pb = 'padding-bottom:'.$this->config->ccn_padding_bottom.'px;';
-
 
77
      } else {
-
 
78
          $ccn_pb = '';
-
 
79
      }
-
 
80
      if(!empty($this->config->ccn_css_class)){
-
 
81
          $ccn_css_class = $this->config->ccn_css_class;
-
 
82
      } else {
-
 
83
          $ccn_css_class = '';
-
 
84
      }
-
 
85
      
-
 
86
      
-
 
87
      $ccn_stylize = $ccn_mt . $ccn_mb . $ccn_pt . $ccn_pb;
-
 
88
      
-
 
89
      
-
 
90
      
-
 
91
      
-
 
92
      
-
 
93
      $attributes['ccn_style'] = $ccn_stylize;
-
 
94
      // $attributes['class'] .= ' block_'. $this->name();
-
 
95
      $attributes['class'] .= ' '. $ccn_css_class;
-
 
96
      */
-
 
97
 
44
    $attributes = parent::html_attributes();
98
 
45
    return $attributes;
99
    return $attributes;
Línea 46... Línea 100...
46
  }
100
  }
47
 
101
 
Línea 53... Línea 107...
53
  public function get_content()
107
  public function get_content()
54
  {
108
  {
55
    global $CFG, $COURSE;
109
    global $CFG, $COURSE;
Línea 56... Línea 110...
56
 
110
 
57
    if ($this->content !== null) {
111
    if ($this->content !== null) {
58
      return $this->content;
112
      // return $this->content;
Línea 59... Línea 113...
59
    }
113
    }
Línea 60... Línea 114...
60
 
114
 
61
    $this->content = new stdClass;
115
    $this->content = new stdClass;
62
 
116
 
63
    if (!empty($this->config->title)) {
117
    if (!empty($this->config->title)) {
64
      $this->content->title = format_text($this->config->title, FORMAT_HTML, array('filter' => true));
118
      $this->content->title =  format_text($this->config->title, FORMAT_HTML, array('filter' => true));
Línea 65... Línea 119...
65
    } else {
119
    } else {
66
      $this->content->title = get_string('pluginname', 'block_cesa_course_rating');
120
      $this->content->title = get_string('pluginname', 'block_cesa_course_rating');
Línea 67... Línea 121...
67
    }
121
    }
-
 
122
 
-
 
123
    $courseid = $COURSE->id;
-
 
124
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
68
 
125
 
-
 
126
    $canRate = has_capability('block/cesa_course_rating:rate', $context);
Línea 69... Línea 127...
69
    $courseid = $COURSE->id;
127
    if ($canRate == 1) {
70
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
128
      $canRateClass = 'ccn-can-rate';
Línea 71... Línea 129...
71
 
129
    } else {
Línea 72... Línea 130...
72
    $canRate = has_capability('block/cesa_course_rating:rate', $context);
130
      $canRateClass = 'ccn-cannot-rate';
73
    $canRateClass = $canRate ? 'ccn-can-rate' : 'ccn-cannot-rate';
131
    }
74
 
132
 
Línea 75... Línea 133...
75
    $ccnSubmitRating = $this->submit_rating();
133
    $ccnSubmitRating = $this->submit_rating();
76
    $this->content->text = '';
134
    $this->content->text = '';
77
 
135
 
78
    $ccnRating = number_format($this->overall_rating($COURSE->id), 1);
136
    $ccnRating    = number_format($this->overall_rating($COURSE->id), 1);
Línea 90... Línea 148...
90
    } elseif ($ccnRating == 3.5) {
148
    } elseif ($ccnRating == 3.5) {
91
      $ccnStars = str_repeat($ccnStar, 3) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 1);
149
      $ccnStars = str_repeat($ccnStar, 3) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 1);
92
    } elseif ($ccnRating == 3) {
150
    } elseif ($ccnRating == 3) {
93
      $ccnStars = str_repeat($ccnStar, 3) . str_repeat($ccnStarVoid, 2);
151
      $ccnStars = str_repeat($ccnStar, 3) . str_repeat($ccnStarVoid, 2);
94
    } elseif ($ccnRating == 2.5) {
152
    } elseif ($ccnRating == 2.5) {
95
      $ccnStars = str_repeat($ccnStar, 2) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 2);
153
      $ccnStars = str_repeat($ccnStar, 2) . str_repeat($ccnStarHalf, 1)  . str_repeat($ccnStarVoid, 2);
96
    } elseif ($ccnRating == 2) {
154
    } elseif ($ccnRating == 2) {
97
      $ccnStars = str_repeat($ccnStar, 2) . str_repeat($ccnStarVoid, 3);
155
      $ccnStars = str_repeat($ccnStar, 2) . str_repeat($ccnStarVoid, 3);
98
    } elseif ($ccnRating == 1.5) {
156
    } elseif ($ccnRating == 1.5) {
99
      $ccnStars = str_repeat($ccnStar, 1) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 3);
157
      $ccnStars = str_repeat($ccnStar, 1) . str_repeat($ccnStarHalf, 1)  . str_repeat($ccnStarVoid, 3);
100
    } elseif ($ccnRating == 0.5) {
158
    } elseif ($ccnRating == 0.5) {
101
      $ccnStars = str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 4);
159
      $ccnStars = str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 4);
102
    } else {
160
    } else {
103
      $ccnStars = str_repeat($ccnStarVoid, 5);
161
      $ccnStars = str_repeat($ccnStarVoid, 5);
104
    }
162
    }
Línea 108... Línea 166...
108
    $ccnThree = $this->get_specific_average($COURSE->id, 3);
166
    $ccnThree = $this->get_specific_average($COURSE->id, 3);
109
    $ccnTwo = $this->get_specific_average($COURSE->id, 2);
167
    $ccnTwo = $this->get_specific_average($COURSE->id, 2);
110
    $ccnOne = $this->get_specific_average($COURSE->id, 1);
168
    $ccnOne = $this->get_specific_average($COURSE->id, 1);
Línea 111... Línea 169...
111
 
169
 
112
    $this->content->text .= '
170
    $this->content->text .= '
113
        <div class="cs_row_five">
171
        	<div class="cs_row_five">
114
          <div class="student_feedback_container">
172
									<div class="student_feedback_container">
115
            <h4 data-ccn="title" class="aii_title">' . $this->content->title . '</h4>
173
										<h4 data-ccn="title" class="aii_title">' . $this->content->title . '</h4>
116
            <div class="s_feeback_content">
174
										<div class="s_feeback_content">
117
              <ul class="skills">
175
									        <ul class="skills">
118
                <li class="list-inline-item">5 estrellas</li>
176
									        	<li class="list-inline-item">' . get_string('stars_5', 'block_cesa_course_rating') . '</li>
119
                <li class="list-inline-item progressbar1" data-width="' . $ccnFive . '" data-target="100">' . $ccnFive . '%</li>
177
									            <li class="list-inline-item progressbar1" data-width="' . $ccnFive . '" data-target="100">' . $ccnFive . '%</li>
120
              </ul>
178
									        </ul>
121
              <ul class="skills">
179
									        <ul class="skills">
122
                <li class="list-inline-item">4 estrellas</li>
180
									        	<li class="list-inline-item">' . get_string('stars_4', 'block_cesa_course_rating') . '</li>
123
                <li class="list-inline-item progressbar2" data-width="' . $ccnFour . '" data-target="100">' . $ccnFour . '%</li>
181
									            <li class="list-inline-item progressbar2" data-width="' . $ccnFour . '" data-target="100">' . $ccnFour . '%</li>
124
              </ul>
182
									        </ul>
125
              <ul class="skills">
183
									        <ul class="skills">
126
                <li class="list-inline-item">3 estrellas</li>
184
									        	<li class="list-inline-item">' . get_string('stars_3', 'block_cesa_course_rating') . '</li>
127
                <li class="list-inline-item progressbar3" data-width="' . $ccnThree . '" data-target="100">' . $ccnThree . '%</li>
185
									            <li class="list-inline-item progressbar3" data-width="' . $ccnThree . '" data-target="100">' . $ccnThree . '%</li>
128
              </ul>
186
									        </ul>
129
              <ul class="skills">
187
									        <ul class="skills">
130
                <li class="list-inline-item">2 estrellas</li>
188
									        	<li class="list-inline-item">' . get_string('stars_2', 'block_cesa_course_rating') . '</li>
131
                <li class="list-inline-item progressbar4" data-width="' . $ccnTwo . '" data-target="100">' . $ccnTwo . '%</li>
189
									            <li class="list-inline-item progressbar4" data-width="' . $ccnTwo . '" data-target="100">' . $ccnTwo . '%</li>
132
              </ul>
190
									        </ul>
133
              <ul class="skills">
191
									        <ul class="skills">
134
                <li class="list-inline-item">1 estrella</li>
192
									        	<li class="list-inline-item">' . get_string('stars_1', 'block_cesa_course_rating') . '</li>
135
                <li class="list-inline-item progressbar5" data-width="' . $ccnOne . '" data-target="100">' . $ccnOne . '%</li>
193
									            <li class="list-inline-item progressbar5" data-width="' . $ccnOne . '" data-target="100">' . $ccnOne . '%</li>
136
              </ul>
194
									        </ul>
137
            </div>
195
										</div>
138
            <div class="aii_average_review text-center ' . $canRateClass . '">
196
										<div class="aii_average_review text-center ' . $canRateClass . '">
139
              <div class="av_content">
197
											<div class="av_content">
140
                <h2>' . $ccnRating . '</h2>
198
												<h2>' . $ccnRating . '</h2>
141
                <ul class="aii_rive_list mb0">
199
												<ul class="aii_rive_list mb0">
142
                  ' . $ccnStars . '
200
													' . $ccnStars . '
143
                </ul>
201
												</ul>
144
                <p>' . $this->count_ratings($COURSE->id) . '</p>';
202
												<p>' . $this->count_ratings($COURSE->id) . '</p>';
145
    if ($canRate == 1) {
203
    if ($canRate == 1) {
146
      $this->content->text .= $ccnSubmitRating;
204
      $this->content->text .= $ccnSubmitRating;
147
    }
205
    }
148
    $this->content->text .= '
206
    $this->content->text .= '
149
              </div>
207
											</div>
150
            </div>
208
										</div>
151
          </div>
209
									</div>
152
        </div>';
210
								</div>';
153
    return $this->content;
211
    return $this->content;
-
 
212
  }
-
 
213
 
-
 
214
  public function overall_rating($courseID)
-
 
215
  {
-
 
216
    global $CFG, $DB;
-
 
217
    $sql = "  SELECT AVG(rating) AS average
-
 
218
                  FROM {block_cesa_course_rating}
-
 
219
                  WHERE course = $courseID
-
 
220
               ";
-
 
221
    $totalAverage = -1;
-
 
222
    if ($getAverage = $DB->get_record_sql($sql)) {
-
 
223
      $totalAverage = round($getAverage->average * 2) / 2;
-
 
224
    }
-
 
225
    return $totalAverage;
-
 
226
  }
-
 
227
 
-
 
228
  public function count_ratings($courseID)
-
 
229
  {
-
 
230
    global $CFG, $DB;
-
 
231
    $countRecords = $DB->count_records('block_cesa_course_rating', array('course' => $courseID));
-
 
232
    $countRatings = '';
-
 
233
    if ($countRecords > 0) {
-
 
234
      $countRatings = get_string('rated_by', 'block_cesa_course_rating', $countRecords);
-
 
235
    } else {
-
 
236
      $countRatings = get_string('rated_by_none', 'block_cesa_course_rating');
-
 
237
    }
-
 
238
    return $countRatings;
-
 
239
  }
-
 
240
  public function count_ratings_external($courseID)
-
 
241
  {
-
 
242
    global $CFG, $DB;
-
 
243
    $countRecords = $DB->count_records('block_cesa_course_rating', array('course' => $courseID));
-
 
244
    return $countRecords;
-
 
245
  }
-
 
246
 
-
 
247
  public function get_specific_average($courseID, $rating)
-
 
248
  {
-
 
249
    global $CFG, $DB;
-
 
250
    $countOnlyRating        = $DB->count_records('block_cesa_course_rating', array('course' => $courseID, 'rating' => $rating));
-
 
251
    $countExcludingRating   = $DB->count_records_sql(
-
 
252
      "       SELECT COUNT(*)
-
 
253
                FROM {block_cesa_course_rating}
-
 
254
                WHERE course = $courseID
-
 
255
                AND rating <> $rating
-
 
256
        "
-
 
257
    );
-
 
258
 
-
 
259
    $countTotal             = $DB->count_records('block_cesa_course_rating', array('course' => $courseID));
-
 
260
 
-
 
261
    if ($countTotal == 0) {
-
 
262
      $result = '0';
-
 
263
    } else {
-
 
264
      $result = $countOnlyRating / $countTotal * 100;
-
 
265
    }
-
 
266
    return $result;
-
 
267
  }
-
 
268
 
-
 
269
  public function submit_rating()
-
 
270
  {
-
 
271
 
-
 
272
    global $CFG, $COURSE;
-
 
273
 
-
 
274
    $courseid = $COURSE->id;
-
 
275
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
-
 
276
 
-
 
277
    $ccnStar =  '<span class="fa fa-star"></span>';
-
 
278
    $return =   '<form id="ccn-star-rate" method="post" action="' . $CFG->wwwroot . '/blocks/cesa_course_rating/rate_course.php">
-
 
279
                    <input name="id" type="hidden" value="' . $courseid . '" />
-
 
280
                    <div class="ccn-star-rate-inner">';
-
 
281
    for ($i = 5; $i >= 1; $i--) {
-
 
282
      $printCcnStar = str_repeat($ccnStar, $i);
-
 
283
      $return .= '    <input required type="radio" id="stars-' . $i . '" name="rating" value="' . $i . '" /><label for="stars-' . $i . '"></label>';
-
 
284
    }
-
 
285
    $return .= '  </div>
-
 
286
                    <button class="btn btn-primary" type="submit">' . get_string('rate_course', 'block_cesa_course_rating') . '</button>
-
 
287
                  </form>';
-
 
288
    return $return;
-
 
289
  }
-
 
290
 
-
 
291
  public function external_star_rating($courseID)
-
 
292
  {
-
 
293
 
-
 
294
    $ccnStar      = '<li class="list-inline-item"><i class="fa fa-star"></i></li>';
-
 
295
    $ccnStarHalf  = '<li class="list-inline-item"><i class="fa fa-star-half-o"></i></li>';
-
 
296
    $ccnStarVoid  = '<li class="list-inline-item"><i class="fa fa-star-o"></i></li>';
-
 
297
    $ccnRating    = $this->overall_rating($courseID);
-
 
298
 
-
 
299
    if ($ccnRating == 5) {
-
 
300
      $ccnStars = str_repeat($ccnStar, 5);
-
 
301
    } elseif ($ccnRating == 4.5) {
-
 
302
      $ccnStars = str_repeat($ccnStar, 4) . str_repeat($ccnStarHalf, 1);
-
 
303
    } elseif ($ccnRating == 4) {
-
 
304
      $ccnStars = str_repeat($ccnStar, 4) . str_repeat($ccnStarVoid, 1);
-
 
305
    } elseif ($ccnRating == 3.5) {
-
 
306
      $ccnStars = str_repeat($ccnStar, 3) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 1);
-
 
307
    } elseif ($ccnRating == 3) {
-
 
308
      $ccnStars = str_repeat($ccnStar, 3) . str_repeat($ccnStarVoid, 2);
-
 
309
    } elseif ($ccnRating == 2.5) {
-
 
310
      $ccnStars = str_repeat($ccnStar, 2) . str_repeat($ccnStarHalf, 1)  . str_repeat($ccnStarVoid, 2);
-
 
311
    } elseif ($ccnRating == 2) {
-
 
312
      $ccnStars = str_repeat($ccnStar, 2) . str_repeat($ccnStarVoid, 3);
-
 
313
    } elseif ($ccnRating == 1.5) {
-
 
314
      $ccnStars = str_repeat($ccnStar, 1) . str_repeat($ccnStarHalf, 1)  . str_repeat($ccnStarVoid, 3);
-
 
315
    } elseif ($ccnRating == 0.5) {
-
 
316
      $ccnStars = str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 4);
-
 
317
    } else {
-
 
318
      $ccnStars = str_repeat($ccnStarVoid, 5);
-
 
319
    }
-
 
320
 
-
 
321
    $return = '<div class="ccn-external-stars">' . $ccnStars . '<li class="list-inline-item"><span>(' . $this->count_ratings_external($courseID) . ')</span></li></div>';
-
 
322
    return $return;
154
  }
323
  }