<?php
defined('BASEPATH') or exit('No direct script access allowed');

$aColumns = [
    'id',
    'maintenance_title',
    'maintenance_description',
    'requested_by',
    'status',
    'created_at',
];

$sIndexColumn = 'id';
$sTable = db_prefix() . 'propertybase_properties_maintenance';
$join = [];
$where = [];

array_push($where, 'AND property_id=' . $property_id);

$result = data_tables_init($aColumns, $sIndexColumn, $sTable, $join, $where, [
    db_prefix() . 'propertybase_properties_maintenance.id',
    db_prefix() . 'propertybase_properties_maintenance.property_id',
    db_prefix() . 'propertybase_properties_maintenance.user_id',
    db_prefix() . 'propertybase_properties_maintenance.requested_by_type',
]);

$output = $result['output'];
$rResult = $result['rResult'];


foreach ($rResult as $aRow) {
    $row = [];
    for ($i = 0; $i < count($aColumns); $i++) {

        $row[] = $aRow['id'];
        $row[] = $aRow['maintenance_title'];
        $row[] = $aRow['maintenance_description'];
        $row[] = $aRow['status'];
        $row[] = $aRow['requested_by'];
        $row[] = $aRow['created_at'];
    }

    $output['aaData'][] = $row;
}
