/system/class_modul_votings_voting.php

The second bean is the the representation of a voting. Since the structure is nearly the same as the answer-bean, only the differences should be analyzed.


protected function updateStateToDb() {
$objStartDate = null;
$objEndDate = null;

if($this->getLongDateStart() != 0 && $this->getLongDateStart() != "")
$objStartDate = new class_date($this->getLongDateStart());

if($this->getLongDateEnd() != 0 && $this->getLongDateEnd() != "")
$objEndDate = new class_date($this->getLongDateEnd());

$this->updateDateRecord($this->getSystemid(), $objStartDate, $objEndDate, null);

$strQuery = "UPDATE ".$this->arrModule["table"]."
SET votings_voting_title ='".dbsafeString($this->getStrTitle())."'
WHERE votings_voting_id ='".dbsafeString($this->getSystemid())."'";

return $this->objDB->_query($strQuery);
}


In addition to the method updateStateToDb() known from the answer-bean, the voting bean saves the start- and end-date to Kajonas' date-table.
See in addition http://apidocs.kajona.de/v3.3.0/modul_system/class_root.html#updateDateRecord.


protected function onInsertToDb() {
$objStartDate = null;
$objEndDate = null;
if($this->getLongDateStart() != 0 && $this->getLongDateStart() != "")
$objStartDate = new class_date($this->getLongDateStart());
if($this->getLongDateEnd() != 0 && $this->getLongDateEnd() != "")
$objEndDate = new class_date($this->getLongDateEnd());
return $this->createDateRecord($this->getSystemid(), $objStartDate, $objEndDate, null);
}


The method onInsertToDb() was added compared to the previous bean, called by the framework in those cases when the bean wasn't saved to the database before. The framework recognizes during an update-request that the bean wasn't persisted yet and creates the initial records. The bean can overwrite this optional method in order to perform an action after the initial creation in the database, needed only at inserts.
In the example, it's the creation of the initial entry in the data-table via createDateRecord().
See in addition

Note: Even due to the fact that Kajona provides a date-management, those functions have to be used explicitly. Since many records don't need associated date-values, the implicit creation of date-values would lead to an unwanted overload.
Additionally, the voting-bean provides the methods getVotings() and getAllAnswers() whereas getVotings() acts like a factoryMethod for voting-beans: the return-value is an array of available voting-objects. The method getAllAnswers() can be called on an instance of a voting-bean and returns the list of answer-objects associated with the current voting.