public function listForfragningar($typ = self::FF_OLASTA) { global $db; $sql = "SELECT medlem_id FROM " . self::RELATION_TABLE . " WHERE kontakt_id = " . $this->getMedlem()->getId() . " AND medlem_id NOT IN (SELECT kontakt_id FROM " . self::RELATION_TABLE . " WHERE medlem_id = " . $this->getMedlem()->getId() . ")"; if ($typ == self::FF_OLASTA) { $sql .= " AND last = 0"; } else { if ($typ == self::FF_LASTA) { $sql .= " AND last = 1"; } } return Medlem::listByIds($db->valuesAsArray($sql)); }
public function listInvitable() { global $db; $sql = "\n\t\t\tSELECT id \n\t\t\tFROM " . Medlem::TABLE . " \n\t\t\tWHERE id IN (\n\t\t\t\tSELECT medlem_id \n\t\t\t\tFROM " . Foretag::KEY_TABLE . "\n\t\t\t\tWHERE \n\t\t\t\t\tforetag_id = " . $this->getForetag()->getId() . "\n\t\t\t\tAND\n\t\t\t\t\tlag_id IS NULL\n\t\t\t) \n\t\t"; $ids = $db->valuesAsArray($sql); return Medlem::listByIds($ids); }
public function listMedlemmar() { if (!$this->medlemmar) { global $db; $sql = "SELECT medlem_id FROM " . self::KEY_TABLE . " WHERE foretag_id = " . $this->getId() . " and medlem_id is not null"; $ids = $db->valuesAsArray($sql); $this->medlemmar = Medlem::listByIds($ids); } return $this->medlemmar; }
public static function listTopMedlemmar($limit = 10) { global $db; $sql = "SELECT medlem_id, sum(steg) FROM " . self::classToTable(get_class()) . " GROUP BY medlem_id LIMIT " . Security::secure_data($limit) . ";"; $ids = $db->valuesAsArray($sql); return Medlem::listByIds($ids); }
public function listMedlemmar($alla = false) { if ($this->medlemmar == null || $alla) { global $db; $sql = "SELECT medlem_id FROM " . self::RELATION_TABLE . " WHERE grupp_id = " . $this->getId(); if (!$alla) { $sql .= " AND godkannd_skapare = 1 AND godkannd_medlem = 1"; } $ids = $db->valuesAsArray($sql); $this->medlemmar = Medlem::listByIds($ids); } return $this->medlemmar; }
/** * undocumented function * * @param string $antal * @param string $inkludera_medlem * @return void */ public function getTopplista($antal = null, $inkludera_medlem = null) { if (!$this->topplista) { global $db; $medlem_inkluderad = false; $sql = $this->makeSQL(); //echo 'sql: '. $sql . "<br/>"; $res = $db->query($sql); $result = array(); $result_temp = array(); $placering = 0; $medlem_placering = 0; $resArray = array(); $ids = array(); while ($data = mysql_fetch_assoc($res)) { $ids[] = $data["medlem_id"]; $resArray[] = $data; } foreach ($resArray as $key => $data) { $data["quiz_antal"] = isset($data["quiz_antal"]) ? $data["quiz_antal"] : 0; $data["kommuner_antal"] = isset($data["kommuner_antal"]) ? $data["kommuner_antal"] : 0; if ($placering < $antal || !$antal) { $result[] = array("placering" => ++$placering, "medlem_id" => $data["medlem_id"], "steg" => $data["steg"], "quiz_antal" => $data["quiz_antal"], "kommuner_antal" => $data["kommuner_antal"]); } else { $result_temp[] = array("placering" => ++$placering, "medlem_id" => $data["medlem_id"], "steg" => $data["steg"], "quiz_antal" => $data["quiz_antal"], "kommuner_antal" => $data["kommuner_antal"]); } if ($inkludera_medlem && $inkludera_medlem->getId() == $data["medlem_id"] && $antal != null) { $medlem_placering = $placering; $medlem_inkluderad = true; } if ($antal && $placering >= $antal && (!$inkludera_medlem || $medlem_inkluderad && $placering >= $medlem_placering + 2)) { break; } } if ($inkludera_medlem && $medlem_inkluderad && $medlem_placering > $antal) { $medlem_placering_mod = $medlem_placering - $antal - 1; if ($medlem_placering_mod - 2 >= 0 && isset($result_temp[$medlem_placering_mod - 2])) { $result[] = $result_temp[$medlem_placering_mod - 2]; } if ($medlem_placering_mod - 1 >= 0 && isset($result_temp[$medlem_placering_mod - 1])) { $result[] = $result_temp[$medlem_placering_mod - 1]; } $result[] = $result_temp[$medlem_placering_mod]; if (sizeof($result_temp) >= $medlem_placering_mod + 2 && isset($result_temp[$medlem_placering_mod + 1])) { $result[] = $result_temp[$medlem_placering_mod + 1]; } if (sizeof($result_temp) >= $medlem_placering_mod + 3 && isset($result_temp[$medlem_placering_mod + 2])) { $result[] = $result_temp[$medlem_placering_mod + 2]; } } // load all needed members at once foreach ($result as $key => $resultrow) { $ids[] = $result[$key]["medlem_id"]; } $medlemArray = Medlem::listByIds($ids); // populate the array with member objects foreach ($result as $key => $resultrow) { $result[$key]["medlem"] = Medlem::loadById($result[$key]["medlem_id"]); } $this->topplista = $result; } return $this->topplista; }