PHP 5 для начинающих

Печать

Следует отметить, что этот класс расширяет класс PersistableLog, поэтому в нем можно использовать некоторые функции PersistableLog. Ниже приведен код конструктора:

<unction _construct ($initdict) // передается по значению

{

$key = "";

$this->db = LogUtils::openDatabase ();

$this->setId(LogUtils::getDef ($initdict["id"],0)); $this->setId(LogUtils::getDef ($initdict["user_log_id"], $this->id)); $this->setProperty ("demo",

LogUtils::getDef ($initdict["demo"], 0), "answer",

LogUtils::getDef ($initdict["question"], "Demographic Answer")); $this->setProperty ("demo",

LogUtils::getDef ($initdict["answer"], $this->demo), "answer",

LogUtils::getDef ($initdict["question"], "Demographic Answer")); $this->question = LogUtils::getDef($initdict["question"], "");

}

Затем определяется функция setId() , используемая в конструкторе:

<unction setId ($id) {

$this->setProperty ("id", $id, "user_log_id", "User ID");

}

Порядок следования ответов очень важен:

<unction setSequence ($seq) {

$this->setProperty ("seq", $seq, "seq", "Sequence");

}

Следует проверить корректность UserLog-объекта, поэтому далее определяется функция getInvalidDate() . Демографические данные проверять не следует, потому что отсутствие ответа вполне может означать корректный ответ:

<unction getInvalidData () {

$badDataEntries = array();

if ($this->id == null || $this->id <= 0) {

array_push ($badDataEntries, "'id' is zero");

}

return $badDataEntries;

}

Наконец, переопределяем функцию toSQL следующим образом:

<unction toSQL ($tableName = "user_demographics") {

return LogUtils::generateSqlInsert ($tableName,

$this->contentMetaDb, $this->contentBase);

}