This commit is contained in:
Joey Kimsey
2024-12-02 17:43:55 -05:00
parent 113499254b
commit de5530b1e3
95 changed files with 3192 additions and 509 deletions

View File

@ -0,0 +1,103 @@
<?php
/**
* app/plugins/portfolio/controllers/admin/portfolio.php
*
* This is the Portfolio admin controller.
*
* @package TP Portfolio
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers\Admin;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Houdini\Classes\Navigation;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Classes\AdminController;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Models\Links;
class Portfolio extends AdminController {
public static $links;
public function __construct() {
parent::__construct();
self::$links = new Links;
self::$title = 'Admin - Portfolio';
$view = Navigation::activePageSelect( 'nav.admin', '/admin/portfolio' );
Components::set( 'ADMINNAV', $view );
}
public function index( $data = null ) {
Views::view( 'portfolio.admin.list', self::$links->listPaginated() );
}
public function create( $data = null ) {
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'portfolio.admin.create' );
}
if ( !Forms::check( 'newLink' ) ) {
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
return $this->index();
}
$result = self::$links->create( Input::post( 'section' ), Input::post( 'title' ), Input::post( 'image' ), Input::post( 'url' ), Input::post( 'description' ) );
if ( $result ) {
Issues::add( 'success', 'Your link has been created.' );
return $this->index();
} else {
Issues::add( 'error', [ 'There was an unknown error submitting your data.' => Check::userErrors() ] );
return $this->index();
}
}
public function edit( $data = null ) {
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'portfolio.admin.edit', self::$links->findById( $data ) );
}
if ( !Forms::check( 'editLink' ) ) {
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
return $this->index();
}
$fields = [
'section' => Input::post( 'section' ),
'title' => Input::post( 'title' ),
'image' => Input::post( 'image' ),
'url' => Input::post( 'url' ),
'description' => Input::post( 'description' ),
];
if ( self::$links->update( $data, $fields ) ) {
Issues::add( 'success', 'Link Updated.' );
return $this->index();
}
Issues::add( 'error', 'There was an error with your request.' );
$this->index();
}
public function view( $data = null ) {
$linkData = self::$links->findById( $data );
if ( $linkData !== false ) {
return Views::view( 'portfolio.admin.view', $linkData );
}
Issues::add( 'error', 'Link not found.' );
$this->index();
}
public function delete( $data = null ) {
if ( $data == null ) {
if ( Input::exists( 'P_' ) ) {
$data = Input::post( 'P_' );
}
}
if ( !self::$links->delete( (array) $data ) ) {
Issues::add( 'error', 'There was an error with your request.' );
} else {
Issues::add( 'success', 'Link has been deleted' );
}
$this->index();
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* app/plugins/portfolio/controllers/portfolio.php
*
* This is the bug reports controller.
*
* @package TP Portfolio
* @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\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Classes\Controller;
use TheTempusProject\Models\Links;
class Portfolio extends Controller {
protected static $links;
public function index() {
self::$links = new Links;
self::$title = '{SITENAME} - Portfolio';
self::$pageDescription = 'Its not the longest portfolio in the world, but I\'m certainly proud of it.';
$links = self::$links->listPaginated();
if ( false == $links ) {
Issues::add( 'error', 'Well, this is embarrassing, surely he wouldn\'t just have no portfolio..... right.... Dave? ... erm Joey?' );
return;
} else {
Views::view( 'portfolio.portfolio', self::$links->listPaginated() );
}
}
}

View File

@ -0,0 +1,79 @@
<?php
/**
* app/plugins/portfolio/forms.php
*
* This houses all of the form checking functions for this plugin.
*
* @package TP Portfolio
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Plugins\Portfolio;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Classes\Forms;
class PortfolioForms extends Forms {
/**
* Adds these functions to the form list.
*/
public function __construct() {
self::addHandler( 'newLink', __CLASS__, 'newLink' );
self::addHandler( 'editLink', __CLASS__, 'editLink' );
}
/**
* Validates the new position post form.
*
* @return {bool}
*/
public static function newLink() {
if ( !Input::exists( 'section' ) ) {
self::addUserError( 'You must specify section' );
return false;
}
if ( !Input::exists( 'title' ) ) {
self::addUserError( 'You must specify title' );
return false;
}
if ( !Input::exists( 'url' ) ) {
self::addUserError( 'You must specify url' );
return false;
}
if ( !Input::exists( 'description' ) ) {
self::addUserError( 'You must specify description' );
return false;
}
return true;
}
/**
* Validates the edit position post form.
*
* @return {bool}
*/
public static function editLink() {
if ( !Input::exists( 'section' ) ) {
self::addUserError( 'You must specify section' );
return false;
}
if ( !Input::exists( 'title' ) ) {
self::addUserError( 'You must specify title' );
return false;
}
if ( !Input::exists( 'url' ) ) {
self::addUserError( 'You must specify url' );
return false;
}
if ( !Input::exists( 'description' ) ) {
self::addUserError( 'You must specify description' );
return false;
}
return true;
}
}
new PortfolioForms;

View File

@ -0,0 +1,71 @@
<?php
/**
* app/plugins/portfolio/models/links.php
*
* This class is used for the manipulation of the links database table.
*
* @package TP Portfolio
* @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\Portfolio as Plugin;
class Links extends DatabaseModel {
public $tableName = 'portfolio_links';
public $databaseMatrix = [
[ 'section', 'varchar', '32' ],
[ 'title', 'varchar', '128' ],
[ 'image', 'varchar', '256' ],
[ 'url', 'varchar', '256' ],
[ 'description', 'text', '' ],
];
public $plugin;
/**
* The model constructor.
*/
public function __construct() {
parent::__construct();
$this->plugin = new Plugin;
}
public function create( $section, $title, $image, $url, $description ) {
if ( !$this->plugin->checkEnabled() ) {
Debug::info( 'Portfolio is disabled in the config.' );
return false;
}
$fields = [
'section' => $section,
'title' => $title,
'image' => $image,
'url' => $url,
'description' => $description,
];
if ( !self::$db->insert( $this->tableName, $fields ) ) {
Debug::info( 'Links::create - failed to insert to db' );
return false;
}
return self::$db->lastId();
}
public function update( $id, $fields ) {
if ( !Check::id( $id ) ) {
Debug::info( 'modelBlog: illegal ID.' );
return false;
}
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
// new CustomException( 'linkUpdate' );
Debug::error( "Links:update: $id not updated: $fields" );
return false;
}
return true;
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* app/plugins/portfolio/plugin.php
*
* This houses all of the main plugin info and functionality.
*
* @package TP Portfolio
* @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 Portfolio extends Plugin {
public $pluginName = 'TP Portfolio';
public $pluginAuthor = 'JoeyK';
public $pluginWebsite = 'https://TheTempusProject.com';
public $modelVersion = '1.0';
public $pluginVersion = '3.0';
public $pluginDescription = 'A simple plugin which adds management for a portfolio.';
public $configName = 'portfolio';
public $configMatrix = [
'enabled' => [
'type' => 'radio',
'pretty' => 'Enable the portfolio Feature.',
'default' => true,
],
];
public $main_links = [
[
'text' => 'Portfolio',
'url' => '{ROOT_URL}portfolio/index',
],
];
public $admin_links = [
[
'text' => '<i class="fa fa-fw fa-support"></i> Portfolio',
'url' => '{ROOT_URL}admin/portfolio',
],
];
}

View File

@ -0,0 +1,19 @@
<h2>Add Portfolio Link</h2>
<form action="#" method="POST">
<label for="section">Section Name:</label><br>
<input type="text" id="section" name="section" required><br><br>
<label for="title">Title:</label><br>
<input type="text" id="title" name="title" required><br><br>
<label for="image">Image:</label><br>
<input type="text" id="image" name="image" required><br><br>
<label for="url">URL:</label><br>
<input type="text" id="url" name="url" required><br><br>
<label for="description">Description:</label><br>
<textarea id="description" name="description" rows="20" cols="50" required></textarea><br><br>
<input type="submit" name="submit" value="Submit">
</form>

View File

@ -0,0 +1,19 @@
<h2>Edit Portfolio Link</h2>
<form action="#" method="POST">
<label for="section">Section Name:</label><br>
<input type="text" id="section" name="section" value="{section}" required><br><br>
<label for="title">Title:</label><br>
<input type="text" id="title" name="title" value="{title}" required><br><br>
<label for="image">Image:</label><br>
<input type="text" id="image" name="image" value="{image}" required><br><br>
<label for="url">URL:</label><br>
<input type="text" id="url" name="url" value="{url}" required><br><br>
<label for="description">Description</label><br>
<textarea id="description" name="description" rows="20" cols="50" required>{description}</textarea><br><br>
<input type="submit" name="submit" value="Submit">
</form>

View File

@ -0,0 +1,41 @@
<legend>Portfolio Links</legend>
{PAGINATION}
<form action="{ROOT_URL}admin/portfolio/delete" method="post">
<table class="table table-striped">
<thead>
<tr>
<th style="width: 30%">title</th>
<th style="width: 30%">section</th>
<th style="width: 25%">url</th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%">
<INPUT type="checkbox" onchange="checkAll(this)" name="check.b" value="B_[]"/>
</th>
</tr>
</thead>
<tbody>
{LOOP}
<tr>
<td><a href="{ROOT_URL}admin/portfolio/view/{ID}">{title}</a></td>
<td>{section}</td>
<td>{url}</td>
<td><a href="{ROOT_URL}admin/portfolio/edit/{ID}" class="btn btn-sm btn-warning" role="button"><i class="glyphicon glyphicon-edit"></i></a></td>
<td><a href="{ROOT_URL}admin/portfolio/delete/{ID}" class="btn btn-sm btn-danger" role="button"><i class="glyphicon glyphicon-trash"></i></a></td>
<td>
<input type="checkbox" value="{ID}" name="P_[]">
</td>
</tr>
{/LOOP}
{ALT}
<tr>
<td colspan="7">
No results to show.
</td>
</tr>
{/ALT}
</tbody>
</table>
<a href="{ROOT_URL}admin/portfolio/create" class="btn btn-sm btn-primary" role="button">Create</a>
<button name="submit" value="submit" type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>

View File

@ -0,0 +1,16 @@
<legend>Portfolio Link</legend>
<hr>
<div class="media portfolio-link">
<div class="media-left">
<a href="#">
<img class="media-object" src="{image}" alt="{title} preview">
</a>
</div>
<div class="media-body">
<h4 class="media-heading"><a href="{url}">{title}</a></h4>
{description}
</div>
</div>

View File

@ -0,0 +1,20 @@
<h1>Portfolio</h1>
<hr>
{LOOP}
<div class="media portfolio-link col-md-8 col-md-offset-2">
<div class="media-left">
<a href="#">
<img class="media-object" src="{image}" alt="{title} preview">
</a>
</div>
<div class="media-body">
<h4 class="media-heading"><a href="{url}">{title}</a></h4>
{description}
</div>
</div>
{/LOOP}
{ALT}
<div class="portfolio-link">
<p>None Found</p>
</div>
{/ALT}