Current File : /home/karenpetzb/application/models/Category.php |
<?php
class Category extends Zend_Db_Table
{
protected $_name = 'category';
protected $_primary = 'ID';
public function getListIdFromParent($idCat) {
$sql = "SELECT c0.ID ID, c1.ID ID1, c2.ID ID2, c3.ID ID3, c4.ID ID4
FROM category AS c0
LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID
LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID
WHERE (c0.ID = ".$idCat."
OR c1.ID = ".$idCat."
OR c2.ID = ".$idCat."
OR c3.ID = ".$idCat."
OR c4.ID = ".$idCat.")";
$result = $idCat;
$catsAllCheck = "/".$idCat."/";
$list = $this->getAdapter()->fetchAll($sql);
foreach ($list as $cat) {
if (!empty($cat['ID']) && strpos($catsAllCheck,"/".$cat['ID']."/") === false) {
$result .= ",".$cat['ID'];
$catsAllCheck .= "/".$cat['ID']."/";
}
if (!empty($cat['ID1']) && strpos($catsAllCheck,"/".$cat['ID1']."/") === false) {
$result .= ",".$cat['ID1'];
$catsAllCheck .= "/".$cat['ID1']."/";
}
if (!empty($cat['ID2']) && strpos($catsAllCheck,"/".$cat['ID2']."/") === false) {
$result .= ",".$cat['ID2'];
$catsAllCheck .= "/".$cat['ID2']."/";
}
if (!empty($cat['ID3']) && strpos($catsAllCheck,"/".$cat['ID3']."/") === false) {
$result .= ",".$cat['ID3'];
$catsAllCheck .= "/".$cat['ID3']."/";
}
if (!empty($cat['ID4']) && strpos($catsAllCheck,"/".$cat['ID4']."/") === false) {
$result .= ",".$cat['ID4'];
$catsAllCheck .= "/".$cat['ID4']."/";
}
}
return $result;
}
public function updateTreeInLineAsPathOfChilds($idParent, $updateCurrent) {
$i = 0;
if ($updateCurrent){
$sqlCurrent = "SELECT c.* FROM category c WHERE c.ID = ".$idParent." ORDER BY c.NOM ASC ";
$dataCurrent = $this->getAdapter()->fetchRow($sqlCurrent);
if ($dataCurrent) {
$dataCurrent['NAVNOM_URLPARENTS'] = $this->getTreeInLineAsPathOf($idParent);
$this->update($dataCurrent, 'ID = '.$idParent);
$i++;
}
}
$sql = "SELECT c.* FROM category c WHERE c.IDPARENT = ".$idParent." ORDER BY c.NOM ASC ";
$cats = $this->getAdapter()->fetchAll($sql);
foreach($cats as $row)
{
$row['NAVNOM_URLPARENTS'] = $this->getTreeInLineAsPathOf($row['ID']);
$this->update($row, 'ID = '.$row['ID']);
$i += $this->updateTreeInLineAsPathOfChilds($row['ID'], false);
$i++;
}
return $i;
}
public function generateAllCategoriesMenu($idCat) {
$dataResult = $this->computeCategoryChildToArray($idCat, 0);
return $dataResult;
}
private function computeCategoryChildsOneArray($idParent, $result) {
$dataChilds = $this->getCategoryByParent($idParent);
$dataResult = array(
'PARENT' => $idParent,
'CHILDS' => $dataChilds
);
array_push($result, $dataResult);
if (!empty($dataChilds) && sizeof($dataChilds) > 0) {
foreach($dataChilds as $row) {
$result = $this->computeCategoryChildsOneArray($row['ID'], $result);
}
}
return $result;
}
private function computeCategoryChildToArray($idParent, $level) {
$dataChilds = $this->getCategoryByParent($idParent);
if (!empty($dataChilds) && sizeof($dataChilds) > 0) {
$dataReturn = array();
foreach($dataChilds as $row) {
$data = array(
'CHILDS' => $this->computeCategoryChildToArray($row['ID'], $level + 1),
'CATEGORIE' => $row,
'LEVEL' => $level
);
array_push($dataReturn, $data);
}
return $dataReturn;
} else { return array(); }
}
private function getCategoryByParent($idParent) {
$sql = "SELECT c.* FROM category c WHERE c.IDPARENT = ".$idParent." AND c.isACTIVE = 1";
if ($idParent == 0) {
$sql .= " ORDER BY c.POSITION ASC, c.ID ASC";
} else {
$sql .= " ORDER BY c.POSITION ASC, c.NOM ASC";
}
return $this->getAdapter()->fetchAll($sql);
}
/**
*
* Getters
*
*/
public function getParentFirstOf($idCat) {
$sql = "SELECT DISTINCT c0.ID ID, c0.NOM NOM, c0.IDPARENT IDPARENT , c0.NAVNOM NAVNOM
FROM category AS c0
LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID
LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID
LEFT JOIN category AS c5 ON c5.IDPARENT = c4.ID
LEFT JOIN category AS c6 ON c6.IDPARENT = c5.ID
LEFT JOIN category AS c7 ON c7.IDPARENT = c6.ID
LEFT JOIN category AS c8 ON c8.IDPARENT = c7.ID
LEFT JOIN category AS c9 ON c9.IDPARENT = c8.ID
LEFT JOIN category AS c10 ON c10.IDPARENT = c9.ID
WHERE ( c0.ID = ".$idCat."
OR c1.ID = ".$idCat."
OR c2.ID = ".$idCat."
OR c3.ID = ".$idCat."
OR c4.ID = ".$idCat."
OR c5.ID = ".$idCat."
OR c6.ID = ".$idCat."
OR c7.ID = ".$idCat."
OR c8.ID = ".$idCat."
OR c9.ID = ".$idCat."
OR c10.ID = ".$idCat." )
ORDER BY c0.IDPARENT ASC
";
return $this->getAdapter()->fetchRow($sql);
}
public function getTreeInLineAsPathOf($idCat) {
$sql = "SELECT DISTINCT c0.ID ID, c0.NOM NOM, c0.IDPARENT IDPARENT , c0.NAVNOM NAVNOM, c0.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
FROM category AS c0
LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID
LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID
LEFT JOIN category AS c5 ON c5.IDPARENT = c4.ID
LEFT JOIN category AS c6 ON c6.IDPARENT = c5.ID
LEFT JOIN category AS c7 ON c7.IDPARENT = c6.ID
LEFT JOIN category AS c8 ON c8.IDPARENT = c7.ID
LEFT JOIN category AS c9 ON c9.IDPARENT = c8.ID
LEFT JOIN category AS c10 ON c10.IDPARENT = c9.ID
WHERE ( c0.ID = ".$idCat."
OR c1.ID = ".$idCat."
OR c2.ID = ".$idCat."
OR c3.ID = ".$idCat."
OR c4.ID = ".$idCat."
OR c5.ID = ".$idCat."
OR c6.ID = ".$idCat."
OR c7.ID = ".$idCat."
OR c8.ID = ".$idCat."
OR c9.ID = ".$idCat."
OR c10.ID = ".$idCat." )
ORDER BY c0.IDPARENT ASC
";
$mylinks = array();
$links = $this->getAdapter()->fetchAll($sql);
if (empty($links)) {
return '';
}
$result = $links[0]['NAVNOM'];
if ($links[0]['IDPARENT'] == 0) {
$result = $links[0]['NAVNOM_URLPARENTS'];
}
$mylinks[0]['ID'] = $links[0]['ID'];
$j=0;
for ($i=1;$i<sizeof($links);$i++) {
foreach ($links as $link) {
if($link['IDPARENT'] == $mylinks[$j]['ID'] && $link['ID'] != $idCat) {
$mylinks[$i]['ID'] = $link['ID'];
$result .= "/".$link['NAVNOM'];
$j++;
break;
}
}
}
return $result;
}
public function getTreeInLineOf($idCat) {
$sql = "SELECT DISTINCT c0.*
FROM category AS c0
LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID
LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID
LEFT JOIN category AS c5 ON c5.IDPARENT = c4.ID
LEFT JOIN category AS c6 ON c6.IDPARENT = c5.ID
LEFT JOIN category AS c7 ON c7.IDPARENT = c6.ID
LEFT JOIN category AS c8 ON c8.IDPARENT = c7.ID
LEFT JOIN category AS c9 ON c9.IDPARENT = c8.ID
LEFT JOIN category AS c10 ON c10.IDPARENT = c9.ID
WHERE ( c0.ID = ".$idCat."
OR c1.ID = ".$idCat."
OR c2.ID = ".$idCat."
OR c3.ID = ".$idCat."
OR c4.ID = ".$idCat."
OR c5.ID = ".$idCat."
OR c6.ID = ".$idCat."
OR c7.ID = ".$idCat."
OR c8.ID = ".$idCat."
OR c9.ID = ".$idCat."
OR c10.ID = ".$idCat." )
ORDER BY c0.IDPARENT ASC
";
$mylinks = array();
$links = $this->getAdapter()->fetchAll($sql);
$mylinks[0]['ID'] = $links[0]['ID'];
$mylinks[0]['NOM'] = $links[0]['NOM'];
$mylinks[0]['IDPARENT'] = $links[0]['IDPARENT'];
$mylinks[0]['NAVNOM'] = $links[0]['NAVNOM'];
$mylinks[0]['NAVNOM_URLPARENTS'] = $links[0]['NAVNOM_URLPARENTS'];
$j=0;
for ($i=1;$i<sizeof($links);$i++) {
foreach ($links as $link) {
if($link['IDPARENT'] == $mylinks[$j]['ID']) {
$mylinks[$i]['ID'] = $link['ID'];
$mylinks[$i]['NOM'] = $link['NOM'];
$mylinks[$i]['IDPARENT'] = $link['IDPARENT'];
$mylinks[$i]['NAVNOM'] = $link['NAVNOM'];
$mylinks[$i]['NAVNOM_URLPARENTS'] = $link['NAVNOM_URLPARENTS'];
$j++;
break;
}
}
}
return $mylinks;
}
public function getTreeCatsOfParent($idCat) {
$sql = "SELECT c0.NOM NOM0, c1.NOM NOM1,
c0.URL URL0, c1.URL URL1,
c0.URL_SLIDE URLSLIDE0, c1.URL_SLIDE URLSLIDE1,
c0.ID ID0, c1.ID ID1,
c0.isACTIVE isACTIVE0, c1.isACTIVE isACTIVE1,
c0.IDPARENT IDPARENT0, c1.IDPARENT IDPARENT1,
c0.NAVNOM NAVNOM0, c1.NAVNOM NAVNOM1,
c0.DESCRIPTION DESCRIPTION0, c1.DESCRIPTION DESCRIPTION1,
c0.DESCRIPTIONLONG DESCRIPTIONLONG0, c1.DESCRIPTIONLONG DESCRIPTIONLONG1,
c0.NAVNOM_URLPARENTS NAVNOM_URLPARENTS0, c1.NAVNOM_URLPARENTS NAVNOM_URLPARENTS1
FROM category AS c0
LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
WHERE c0.IDPARENT = ".$idCat."
ORDER BY c0.ID,c1.ID ASC;
";
$results = $this->getAdapter()->fetchAll($sql);
$listCat = array();
$i = 0;
$j = 0;
$idParent = 0;
$isNew = true;
$isFirst = true;
foreach($results as $row) {
if ($row['ID0'] != $idParent) {
$idParent = $row['ID0'];
$isNew = true;
$i++;
$j = 0 ;
if ($isFirst) {$i = 0; $isFirst = false;}
} else {
$isNew = false;
}
if ($isNew) {
if ($row['isACTIVE0'] == true) {
$listCat[$i]['NOM'] = $row['NOM0'];
$listCat[$i]['ID'] = $row['ID0'];
$listCat[$i]['URL'] = $row['URL0'];
$listCat[$i]['URL_SLIDE'] = $row['URLSLIDE0'];
$listCat[$i]['NAVNOM'] = $row['NAVNOM0'];
$listCat[$i]['DESCRIPTION'] = $row['DESCRIPTION0'];
$listCat[$i]['DESCRIPTIONLONG'] = $row['DESCRIPTIONLONG0'];
$listCat[$i]['isACTIVE'] = $row['isACTIVE0'];
$listCat[$i]['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS0'];
$listCat[$i]['SUBS'] = array();
}
}
if ($row['isACTIVE1'] == true) {
$listCat[$i]['SUBS'][$j]['NOM'] = $row['NOM1'];
$listCat[$i]['SUBS'][$j]['ID'] = $row['ID1'];
$listCat[$i]['SUBS'][$j]['URL'] = $row['URL1'];
$listCat[$i]['SUBS'][$j]['URL_SLIDE'] = $row['URLSLIDE1'];
$listCat[$i]['SUBS'][$j]['DESCRIPTION'] = $row['DESCRIPTION1'];
$listCat[$i]['SUBS'][$j]['DESCRIPTIONLONG'] = $row['DESCRIPTIONLONG1'];
$listCat[$i]['SUBS'][$j]['NAVNOM'] = $row['NAVNOM1'];
$listCat[$i]['SUBS'][$j]['isACTIVE'] = $row['isACTIVE1'];
$listCat[$i]['SUBS'][$j]['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS1'];
$j++;
}
}
return $listCat;
}
private function getTreeCatsOfWithLevelCompute(&$listCat, $row, $index) {
$listCat['NOM'] = $row["NOM".$index];
$listCat['NAVTITRENOM'] = $row['NAVTITRENOM'.$index];
$listCat['NAVDESCRIPTION'] = $row['NAVDESC'.$index];
$listCat['ID'] = $row['ID'.$index];
$listCat['URL'] = $row['URL'.$index];
$listCat['URL_SLIDE'] = $row['URLSLIDE'.$index];
$listCat['NAVNOM'] = $row['NAVNOM'.$index];
$listCat['KEYWORDS'] = $row['KEYWORDS'.$index];
$listCat['DESCRIPTION'] = $row['DESCRIPTION'.$index];
$listCat['DESCRIPTIONLONG'] = $row['DESCRIPTIONLONG'.$index];
$listCat['DESCRIPTIONSHORT'] = $row['DESCRIPTIONSHORT'.$index];
$listCat['CHOICEURL'] = $row['CHOICEURL'.$index];
$listCat['CHOICEDOC'] = $row['CHOICEDOC'.$index];
$listCat['isACTIVE'] = $row['isACTIVE'.$index];
$listCat['IDPARENT'] = $row['IDPARENT'.$index];
$listCat['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS'.$index];
$listCat['NBPRODUCT'] = $row['NBPRODUCT'];
}
public function getTreeCatsOfWithLevel($idCat, $isSubLevels) {
$sql = "SELECT c0.NOM NOM0, c1.NOM NOM1,
c0.NAVTITRENOM NAVTITRENOM0, c1.NAVTITRENOM NAVTITRENOM1,
c0.NAVDESCRIPTION NAVDESC0, c1.NAVDESCRIPTION NAVDESC1,
c0.URL URL0, c1.URL URL1,
c0.URL_SLIDE URLSLIDE0, c1.URL_SLIDE URLSLIDE1,
c0.ID ID0, c1.ID ID1,
c0.IDPARENT IDPARENT0, c1.IDPARENT IDPARENT1,
c0.NAVNOM NAVNOM0, c1.NAVNOM NAVNOM1,
c0.DESCRIPTION DESCRIPTION0, c1.DESCRIPTION DESCRIPTION1,
c0.DESCRIPTIONLONG DESCRIPTIONLONG0, c1.DESCRIPTIONLONG DESCRIPTIONLONG1,
c0.DESCRIPTIONSHORT DESCRIPTIONSHORT0, c1.DESCRIPTIONSHORT DESCRIPTIONSHORT1,
c0.KEYWORDS KEYWORDS0, c1.KEYWORDS KEYWORDS1,
c0.CHOICEURL CHOICEURL0, c1.CHOICEURL CHOICEURL1,
c0.CHOICEDOC CHOICEDOC0, c1.CHOICEDOC CHOICEDOC1,
c0.isACTIVE isACTIVE0, c1.isACTIVE isACTIVE1,
c0.NAVNOM_URLPARENTS NAVNOM_URLPARENTS0, c1.NAVNOM_URLPARENTS NAVNOM_URLPARENTS1,
(Select count(1) from product as p where p.idcategory = c1.id and p.isactive = 0) NBPRODUCT";
if ($isSubLevels) {
$sql .= ", c2.NOM NOM2,
c2.NAVTITRENOM NAVTITRENOM2,
c2.NAVDESCRIPTION NAVDESC2,
c2.URL URL2,
c2.URL_SLIDE URLSLIDE2,
c2.ID ID2,
c2.IDPARENT IDPARENT2,
c2.NAVNOM NAVNOM2,
c2.DESCRIPTION DESCRIPTION2,
c2.DESCRIPTIONLONG DESCRIPTIONLONG2,
c2.DESCRIPTIONSHORT DESCRIPTIONSHORT2,
c2.KEYWORDS KEYWORDS2,
c2.CHOICEURL CHOICEURL2,
c2.CHOICEDOC CHOICEDOC2,
c2.isACTIVE isACTIVE2,
c2.NAVNOM_URLPARENTS NAVNOM_URLPARENTS2
FROM category AS c0
LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
WHERE c0.ID = ".$idCat."
ORDER BY c0.POSITION ASC,c1.POSITION,c2.POSITION ASC;
";
} else {
$sql .= " FROM category AS c0
LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
WHERE c0.ID = ".$idCat."
ORDER BY c0.POSITION ASC,c1.POSITION ASC;
";
}
$results = $this->getAdapter()->fetchAll($sql);
$listCat = array();
$listCat['SUBS'] = array();
$j = -1;
$k = -1;
$lastLvl0 = 0;
$lastLvl1 = 0;
$lastLvl2 = 0;
foreach($results as $row) {
if ($lastLvl0 != $row['ID0']) {
$this->getTreeCatsOfWithLevelCompute($listCat, $row, "0");
$lastLvl0 = $row['ID0'];
}
if (!empty($row['isACTIVE1']) && $row['isACTIVE1'] == true && !empty($row['NOM1'])) {
if ($lastLvl1 != $row['ID1']) {
$j++;
$listCat['SUBS'][$j] = array();
$this->getTreeCatsOfWithLevelCompute($listCat['SUBS'][$j], $row, "1");
$lastLvl1 = $row['ID1'];
}
if ($isSubLevels && $lastLvl2 != $row['ID2']) {
if (!empty($row['isACTIVE2']) && $row['isACTIVE2'] == true && !empty($row['NOM2'])) {
$k++;
$listCat['SUBS'][$j]['SUBS'][$k] = array();
$this->getTreeCatsOfWithLevelCompute($listCat['SUBS'][$j]['SUBS'][$k], $row, "2");
$lastLvl2 = $row['ID2'];
}
}
}
}
return $listCat;
}
public function getTreeCatsOf($idCat) {
return $this->getTreeCatsOfWithLevel($idCat, false);
}
public function getAllCategoriesByID ($idParent) {
$sql = "
SELECT c0.NOM NOM0, c1.NOM NOM1, c2.NOM NOM2, c3.NOM NOM3, c4.NOM NOM4, c5.NOM NOM5,
c6.NOM NOM6, c7.NOM NOM7, c8.NOM NOM8, c9.NOM NOM9, c10.NOM NOM10,
c0.isACTIVE isACTIVE0, c1.isACTIVE isACTIVE1, c2.isACTIVE isACTIVE2, c3.isACTIVE isACTIVE3, c4.isACTIVE isACTIVE4, c5.isACTIVE isACTIVE5,
c6.isACTIVE isACTIVE6, c7.isACTIVE isACTIVE7, c8.isACTIVE isACTIVE8, c9.isACTIVE isACTIVE9, c10.isACTIVE isACTIVE10,
c0.URL URL0, c1.URL URL1, c2.URL URL2, c3.URL URL3, c4.URL URL4, c5.URL URL5,
c6.URL URL6, c7.URL URL7, c8.URL URL8, c9.URL URL9, c10.URL URL10,
c0.ID ID0, c1.ID ID1, c2.ID ID2, c3.ID ID3, c4.ID ID4, c5.ID ID5,
c6.ID ID6, c7.ID ID7, c8.ID ID8, c9.ID ID9, c10.ID ID10,
c0.IDPARENT IDPARENT0, c1.IDPARENT IDPARENT1, c2.IDPARENT IDPARENT2, c3.IDPARENT IDPARENT3, c4.IDPARENT IDPARENT4, c5.IDPARENT IDPARENT5,
c6.IDPARENT IDPARENT6, c7.IDPARENT IDPARENT7, c8.IDPARENT IDPARENT8, c9.IDPARENT IDPARENT9, c10.IDPARENT IDPARENT10
FROM category AS c0
LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID
LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID
LEFT JOIN category AS c5 ON c5.IDPARENT = c4.ID
LEFT JOIN category AS c6 ON c6.IDPARENT = c5.ID
LEFT JOIN category AS c7 ON c7.IDPARENT = c6.ID
LEFT JOIN category AS c8 ON c8.IDPARENT = c7.ID
LEFT JOIN category AS c9 ON c9.IDPARENT = c8.ID
LEFT JOIN category AS c10 ON c10.IDPARENT = c9.ID
WHERE c0.IDPARENT = ".$idParent."
ORDER BY c0.ID,c1.POSITION,c2.POSITION,c3.POSITION,c4.POSITION,c5.POSITION,c6.POSITION,c7.POSITION,c8.POSITION,c9.POSITION,c10.POSITION ASC;
";
return $this->getAdapter()->fetchAll($sql);
}
public function getAllCategoriesIDByID ($idParent) {
$sql = "
SELECT c0.ID ID0, c1.ID ID1, c2.ID ID2, c3.ID ID3, c4.ID ID4, c5.ID ID5,
c6.ID ID6, c7.ID ID7, c8.ID ID8, c9.ID ID9, c10.ID ID10
FROM category AS c0
LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID
LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID
LEFT JOIN category AS c5 ON c5.IDPARENT = c4.ID
LEFT JOIN category AS c6 ON c6.IDPARENT = c5.ID
LEFT JOIN category AS c7 ON c7.IDPARENT = c6.ID
LEFT JOIN category AS c8 ON c8.IDPARENT = c7.ID
LEFT JOIN category AS c9 ON c9.IDPARENT = c8.ID
LEFT JOIN category AS c10 ON c10.IDPARENT = c9.ID
WHERE c0.IDPARENT = ".$idParent;
return $this->getAdapter()->fetchAll($sql);
}
public function getIdCatFromProductId($idProd) {
$sql = "
SELECT p.IDCATEGORY ID
FROM product AS p
WHERE p.ID = ".$idProd;
$data = $this->getAdapter()->fetchRow($sql);
return $data['ID'];
}
public function getAllSubsIDByIDToString($idCat) {
if ($idCat != null && (int)$idCat > 0) {
$listCat = $this->getAllCategoriesIDByID($idCat);
$listTemp = array();
$value = 'ID';
$listCatString = $idCat;
//list of sub cats
foreach ($listCat as $row) {
for ($level=0 ; $level<11; $level++) {
if ((!isset($listTemp[$value.$level]) || $listTemp[$value.$level] != $row[$value.$level]) && $row[$value.$level] != null) {
$listTemp[$value.$level] = $row[$value.$level];
if ($listCatString !="") {
$listCatString .= ' ,'.$row[$value.$level];
} else {
$listCatString = $row[$value.$level];
}
}
}
}
return $listCatString;
}
return "";
}
public function getAllCategoriesProperties() {
$sql = "SELECT c.* FROM category c ORDER BY c.NOM ASC ";
$cats = $this->getAdapter()->fetchAll($sql);
$data = array();
foreach($cats as $row)
{
$data[$row['ID']] = array(
'ID' => $row['ID'],
'NOM' => $row['NOM'],
'URL' => $row['URL'],
'NAVNOM' => $row['NAVNOM'],
'isACTIVE' => $row['isACTIVE']
);
}
return $data;
}
private function getCategoryById($idCat) {
$sql = "SELECT c.* FROM category c WHERE c.ID = ".$idCat." ORDER BY c.NOM ASC";
$cats = $this->getAdapter()->fetchAll($sql);
$data = array();
foreach ($cats AS $row) {
$data[$row['ID']] = $row['NOM'];
}
return $data;
}
public function canBeMigrate($id) {
$sql = "
SELECT count(*) TOTAL
FROM category AS c
WHERE c.isACTIVE = 0 AND c.IDPARENT = ".$id;
$data = $this->getAdapter()->fetchRow($sql);
return (int)$data['TOTAL'] == 0;
}
}
?>