Warning, file /webapps/ocs-webserver/application/modules/default/views/helpers/PrintRatingWidget.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 <?php
0002 /**
0003  *  ocs-webserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-webserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 class Default_View_Helper_PrintRatingWidget extends Zend_View_Helper_Abstract
0023 {
0024 
0025     public function printRatingWidget($project_id)
0026     {
0027         $modelRating = new Default_Model_DbTable_ProjectRating();
0028         $rating = $modelRating->fetchRating($project_id);
0029         $likesAndDislikes = ($rating['count_likes'] == 0 and $rating['count_dislikes'] == 0) ? '' : '(' . $rating['count_likes'] . '/' . $rating['count_dislikes'] . ')';
0030         $cssNoVotes = ($rating['votes_total'] == 0) ? ';opacity:0.5;' : '';
0031 
0032         // calculate colour
0033         $blue = $red = $green = $default=200;
0034         $score = $rating['laplace_score'] * 100;
0035 
0036         if($score>50) {
0037             $red=dechex($default-(($score-50)*4));
0038             $green=dechex($default);
0039             $blue=dechex($default-(($score-50)*4));
0040         }elseif($score<51) {
0041             $red=dechex($default);
0042             $green=dechex($default-((50-$score)*4));
0043             $blue=dechex($default-((50-$score)*4));
0044         }
0045         if(strlen($green)==1) $green='0'.$green;
0046         if(strlen($red)==1) $red='0'.$red;
0047 
0048         return $this->getHTML(
0049             floor($rating['laplace_score'] * 100),
0050             $red, $green, $blue,
0051             floor((1 - $rating['laplace_score']) * 100),
0052             $cssNoVotes
0053             );
0054     }
0055 
0056     protected function getHTML($likes, $red, $green , $blue, $dislikes, $cssNoVotes)
0057     {
0058         return <<< _END_HTML_
0059                 <div class="rating">
0060                   
0061                     <div class="rating-text">
0062                         <small class="center-block text-center">Score {$likes}%</small>
0063                     </div>
0064                     <div class="progress">
0065                         <div class="progress-bar" style="background-color: #{$red}{$green}{$blue};width: {$likes}%;">
0066                             <span class="sr-only">{$likes} Likes</span>
0067                         </div>
0068                         <div class="progress-bar" style="background-color:#eeeeee;width: {$dislikes}%;{$cssNoVotes}">
0069                             <span class="sr-only">{$dislikes} Dislikes</span>
0070                         </div>
0071                     </div>
0072                 </div>
0073 _END_HTML_;
0074     }
0075 
0076 }