/admin/elemente/class_element_votings.php

The creation of page-element was already part of two tutorials, unfortunately available only in german:

Nevertheless, we'll have a look at the elements.


class class_element_votings extends class_element_admin implements interface_admin_element {
public function __construct() {
$arrModule = array();
$arrModule["name"] = "element_votings";
$arrModule["author"] = "sidler @ mulchprod.de";
$arrModule["moduleId"] = _pages_elemente_modul_id_;
$arrModule["table"] = _dbprefix_."element_universal";
$arrModule["modul"] = "elemente";
$arrModule["tableColumns"] = "char1|char,char2|char,int1|number";
parent::__construct($arrModule);
}


As usual, the constructor defines the metadata. Absolutely relevant are the entries “table” and “tableColumns”, based on those values the framework creates the SQL-code to save the elements' data.
See in addition

public function getEditForm($arrElementData) {
$strReturn = "";
$arrRawVotings = class_modul_votings_voting::getVotings(true);
$arrVotings = array();

foreach ($arrRawVotings as $objOneVoting)
$arrVotings[$objOneVoting->getSystemid()] = $objOneVoting->getStrTitle();
$strReturn .= $this->objToolkit->formInputDropdown("char1", $arrVotings, $this->getText("votings_voting"), (isset($arrElementData["char1"]) ? $arrElementData["char1"] : "" ));


The element of the form provides a dropdown to select the voting to display. Only active votings are provided due to the “true”-parameter when loading the votings.


$objFilesystem = new class_filesystem();
$arrTemplates = $objFilesystem->getFilelist("/templates/modul_votings", ".tpl");
$arrTemplatesDD = array();
if(count($arrTemplates) > 0) {
foreach($arrTemplates as $strTemplate) {
$arrTemplatesDD[$strTemplate] = $strTemplate;
}
}

if(count($arrTemplates) == 1)
$this->addOptionalFormElement($this->objToolkit->formInputDropdown("char2", $arrTemplatesDD, $this->getText("votings_template"), (isset($arrElementData["char2"]) ? $arrElementData["char2"] : "" )));
else
$strReturn .= $this->objToolkit->formInputDropdown("char2", $arrTemplatesDD, $this->getText("votings_template"), (isset($arrElementData["char2"]) ? $arrElementData["char2"] : "" ));


All available templates are loaded from the file system. If there's only one template, the dropdown is added as an optional element, so it's hidden by default (http://apidocs.kajona.de/v3.3.0/modul_pages/class_element_admin.html#addOptionalFormElement). If there's more then one template, the dropdown is added to the form as usual.


$arrModeDD = array(
"0" => $this->getText("votings_mode_voting"),
"1" => $this->getText("votings_mode_result")
);

$strReturn .= $this->objToolkit->formInputDropdown("int1", $arrModeDD, $this->getText("votings_mode"), (isset($arrElementData["int1"]) ? $arrElementData["int1"] : "" ));

$strReturn .= $this->objToolkit->setBrowserFocus("char1");
return $strReturn;
}
}


As defined in the requirements of the module, the last dropdown is used to set up the elements' mode: voting or results.

/portal/elemente/class_element_votings.php

class class_element_votings extends class_element_portal implements interface_portal_element {
public function __construct($objElementData) {
$arrModule = array();
$arrModule["name"] = "element_votings";
$arrModule["author"] = "sidler @ mulchprod.de";
$arrModule["moduleId"] = _pages_elemente_modul_id_;
$arrModule["table"] = _dbprefix_."element_universal";
parent::__construct($arrModule, $objElementData);
}

No further comments ;). As you already may have guessed, especially the entry “table” is an important one. The framework loads the data out of this table and passes the loaded data to the element for further usage.


public function loadData() {
$strReturn = "";
$objvotingsModule = class_modul_system_module::getModuleByName("votings");
if($objvotingsModule != null) {
$strClassName = uniStrReplace(".php", "", $objvotingsModule->getStrNamePortal());
$objVotings = new $strClassName($this->arrElementData);
$strReturn = $objVotings->action();
}
return $strReturn;
}
}


The functionality of the element is limited to loading the metadata of the votings-module and to create an instance of the portal-class. Control is passed to this objects afterwards. To summarize it, the only function of the page-element is to act as a factory for the voting and as a bridge between page and module.