wefra/modules/ClassContent.php

104 lines
3.1 KiB
PHP

<?php
class ClassContent extends ClassConfig {
public function __construct(){}
public function __destruct(){}
public function listContent($lang_code){
$this->_langCode = $lang_code;
$oPDOLink = ClassConfig::databaseConnect();
$sql = "
SELECT id, code, source, ".$this->_langCode."
FROM content_content;
";
$execSQL = $oPDOLink->prepare($sql);
$execSQL->execute(array());
$rows = $execSQL->fetchAll(PDO::FETCH_ASSOC);
$res = array();
foreach($rows as $k=>$v){
$res[$rows[$k]['code']] = array('source'=>$rows[$k]['source'], $this->_langCode=>$rows[$k][$this->_langCode]);
}
return $res;
}
public function getContentFromDatabase($code, $lang){
$this->_code = $code;
$this->_lang = $lang;
$oPDOLink = ClassConfig::databaseConnect();
$sql="
SELECT source, ".$this->_lang."
FROM content_content
WHERE code=:code
LIMIT 1
";
$execSQL = $oPDOLink->prepare($sql);
$execSQL->execute(array(':code'=>$this->_code));
$row = $execSQL->fetch(PDO::FETCH_ASSOC);
return $row;
}
public function getContent($code, $lang){
$this->_code = $code;
$this->_lang = $lang;
if(!isset($_SESSION['content'][$this->_code]) or $_SESSION['content'][$this->_code]['source']==''){
$row = $this->getContentFromDatabase($this->_code, $this->_lang);
$_SESSION['content'][$this->_code][$this->_lang] = $row[$this->_lang];
$_SESSION['content'][$this->_code]['source'] = $row['source'];
}
if($_SESSION['content'][$this->_code][$this->_lang] != ''){
return $_SESSION['content'][$this->_code][$this->_lang];
} else {
return $_SESSION['content'][$this->_code]['source'];
}
}
public function listContentForTranslation($lang_code){
$this->_langCode = $lang_code;
$oPDOLink = ClassConfig::databaseConnect();
$sql = "
SELECT id, code, source, ".$this->_langCode." AS content, is_active
FROM content_content;
";
$execSQL = $oPDOLink->prepare($sql);
$execSQL->execute(array());
$rows = $execSQL->fetchAll(PDO::FETCH_ASSOC);
return $rows;
}
public function getContentDependingOnId($lang_code, $content_id){
$this->_langCode = $lang_code;
$this->_contentId = $content_id;
$oPDOLink = ClassConfig::databaseConnect();
$sql = "
SELECT id, code, source, ".$this->_langCode." AS content, is_active
FROM content_content
WHERE id=:id;
";
$execSQL = $oPDOLink->prepare($sql);
$execSQL->execute(array(':id'=>$this->_contentId));
$rows = $execSQL->fetch(PDO::FETCH_ASSOC);
return $rows;
}
public function updateContentDependingOnId($lang_code, $content_id, $content){
$this->_langCode = $lang_code;
$this->_contentId = $content_id;
$this->_content = $content;
$oPDOLink = ClassConfig::databaseConnect();
$sql = "
UPDATE content_content SET ".$this->_langCode."=:content
WHERE id=:id;
";
$execSQL = $oPDOLink->prepare($sql);
if($execSQL->execute(array(':content'=>$this->_content, ':id'=>$this->_contentId))){
return 'success';
} else {
return 'failure';
}
}
}