<?php

namespace PHPMaker2021\rdigital21;

use Doctrine\DBAL\ParameterType;

/**
 * Table class for penilaian
 */
class Penilaian extends DbTable
{
    protected $SqlFrom = "";
    protected $SqlSelect = null;
    protected $SqlSelectList = null;
    protected $SqlWhere = "";
    protected $SqlGroupBy = "";
    protected $SqlHaving = "";
    protected $SqlOrderBy = "";
    public $UseSessionForListSql = true;

    // Column CSS classes
    public $LeftColumnClass = "col-sm-2 col-form-label ew-label";
    public $RightColumnClass = "col-sm-10";
    public $OffsetColumnClass = "col-sm-10 offset-sm-2";
    public $TableLeftColumnClass = "w-col-2";

    // Export
    public $ExportDoc;

    // Fields
    public $penilaian_id;
    public $kode_tapel;
    public $guru_id;
    public $mapel_id;
    public $kelas;
    public $materi;
    public $tujuan_pembelajaran;
    public $fase;

    // Page ID
    public $PageID = ""; // To be overridden by subclass

    // Constructor
    public function __construct()
    {
        global $Language, $CurrentLanguage;
        parent::__construct();

        // Language object
        $Language = Container("language");
        $this->TableVar = 'penilaian';
        $this->TableName = 'penilaian';
        $this->TableType = 'TABLE';

        // Update Table
        $this->UpdateTable = "\"penilaian\"";
        $this->Dbid = 'DB';
        $this->ExportAll = true;
        $this->ExportPageBreakCount = 0; // Page break per every n record (PDF only)
        $this->ExportPageOrientation = "portrait"; // Page orientation (PDF only)
        $this->ExportPageSize = "a4"; // Page size (PDF only)
        $this->ExportExcelPageOrientation = ""; // Page orientation (PhpSpreadsheet only)
        $this->ExportExcelPageSize = ""; // Page size (PhpSpreadsheet only)
        $this->ExportWordPageOrientation = "portrait"; // Page orientation (PHPWord only)
        $this->ExportWordColumnWidth = null; // Cell width (PHPWord only)
        $this->DetailAdd = false; // Allow detail add
        $this->DetailEdit = false; // Allow detail edit
        $this->DetailView = false; // Allow detail view
        $this->ShowMultipleDetails = false; // Show multiple details
        $this->GridAddRowCount = 5;
        $this->AllowAddDeleteRow = true; // Allow add/delete row
        $this->BasicSearch = new BasicSearch($this->TableVar);

        // penilaian_id
        $this->penilaian_id = new DbField('penilaian', 'penilaian', 'x_penilaian_id', 'penilaian_id', '"penilaian_id"', '"penilaian_id"', 3, 0, -1, false, '"penilaian_id"', false, false, false, 'FORMATTED TEXT', 'NO');
        $this->penilaian_id->IsAutoIncrement = true; // Autoincrement field
        $this->penilaian_id->IsPrimaryKey = true; // Primary key field
        $this->penilaian_id->IsForeignKey = true; // Foreign key field
        $this->penilaian_id->Nullable = false; // NOT NULL field
        $this->penilaian_id->Sortable = true; // Allow sort
        $this->penilaian_id->DefaultErrorMessage = $Language->phrase("IncorrectInteger");
        $this->penilaian_id->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->penilaian_id->Param, "CustomMsg");
        $this->Fields['penilaian_id'] = &$this->penilaian_id;

        // kode_tapel
        $this->kode_tapel = new DbField('penilaian', 'penilaian', 'x_kode_tapel', 'kode_tapel', '"kode_tapel"', '"kode_tapel"', 203, 255, -1, false, '"kode_tapel"', false, false, false, 'FORMATTED TEXT', 'TEXTAREA');
        $this->kode_tapel->Sortable = true; // Allow sort
        $this->kode_tapel->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->kode_tapel->Param, "CustomMsg");
        $this->Fields['kode_tapel'] = &$this->kode_tapel;

        // guru_id
        $this->guru_id = new DbField('penilaian', 'penilaian', 'x_guru_id', 'guru_id', '"guru_id"', '"guru_id"', 203, 255, -1, false, '"guru_id"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->guru_id->Required = true; // Required field
        $this->guru_id->Sortable = true; // Allow sort
        $this->guru_id->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->guru_id->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->guru_id->Lookup = new Lookup('guru_id', 'guru', false, 'guru_id', ["nama","","",""], [], [], [], [], [], [], '', '');
        $this->guru_id->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->guru_id->Param, "CustomMsg");
        $this->Fields['guru_id'] = &$this->guru_id;

        // mapel_id
        $this->mapel_id = new DbField('penilaian', 'penilaian', 'x_mapel_id', 'mapel_id', '"mapel_id"', '"mapel_id"', 203, 255, -1, false, '"mapel_id"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->mapel_id->Required = true; // Required field
        $this->mapel_id->Sortable = true; // Allow sort
        $this->mapel_id->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->mapel_id->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->mapel_id->Lookup = new Lookup('mapel_id', 'mata_pelajaran', false, 'kode_mapel', ["kode_mapel","mata_pelajaran","ket",""], [], ["x_materi[]","x_tujuan_pembelajaran[]"], [], [], [], [], '', '<div><b><p>{{:df1}}</p></b> {{:df2}}, {{:df3}}</div>');
        $this->mapel_id->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->mapel_id->Param, "CustomMsg");
        $this->Fields['mapel_id'] = &$this->mapel_id;

        // kelas
        $this->kelas = new DbField('penilaian', 'penilaian', 'x_kelas', 'kelas', '"kelas"', '"kelas"', 203, 255, -1, false, '"kelas"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->kelas->Required = true; // Required field
        $this->kelas->Sortable = true; // Allow sort
        $this->kelas->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->kelas->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->kelas->Lookup = new Lookup('kelas', 'peserta_didik', true, 'kelas', ["kelas","","",""], [], [], [], [], [], [], '"kelas" ASC', '');
        $this->kelas->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->kelas->Param, "CustomMsg");
        $this->Fields['kelas'] = &$this->kelas;

        // materi
        $this->materi = new DbField('penilaian', 'penilaian', 'x_materi', 'materi', '"materi"', '"materi"', 203, 255, -1, false, '"materi"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->materi->Sortable = true; // Allow sort
        $this->materi->SelectMultiple = true; // Multiple select
        $this->materi->Lookup = new Lookup('materi', 'materi', false, 'materi_id', ["kode_mapel","kode","tujuan_pembelajaran",""], ["x_mapel_id"], [], ["kode_mapel"], ["x_kode_mapel"], [], [], '', '<div><b><span class="text-primary">{{:df1}}</span></b> :  {{:df3}}</div>');
        $this->materi->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->materi->Param, "CustomMsg");
        $this->Fields['materi'] = &$this->materi;

        // tujuan_pembelajaran
        $this->tujuan_pembelajaran = new DbField('penilaian', 'penilaian', 'x_tujuan_pembelajaran', 'tujuan_pembelajaran', '"tujuan_pembelajaran"', '"tujuan_pembelajaran"', 203, 255, -1, false, '"tujuan_pembelajaran"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->tujuan_pembelajaran->Sortable = true; // Allow sort
        $this->tujuan_pembelajaran->SelectMultiple = true; // Multiple select
        $this->tujuan_pembelajaran->Lookup = new Lookup('tujuan_pembelajaran', 'tujuan_pembelajaran', false, 'tp_id', ["kode_mapel","tujuan_pembelajaran","",""], ["x_mapel_id"], [], ["kode_mapel"], ["x_kode_mapel"], [], [], '', '<div><b><span class="text-primary">{{:df1}}</span></b> :  {{:df2}}</div>');
        $this->tujuan_pembelajaran->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->tujuan_pembelajaran->Param, "CustomMsg");
        $this->Fields['tujuan_pembelajaran'] = &$this->tujuan_pembelajaran;

        // fase
        $this->fase = new DbField('penilaian', 'penilaian', 'x_fase', 'fase', '"fase"', '"fase"', 203, 0, -1, false, '"fase"', false, false, false, 'FORMATTED TEXT', 'RADIO');
        $this->fase->Required = true; // Required field
        $this->fase->Sortable = true; // Allow sort
        $this->fase->Lookup = new Lookup('fase', 'penilaian', false, '', ["","","",""], [], [], [], [], [], [], '', '');
        $this->fase->OptionCount = 5;
        $this->fase->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->fase->Param, "CustomMsg");
        $this->Fields['fase'] = &$this->fase;
    }

    // Field Visibility
    public function getFieldVisibility($fldParm)
    {
        global $Security;
        return $this->$fldParm->Visible; // Returns original value
    }

    // Set left column class (must be predefined col-*-* classes of Bootstrap grid system)
    public function setLeftColumnClass($class)
    {
        if (preg_match('/^col\-(\w+)\-(\d+)$/', $class, $match)) {
            $this->LeftColumnClass = $class . " col-form-label ew-label";
            $this->RightColumnClass = "col-" . $match[1] . "-" . strval(12 - (int)$match[2]);
            $this->OffsetColumnClass = $this->RightColumnClass . " " . str_replace("col-", "offset-", $class);
            $this->TableLeftColumnClass = preg_replace('/^col-\w+-(\d+)$/', "w-col-$1", $class); // Change to w-col-*
        }
    }

    // Single column sort
    public function updateSort(&$fld)
    {
        if ($this->CurrentOrder == $fld->Name) {
            $sortField = $fld->Expression;
            $lastSort = $fld->getSort();
            if (in_array($this->CurrentOrderType, ["ASC", "DESC", "NO"])) {
                $curSort = $this->CurrentOrderType;
            } else {
                $curSort = $lastSort;
            }
            $fld->setSort($curSort);
            $orderBy = in_array($curSort, ["ASC", "DESC"]) ? $sortField . " " . $curSort : "";
            $this->setSessionOrderBy($orderBy); // Save to Session
        } else {
            $fld->setSort("");
        }
    }

    // Current detail table name
    public function getCurrentDetailTable()
    {
        return Session(PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_DETAIL_TABLE"));
    }

    public function setCurrentDetailTable($v)
    {
        $_SESSION[PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_DETAIL_TABLE")] = $v;
    }

    // Get detail url
    public function getDetailUrl()
    {
        // Detail url
        $detailUrl = "";
        if ($this->getCurrentDetailTable() == "nilai_sumatif") {
            $detailUrl = Container("nilai_sumatif")->getListUrl() . "?" . Config("TABLE_SHOW_MASTER") . "=" . $this->TableVar;
            $detailUrl .= "&" . GetForeignKeyUrl("fk_penilaian_id", $this->penilaian_id->CurrentValue);
        }
        if ($this->getCurrentDetailTable() == "nilai_formatif") {
            $detailUrl = Container("nilai_formatif")->getListUrl() . "?" . Config("TABLE_SHOW_MASTER") . "=" . $this->TableVar;
            $detailUrl .= "&" . GetForeignKeyUrl("fk_penilaian_id", $this->penilaian_id->CurrentValue);
        }
        if ($detailUrl == "") {
            $detailUrl = "PenilaianList";
        }
        return $detailUrl;
    }

    // Table level SQL
    public function getSqlFrom() // From
    {
        return ($this->SqlFrom != "") ? $this->SqlFrom : "\"penilaian\"";
    }

    public function sqlFrom() // For backward compatibility
    {
        return $this->getSqlFrom();
    }

    public function setSqlFrom($v)
    {
        $this->SqlFrom = $v;
    }

    public function getSqlSelect() // Select
    {
        return $this->SqlSelect ?? $this->getQueryBuilder()->select("*");
    }

    public function sqlSelect() // For backward compatibility
    {
        return $this->getSqlSelect();
    }

    public function setSqlSelect($v)
    {
        $this->SqlSelect = $v;
    }

    public function getSqlWhere() // Where
    {
        $where = ($this->SqlWhere != "") ? $this->SqlWhere : "";
        $this->DefaultFilter = "`kode_tapel`='".kode_tapel()."'";
        AddFilter($where, $this->DefaultFilter);
        return $where;
    }

    public function sqlWhere() // For backward compatibility
    {
        return $this->getSqlWhere();
    }

    public function setSqlWhere($v)
    {
        $this->SqlWhere = $v;
    }

    public function getSqlGroupBy() // Group By
    {
        return ($this->SqlGroupBy != "") ? $this->SqlGroupBy : "";
    }

    public function sqlGroupBy() // For backward compatibility
    {
        return $this->getSqlGroupBy();
    }

    public function setSqlGroupBy($v)
    {
        $this->SqlGroupBy = $v;
    }

    public function getSqlHaving() // Having
    {
        return ($this->SqlHaving != "") ? $this->SqlHaving : "";
    }

    public function sqlHaving() // For backward compatibility
    {
        return $this->getSqlHaving();
    }

    public function setSqlHaving($v)
    {
        $this->SqlHaving = $v;
    }

    public function getSqlOrderBy() // Order By
    {
        return ($this->SqlOrderBy != "") ? $this->SqlOrderBy : $this->DefaultSort;
    }

    public function sqlOrderBy() // For backward compatibility
    {
        return $this->getSqlOrderBy();
    }

    public function setSqlOrderBy($v)
    {
        $this->SqlOrderBy = $v;
    }

    // Apply User ID filters
    public function applyUserIDFilters($filter)
    {
        global $Security;
        // Add User ID filter
        if ($Security->currentUserID() != "" && !$Security->isAdmin()) { // Non system admin
            $filter = $this->addUserIDFilter($filter);
        }
        return $filter;
    }

    // Check if User ID security allows view all
    public function userIDAllow($id = "")
    {
        $allow = $this->UserIDAllowSecurity;
        switch ($id) {
            case "add":
            case "copy":
            case "gridadd":
            case "register":
            case "addopt":
                return (($allow & 1) == 1);
            case "edit":
            case "gridedit":
            case "update":
            case "changepassword":
            case "resetpassword":
                return (($allow & 4) == 4);
            case "delete":
                return (($allow & 2) == 2);
            case "view":
                return (($allow & 32) == 32);
            case "search":
                return (($allow & 64) == 64);
            default:
                return (($allow & 8) == 8);
        }
    }

    /**
     * Get record count
     *
     * @param string|QueryBuilder $sql SQL or QueryBuilder
     * @param mixed $c Connection
     * @return int
     */
    public function getRecordCount($sql, $c = null)
    {
        $cnt = -1;
        $rs = null;
        if ($sql instanceof \Doctrine\DBAL\Query\QueryBuilder) { // Query builder
            $sqlwrk = clone $sql;
            $sqlwrk = $sqlwrk->resetQueryPart("orderBy")->getSQL();
        } else {
            $sqlwrk = $sql;
        }
        $pattern = '/^SELECT\s([\s\S]+)\sFROM\s/i';
        // Skip Custom View / SubQuery / SELECT DISTINCT / ORDER BY
        if (
            ($this->TableType == 'TABLE' || $this->TableType == 'VIEW' || $this->TableType == 'LINKTABLE') &&
            preg_match($pattern, $sqlwrk) && !preg_match('/\(\s*(SELECT[^)]+)\)/i', $sqlwrk) &&
            !preg_match('/^\s*select\s+distinct\s+/i', $sqlwrk) && !preg_match('/\s+order\s+by\s+/i', $sqlwrk)
        ) {
            $sqlwrk = "SELECT COUNT(*) FROM " . preg_replace($pattern, "", $sqlwrk);
        } else {
            $sqlwrk = "SELECT COUNT(*) FROM (" . $sqlwrk . ") COUNT_TABLE";
        }
        $conn = $c ?? $this->getConnection();
        $rs = $conn->executeQuery($sqlwrk);
        $cnt = $rs->fetchColumn();
        if ($cnt !== false) {
            return (int)$cnt;
        }

        // Unable to get count by SELECT COUNT(*), execute the SQL to get record count directly
        return ExecuteRecordCount($sql, $conn);
    }

    // Get SQL
    public function getSql($where, $orderBy = "")
    {
        return $this->buildSelectSql(
            $this->getSqlSelect(),
            $this->getSqlFrom(),
            $this->getSqlWhere(),
            $this->getSqlGroupBy(),
            $this->getSqlHaving(),
            $this->getSqlOrderBy(),
            $where,
            $orderBy
        )->getSQL();
    }

    // Table SQL
    public function getCurrentSql()
    {
        $filter = $this->CurrentFilter;
        $filter = $this->applyUserIDFilters($filter);
        $sort = $this->getSessionOrderBy();
        return $this->getSql($filter, $sort);
    }

    /**
     * Table SQL with List page filter
     *
     * @return QueryBuilder
     */
    public function getListSql()
    {
        $filter = $this->UseSessionForListSql ? $this->getSessionWhere() : "";
        AddFilter($filter, $this->CurrentFilter);
        $filter = $this->applyUserIDFilters($filter);
        $this->recordsetSelecting($filter);
        $select = $this->getSqlSelect();
        $from = $this->getSqlFrom();
        $sort = $this->UseSessionForListSql ? $this->getSessionOrderBy() : "";
        $this->Sort = $sort;
        return $this->buildSelectSql(
            $select,
            $from,
            $this->getSqlWhere(),
            $this->getSqlGroupBy(),
            $this->getSqlHaving(),
            $this->getSqlOrderBy(),
            $filter,
            $sort
        );
    }

    // Get ORDER BY clause
    public function getOrderBy()
    {
        $orderBy = $this->getSqlOrderBy();
        $sort = $this->getSessionOrderBy();
        if ($orderBy != "" && $sort != "") {
            $orderBy .= ", " . $sort;
        } elseif ($sort != "") {
            $orderBy = $sort;
        }
        return $orderBy;
    }

    // Get record count based on filter (for detail record count in master table pages)
    public function loadRecordCount($filter)
    {
        $origFilter = $this->CurrentFilter;
        $this->CurrentFilter = $filter;
        $this->recordsetSelecting($this->CurrentFilter);
        $select = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlSelect() : $this->getQueryBuilder()->select("*");
        $groupBy = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlGroupBy() : "";
        $having = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlHaving() : "";
        $sql = $this->buildSelectSql($select, $this->getSqlFrom(), $this->getSqlWhere(), $groupBy, $having, "", $this->CurrentFilter, "");
        $cnt = $this->getRecordCount($sql);
        $this->CurrentFilter = $origFilter;
        return $cnt;
    }

    // Get record count (for current List page)
    public function listRecordCount()
    {
        $filter = $this->getSessionWhere();
        AddFilter($filter, $this->CurrentFilter);
        $filter = $this->applyUserIDFilters($filter);
        $this->recordsetSelecting($filter);
        $select = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlSelect() : $this->getQueryBuilder()->select("*");
        $groupBy = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlGroupBy() : "";
        $having = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlHaving() : "";
        $sql = $this->buildSelectSql($select, $this->getSqlFrom(), $this->getSqlWhere(), $groupBy, $having, "", $filter, "");
        $cnt = $this->getRecordCount($sql);
        return $cnt;
    }

    /**
     * INSERT statement
     *
     * @param mixed $rs
     * @return QueryBuilder
     */
    protected function insertSql(&$rs)
    {
        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder->insert($this->UpdateTable);
        foreach ($rs as $name => $value) {
            if (!isset($this->Fields[$name]) || $this->Fields[$name]->IsCustom) {
                continue;
            }
            $type = GetParameterType($this->Fields[$name], $value, $this->Dbid);
            $queryBuilder->setValue($this->Fields[$name]->Expression, $queryBuilder->createPositionalParameter($value, $type));
        }
        return $queryBuilder;
    }

    // Insert
    public function insert(&$rs)
    {
        $conn = $this->getConnection();
        $success = $this->insertSql($rs)->execute();
        if ($success) {
            // Get insert id if necessary
            $this->penilaian_id->setDbValue($conn->lastInsertId());
            $rs['penilaian_id'] = $this->penilaian_id->DbValue;
        }
        return $success;
    }

    /**
     * UPDATE statement
     *
     * @param array $rs Data to be updated
     * @param string|array $where WHERE clause
     * @param string $curfilter Filter
     * @return QueryBuilder
     */
    protected function updateSql(&$rs, $where = "", $curfilter = true)
    {
        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder->update($this->UpdateTable);
        foreach ($rs as $name => $value) {
            if (!isset($this->Fields[$name]) || $this->Fields[$name]->IsCustom || $this->Fields[$name]->IsAutoIncrement) {
                continue;
            }
            $type = GetParameterType($this->Fields[$name], $value, $this->Dbid);
            $queryBuilder->set($this->Fields[$name]->Expression, $queryBuilder->createPositionalParameter($value, $type));
        }
        $filter = ($curfilter) ? $this->CurrentFilter : "";
        if (is_array($where)) {
            $where = $this->arrayToFilter($where);
        }
        AddFilter($filter, $where);
        if ($filter != "") {
            $queryBuilder->where($filter);
        }
        return $queryBuilder;
    }

    // Update
    public function update(&$rs, $where = "", $rsold = null, $curfilter = true)
    {
        // Cascade Update detail table 'nilai_sumatif'
        $cascadeUpdate = false;
        $rscascade = [];
        if ($rsold && (isset($rs['penilaian_id']) && $rsold['penilaian_id'] != $rs['penilaian_id'])) { // Update detail field 'penilaian_id'
            $cascadeUpdate = true;
            $rscascade['penilaian_id'] = $rs['penilaian_id'];
        }
        if ($cascadeUpdate) {
            $rswrk = Container("nilai_sumatif")->loadRs("\"penilaian_id\" = " . QuotedValue($rsold['penilaian_id'], DATATYPE_NUMBER, 'DB'))->fetchAll(\PDO::FETCH_ASSOC);
            foreach ($rswrk as $rsdtlold) {
                $rskey = [];
                $fldname = 'nilai_s_id';
                $rskey[$fldname] = $rsdtlold[$fldname];
                $rsdtlnew = array_merge($rsdtlold, $rscascade);
                // Call Row_Updating event
                $success = Container("nilai_sumatif")->rowUpdating($rsdtlold, $rsdtlnew);
                if ($success) {
                    $success = Container("nilai_sumatif")->update($rscascade, $rskey, $rsdtlold);
                }
                if (!$success) {
                    return false;
                }
                // Call Row_Updated event
                Container("nilai_sumatif")->rowUpdated($rsdtlold, $rsdtlnew);
            }
        }

        // If no field is updated, execute may return 0. Treat as success
        $success = $this->updateSql($rs, $where, $curfilter)->execute();
        $success = ($success > 0) ? $success : true;
        return $success;
    }

    /**
     * DELETE statement
     *
     * @param array $rs Key values
     * @param string|array $where WHERE clause
     * @param string $curfilter Filter
     * @return QueryBuilder
     */
    protected function deleteSql(&$rs, $where = "", $curfilter = true)
    {
        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder->delete($this->UpdateTable);
        if (is_array($where)) {
            $where = $this->arrayToFilter($where);
        }
        if ($rs) {
            if (array_key_exists('penilaian_id', $rs)) {
                AddFilter($where, QuotedName('penilaian_id', $this->Dbid) . '=' . QuotedValue($rs['penilaian_id'], $this->penilaian_id->DataType, $this->Dbid));
            }
        }
        $filter = ($curfilter) ? $this->CurrentFilter : "";
        AddFilter($filter, $where);
        return $queryBuilder->where($filter != "" ? $filter : "0=1");
    }

    // Delete
    public function delete(&$rs, $where = "", $curfilter = false)
    {
        $success = true;

        // Cascade delete detail table 'nilai_sumatif'
        $dtlrows = Container("nilai_sumatif")->loadRs("\"penilaian_id\" = " . QuotedValue($rs['penilaian_id'], DATATYPE_NUMBER, "DB"))->fetchAll(\PDO::FETCH_ASSOC);
        // Call Row Deleting event
        foreach ($dtlrows as $dtlrow) {
            $success = Container("nilai_sumatif")->rowDeleting($dtlrow);
            if (!$success) {
                break;
            }
        }
        if ($success) {
            foreach ($dtlrows as $dtlrow) {
                $success = Container("nilai_sumatif")->delete($dtlrow); // Delete
                if (!$success) {
                    break;
                }
            }
        }
        // Call Row Deleted event
        if ($success) {
            foreach ($dtlrows as $dtlrow) {
                Container("nilai_sumatif")->rowDeleted($dtlrow);
            }
        }
        if ($success) {
            $success = $this->deleteSql($rs, $where, $curfilter)->execute();
        }
        return $success;
    }

    // Load DbValue from recordset or array
    protected function loadDbValues($row)
    {
        if (!is_array($row)) {
            return;
        }
        $this->penilaian_id->DbValue = $row['penilaian_id'];
        $this->kode_tapel->DbValue = $row['kode_tapel'];
        $this->guru_id->DbValue = $row['guru_id'];
        $this->mapel_id->DbValue = $row['mapel_id'];
        $this->kelas->DbValue = $row['kelas'];
        $this->materi->DbValue = $row['materi'];
        $this->tujuan_pembelajaran->DbValue = $row['tujuan_pembelajaran'];
        $this->fase->DbValue = $row['fase'];
    }

    // Delete uploaded files
    public function deleteUploadedFiles($row)
    {
        $this->loadDbValues($row);
    }

    // Record filter WHERE clause
    protected function sqlKeyFilter()
    {
        return "\"penilaian_id\" = @penilaian_id@";
    }

    // Get Key
    public function getKey($current = false)
    {
        $keys = [];
        $val = $current ? $this->penilaian_id->CurrentValue : $this->penilaian_id->OldValue;
        if (EmptyValue($val)) {
            return "";
        } else {
            $keys[] = $val;
        }
        return implode(Config("COMPOSITE_KEY_SEPARATOR"), $keys);
    }

    // Set Key
    public function setKey($key, $current = false)
    {
        $this->OldKey = strval($key);
        $keys = explode(Config("COMPOSITE_KEY_SEPARATOR"), $this->OldKey);
        if (count($keys) == 1) {
            if ($current) {
                $this->penilaian_id->CurrentValue = $keys[0];
            } else {
                $this->penilaian_id->OldValue = $keys[0];
            }
        }
    }

    // Get record filter
    public function getRecordFilter($row = null)
    {
        $keyFilter = $this->sqlKeyFilter();
        if (is_array($row)) {
            $val = array_key_exists('penilaian_id', $row) ? $row['penilaian_id'] : null;
        } else {
            $val = $this->penilaian_id->OldValue !== null ? $this->penilaian_id->OldValue : $this->penilaian_id->CurrentValue;
        }
        if (!is_numeric($val)) {
            return "0=1"; // Invalid key
        }
        if ($val === null) {
            return "0=1"; // Invalid key
        } else {
            $keyFilter = str_replace("@penilaian_id@", AdjustSql($val, $this->Dbid), $keyFilter); // Replace key value
        }
        return $keyFilter;
    }

    // Return page URL
    public function getReturnUrl()
    {
        $referUrl = ReferUrl();
        $referPageName = ReferPageName();
        $name = PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_RETURN_URL");
        // Get referer URL automatically
        if ($referUrl != "" && $referPageName != CurrentPageName() && $referPageName != "login") { // Referer not same page or login page
            $_SESSION[$name] = $referUrl; // Save to Session
        }
        return $_SESSION[$name] ?? GetUrl("PenilaianList");
    }

    // Set return page URL
    public function setReturnUrl($v)
    {
        $_SESSION[PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_RETURN_URL")] = $v;
    }

    // Get modal caption
    public function getModalCaption($pageName)
    {
        global $Language;
        if ($pageName == "PenilaianView") {
            return $Language->phrase("View");
        } elseif ($pageName == "PenilaianEdit") {
            return $Language->phrase("Edit");
        } elseif ($pageName == "PenilaianAdd") {
            return $Language->phrase("Add");
        } else {
            return "";
        }
    }

    // API page name
    public function getApiPageName($action)
    {
        switch (strtolower($action)) {
            case Config("API_VIEW_ACTION"):
                return "PenilaianView";
            case Config("API_ADD_ACTION"):
                return "PenilaianAdd";
            case Config("API_EDIT_ACTION"):
                return "PenilaianEdit";
            case Config("API_DELETE_ACTION"):
                return "PenilaianDelete";
            case Config("API_LIST_ACTION"):
                return "PenilaianList";
            default:
                return "";
        }
    }

    // List URL
    public function getListUrl()
    {
        return "PenilaianList";
    }

    // View URL
    public function getViewUrl($parm = "")
    {
        if ($parm != "") {
            $url = $this->keyUrl("PenilaianView", $this->getUrlParm($parm));
        } else {
            $url = $this->keyUrl("PenilaianView", $this->getUrlParm(Config("TABLE_SHOW_DETAIL") . "="));
        }
        return $this->addMasterUrl($url);
    }

    // Add URL
    public function getAddUrl($parm = "")
    {
        if ($parm != "") {
            $url = "PenilaianAdd?" . $this->getUrlParm($parm);
        } else {
            $url = "PenilaianAdd";
        }
        return $this->addMasterUrl($url);
    }

    // Edit URL
    public function getEditUrl($parm = "")
    {
        if ($parm != "") {
            $url = $this->keyUrl("PenilaianEdit", $this->getUrlParm($parm));
        } else {
            $url = $this->keyUrl("PenilaianEdit", $this->getUrlParm(Config("TABLE_SHOW_DETAIL") . "="));
        }
        return $this->addMasterUrl($url);
    }

    // Inline edit URL
    public function getInlineEditUrl()
    {
        $url = $this->keyUrl(CurrentPageName(), $this->getUrlParm("action=edit"));
        return $this->addMasterUrl($url);
    }

    // Copy URL
    public function getCopyUrl($parm = "")
    {
        if ($parm != "") {
            $url = $this->keyUrl("PenilaianAdd", $this->getUrlParm($parm));
        } else {
            $url = $this->keyUrl("PenilaianAdd", $this->getUrlParm(Config("TABLE_SHOW_DETAIL") . "="));
        }
        return $this->addMasterUrl($url);
    }

    // Inline copy URL
    public function getInlineCopyUrl()
    {
        $url = $this->keyUrl(CurrentPageName(), $this->getUrlParm("action=copy"));
        return $this->addMasterUrl($url);
    }

    // Delete URL
    public function getDeleteUrl()
    {
        return $this->keyUrl("PenilaianDelete", $this->getUrlParm());
    }

    // Add master url
    public function addMasterUrl($url)
    {
        return $url;
    }

    public function keyToJson($htmlEncode = false)
    {
        $json = "";
        $json .= "penilaian_id:" . JsonEncode($this->penilaian_id->CurrentValue, "number");
        $json = "{" . $json . "}";
        if ($htmlEncode) {
            $json = HtmlEncode($json);
        }
        return $json;
    }

    // Add key value to URL
    public function keyUrl($url, $parm = "")
    {
        if ($this->penilaian_id->CurrentValue !== null) {
            $url .= "/" . rawurlencode($this->penilaian_id->CurrentValue);
        } else {
            return "javascript:ew.alert(ew.language.phrase('InvalidRecord'));";
        }
        if ($parm != "") {
            $url .= "?" . $parm;
        }
        return $url;
    }

    // Render sort
    public function renderSort($fld)
    {
        $classId = $fld->TableVar . "_" . $fld->Param;
        $scriptId = str_replace("%id%", $classId, "tpc_%id%");
        $scriptStart = $this->UseCustomTemplate ? "<template id=\"" . $scriptId . "\">" : "";
        $scriptEnd = $this->UseCustomTemplate ? "</template>" : "";
        $jsSort = " class=\"ew-pointer\" onclick=\"ew.sort(event, '" . $this->sortUrl($fld) . "', 1);\"";
        if ($this->sortUrl($fld) == "") {
            $html = <<<NOSORTHTML
{$scriptStart}<div class="ew-table-header-caption">{$fld->caption()}</div>{$scriptEnd}
NOSORTHTML;
        } else {
            if ($fld->getSort() == "ASC") {
                $sortIcon = '<i class="fas fa-sort-up"></i>';
            } elseif ($fld->getSort() == "DESC") {
                $sortIcon = '<i class="fas fa-sort-down"></i>';
            } else {
                $sortIcon = '';
            }
            $html = <<<SORTHTML
{$scriptStart}<div{$jsSort}><div class="ew-table-header-btn"><span class="ew-table-header-caption">{$fld->caption()}</span><span class="ew-table-header-sort">{$sortIcon}</span></div></div>{$scriptEnd}
SORTHTML;
        }
        return $html;
    }

    // Sort URL
    public function sortUrl($fld)
    {
        if (
            $this->CurrentAction || $this->isExport() ||
            in_array($fld->Type, [141, 201, 203, 128, 204, 205])
        ) { // Unsortable data type
                return "";
        } elseif ($fld->Sortable) {
            $urlParm = $this->getUrlParm("order=" . urlencode($fld->Name) . "&amp;ordertype=" . $fld->getNextSort());
            return $this->addMasterUrl(CurrentPageName() . "?" . $urlParm);
        } else {
            return "";
        }
    }

    // Get record keys from Post/Get/Session
    public function getRecordKeys()
    {
        $arKeys = [];
        $arKey = [];
        if (Param("key_m") !== null) {
            $arKeys = Param("key_m");
            $cnt = count($arKeys);
        } else {
            if (($keyValue = Param("penilaian_id") ?? Route("penilaian_id")) !== null) {
                $arKeys[] = $keyValue;
            } elseif (IsApi() && (($keyValue = Key(0) ?? Route(2)) !== null)) {
                $arKeys[] = $keyValue;
            } else {
                $arKeys = null; // Do not setup
            }

            //return $arKeys; // Do not return yet, so the values will also be checked by the following code
        }
        // Check keys
        $ar = [];
        if (is_array($arKeys)) {
            foreach ($arKeys as $key) {
                if (!is_numeric($key)) {
                    continue;
                }
                $ar[] = $key;
            }
        }
        return $ar;
    }

    // Get filter from record keys
    public function getFilterFromRecordKeys($setCurrent = true)
    {
        $arKeys = $this->getRecordKeys();
        $keyFilter = "";
        foreach ($arKeys as $key) {
            if ($keyFilter != "") {
                $keyFilter .= " OR ";
            }
            if ($setCurrent) {
                $this->penilaian_id->CurrentValue = $key;
            } else {
                $this->penilaian_id->OldValue = $key;
            }
            $keyFilter .= "(" . $this->getRecordFilter() . ")";
        }
        return $keyFilter;
    }

    // Load recordset based on filter
    public function &loadRs($filter)
    {
        $sql = $this->getSql($filter); // Set up filter (WHERE Clause)
        $conn = $this->getConnection();
        $stmt = $conn->executeQuery($sql);
        return $stmt;
    }

    // Load row values from record
    public function loadListRowValues(&$rs)
    {
        if (is_array($rs)) {
            $row = $rs;
        } elseif ($rs && property_exists($rs, "fields")) { // Recordset
            $row = $rs->fields;
        } else {
            return;
        }
        $this->penilaian_id->setDbValue($row['penilaian_id']);
        $this->kode_tapel->setDbValue($row['kode_tapel']);
        $this->guru_id->setDbValue($row['guru_id']);
        $this->mapel_id->setDbValue($row['mapel_id']);
        $this->kelas->setDbValue($row['kelas']);
        $this->materi->setDbValue($row['materi']);
        $this->tujuan_pembelajaran->setDbValue($row['tujuan_pembelajaran']);
        $this->fase->setDbValue($row['fase']);
    }

    // Render list row values
    public function renderListRow()
    {
        global $Security, $CurrentLanguage, $Language;

        // Call Row Rendering event
        $this->rowRendering();

        // Common render codes

        // penilaian_id
        $this->penilaian_id->CellCssStyle = "white-space: nowrap;";

        // kode_tapel
        $this->kode_tapel->CellCssStyle = "white-space: nowrap;";

        // guru_id
        $this->guru_id->CellCssStyle = "white-space: nowrap;";

        // mapel_id
        $this->mapel_id->CellCssStyle = "white-space: nowrap;";

        // kelas
        $this->kelas->CellCssStyle = "white-space: nowrap;";

        // materi
        $this->materi->CellCssStyle = "white-space: nowrap;";

        // tujuan_pembelajaran
        $this->tujuan_pembelajaran->CellCssStyle = "white-space: nowrap;";

        // fase
        $this->fase->CellCssStyle = "white-space: nowrap;";

        // penilaian_id
        $this->penilaian_id->ViewValue = $this->penilaian_id->CurrentValue;
        $this->penilaian_id->ViewCustomAttributes = "";

        // kode_tapel
        $this->kode_tapel->ViewValue = $this->kode_tapel->CurrentValue;
        $this->kode_tapel->ViewCustomAttributes = "";

        // guru_id
        $curVal = trim(strval($this->guru_id->CurrentValue));
        if ($curVal != "") {
            $this->guru_id->ViewValue = $this->guru_id->lookupCacheOption($curVal);
            if ($this->guru_id->ViewValue === null) { // Lookup from database
                $filterWrk = "\"guru_id\"" . SearchString("=", $curVal, DATATYPE_NUMBER, "");
                $lookupFilter = function() {
                    return "`kode_tapel`='".kode_tapel()."'";
                };
                $lookupFilter = $lookupFilter->bindTo($this);
                $sqlWrk = $this->guru_id->Lookup->getSql(false, $filterWrk, $lookupFilter, $this, true, true);
                $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                $ari = count($rswrk);
                if ($ari > 0) { // Lookup values found
                    $arwrk = $this->guru_id->Lookup->renderViewRow($rswrk[0]);
                    $this->guru_id->ViewValue = $this->guru_id->displayValue($arwrk);
                } else {
                    $this->guru_id->ViewValue = $this->guru_id->CurrentValue;
                }
            }
        } else {
            $this->guru_id->ViewValue = null;
        }
        $this->guru_id->ViewCustomAttributes = "";

        // mapel_id
        $curVal = trim(strval($this->mapel_id->CurrentValue));
        if ($curVal != "") {
            $this->mapel_id->ViewValue = $this->mapel_id->lookupCacheOption($curVal);
            if ($this->mapel_id->ViewValue === null) { // Lookup from database
                $filterWrk = "\"kode_mapel\"" . SearchString("=", $curVal, DATATYPE_STRING, "");
                $sqlWrk = $this->mapel_id->Lookup->getSql(false, $filterWrk, '', $this, true, true);
                $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                $ari = count($rswrk);
                if ($ari > 0) { // Lookup values found
                    $arwrk = $this->mapel_id->Lookup->renderViewRow($rswrk[0]);
                    $this->mapel_id->ViewValue = $this->mapel_id->displayValue($arwrk);
                } else {
                    $this->mapel_id->ViewValue = $this->mapel_id->CurrentValue;
                }
            }
        } else {
            $this->mapel_id->ViewValue = null;
        }
        $this->mapel_id->ViewCustomAttributes = "";

        // kelas
        $curVal = trim(strval($this->kelas->CurrentValue));
        if ($curVal != "") {
            $this->kelas->ViewValue = $this->kelas->lookupCacheOption($curVal);
            if ($this->kelas->ViewValue === null) { // Lookup from database
                $filterWrk = "\"kelas\"" . SearchString("=", $curVal, DATATYPE_MEMO, "");
                $lookupFilter = function() {
                    return "`kode_tapel`='".kode_tapel()."'";
                };
                $lookupFilter = $lookupFilter->bindTo($this);
                $sqlWrk = $this->kelas->Lookup->getSql(false, $filterWrk, $lookupFilter, $this, true, true);
                $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                $ari = count($rswrk);
                if ($ari > 0) { // Lookup values found
                    $arwrk = $this->kelas->Lookup->renderViewRow($rswrk[0]);
                    $this->kelas->ViewValue = $this->kelas->displayValue($arwrk);
                } else {
                    $this->kelas->ViewValue = $this->kelas->CurrentValue;
                }
            }
        } else {
            $this->kelas->ViewValue = null;
        }
        $this->kelas->ViewCustomAttributes = "";

        // materi
        $curVal = trim(strval($this->materi->CurrentValue));
        if ($curVal != "") {
            $this->materi->ViewValue = $this->materi->lookupCacheOption($curVal);
            if ($this->materi->ViewValue === null) { // Lookup from database
                $arwrk = explode(",", $curVal);
                $filterWrk = "";
                foreach ($arwrk as $wrk) {
                    if ($filterWrk != "") {
                        $filterWrk .= " OR ";
                    }
                    $filterWrk .= "\"materi_id\"" . SearchString("=", trim($wrk), DATATYPE_NUMBER, "");
                }
                $sqlWrk = $this->materi->Lookup->getSql(false, $filterWrk, '', $this, true, true);
                $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                $ari = count($rswrk);
                if ($ari > 0) { // Lookup values found
                    $this->materi->ViewValue = new OptionValues();
                    foreach ($rswrk as $row) {
                        $arwrk = $this->materi->Lookup->renderViewRow($row);
                        $this->materi->ViewValue->add($this->materi->displayValue($arwrk));
                    }
                } else {
                    $this->materi->ViewValue = $this->materi->CurrentValue;
                }
            }
        } else {
            $this->materi->ViewValue = null;
        }
        $this->materi->CellCssStyle .= "text-align: justify;";
        $this->materi->ViewCustomAttributes = "";

        // tujuan_pembelajaran
        $curVal = trim(strval($this->tujuan_pembelajaran->CurrentValue));
        if ($curVal != "") {
            $this->tujuan_pembelajaran->ViewValue = $this->tujuan_pembelajaran->lookupCacheOption($curVal);
            if ($this->tujuan_pembelajaran->ViewValue === null) { // Lookup from database
                $arwrk = explode(",", $curVal);
                $filterWrk = "";
                foreach ($arwrk as $wrk) {
                    if ($filterWrk != "") {
                        $filterWrk .= " OR ";
                    }
                    $filterWrk .= "\"tp_id\"" . SearchString("=", trim($wrk), DATATYPE_NUMBER, "");
                }
                $sqlWrk = $this->tujuan_pembelajaran->Lookup->getSql(false, $filterWrk, '', $this, true, true);
                $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                $ari = count($rswrk);
                if ($ari > 0) { // Lookup values found
                    $this->tujuan_pembelajaran->ViewValue = new OptionValues();
                    foreach ($rswrk as $row) {
                        $arwrk = $this->tujuan_pembelajaran->Lookup->renderViewRow($row);
                        $this->tujuan_pembelajaran->ViewValue->add($this->tujuan_pembelajaran->displayValue($arwrk));
                    }
                } else {
                    $this->tujuan_pembelajaran->ViewValue = $this->tujuan_pembelajaran->CurrentValue;
                }
            }
        } else {
            $this->tujuan_pembelajaran->ViewValue = null;
        }
        $this->tujuan_pembelajaran->CellCssStyle .= "text-align: justify;";
        $this->tujuan_pembelajaran->ViewCustomAttributes = "";

        // fase
        if (strval($this->fase->CurrentValue) != "") {
            $this->fase->ViewValue = $this->fase->optionCaption($this->fase->CurrentValue);
        } else {
            $this->fase->ViewValue = null;
        }
        $this->fase->ViewCustomAttributes = "";

        // penilaian_id
        $this->penilaian_id->LinkCustomAttributes = "";
        $this->penilaian_id->HrefValue = "";
        $this->penilaian_id->TooltipValue = "";

        // kode_tapel
        $this->kode_tapel->LinkCustomAttributes = "";
        $this->kode_tapel->HrefValue = "";
        $this->kode_tapel->TooltipValue = "";

        // guru_id
        $this->guru_id->LinkCustomAttributes = "";
        $this->guru_id->HrefValue = "";
        $this->guru_id->TooltipValue = "";

        // mapel_id
        $this->mapel_id->LinkCustomAttributes = "";
        $this->mapel_id->HrefValue = "";
        $this->mapel_id->TooltipValue = "";

        // kelas
        $this->kelas->LinkCustomAttributes = "";
        $this->kelas->HrefValue = "";
        $this->kelas->TooltipValue = "";

        // materi
        $this->materi->LinkCustomAttributes = "";
        $this->materi->HrefValue = "";
        $this->materi->TooltipValue = "";

        // tujuan_pembelajaran
        $this->tujuan_pembelajaran->LinkCustomAttributes = "";
        $this->tujuan_pembelajaran->HrefValue = "";
        $this->tujuan_pembelajaran->TooltipValue = "";

        // fase
        $this->fase->LinkCustomAttributes = "";
        $this->fase->HrefValue = "";
        $this->fase->TooltipValue = "";

        // Call Row Rendered event
        $this->rowRendered();

        // Save data for Custom Template
        $this->Rows[] = $this->customTemplateFieldValues();
    }

    // Render edit row values
    public function renderEditRow()
    {
        global $Security, $CurrentLanguage, $Language;

        // Call Row Rendering event
        $this->rowRendering();

        // penilaian_id
        $this->penilaian_id->EditAttrs["class"] = "form-control";
        $this->penilaian_id->EditCustomAttributes = "";
        $this->penilaian_id->EditValue = $this->penilaian_id->CurrentValue;
        $this->penilaian_id->ViewCustomAttributes = "";

        // kode_tapel

        // guru_id
        $this->guru_id->EditAttrs["class"] = "form-control";
        $this->guru_id->EditCustomAttributes = "";

        // mapel_id
        $this->mapel_id->EditAttrs["class"] = "form-control";
        $this->mapel_id->EditCustomAttributes = "";

        // kelas
        $this->kelas->EditAttrs["class"] = "form-control";
        $this->kelas->EditCustomAttributes = "";
        if (!$Security->isAdmin() && $Security->isLoggedIn() && !$this->userIDAllow("info")) { // Non system admin
            $this->kelas->CurrentValue = CurrentUserID();
            $curVal = trim(strval($this->kelas->CurrentValue));
            if ($curVal != "") {
                $this->kelas->EditValue = $this->kelas->lookupCacheOption($curVal);
                if ($this->kelas->EditValue === null) { // Lookup from database
                    $filterWrk = "\"kelas\"" . SearchString("=", $curVal, DATATYPE_MEMO, "");
                    $lookupFilter = function() {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    $sqlWrk = $this->kelas->Lookup->getSql(false, $filterWrk, $lookupFilter, $this, true, true);
                    $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                    $ari = count($rswrk);
                    if ($ari > 0) { // Lookup values found
                        $arwrk = $this->kelas->Lookup->renderViewRow($rswrk[0]);
                        $this->kelas->EditValue = $this->kelas->displayValue($arwrk);
                    } else {
                        $this->kelas->EditValue = $this->kelas->CurrentValue;
                    }
                }
            } else {
                $this->kelas->EditValue = null;
            }
            $this->kelas->ViewCustomAttributes = "";
        } else {
        }

        // materi
        $this->materi->EditAttrs["class"] = "form-control";
        $this->materi->EditCustomAttributes = "";

        // tujuan_pembelajaran
        $this->tujuan_pembelajaran->EditAttrs["class"] = "form-control";
        $this->tujuan_pembelajaran->EditCustomAttributes = "";

        // fase
        $this->fase->EditCustomAttributes = "";
        $this->fase->EditValue = $this->fase->options(false);

        // Call Row Rendered event
        $this->rowRendered();
    }

    // Aggregate list row values
    public function aggregateListRowValues()
    {
    }

    // Aggregate list row (for rendering)
    public function aggregateListRow()
    {
        // Call Row Rendered event
        $this->rowRendered();
    }

    // Export data in HTML/CSV/Word/Excel/Email/PDF format
    public function exportDocument($doc, $recordset, $startRec = 1, $stopRec = 1, $exportPageType = "")
    {
        if (!$recordset || !$doc) {
            return;
        }
        if (!$doc->ExportCustom) {
            // Write header
            $doc->exportTableHeader();
            if ($doc->Horizontal) { // Horizontal format, write header
                $doc->beginExportRow();
                if ($exportPageType == "view") {
                    $doc->exportCaption($this->kode_tapel);
                    $doc->exportCaption($this->guru_id);
                    $doc->exportCaption($this->mapel_id);
                    $doc->exportCaption($this->kelas);
                    $doc->exportCaption($this->materi);
                    $doc->exportCaption($this->tujuan_pembelajaran);
                    $doc->exportCaption($this->fase);
                } else {
                }
                $doc->endExportRow();
            }
        }

        // Move to first record
        $recCnt = $startRec - 1;
        $stopRec = ($stopRec > 0) ? $stopRec : PHP_INT_MAX;
        while (!$recordset->EOF && $recCnt < $stopRec) {
            $row = $recordset->fields;
            $recCnt++;
            if ($recCnt >= $startRec) {
                $rowCnt = $recCnt - $startRec + 1;

                // Page break
                if ($this->ExportPageBreakCount > 0) {
                    if ($rowCnt > 1 && ($rowCnt - 1) % $this->ExportPageBreakCount == 0) {
                        $doc->exportPageBreak();
                    }
                }
                $this->loadListRowValues($row);

                // Render row
                $this->RowType = ROWTYPE_VIEW; // Render view
                $this->resetAttributes();
                $this->renderListRow();
                if (!$doc->ExportCustom) {
                    $doc->beginExportRow($rowCnt); // Allow CSS styles if enabled
                    if ($exportPageType == "view") {
                        $doc->exportField($this->kode_tapel);
                        $doc->exportField($this->guru_id);
                        $doc->exportField($this->mapel_id);
                        $doc->exportField($this->kelas);
                        $doc->exportField($this->materi);
                        $doc->exportField($this->tujuan_pembelajaran);
                        $doc->exportField($this->fase);
                    } else {
                    }
                    $doc->endExportRow($rowCnt);
                }
            }

            // Call Row Export server event
            if ($doc->ExportCustom) {
                $this->rowExport($row);
            }
            $recordset->moveNext();
        }
        if (!$doc->ExportCustom) {
            $doc->exportTableFooter();
        }
    }

    // Add User ID filter
    public function addUserIDFilter($filter = "")
    {
        global $Security;
        $filterWrk = "";
        $id = (CurrentPageID() == "list") ? $this->CurrentAction : CurrentPageID();
        if (!$this->userIDAllow($id) && !$Security->isAdmin()) {
            $filterWrk = $Security->userIdList();
            if ($filterWrk != "") {
                $filterWrk = '"kelas" IN (' . $filterWrk . ')';
            }
        }

        // Call User ID Filtering event
        $this->userIdFiltering($filterWrk);
        AddFilter($filter, $filterWrk);
        return $filter;
    }

    // User ID subquery
    public function getUserIDSubquery(&$fld, &$masterfld)
    {
        global $UserTable;
        $wrk = "";
        $sql = "SELECT " . $masterfld->Expression . " FROM \"penilaian\"";
        $filter = $this->addUserIDFilter("");
        if ($filter != "") {
            $sql .= " WHERE " . $filter;
        }

        // List all values
        if ($rs = Conn($UserTable->Dbid)->executeQuery($sql)->fetchAll(\PDO::FETCH_NUM)) {
            foreach ($rs as $row) {
                if ($wrk != "") {
                    $wrk .= ",";
                }
                $wrk .= QuotedValue($row[0], $masterfld->DataType, Config("USER_TABLE_DBID"));
            }
        }
        if ($wrk != "") {
            $wrk = $fld->Expression . " IN (" . $wrk . ")";
        } else { // No User ID value found
            $wrk = "0=1";
        }
        return $wrk;
    }

    // Get file data
    public function getFileData($fldparm, $key, $resize, $width = 0, $height = 0, $plugins = [])
    {
        // No binary fields
        return false;
    }

    // Table level events

    // Recordset Selecting event
    public function recordsetSelecting(&$filter)
    {
        // Enter your code here
    }

    // Recordset Selected event
    public function recordsetSelected(&$rs)
    {
        //Log("Recordset Selected");
    }

    // Recordset Search Validated event
    public function recordsetSearchValidated()
    {
        // Example:
        //$this->MyField1->AdvancedSearch->SearchValue = "your search criteria"; // Search value
    }

    // Recordset Searching event
    public function recordsetSearching(&$filter)
    {
        // Enter your code here
    }

    // Row_Selecting event
    public function rowSelecting(&$filter)
    {
        // Enter your code here
    }

    // Row Selected event
    public function rowSelected(&$rs)
    {
        //Log("Row Selected");
    }

    // Row Inserting event
    public function rowInserting($rsold, &$rsnew)
    {
        // Enter your code here
        // To cancel, set return value to false
        return true;
    }

    // Row Inserted event
    public function rowInserted($rsold, &$rsnew)
    {
        //Log("Row Inserted");
    }

    // Row Updating event
    public function rowUpdating($rsold, &$rsnew)
    {
        // Enter your code here
        // To cancel, set return value to false
        return true;
    }

    // Row Updated event
    public function rowUpdated($rsold, &$rsnew)
    {
        //Log("Row Updated");
    }

    // Row Update Conflict event
    public function rowUpdateConflict($rsold, &$rsnew)
    {
        // Enter your code here
        // To ignore conflict, set return value to false
        return true;
    }

    // Grid Inserting event
    public function gridInserting()
    {
        // Enter your code here
        // To reject grid insert, set return value to false
        return true;
    }

    // Grid Inserted event
    public function gridInserted($rsnew)
    {
        //Log("Grid Inserted");
    }

    // Grid Updating event
    public function gridUpdating($rsold)
    {
        // Enter your code here
        // To reject grid update, set return value to false
        return true;
    }

    // Grid Updated event
    public function gridUpdated($rsold, $rsnew)
    {
        //Log("Grid Updated");
    }

    // Row Deleting event
    public function rowDeleting(&$rs)
    {
        // Enter your code here
        // To cancel, set return value to False
        return true;
    }

    // Row Deleted event
    public function rowDeleted(&$rs)
    {
        //Log("Row Deleted");
    }

    // Email Sending event
    public function emailSending($email, &$args)
    {
        //var_dump($email); var_dump($args); exit();
        return true;
    }

    // Lookup Selecting event
    public function lookupSelecting($fld, &$filter)
    {
        //var_dump($fld->Name, $fld->Lookup, $filter); // Uncomment to view the filter
        // Enter your code here
    }

    // Row Rendering event
    public function rowRendering()
    {
        // Enter your code here
    }

    // Row Rendered event
    public function rowRendered()
    {
        // To view properties of field class, use:
        //var_dump($this-><FieldName>);
    }

    // User ID Filtering event
    public function userIdFiltering(&$filter)
    {
        // Enter your code here
    }
}
