mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
changes how the pagination is done in the DB_Model
This commit is contained in:
@@ -25,6 +25,11 @@ class Cms extends FHC_Controller
|
||||
$this->loadPhrases([
|
||||
'global'
|
||||
]);
|
||||
|
||||
$this->load->model('content/News_model', 'NewsModel');
|
||||
|
||||
// setting up the papgination_size
|
||||
$this->pagination_size = 10;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
@@ -67,12 +72,36 @@ class Cms extends FHC_Controller
|
||||
public function getNews($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $edit = false, $sichtbar = true)
|
||||
{
|
||||
$page = intval($this->input->get('page', true));
|
||||
$pagination_size = 10;
|
||||
$news = $this->cmslib->getNews($infoscreen, $studiengang_kz, $semester, $mischen, $titel, $edit, $sichtbar, $page, $pagination_size);
|
||||
|
||||
|
||||
$news = $this->cmslib->getNews($infoscreen, $studiengang_kz, $semester, $mischen, $titel, $edit, $sichtbar, $page, $this->pagination_size);
|
||||
|
||||
if (isError($news)) {
|
||||
echo json_encode(getError($news));
|
||||
}
|
||||
echo json_encode(getData($news));
|
||||
}
|
||||
|
||||
public function getNewsMaxPage($infoscreen = false, $studiengang_kz = null, $semester = null, $mischen = true, $titel = '', $fachbereich_kurzbz = null, $maxalter = 0, $edit = false, $sichtbar = true, $page = 1, $page_size = 10)
|
||||
{
|
||||
$this->load->model('crm/Student_model', 'StudentModel');
|
||||
$this->load->model('organisation/Studiengang_model', 'StudiengangModel');
|
||||
|
||||
if (!$infoscreen && ($studiengang_kz === null || $semester === null)) {
|
||||
//Zum anzeigen der Studiengang-Details neben den News
|
||||
$student = $this->StudentModel->loadWhere(['student_uid' => get_uid()]);
|
||||
if (isError($student))
|
||||
return $student;
|
||||
if (getData($student)) {
|
||||
$student = current(getData($student));
|
||||
if ($studiengang_kz === null)
|
||||
$studiengang_kz = $student->studiengang_kz;
|
||||
if ($semester === null)
|
||||
$semester = $student->semester;
|
||||
}
|
||||
}
|
||||
$all = $edit;
|
||||
$query = $this->NewsModel->getNewsWithContentQuery(getSprache(), $studiengang_kz, $semester, $fachbereich_kurzbz, $sichtbar, $maxalter, $page, $this->pagination_size, $all, $mischen);
|
||||
echo json_encode($query->maxPageCount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ class DB_Model extends CI_Model
|
||||
protected $pk; // Name of the PrimaryKey for DB-Update, Load, ...
|
||||
protected $hasSequence; // False if this table has a composite primary key that is not using a sequence
|
||||
// True if this table has a primary key that uses a sequence
|
||||
//protected $paginationOptions; // $page and $page_size together in an associative array
|
||||
protected $page;
|
||||
protected $page_size;
|
||||
|
||||
private $executedQueryMetaData;
|
||||
private $executedQueryListFields;
|
||||
@@ -484,7 +487,7 @@ class DB_Model extends CI_Model
|
||||
if (!is_numeric($start) || (is_numeric($start) && $start <= 0))
|
||||
return error('The start parameter is not valid', EXIT_MODEL);
|
||||
|
||||
if (is_numeric($end) && $end > $start)
|
||||
if (is_numeric($end))
|
||||
{
|
||||
$this->db->limit($start, $end);
|
||||
}
|
||||
@@ -1073,5 +1076,46 @@ class DB_Model extends CI_Model
|
||||
|
||||
return $udfs;
|
||||
}
|
||||
|
||||
function addPagination( $page, $page_size, $maxPageCount=null)
|
||||
{
|
||||
if (isset($page) && is_numeric($page) && isset($page_size) && is_numeric($page_size) && $page > 0 && $page_size > 0) {
|
||||
|
||||
if (isset($maxPageCount) && is_numeric($maxPageCount) && $maxPageCount > 0) {
|
||||
$floatMaxPageCount = $maxPageCount / $page_size;
|
||||
$floatMaxPageCount = ceil($floatMaxPageCount);
|
||||
if($page > $floatMaxPageCount){
|
||||
$page = $floatMaxPageCount;
|
||||
}
|
||||
}
|
||||
// else if page is to big
|
||||
$offset = (($page-1) * $page_size);
|
||||
$this->addLimit($page_size, $offset);
|
||||
|
||||
} else {
|
||||
$this->addLimit($page_size);
|
||||
}
|
||||
}
|
||||
|
||||
function getMaxPageCount( $page_size, $params=null )
|
||||
{
|
||||
// we clone the original query, so we dont have to change the origial query
|
||||
$instance_copy = clone $this;
|
||||
$db_copy = clone $this->db;
|
||||
$countSql = $db_copy->get_compiled_select($instance_copy->dbTable,false);
|
||||
$countSql = "SELECT COUNT(*) FROM (". $countSql .") as count;";
|
||||
|
||||
// calculating the maxPageCount and adding the pagination to the query
|
||||
$num_rows_query_result = $instance_copy->execReadOnlyQuery($countSql, $params);
|
||||
|
||||
if(isError($num_rows_query_result)){
|
||||
return error($this->db->error(), EXIT_DATABASE);
|
||||
}
|
||||
$num_rows = getData($num_rows_query_result)[0]->count;
|
||||
|
||||
|
||||
// ceil, to include remaining rows into the last page
|
||||
return $num_rows;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,6 +213,7 @@ class CmsLib
|
||||
return $news;
|
||||
|
||||
$news = getData($news);
|
||||
//var_dump($news->maxPageCount);
|
||||
foreach ($news as $newsobj) {
|
||||
if ($studiengang_kz && $edit && !$newsobj->studiengang_kz)
|
||||
continue;
|
||||
|
||||
@@ -27,16 +27,7 @@ class News_model extends DB_Model
|
||||
);
|
||||
}
|
||||
|
||||
private function getMaxPageCount($page_size)
|
||||
{
|
||||
$this->addSelect(['Count(*)']);
|
||||
$count = $this->load();
|
||||
$count = hasData($count) ? getData($count)[0]->count : null;
|
||||
$floatMaxPageCount = $count / $page_size;
|
||||
|
||||
// ceil, to include remaining rows into the last page
|
||||
return ceil($floatMaxPageCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sprache
|
||||
@@ -53,20 +44,8 @@ class News_model extends DB_Model
|
||||
*
|
||||
* @return stdObj
|
||||
*/
|
||||
public function getNewsWithContent($sprache, $studiengang_kz, $semester, $fachbereich_kurzbz = null, $sichtbar = true, $maxalter = 0, $page = 1, $page_size = 10, $all = false, $mischen = true)
|
||||
public function getNewsWithContentQuery($sprache, $studiengang_kz, $semester, $fachbereich_kurzbz = null, $sichtbar = true, $maxalter = 0, $page = 1, $page_size = 10, $all = false, $mischen = true)
|
||||
{
|
||||
if (isset($page) && is_numeric($page) && isset($page_size) && is_numeric($page_size) && $page > 0 && $page_size > 0) {
|
||||
|
||||
$maxPageCount = $this->getMaxPageCount($page_size);
|
||||
if ($maxPageCount) {
|
||||
$page = $page % $maxPageCount;
|
||||
}
|
||||
$offset = $page * $page_size;
|
||||
$this->addLimit($page_size, $offset);
|
||||
|
||||
} else {
|
||||
$this->addLimit($page_size);
|
||||
}
|
||||
|
||||
$this->addOrder('datum', 'DESC');
|
||||
|
||||
@@ -124,9 +103,24 @@ class News_model extends DB_Model
|
||||
|
||||
$this->db->where($where, NULL, FALSE);
|
||||
|
||||
$sql = $this->db->get_compiled_select($this->dbTable);
|
||||
// calculating the maxPageCount and adding pagination to the query
|
||||
$maxPageCount = $this->getMaxPageCount($page_size, $params);
|
||||
$this->addPagination($page, $page_size, $maxPageCount);
|
||||
|
||||
// creating the select query
|
||||
$query = new stdClass();
|
||||
$query->sql = $this->db->get_compiled_select($this->dbTable);
|
||||
$query->params = $params;
|
||||
$query->maxPageCount = $maxPageCount;
|
||||
return $query;
|
||||
|
||||
}
|
||||
|
||||
function getNewsWithContent($sprache, $studiengang_kz, $semester, $fachbereich_kurzbz = null, $sichtbar = true, $maxalter = 0, $page = 1, $page_size = 10, $all = false, $mischen = true)
|
||||
{
|
||||
$query = $this->getNewsWithContentQuery($sprache, $studiengang_kz, $semester, $fachbereich_kurzbz, $sichtbar, $maxalter, $page, $page_size, $all, $mischen);
|
||||
return $this->execReadOnlyQuery($query->sql, $query->params);
|
||||
|
||||
return $this->execQuery($sql, $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export default {
|
||||
getNews: function (page = 1, pageSize = 10) {
|
||||
getNews: function (page = 1) {
|
||||
console.log("this is the page that was passed", page);
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
@@ -7,8 +8,14 @@ export default {
|
||||
return axios.get(url, {
|
||||
params: {
|
||||
page,
|
||||
pageSize,
|
||||
},
|
||||
});
|
||||
},
|
||||
getNewsMaxPage: function () {
|
||||
const url =
|
||||
FHC_JS_DATA_STORAGE_OBJECT.app_root +
|
||||
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
|
||||
"/CisHtml/Cms/getNewsMaxPage";
|
||||
return axios.get(url);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -7,11 +7,13 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
content: null,
|
||||
maxPageCount: 0,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
loadNewPageContent: function (data) {
|
||||
Vue.$fhcapi.Cms.getNews(data.page).then((result) => {
|
||||
console.log("fetched url :", result.data);
|
||||
this.content = result.data;
|
||||
});
|
||||
},
|
||||
@@ -20,9 +22,13 @@ export default {
|
||||
Vue.$fhcapi.Cms.getNews().then((result) => {
|
||||
this.content = result.data;
|
||||
});
|
||||
|
||||
Vue.$fhcapi.Cms.getNewsMaxPage().then((result) => {
|
||||
this.maxPageCount = result.data;
|
||||
});
|
||||
},
|
||||
template: /*html*/ `
|
||||
<pagination @page="loadNewPageContent">
|
||||
<pagination @page="loadNewPageContent" :maxPageCount="maxPageCount">
|
||||
<div v-html="content"></div>
|
||||
</pagination>`,
|
||||
};
|
||||
|
||||
@@ -2,6 +2,12 @@ export default {
|
||||
components: {
|
||||
paginator: primevue.paginator,
|
||||
},
|
||||
props: {
|
||||
maxPageCount: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {};
|
||||
},
|
||||
@@ -15,10 +21,10 @@ export default {
|
||||
},
|
||||
template: /*html*/ `
|
||||
|
||||
|
||||
<paginator @page="(page)=>$emit('page',{...page, page:page.page+1})" :rows="1" :totalRecords="120" ></paginator>
|
||||
<pre>{{JSON.stringify(maxPageCount,null,2)}}</pre>
|
||||
<paginator @page="(data)=>$emit('page',{...data, page:data.page+1})" :rows="10" :totalRecords="maxPageCount" :rowsPerPageOptions="[10, 20, 30]" ></paginator>
|
||||
<slot>
|
||||
NO CONTENT WAS PROVIDED
|
||||
Placeholder
|
||||
</slot>
|
||||
<paginator :rows="10" :totalRecords="120" :rowsPerPageOptions="[10, 20, 30]"></paginator>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user