Quellcode durchsuchen

Team list in unit page.

Iñigo Valentin vor 6 Jahren
Ursprung
Commit
69f7c3ceba

+ 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

+ 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;