Iñigo Valentin преди 6 години
родител
ревизия
d41d26f9ac
променени са 7 файла, в които са добавени 95 реда и са изтрити 2 реда
  1. 1 1
      application/entity/Team.php
  2. 29 0
      application/entity/Unit.php
  3. 11 0
      application/helper/html.php
  4. 1 0
      application/page/Monster_Page.php
  5. 24 0
      application/view/monster.php
  6. 8 0
      public/css/monster.css
  7. 21 1
      public/css/ui.css

+ 1 - 1
application/entity/Team.php

@@ -54,7 +54,7 @@
          *
          * @param SQLite3 $db Connection to the database.
          * @param int $id Monster identifier.
-         * @param complete If false, query only monster and k_monster.
+         * @param complete If false, it won't load the units.
          */
         public function __construct($db, $id, $complete = true){
             global $path;

+ 29 - 0
application/entity/Unit.php

@@ -2,6 +2,7 @@
 
     require_once($path["entity"] . "Entity.php");
     require_once($path["entity"] . "K_Unit.php");
+    require_once($path["entity"] . "Team.php");
     require_once($path["entity"] . "Rune.php");
 
 
@@ -182,6 +183,11 @@
          */
         public $rune = [];
 
+        /**
+         * The {@see Teams}s the unit is on.
+         */
+        public $teams = [];
+
         /**
          * Array with the levels of the skills.
          */
@@ -284,6 +290,7 @@
             #$this->notes = $r["notes"];
             if ($complete){
                 $this->load_runes();
+                $this->load_teams();
                 $s =
                   "SELECT level " .
                   "FROM " .
@@ -316,6 +323,28 @@
             }
         }
 
+        /**
+         * Loads the teams array, with the @{Team}s the unit is on.
+         */
+        public function load_teams(){
+            global $UID;
+            $this->teams = [];
+            $s = "
+              SELECT DISTINCT team.id AS id
+              FROM 
+                team,
+                team_unit
+              WHERE
+                team.uid = '$UID' AND
+                team.id = team_unit.team AND
+                team_unit.unit = '" . $this->id . "';
+            ";
+            $q = $this->db->query($s);
+            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                array_push($this->teams, new Team($this->db, $r["id"], false));
+            }
+        }
+
         /**
          * Loads the information about the equiped runes. 
          * It is autoatically called at construction time if the

+ 11 - 0
application/helper/html.php

@@ -12,11 +12,13 @@
             $k = $unit->unit;
             $stars = $unit->stars;
             $level = true;
+            $teams = (sizeof($unit->teams) > 0);
         }
         elseif ($unit instanceof K_Unit){
             $k = $unit;
             $stars = $unit->base_stars;
             $level = false;
+            $teams = 0;
         }
         else{
             return "";
@@ -52,6 +54,15 @@
             $html .= $unit->level . "\n";
             $html .= "</span>\n";
         }
+        $html .= "<span class='badges'>\n";
+        if ($teams > 0){
+            $title = $teams . " teams";
+            if ($teams == 1){
+                $title = "1 team: " . $unit->teams[0]->name;
+            }
+            $html .= "<img title='$title' src='" . $path["img"]["icon"] . "team.png'>";
+        }
+        $html .= "</span>\n";
         return $html;
     }
 

+ 1 - 0
application/page/Monster_Page.php

@@ -59,6 +59,7 @@
         private function calculate_buildings(){
             global $STAT;
             global $EFFECT_AREA;
+            global $UID;
             $s = "
               SELECT
                 affected_stat,

+ 24 - 0
application/view/monster.php

@@ -67,6 +67,30 @@
                             </span>
                         </div>
                         Obtained on <?=$page->unit->create_time->format('Y-m-d')?> (<?=$datediff?> days ago)<!-- from <?=$page->unit->source->name?> TODO SOurce name, days ago -->
+<?php
+                        if (sizeof($page->unit->teams) > 0){
+?>
+                            <div id='teams'>
+                                <h4>
+                                    Teams:
+                                </h4>
+                                <ul>
+<?php
+                                    foreach($page->unit->teams as $team){
+?>
+                                        <li>
+                                            <a target='blank' href='/<?=$UID?>/teams/<?=$team->id?>'>
+                                                <?=$team->name?>
+                                            </a>
+                                        </li>
+<?php
+                                    }
+?>
+                                </ul>
+                            </div>
+<?php
+                        }
+?>
                     </div>
                 </div>
 <?php

+ 8 - 0
public/css/monster.css

@@ -27,6 +27,14 @@ section#monster article#profile div#monster_info div#monster_details{
     margin-top: -3em;
 }
 
+section#monster article#profile div#monster_info div#monster_details div#teams{
+    text-align: left;
+}
+
+section#monster article#profile div#monster_info div#monster_details div#teams h4{
+    margin: 0.2em auto;
+}
+
 section#monster article#profile div#monster_info div#exp{
     border: 0.3em solid var(--ui-color-border);
     border-radius: 0.5em;

+ 21 - 1
public/css/ui.css

@@ -555,7 +555,7 @@ div.monster_panel span.level{
     font-weight: bold;
     color: #000;
     text-shadow: 0 0 0.1em #fff, 0 0 0.1em #fff, 0 0 0.2em #fff, 0 0 0.2em #fff, 0 0 0.5em #fff, 0 0 0.5em #fff;
-    font-size: 2.5em;
+    font-size: 2em;
     width: 90%;
     text-align: right;
     bottom: 1.3em;
@@ -564,6 +564,26 @@ div.monster_panel span.level{
     display: block;
 }
 
+div.monster_panel span.badges{
+    position: absolute;
+    width: 90%;
+    text-align: left;
+    bottom: 0.2em;
+    left: 0.2em;
+    z-index: 1;
+    pointer-events: none;
+    display: block;
+}
+
+div.monster_panel span.badges img{
+    width: 1.4em;
+    height: 1.4em;
+    /* filter: drop-shadow(0 0 0.3em #ffffff) drop-shadow(0 0 0.1em #ffffff); */
+    border-radius: 50%;
+    border: 0.15em solid #000000;
+    background-color: #ffffff;
+}
+
 /**
  * /Monster panel
  */