Пример #1
0
 /**
  * @desc This function required object Notation containing the module_name, id_in_module, user_id, note and notation_scale.
  * @param object $notation Notation
  */
 public static function display_active_image(Notation $notation)
 {
     $note_post = AppContext::get_request()->get_int('note', 0);
     $id_post = AppContext::get_request()->get_int('id', 0);
     if (!empty($note_post) && !empty($id_post)) {
         $notation->set_id_in_module($id_post);
         $notation->set_note($note_post);
         self::register_notation($notation);
     } else {
         $template = new FileTemplate('framework/content/notation/notation.tpl');
         $average_notes = $notation->get_average_notes();
         $int = intval($average_notes);
         $decimal = floatval('0.' . substr($average_notes, strpos($average_notes, '.') + 1));
         for ($i = 1; $i <= $notation->get_notation_scale(); $i++) {
             $star_full = false;
             $star_half = false;
             $star_empty = false;
             if ($int >= $i || $int + 1 == $i && $decimal >= 0.75) {
                 $star_full = true;
             } else {
                 if ($int + 1 == $i && $decimal > 0.25 && $decimal < 0.75) {
                     $star_half = true;
                 } else {
                     $star_empty = true;
                 }
             }
             $template->assign_block_vars('star', array('I' => $i, 'STAR_EMPTY' => $star_empty, 'STAR_HALF' => $star_half, 'STAR_FULL' => $star_full));
         }
         $count_notes = $notation->get_number_notes();
         $template->put_all(array('C_JS_NOT_ALREADY_INCLUDED' => !self::$js_already_included, 'C_NOTES' => $count_notes > 0 ? true : false, 'C_MORE_1_NOTES' => $count_notes > 1 ? true : false, 'CURRENT_URL' => REWRITED_SCRIPT, 'ID_IN_MODULE' => $notation->get_id_in_module(), 'NOTATION_SCALE' => $notation->get_notation_scale(), 'NUMBER_NOTES' => $count_notes, 'AVERAGE_NOTES' => $average_notes, 'ALREADY_NOTE' => $notation->user_already_noted(), 'L_NO_NOTE' => LangLoader::get_message('no_note', 'common'), 'L_AUTH_ERROR' => LangLoader::get_message('error.auth', 'status-messages-common'), 'L_ALREADY_NOTE' => self::$lang['already_vote'], 'L_NOTES' => LangLoader::get_message('notes', 'common'), 'L_NOTE' => LangLoader::get_message('note', 'common'), 'L_VALID_NOTE' => LangLoader::get_message('add_note', 'common')));
         self::$js_already_included = true;
         return $template->render();
     }
 }