wip
This commit is contained in:
101
app/plugins/portfolio/controllers/admin/portfolio.php
Normal file
101
app/plugins/portfolio/controllers/admin/portfolio.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?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';
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
36
app/plugins/portfolio/controllers/portfolio.php
Normal file
36
app/plugins/portfolio/controllers/portfolio.php
Normal 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() );
|
||||
}
|
||||
}
|
||||
}
|
79
app/plugins/portfolio/forms.php
Normal file
79
app/plugins/portfolio/forms.php
Normal 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;
|
71
app/plugins/portfolio/models/links.php
Normal file
71
app/plugins/portfolio/models/links.php
Normal 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;
|
||||
}
|
||||
}
|
44
app/plugins/portfolio/plugin.php
Normal file
44
app/plugins/portfolio/plugin.php
Normal 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-solid fa-star"></i> Portfolio',
|
||||
'url' => '{ROOT_URL}admin/portfolio',
|
||||
],
|
||||
];
|
||||
}
|
19
app/plugins/portfolio/views/admin/create.html
Normal file
19
app/plugins/portfolio/views/admin/create.html
Normal 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>
|
19
app/plugins/portfolio/views/admin/edit.html
Normal file
19
app/plugins/portfolio/views/admin/edit.html
Normal 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>
|
44
app/plugins/portfolio/views/admin/list.html
Normal file
44
app/plugins/portfolio/views/admin/list.html
Normal file
@ -0,0 +1,44 @@
|
||||
<div class="context-main-bg context-main p-3">
|
||||
<legend class="text-center">Portfolio Links</legend>
|
||||
<hr>
|
||||
{ADMIN_BREADCRUMBS}
|
||||
<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="P_[]"/>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{LOOP}
|
||||
<tr>
|
||||
<td><a href="{ROOT_URL}admin/portfolio/view/{ID}" class="text-decoration-none">{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="fa fa-fw fa-pencil"></i></a></td>
|
||||
<td><a href="{ROOT_URL}admin/portfolio/delete/{ID}" class="btn btn-sm btn-danger" role="button"><i class="fa fa-fw fa-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"><i class="fa fa-fw fa-trash"></i></button>
|
||||
</form>
|
||||
</div>
|
16
app/plugins/portfolio/views/admin/view.html
Normal file
16
app/plugins/portfolio/views/admin/view.html
Normal 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>
|
||||
|
||||
|
30
app/plugins/portfolio/views/portfolio.html
Normal file
30
app/plugins/portfolio/views/portfolio.html
Normal file
@ -0,0 +1,30 @@
|
||||
<div class="col-12 col-md-10 col-lg-8 offset-lg-2 offset-md-1 offset-0 mb-3 mb-lg-5 mt-2 mt-lg-4">
|
||||
<div class="p-2 p-lg-4 mb-lg-4 m-2 rounded-3 context-main context-main-bg">
|
||||
<h2 class="text-center">Portfolio</h2>
|
||||
<hr>
|
||||
{LOOP}
|
||||
<div class="card context-main context-third-bg py-2 my-2">
|
||||
<div class="row g-0 p-lg-2">
|
||||
<div class="col-md-4 ps-2 d-flex justify-content-center align-items-center">
|
||||
<a href="{url}">
|
||||
<img class="img-fluid rounded" src="{image}" alt="{title} preview">
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">{title}</h4>
|
||||
<p class="card-text">
|
||||
{description}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/LOOP}
|
||||
{ALT}
|
||||
<div class="card context-main context-main-bg">
|
||||
<p>None Found</p>
|
||||
</div>
|
||||
{/ALT}
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user