<?php

namespace App\System\Controller;
use App\System\Basic\beContoller;
use App\System\Model\AnnouncementModel;
use App\System\Vendor\Auth;
use App\System\Vendor\beLanguage;

class AnnouncementController extends beContoller {
    //@ioncube.dk beEncrypt("be_diyocp","all") -> "54b4be5184e487a534e6f72e187d2ff4" RANDOM
    public function all(){
        beLanguage::beReadLang("clientarea");
        beLanguage::beReadLang("announcement");
        NavController::beAddBreadcumb(beGetLang("clientarea"),beGetRoute("client.dashboard.alternative"));
        NavController::beAddBreadcumb(beGetLang("announcement"));
        $user = Auth::beGetUser();
        $page = (int)$_GET["page"];
        if(!$page){
            $page = 1;
        }
        $itemcount = AnnouncementModel::beSelect("COUNT(aid) as total")->beWhere("lid",$user["lid"])->beGet()["total"];
        $paganation = bePaganation($page,$itemcount,beGetRoute("client.announcement"),15,"user");
        $items = AnnouncementModel::beWhere("lid",$user["lid"]);
        if($paganation["itemstart"] == 0){
            $items = $items->beLimit($paganation["itemlimit"]);
        }
        else{
            $items = $items->beLimit($paganation["itemstart"],$paganation["itemlimit"]);
        }
        $items = $items->beOrder("lid","DESC")->beGetAll();
        beSetHeaderContent("",1);
        return beGetView("clientarea.announcements",["items" => $items,"itemcount" => $itemcount,"paganation" => $paganation]);
    }
}

?>