<?php
class TawePageItem extends TaweBaseListItem {
protected $awePageItemTempOpt = array (0, 1, 2, 3, "distinct_selected" => 1, "distinct_first" => 2 , "distinct_last" => 3);
function view($dataSource, $dataSourceParams, $currentAddress, $template, $templateOpt, $pictureExt) {
global $tempItemSelectedSufix;
global $tempItemFirstSufix;
global $tempItemLastSufix;
global $aweSqlPrimaryKey;
$templateOpt = optionsToTable($templateOpt, $this->awePageItemTempOpt);
$itemsData = $this->call($dataSource, $dataSourceParams);
$last = start_value; $extra ="";
for ($t=0;$t<sizeof($itemsData);$t++) {
if ($this->itemIsSelected($currentAddress, $itemsData[$t][$aweSqlPrimaryKey]) && $templateOpt[$this->awePageItemTempOpt["distinct_selected"]])
{$extra .= $tempItemSelectedSufix; };
if ($t==0 && $templateOpt[$this->awePageItemTempOpt["distinct_first"]])
{$extra .= $tempItemFirstSufix; };
if (($t+1)==sizeof($itemsData) && $templateOpt[$this->awePageItemTempOpt["distinct_last"]])
{$extra .= $tempItemLastSufix; };
if (strcmp($last,$extra)) {
$itemTemplate = file_get_contents(getItemTemplate($this->moduleName,$template,$extra));
$last =$extra; $extra="";
};
$content .= $this->makeListItem($itemsData[$t], $itemTemplate, $template, $pictureExt);
}
if (sizeof($itemsData))
$result = $this->makeListForm($content, file_get_contents(getFormTemplate($this->moduleName,$template,$inactive)));
return $result;
}
function viewDetails() {
}
public function makeAddress($itemId) {
global $aweSqlParentField;
global $addressItemTemplate;
global $addressDelimiter;
$result = $this->makeParentAddress($itemId);
$result .= sprintf($addressItemTemplate, $this->navPrefix,$itemId.$addressDelimiter);
return $result;
}
public function makePrevAddress($itemId) {
return $this->makeParentAddress($itemId);
}
public function getDirlist($dirId, $deepth = -1) {
global $aweSqlParentField;
global $aweSqlPositionField;
global $aweDataTable;
global $aweSqlPrimaryKey;
$result = $this->aweQuery->select("", $this->moduleName.$aweDataTable, sqlText(equals, $aweSqlParentField, $dirId), $aweSqlPositionField);
if ($deepth!=0 && is_a($this->parent, TawePageMenu)) {
$dirChildren = $this->parent->getSuccessors($dirId, "");
if (is_array($dirChildren))
for ($i=0; $i<sizeof($dirChildren); $i++) {
$childItems = $this->getDirlist($dirChildren[$i][$aweSqlPrimaryKey], $deepth-1);
if (is_array($result) && is_array($childItems)) $result = array_merge($result, $childItems);
else if (is_array($childItems)) $result = $childItems;
}
}
return $result;
}
function getNewest($count, $onlyLookInDir = false, $deepth = -1, $recurent = false) { //visibility
global $aweDataTable;
global $aweSqlPrimaryKey;
global $aweSqlParentField;
if ($onlyLookInDir) {
$result = $this->aweQuery->select("", $this->moduleName.$aweDataTable, sqlText(equals, $aweSqlParentField, $onlyLookInDir), $aweSqlPrimaryKey, "DESC", $count);
if ($deepth!=0) {
$dirChildren = $this->parent->getChildren($onlyLookInDir,"","","");
if (is_array($dirChildren))
for ($i=0; $i<sizeof($dirChildren); $i++) {
$childItems = $this->getNewest($count, $dirChildren[$i][$aweSqlPrimaryKey], $deepth-1, true);
if (is_array($result) && is_array($childItems)) $result = array_merge($result, $childItems);
else if (is_array($childItems)) $result = $childItems;
}
}
}
else $result = $this->aweQuery->select("", $this->moduleName.$aweDataTable, "", $aweSqlPrimaryKey, "DESC", $count);
if (is_array($result)) {
for ($i=0; $i<sizeof($result); $i++) $itemId[$i] = $result[$i][$aweSqlPrimaryKey];
array_multisort ($itemId, SORT_DESC, $result);
if (!$recurent) $result = array_slice($result, 0, $count);
}
return $result;
}
public function itemSelected($currentAddress) {
return $currentAddress[$this->navPrefix];
}
public function itemIsSelected($currentAddress, $itemId) {
if (!strcmp($this->itemSelected($currentAddress), $itemId))
return true;
else
return false;
}
public function updateNewItem() {
global $aweSqlPrimaryKey;
global $aweSqlParentField;
global $aweSqlPositionField;
global $aweDataTable;
global $aweSqlHiddenField;
global $aweSqlSystemField;
global $aweSqlNameField;
global $aweSqlLangTmp;
if (func_num_args() <2) return NULL;
$name = func_get_arg(0);
$parent = func_get_arg(1);
$itemId = 1 + $this->aweQuery->getMax($this->moduleName.$aweDataTable, $aweSqlPrimaryKey);
$position = 1 + $this->aweQuery->getMax($this->moduleName.$aweDataTable, $aweSqlPositionField, sqlText(equals, $aweSqlParentField, $parent));
//position handle
if (func_num_args() >=4) $hidden = func_get_arg(3); else $hidden = $aweSqlHiddenDefault;
if (func_num_args() >=5) $system = func_get_arg(4); else $system = $aweSqlSystemDefault;
$this->aweQuery->insert(
$this->moduleName.$aweDataTable,
array($aweSqlPrimaryKey, $aweSqlParentField, $aweSqlPositionField, $aweSqlHiddenField, $aweSqlSystemField, $aweSqlNameField.$aweSqlLangTmp),
array($itemId, $parent, $position, $hidden, $system, $name)
);
}
public function updateChangeItem() {
global $aweSqlNameField;
global $aweSqlPrimaryKey;
global $aweDataTable;
global $sqlValueAreola;
global $aweSqlLangTmp;
if (func_num_args() <2) return NULL; //:Logger->PageMenuChangeItem->not enough parameters
$itemId = func_get_arg(0);
$itemName = func_get_arg(1);
$this->aweQuery->update(
$this->moduleName.$aweDataTable,
array($aweSqlNameField.$aweSqlLangTmp),
array(valueInQuotes($itemName, $sqlValueAreola), valueInQuotes($catNumber, $sqlValueAreola)),
sqlText(equals, $aweSqlPrimaryKey, $itemId)
);
}
}
?>