Esempio n. 1
0
 public function genereraLag()
 {
     global $db;
     $lag = $this->listLag();
     foreach ($lag as $thislag) {
         $thislag->delete();
     }
     $nycklar = $this->listNycklar();
     $antalAnstallda = count($nycklar);
     $medlemmar = array();
     foreach ($nycklar as $nyckel) {
         $medlemmar[] = $nyckel["nyckel"];
     }
     $antalAnstallda = count($medlemmar);
     if ($antalAnstallda < 10) {
         $antalLag = 1;
     } else {
         if ($antalAnstallda == 10) {
             // lite specialfall, det blir tv㟬ag med fem personer i varje vid tio anst㫬da
             $antalLag = 2;
         } else {
             if ($antalAnstallda < 591) {
                 $antalLag = ceil($antalAnstallda / 10);
             } else {
                 $antalLag = 59;
             }
         }
     }
     $anstalldaPerLag = $antalLag > 0 ? $antalAnstallda / $antalLag : 0;
     $lag = array();
     for ($i = 0; $i < $antalLag; $i++) {
         for ($j = $i * floor($anstalldaPerLag); $j < $i * floor($anstalldaPerLag) + floor($anstalldaPerLag); $j++) {
             $lag[$i][] = $medlemmar[$j];
         }
     }
     if ($antalLag > 0) {
         $rest = $antalAnstallda - floor($anstalldaPerLag) * $antalLag;
         $j = 0;
         for ($i = floor($anstalldaPerLag) * $antalLag; $i < $antalAnstallda; $i++) {
             $lag[$j][] = $medlemmar[$i];
             $j++;
         }
         $lagnamnList = LagNamn::listAll();
         $lagkeys = array_rand($lagnamnList, count($lag));
         if (count($lagkeys) == 1) {
             $lagkeys = array($lagkeys);
         }
     }
     $i = 0;
     foreach ($lag as $lagtemp) {
         $lagnamn = $lagnamnList[$lagkeys[$i]];
         $namn = $lagnamn->getNamn();
         $bild = $lagnamn->getImgO();
         $lag = $this->skapaLag($lagnamn->getNamn(), $bild);
         $id = $lag->getId();
         $sql = "UPDATE " . self::KEY_TABLE . " SET lag_id = {$id} WHERE nyckel in (";
         foreach ($lagtemp as $nyckel) {
             $sql .= "'" . $nyckel . "',";
         }
         $sql = substr($sql, 0, -1);
         $sql .= ")";
         $db->nonquery($sql);
         $i++;
     }
 }
Esempio n. 2
0
<?php

require_once $_SERVER["DOCUMENT_ROOT"] . "/php/init.php";
Security::demand(ADMIN);
$smarty = new AdminSmarty();
$listLagNamn = LagNamn::listAll();
$smarty->assign("listLagNamn", $listLagNamn);
$smarty->display('listlagnamn.tpl');