Initial commit

This commit is contained in:
Joey Kimsey
2024-08-04 21:15:59 -04:00
parent c9d1fb983f
commit 0d469501ee
695 changed files with 70184 additions and 71 deletions

View File

@ -0,0 +1,85 @@
<?php
/**
* app/plugins/updates/controllers/updates.php
*
* This is the status updates controller.
*
* @package TP Status-Updates
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers;
use TheTempusProject\Hermes\Functions\Redirect;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Functions\Session;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Classes\Controller;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Models\Update;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Houdini\Classes\Components;
class Updates extends Controller {
protected static $updates;
public function __construct() {
parent::__construct();
self::$updates = new Update;
self::$title = 'Status Updates - {SITENAME}';
self::$pageDescription = 'On this page you can view and post new status updates.';
if ( ! App::$isLoggedIn ) {
return Issues::add( 'notice', 'You must be logged in to post or view statuses.' );
}
}
public function index() {
$updates = self::$updates->byUser( App::$activeUser->ID );
Components::set( 'list', Views::simpleView( 'updates.list', $updates ) );
Components::set( 'create', Views::simpleView( 'updates.create' ) );
if ( ! Input::exists() ) {
return Views::view( 'updates.dash' );
}
if ( ! Forms::check( 'createUpdate' ) ) {
Issues::add( 'error', [ 'There was an error with your report.' => Check::userErrors() ] );
return Views::view( 'updates.dash' );
}
$result = self::$updates->create( Input::post( 'status' ) );
if ( true === $result ) {
Issues::add( 'success', 'Your status has been posted.' );
} else {
Issues::add( 'error', 'There was an unresolved error while submitting your status.' );
}
return Views::view( 'updates.dash' );
}
public function post() {
if ( ! Input::exists() ) {
return Views::view( 'updates.create' );
}
if ( !Forms::check( 'createUpdate' ) ) {
Issues::add( 'error', [ 'There was an error with your report.' => Check::userErrors() ] );
return Views::view( 'updates.create' );
}
$result = self::$updates->create( Input::post( 'status' ) );
if ( true === $result ) {
Session::flash( 'success', 'Your status has been posted.' );
Redirect::to( 'home/index' );
} else {
Issues::add( 'error', 'There was an unresolved error while submitting your status.' );
return Views::view( 'updates.create' );
}
}
public function byUser( $id = null ) {
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* app/plugins/updates/forms.php
*
* This houses all of the form checking functions for this plugin.
*
* @package TP Status-Updates
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Plugins\Updates;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Classes\Forms;
class UpdateForms extends Forms {
/**
* Adds these functions to the form list.
*/
public function __construct() {
self::addHandler( 'createUpdate', __CLASS__, 'createUpdate' );
}
public static function createUpdate() {
if ( ! Input::exists( 'status' ) ) {
Check::addUserError( 'You must provide an status.' );
return false;
}
return true;
}
}
new UpdateForms;

View File

@ -0,0 +1,87 @@
<?php
/**
* app/plugins/updates/models/update.php
*
* This class is used for the manipulation of the status_updates database table.
*
* @package TP Status-Updates
* @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\Canary as Debug;
use TheTempusProject\Classes\DatabaseModel;
use TheTempusProject\Plugins\Updates as Plugin;
use TheTempusProject\TheTempusProject as App;
class Update extends DatabaseModel {
public $tableName = 'status_updates';
public $databaseMatrix = [
[ 'status', 'varchar', '512' ],
[ 'createdAt', 'int', '10' ],
[ 'createdBy', 'int', '10' ],
[ 'updatedAt', 'int', '10' ],
[ 'updatedBy', 'int', '10' ],
[ 'deletedAt', 'int', '10' ],
[ 'deletedBy', 'int', '10' ],
];
public $plugin;
/**
* The model constructor.
*/
public function __construct() {
parent::__construct();
$this->plugin = new Plugin;
}
public function create( $status ) {
if ( ! $this->plugin->checkEnabled() ) {
Debug::info( 'Status-Updates are disabled in the config.' );
return false;
}
$fields = [
'status' => $status,
'createdAt' => time(),
'createdBy' => App::$activeUser->ID,
];
if ( !self::$db->insert( $this->tableName, $fields ) ) {
Debug::info( 'Status-Updates::create - failed to insert to db' );
return false;
}
return self::$db->lastId();
}
public function update( $status ) {
if ( !$this->plugin->checkEnabled() ) {
Debug::info( 'Status-Updates are disabled in the config.' );
return false;
}
$fields = [
'status' => $status,
'updatedAt' => time(),
'updatedBy' => App::$activeUser->ID,
];
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
Debug::info( 'Status-Updates::update - failed to update to db' );
return false;
}
return true;
}
public function byUser( $userID, $limit = null ) {
$whereClause = [ 'createdBy', '=', $userID ];
if ( empty( $limit ) ) {
$reviews = self::$db->get( $this->tableName, $whereClause );
} else {
$reviews = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
}
if ( !$reviews->count() ) {
Debug::info( 'No Reviews found.' );
return false;
}
return $this->filter( $reviews->results() );
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* app/plugins/updates/plugin.php
*
* This houses all of the main plugin info and functionality.
*
* @package TP Status-Updates
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Plugins;
use TheTempusProject\Classes\Plugin;
class Updates extends Plugin {
public $pluginName = 'TP Status-Updates';
public $pluginAuthor = 'JoeyK';
public $pluginWebsite = 'https://TheTempusProject.com';
public $modelVersion = '1.0';
public $pluginVersion = '3.0';
public $pluginDescription = 'A simple plugin which adds a user status update system.';
public $permissionMatrix = [
'updates' => [
'pretty' => 'Can create status updates',
'default' => false,
],
];
}

View File

@ -0,0 +1,10 @@
<div class="container mt-5">
<h2>Update your status</h2>
<form id="status-form" method="post">
<div class="form-group">
<label for="status">Your Status:</label>
<textarea class="form-control" id="status" name="status" rows="5" required></textarea>
</div>
<button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary center-block ">Submit</button>
</form>
</div>

View File

@ -0,0 +1,2 @@
{list}
{create}

View File

@ -0,0 +1,26 @@
<legend>Updates</legend>
<table class="table table-striped">
<thead>
<tr>
<th style="width: 20%">Date</th>
<th style="width: 70%">Status</th>
<th style="width: 10%"></th>
</tr>
</thead>
<tbody>
{LOOP}
<tr>
<td align="center">{DTC}{createdAt}{/DTC}</td>
<td align="center">{status}</td>
<td><a href="{ROOT_URL}updates/delete/{ID}" class="btn btn-sm btn-danger" role="button"><i class="glyphicon glyphicon-trash"></i></a></td>
</tr>
{/LOOP}
{ALT}
<tr>
<td align="center" colspan="6">
No results to show.
</td>
</tr>
{/ALT}
</tbody>
</table>