added CRUD for Projects,
added set project for report
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/*
|
||||
TPsoft.org 2000-2026
|
||||
file for controlers/*.php
|
||||
|
||||
Milestones:
|
||||
2026-08-22 20:39 Created
|
||||
*/
|
||||
|
||||
namespace TPsoft\BugreportBackend\Models;
|
||||
|
||||
class Projects extends \TPsoft\DBmodel\DBmodel {
|
||||
|
||||
public $tables = array(
|
||||
'projects' => array(
|
||||
'name' => 'projects',
|
||||
'primary_key_name' => 'project_id',
|
||||
'allow_attributes' => array(
|
||||
'project_name' => 'VARCHAR(255)',
|
||||
'project_code' => 'VARCHAR(64)',
|
||||
'project_color' => 'VARCHAR(7)',
|
||||
'project_active' => 'INTEGER',
|
||||
'project_system' => 'INTEGER',
|
||||
'created_dt' => 'DATETIME',
|
||||
'updated_dt' => 'DATETIME'
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
public function exist($primary_key = null) {
|
||||
return $this->existRecord('projects', $primary_key);
|
||||
}
|
||||
|
||||
public function project($primary_key = null, $data = array()) {
|
||||
if (is_null($primary_key)
|
||||
&& !isset($data['created_dt']))
|
||||
{
|
||||
$data['created_dt'] = date('Y-m-d H:i:s');
|
||||
}
|
||||
if (!is_null($primary_key)
|
||||
&& is_array($data)
|
||||
&& count($data) > 0
|
||||
&& !isset($data['updated_dt']))
|
||||
{
|
||||
$data['updated_dt'] = date('Y-m-d H:i:s');
|
||||
}
|
||||
return $this->record('projects', $primary_key, $data);
|
||||
}
|
||||
|
||||
public function projectBy($colname, $colvalue) {
|
||||
return $this->recordBy('projects', $colname, $colvalue);
|
||||
}
|
||||
|
||||
public function projectSave($data = array()) {
|
||||
return $this->project($this->exist($data) ? $data : null, $data);
|
||||
}
|
||||
|
||||
public function projectEmpty() {
|
||||
return $this->recordEmpty('projects');
|
||||
}
|
||||
|
||||
public function projectAttributes() {
|
||||
return $this->typesAttributes('projects');
|
||||
}
|
||||
|
||||
public function projectCount() {
|
||||
return $this->count('projects');
|
||||
}
|
||||
|
||||
public function getList($search = array(), $reverse = false, $concat_or = false) {
|
||||
return $this->search('projects')
|
||||
->where($search, $concat_or)
|
||||
->order(array('project_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('project_id', $search, $reverse, $concat_or);
|
||||
}
|
||||
|
||||
public function projectCombo($col_key, $col_value, $add_empty = false) {
|
||||
return $this->search('projects')
|
||||
->toCombo($col_key, $col_value, $add_empty);
|
||||
}
|
||||
|
||||
public function getListWithReportCount($include_archived = false) {
|
||||
$where = $include_archived ? '' : ' WHERE `project_active` = 1';
|
||||
return $this->getAll(
|
||||
'SELECT `projects`.*,'
|
||||
. ' (SELECT COUNT(*) FROM `reports` WHERE `reports`.`project_id` = `projects`.`project_id`) AS `report_count`'
|
||||
. ' FROM `projects`'
|
||||
. $where
|
||||
. ' ORDER BY `project_active` DESC, `project_system` DESC, `project_name` ASC'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user