Jump to content

DarkAngelBGE

WFG Retired
  • Posts

    7.686
  • Joined

  • Last visited

Posts posted by DarkAngelBGE

  1. I am through the campaign already...it is a good campaign, but a bit too much base building IMO. There should have been more scenarios with time constraints or a one-man-show..like you get a hero and have to go through an enemy fort without being seen.

    The skirmish modus is okay either...however, the AI is not very good. :)

  2. I would like to propose that the list of fonts we are able to post with in the WFG forums be increased with fonts relating to 0ad and TLA. For example, some fonts pertaining to the various civilizations in 0ad be included (Greek, Old Persian, Celtic/Germanic Runes, an informal Latin script or two, ect.), and for TLA there could be a few Tengwar fonts, and some Angerthas and Cirith fonts.

    John, that will be some kind of problem, because in order for the fonts to be displayed properly we will need to have them installed on all forumers' computers, or else they won't see them. Of course, we would have an alternative "fall back" font if a particular font is missing, but at least not all forumers will have the same community experience anymore.

    Personally I would like to keep it that way. If an Arda font is needed, and that is not too often the case, images would do the job awesomely, non?

  3. Hey guys, I cannot get one of my unit tests to pass. :)

    Vertreter := (German) Spokesman.

    Mitglied := (German) Member.

    The application is to make members into spokesmen and providing a CRUD (Create, Read, Update, delete) interface to do it.


    <?php
    require_once('simpletest/unit_tester.php');
    require_once('simpletest/reporter.php');

    require_once('../Mitglied.php');
    require_once('../Vertreter.php');
    require_once('../lib/Database.php');

    class TestOfMitglied extends UnitTestCase {
    function testMitgliedId() {
    $m=new Mitglied(1);
    $this->assertEqual($m->id(),1);

    $v=Mitglied::findByID(1);
    $this->assertEqual($m->wb(), $v->wb());
    }

    function testMitgliedIsVertreter() {
    $m=new Mitglied(1);
    $this->assertFalse($m->isVertreter());

    $m->setVertreter(false);
    $m->save();
    $this->assertFalse($m->isVertreter());

    $m->setVertreter(true);
    $m->save();
    $this->assertTrue($m->isVertreter()); // *
    }

    }

    $test = new TestOfMitglied;
    $test->run(new HtmlReporter());
    ?>

    The assertion at the line with the // * comment is always false. :D

    Here is my code. Thanks a lot for taking a look.


    <?php
    // Tim Koschützki Webdesign
    // Date Started: October 30th 2005
    require_once('lib/Database.php');

    class Mitglied {
    const NEW_MITGLIED=-1;
    const UNSET_VERTRETER=-1;

    protected $id=Mitglied::NEW_MITGLIED;
    protected $titel;
    protected $name;
    protected $vorname;
    protected $str;
    protected $plz;
    protected $ort;
    protected $wb;
    protected $hasVotedOK=0;
    protected $isVertreter=Mitglied::UNSET_VERTRETER;
    protected $isWantedVertreter=Mitglied::UNSET_VERTRETER;

    protected $conn;

    const INSERT_SQL = "insert into mitglieder
    (id,wb,titel,vorname,name,str,plz,ort,hasVotedOK)
    values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
    const UPDATE_SQL = "update mitglieder SET
    wb=?,titel=?,vorname=?,name=?,str=?,plz=?,ort=?,hasVotedOK=?
    where id=?";
    const DELETE_SQL = "delete from mitglieder where id=?";
    const FIND_BY_ID_SQL = 'select * from mitglieder where id=?';
    const FIND_BY_WB_SQL = 'select * from mitglieder where wb=?';
    const FIND_VERTRETER_BY_ID_SQL = 'select id from vertreter where mitgl_id=?';
    const INSERT_VERTRETER_SQL = "insert into vertreter (mitgl_id) values (?)";
    const DELETE_VERTRETER_SQL = "delete from vertreter WHERE mitgl_id=?";

    public function __construct($id=false) {
    $this->conn = Database::conn();

    if($id) {
    $rs=$this->conn->execute(
    self::FIND_BY_ID_SQL, array((int)$id));

    if($rs) {
    $row=$rs->fetchRow();
    foreach($row as $field => $value) {
    $this->$field=$value;
    }
    } else {
    trigger_error('DB Error: '.$this->conn->errorMsg());
    }
    }
    }

    public static function findByID($id) {
    $rs = Database::conn()->execute(
    self::FIND_BY_ID_SQL, array((int)$id));

    $ret=array();

    if($rs) {
    $row=$rs->fetchRow();
    return new Mitglied($row['id']);
    }

    return null;
    }

    public static function findByWB($wb) {
    $rs = Database::conn()->execute(
    self::FIND_BY_WB_SQL, array((int)$wb));

    $ret=array();

    if($rs) {
    foreach($rs->getArray() as $row) {
    $ret[] = new Mitglied($row['id']);
    }
    }

    return $ret;
    }

    public function save() {
    if($this->id() == Mitglied::NEW_MITGLIED) {
    $this->insert();
    } else {
    $this->update();
    }
    }

    private function insert() {
    $rs = $this->conn->execute(
    self::INSERT_SQL, array($this->id(),$this->wb(),$this->titel(),$this->vorname(),
    $this->name(),$this->str(),$this->plz(),$this->ort(),$this->hasVotedOK()));

    if($rs) {
    $this->id = (int)$this->conn->Insert_ID();
    $this->updateVertreterStatus();
    } else {
    trigger_error('DB Error: '.$this->conn->errorMsg());
    }
    }

    private function update() {
    $rs = $this->conn->execute(
    self::UPDATE_SQL, array($this->id,$this->wb,$this->titel,$this->vorname,
    $this->name,$this->str,$this->plz,$this->ort,$this->hasVotedOK));

    $this->updateVertreterStatus();

    if(!$rs) {
    trigger_error('DB Error: '.$this->conn->errorMsg());
    }
    }

    private function updateVertreterStatus() {
    if(!$this->isVertreter() && $this->isWantedVertreter()) {
    echo 'here';

    $rs = $this->conn->execute(
    self::INSERT_VERTRETER_SQL, array($this->id()));

    if(!$rs) {
    trigger_error('DB Error: '.$this->conn->errorMsg());
    }

    $this->isVertreter=true;
    }

    if($this->isVertreter() && !$this->isWantedVertreter()) {
    echo 'here2';

    $rs = $this->conn->execute(
    self::DELETE_VERTRETER_SQL, array($this->id()));

    if(!$rs) {
    trigger_error('DB Error: '.$this->conn->errorMsg());
    }

    $this->isVertreter=false;
    }
    }

    public function isVertreter() {
    if($this->isVertreter == Mitglied::UNSET_VERTRETER) {
    $rs = $this->conn->execute(
    self::FIND_VERTRETER_BY_ID_SQL, array($this->id()));

    if($rs) {
    $this->isVertreter = ($rs->fetchRow()) ? true : false;
    } else {
    trigger_error('DB Error: '.$this->conn->errorMsg());
    }
    }

    return $this->isVertreter;
    }

    public function isWantedVertreter() {
    if($this->isWantedVertreter == Mitglied::UNSET_VERTRETER) {
    return $this->isVertreter();
    } else {
    return $this->isWantedVertreter;
    }
    }

    public function id() {
    return $this->id;
    }
    public function wb() {
    return $this->wb;
    }
    public function titel() {
    return $this->titel;
    }
    public function hasVotedOK() {
    return $this->hasVotedOK;
    }
    public function vorname() {
    return $this->vorname;
    }
    public function name() {
    return $this->name;
    }
    public function str() {
    return $this->str;
    }
    public function plz() {
    return $this->plz;
    }
    public function ort() {
    return $this->ort;
    }

    public function setId($id) {
    $this->id=$id;
    }
    public function setWb($wb) {
    $this->wb=$wb;
    }
    public function setVorname($s) {
    $this->vorname=$s;
    }
    public function setName($s) {
    $this->name=$s;
    }
    public function setStr($s) {
    $this->str=$s;
    }
    public function setPlz($s) {
    $this->plz=$s;
    }
    public function setOrt($s) {
    $this->ort=$s;
    }
    public function setVertreter($boolean) {
    $this->isWantedVertreter=$boolean;
    }

    }
    ?>

    I think there is problem with my treatment of the boolean variables. When Mitglied::setVertreter(true) is executed Mitglied::isWantedVertreter() should return true. Since the table 'vertreter' is empty Mitglied::isVertreter() returns false, which means that the first if statement in Mitglied::updatevertreterStatus is executed, but it never is (used echoed commentst here). :(

    Anybody got any idea? Thanks a lot in advance!

×
×
  • Create New...