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

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

namespace TPsoft\BugreportBackend\Models;

class Options extends \TPsoft\DBmodel\DBmodel {

	public $tables = array(
		'options' => array(
			'name'             => 'options',
			'primary_key_name' => '',
			'allow_attributes' => array(
				'key' => 'VARCHAR(64)',
				'value' => 'TEXT',
				'created_at' => 'DATETIME'
			)
		),
	);

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

	public function option($primary_key = null, $data = array()) {
		return $this->record('options', $primary_key, $data);
	}

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

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

	public function optionEmpty() {
		return $this->recordEmpty('options');
	}

	public function optionAttributes() {
		return $this->typesAttributes('options');
	}

	public function optionCount() {
		return $this->count('options');
	}

	public function getList($search = array(), $reverse = false, $concat_or = false) {
		return $this->search('options')
			->where($search, $concat_or)
			->order(array('' => $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('', $search, $reverse, $concat_or);
	}

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

}

?>
