This commit is contained in:
Joey Kimsey
2025-02-06 03:18:45 -05:00
parent a893698a13
commit 825d422d93
189 changed files with 2628 additions and 5839 deletions

View File

@ -0,0 +1,100 @@
<?php
/**
* app/plugins/wip/models/projects.php
*
* This class is used for the manipulation of the projects database table.
*
* @package TP WIP
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Models;
use TheTempusProject\Bedrock\Classes\Config;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Canary\Bin\Canary as Debug;
use TheTempusProject\Classes\DatabaseModel;
use TheTempusProject\Plugins\Wip as Plugin;
use DateTime;
class Projects extends DatabaseModel {
public $tableName = 'projects';
public $databaseMatrix = [
[ 'title', 'varchar', '128' ],
[ 'description', 'text', '' ],
[ 'progress', 'int', '3' ],
[ 'startDate', 'varchar', '32' ],
[ 'endDate', 'varchar', '32' ],
];
public $plugin;
/**
* The model constructor.
*/
public function __construct() {
parent::__construct();
$this->plugin = new Plugin;
}
public function create( $title, $description, $progress, $startDate ) {
if ( !$this->plugin->checkEnabled() ) {
Debug::info( 'Wip is disabled in the config.' );
return false;
}
$fields = [
'title' => $title,
'description' => $description,
'progress' => $progress,
'startDate' => $startDate,
];
if ( !self::$db->insert( $this->tableName, $fields ) ) {
Debug::info( 'Projects::create - failed to insert to db' );
return false;
}
return self::$db->lastId();
}
public function update( $id, $fields ) {
if ( !Check::id( $id ) ) {
Debug::info( 'Project:update: illegal ID.' );
return false;
}
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
// new CustomException( 'projectUpdate' );
Debug::error( "Project:update: $id not updated: $fields" );
return false;
}
return true;
}
public function filter( $postArray, $params = [] ) {
foreach ( $postArray as $instance ) {
if ( !is_object( $instance ) ) {
$instance = $postArray;
$end = true;
}
if ( ! empty( $instance->startDate ) ) {
$startDate = DateTime::createFromFormat( 'Y-m', $instance->startDate );
$startDateFormatted = $startDate->format('F Y');
$instance->prettyStart = $startDateFormatted;
} else {
$instance->prettyStart = 'TBD';
}
if ( ! empty( $instance->endDate ) ) {
$endDate = DateTime::createFromFormat( 'Y-m', $instance->endDate );
$endDateFormatted = $endDate->format('F Y');
$instance->prettyEnd = $endDateFormatted;
} else {
$instance->prettyEnd = 'TBD';
}
$out[] = $instance;
if ( !empty( $end ) ) {
$out = $out[0];
break;
}
}
return $out;
}
}