<?php
/*
	TPsoft.org 2000-2025
	file for controlers/*.php

	Milestones:
	2025-09-30 22:21  Created
*/

namespace TPsoft\BugreportBackend\Models;

class Reports extends \TPsoft\DBmodel\DBmodel {

	public $tables = array(
		'reports' => array(
			'name'             => 'reports',
			'primary_key_name' => 'report_id',
			'allow_attributes' => array(
				'report_title' => 'VARCHAR(255)',
				'report_description' => 'TEXT',
				'report_status' => 'INTEGER',
				'report_group' => 'VARCHAR(255)',
				'report_priority' => 'INTEGER',
				'created_dt' => 'DATETIME',
				'ordnum' => 'INTEGER'
			)
		),
	);

	public function exist($primary_key = null) {
		return $this->existRecord('reports', $primary_key);
	}

	public function report($primary_key = null, $data = array()) {
		if (is_null($primary_key)
			&& !isset($data['created_dt']))
		{
			$data['created_dt'] = date('Y-m-d H:i:s');
		}
		return $this->record('reports', $primary_key, $data);
	}

	public function reportBy($colname, $colvalue) {
		return $this->recordBy('reports', $colname, $colvalue);
	}

	public function reportSave($data = array()) {
		return $this->report($this->exist($data) ? $data : null, $data);
	}

	public function reportEmpty() {
		return $this->recordEmpty('reports');
	}

	public function reportAttributes() {
		return $this->typesAttributes('reports');
	}

	public function reportCount() {
		return $this->count('reports');
	}

	public function getList($search = array(), $reverse = false, $concat_or = false) {
		return $this->search('reports')
			->where($search, $concat_or)
			->order(array('report_id' => $reverse ? 'DESC' : 'ASC'))
			->toArray();
	}

	public function getListOrganize($cola_name, $search = array(), $reverse = false, $concat_or = false) {
		$all = $this->getList($search, $reverse, $concat_or);
		$ret = array();
		if (is_array($all)) foreach ($all as $key => $row) {
			$ret[$row[$cola_name]] = $row;
		}
		return $ret;
	}

	public function getListByID($search = array(), $reverse = false, $concat_or = false) {
		return $this->getListOrganize('report_id', $search, $reverse, $concat_or);
	}

	public function reportCombo($col_key, $col_value, $add_empty = false) {
		return $this->search('reports')
			->toCombo($col_key, $col_value, $add_empty);
	}

}

?>
