Add new plugins: WIP, Suggestions, Reviews

This commit is contained in:
Joey Kimsey
2024-12-11 08:00:06 -05:00
parent 6a6fe4171f
commit a8a99b37e3
41 changed files with 2079 additions and 0 deletions

View File

@ -0,0 +1,140 @@
<?php
/**
* app/plugins/reviews/controllers/admin/reviews.php
*
* This is the reviews admin controller.
*
* @package TP Reviews
* @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\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\Models\Review;
use TheTempusProject\Models\Reviewcategory;
use TheTempusProject\Classes\Forms;
class Reviews extends AdminController {
protected static $reviews;
protected static $categories;
public function __construct() {
parent::__construct();
self::$title = 'Admin - Reviews';
self::$reviews = new Review;
self::$categories = new Reviewcategory;
$view = Navigation::activePageSelect( 'nav.admin', '/admin/reviews' );
Components::set( 'ADMINNAV', $view );
}
public function index( $data = null ) {
$reviews = Views::simpleView( 'reviews.admin.reviewList', self::$reviews->list() );
$categories = Views::simpleView( 'reviews.admin.categoryList', self::$categories->list() );
Components::set( 'reviews', $reviews );
Components::set( 'reviewCategories', $categories );
Views::view( 'reviews.admin.dashboard' );
}
public function categoryView( $id = null ) {
$category = self::$categories->findById( $id );
if ( ! $category ) {
Issues::add( 'error', 'Unknown Category.' );
return $this->index();
}
Views::view( 'reviews.admin.category', $category );
}
public function categoryCreate( ) {
if ( ! Input::exists( 'submit' ) ) {
return Views::view( 'reviews.admin.categoryCreate' );
}
if ( ! Forms::check( 'categoryCreate' ) ) {
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
return Views::view( 'reviews.admin.categoryCreate' );
}
$result = self::$categories->create(
Input::post( 'name' ),
Input::post( 'slug' ),
);
if ( $result ) {
Issues::add( 'success', 'Your review category has been created.' );
return $this->index();
}
Issues::add( 'error', [ 'There was an unknown error submitting your data.' => Check::userErrors() ] );
Views::view( 'reviews.admin.categoryCreate' );
}
public function categoryEdit( $id = null ) {
$category = self::$categories->findById( $id );
if ( ! $category ) {
Issues::add( 'error', 'Unknown Category.' );
return $this->index();
}
if ( ! Input::exists( 'submit' ) ) {
return Views::view( 'reviews.admin.categoryEdit', $category );
}
if ( ! Forms::check( 'categoryEdit' ) ) {
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
return Views::view( 'reviews.admin.categoryEdit', $category );
}
$result = self::$categories->update(
$id,
Input::post( 'name' ),
Input::post( 'slug' ),
);
if ( $result ) {
Issues::add( 'success', 'Your review category has been updated.' );
return $this->index();
}
Issues::add( 'error', [ 'There was an unknown error submitting your data.' => Check::userErrors() ] );
Views::view( 'reviews.admin.categoryEdit', $category );
}
public function categoryDelete( $id = null ) {
if ( self::$categories->delete( $id ) ) {
Issues::add( 'success', 'review category deleted' );
} else {
Issues::add( 'error', 'There was an error with your request.' );
}
$this->index();
}
public function reviewView( $id = null ) {
Views::view( 'reviews.admin.review', self::$reviews->findById( $id ) );
}
public function reviewApprove( $id = null ) {
if ( self::$reviews->approve( $id ) ) {
Issues::add( 'success', 'review approved' );
} else {
Issues::add( 'error', 'There was an error with your request.' );
}
$this->index();
}
public function reviewHide( $id = null ) {
if ( self::$reviews->hide( $id ) ) {
Issues::add( 'success', 'review hidden' );
} else {
Issues::add( 'error', 'There was an error with your request.' );
}
$this->index();
}
public function reviewDelete( $id = null ) {
if ( self::$reviews->delete( $id ) ) {
Issues::add( 'success', 'review deleted' );
} else {
Issues::add( 'error', 'There was an error with your request.' );
}
$this->index();
}
}

View File

@ -0,0 +1,89 @@
<?php
/**
* app/plugins/reviews/controllers/reviews.php
*
* This is the reviews controller.
*
* @package TP Reviews
* @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\Review;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Houdini\Classes\Template;
use TheTempusProject\Models\Reviewcategory;
use TheTempusProject\Houdini\Classes\Forms as HoudiniForms;
class Reviews extends Controller {
protected static $reviews;
protected static $categories;
public function __construct() {
self::$title = 'Reviews - {SITENAME}';
self::$pageDescription = 'On this page you can submit a reviews for a product from the site.';
if ( ! App::$isLoggedIn ) {
Session::flash( 'notice', 'You must be logged in to review products.' );
return Redirect::home();
}
parent::__construct();
self::$reviews = new Review;
self::$categories = new Reviewcategory;
Components::append( 'TEMPLATE_JS_INCLUDES', Template::parse('<script language="JavaScript" crossorigin="anonymous" type="text/javascript" src="{ROOT_URL}app/plugins/reviews/js/reviews.js"></script>' ) );
Components::append( 'TEMPLATE_CSS_INCLUDES', Template::parse('<link rel="stylesheet" href="{ROOT_URL}app/plugins/reviews/css/reviews.css" />') );
}
public function index() {
$reviews = Views::simpleView( 'reviews.list', self::$reviews->byUser() );
Components::set( 'reviews', $reviews );
Views::view( 'reviews.index' );
}
public function review( $slug = null ) {
$category = self::$categories->findBySlug( $slug );
if ( ! $category ) {
$selectedCategory = '0';
$reviewCategorySelect = HoudiniForms::getSelectHtml(
'review_category_id',
self::$categories->simple(),
$selectedCategory,
);
Components::set( 'reviewCategorySelect', $reviewCategorySelect );
} else {
$selectedCategory = $category->ID;
Components::set(
'reviewCategorySelect',
'<input type="hidden" name="review_category_id" id="review_category_id" value="' . $selectedCategory . '" />'
);
}
if ( ! Input::exists('submit') ) {
return Views::view( 'reviews.create' );
}
if ( ! Forms::check( 'createReview' ) ) {
Issues::add( 'error', [ 'There was an error with your review.' => Check::userErrors() ] );
return Views::view( 'reviews.create' );
}
$result = self::$reviews->create( Input::post('title'), Input::post('rating'), Input::post('review'), Input::post('review_category_id') );
if ( true === $result ) {
Session::flash( 'success', 'Your review has been received.' );
Redirect::to( 'home/index' );
} else {
Issues::add( 'error', 'There was an unresolved error while submitting your review.' );
return Views::view( 'reviews.create' );
}
}
}

View File

@ -0,0 +1,9 @@
.star-rating .fa-star {
font-size: 24px;
color: grey;
cursor: pointer;
}
.star-rating .fa-star.checked {
color: gold;
}

View File

@ -0,0 +1,93 @@
<?php
/**
* app/plugins/reviews/forms.php
*
* This houses all of the form checking functions for this plugin.
*
* @package TP Reviews
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Plugins\Reviews;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Classes\Forms;
class ReviewForms extends Forms {
/**
* Adds these functions to the form list.
*/
public function __construct() {
self::addHandler( 'createReview', __CLASS__, 'createReview' );
self::addHandler( 'editReview', __CLASS__, 'editReview' );
self::addHandler( 'categoryCreate', __CLASS__, 'categoryCreate' );
self::addHandler( 'categoryEdit', __CLASS__, 'categoryEdit' );
}
/**
* Validates the createReview form.
*
* @return {bool}
*/
public static function createReview() {
if ( ! Input::exists( 'review' ) ) {
Check::addUserError( 'You must provide a review.' );
return false;
}
if ( ! Input::exists( 'title' ) ) {
Check::addUserError( 'You must provide a title.' );
return false;
}
if ( ! Input::exists( 'rating' ) ) {
Check::addUserError( 'You must provide a rating.' );
return false;
}
if ( ! Input::exists( 'review_category_id' ) ) {
Check::addUserError( 'You must provide a review_category_id.' );
return false;
}
return true;
}
public static function editReview() {
if ( ! Input::exists( 'review' ) ) {
Check::addUserError( 'You must provide a review.' );
return false;
}
if ( ! Input::exists( 'title' ) ) {
Check::addUserError( 'You must provide a title.' );
return false;
}
if ( ! Input::exists( 'rating' ) ) {
Check::addUserError( 'You must provide a rating.' );
return false;
}
return true;
}
public static function categoryCreate() {
if ( ! Input::exists( 'name' ) ) {
Check::addUserError( 'You must provide a name.' );
return false;
}
if ( ! Input::exists( 'slug' ) ) {
Check::addUserError( 'You must provide a slug.' );
return false;
}
return true;
}
public static function categoryEdit() {
if ( ! Input::exists( 'name' ) ) {
Check::addUserError( 'You must provide a name.' );
return false;
}
if ( ! Input::exists( 'slug' ) ) {
Check::addUserError( 'You must provide a slug.' );
return false;
}
return true;
}
}
new ReviewForms;

View File

@ -0,0 +1,20 @@
$(document).ready(function() {
var $star_rating = $('.star-rating .fa-star');
var SetRatingStar = function() {
return $star_rating.each(function() {
if (parseInt($(this).siblings('input.rating-value').val()) >= parseInt($(this).data('rating'))) {
return $(this).addClass('checked');
} else {
return $(this).removeClass('checked');
}
});
};
$star_rating.on('click', function() {
$(this).siblings('input.rating-value').val($(this).data('rating'));
return SetRatingStar();
});
SetRatingStar();
});

View File

@ -0,0 +1,149 @@
<?php
/**
* app/plugins/reviews/models/review.php
*
* This class is used for the manipulation of the reviews database table.
*
* @package TP Reviews
* @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\Reviews as Plugin;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Canary\Classes\CustomException;
class Review extends DatabaseModel {
public $tableName = 'reviews';
public $databaseMatrix = [
[ 'review_category_id', 'int', '11' ],
[ 'title', 'varchar', '128' ],
[ 'rating', 'int', '1' ],
[ 'review', 'text', '' ],
[ 'createdBy', 'int', '11' ],
[ 'createdAt', 'int', '11' ],
[ 'approvedAt', 'int', '11' ],
[ 'approvedBy', 'int', '11' ],
];
public $plugin;
/**
* The model constructor.
*/
public function __construct() {
parent::__construct();
$this->plugin = new Plugin;
}
public function create( $title, $rating, $review, $review_category_id = '0' ) {
if ( ! $this->plugin->checkEnabled() ) {
Debug::info( 'Reviews are disabled in the config.' );
return false;
}
$fields = [
'title' => $title,
'rating' => $rating,
'review' => $review,
'review_category_id' => $review_category_id,
'createdAt' => time(),
'createdBy' => App::$activeUser->ID,
];
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
Debug::info( 'Reviews::create - failed to insert to db' );
return false;
}
return self::$db->lastId();
}
public function update( $id, $title, $rating, $review, $review_category_id = '0' ) {
if ( ! $this->plugin->checkEnabled() ) {
Debug::info( 'Reviews are disabled in the config.' );
return false;
}
if ( !Check::dataTitle( $slug ) ) {
Debug::info( 'Review Categories: illegal title.' );
return false;
}
$fields = [
'title' => $title,
'rating' => $rating,
'review' => $review,
'review_category_id' => $review_category_id,
];
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
new CustomException( 'reviewUpdate' );
Debug::error( "Review: $id not updated: $fields" );
return false;
}
return true;
}
public function approve( $ID ) {
if ( !Check::id( $ID ) ) {
Debug::info( 'Review Categories: illegal ID.' );
return false;
}
$fields = [
'approvedAt' => time(),
'approvedBy' => App::$activeUser->ID,
];
if ( !self::$db->update( $this->tableName, $ID, $fields ) ) {
new CustomException( $this->tableName );
Debug::error( "Review Categories: $ID Approved: $fields" );
return false;
}
return true;
}
public function hide( $ID ) {
// if ( !Check::id( $ID ) ) {
// Debug::info( 'Review Categories: illegal ID.' );
// return false;
// }
// $fields = [
// 'approvedAt' => null,
// 'approvedBy' => null,
// ];
// if ( !self::$db->update( $this->tableName, $ID, $fields ) ) {
// new CustomException( $this->tableName );
// Debug::error( "Review Categories: $ID not Approved: $fields" );
// return false;
// }
return true;
}
public function byUser( $limit = null ) {
$whereClause = ['createdBy', '=', App::$activeUser->ID];
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() );
}
public function byCategory( $id, $limit = null ) {
$whereClause = [ 'review_category_id', '=', $id ];
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,112 @@
<?php
/**
* app/plugins/reviews/models/reviewcategory.php
*
* This class is used for the manipulation of the review_categories database table.
*
* @package TP Reviews
* @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\Reviews as Plugin;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Canary\Classes\CustomException;
class Reviewcategory extends DatabaseModel {
public $tableName = 'review_categories';
public $databaseMatrix = [
[ 'name', 'varchar', '128' ],
[ 'slug', 'varchar', '64' ],
[ 'createdBy', 'int', '11' ],
[ 'createdAt', 'int', '11' ],
];
public $plugin;
/**
* The model constructor.
*/
public function __construct() {
parent::__construct();
$this->plugin = new Plugin;
}
public function create( $name, $slug ) {
if ( ! $this->plugin->checkEnabled() ) {
Debug::info( 'Reviews are disabled in the config.' );
return false;
}
if ( !Check::dataTitle( $slug ) ) {
Debug::info( 'Review Categories: illegal title.' );
return false;
}
$fields = [
'name' => $name,
'slug' => $slug,
'createdAt' => time(),
'createdBy' => App::$activeUser->ID,
];
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
Debug::info( 'ReviewCategories::create - failed to insert to db' );
return false;
}
return self::$db->lastId();
}
public function update( $id, $name, $slug ) {
if ( ! $this->plugin->checkEnabled() ) {
Debug::info( 'Reviews are disabled in the config.' );
return false;
}
if ( !Check::dataTitle( $slug ) ) {
Debug::info( 'Review Categories: illegal title.' );
return false;
}
$fields = [
'name' => $name,
'slug' => $slug,
];
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
new CustomException( 'reviewCategoryUpdate' );
Debug::error( "Review Categories: $id not updated: $fields" );
return false;
}
return true;
}
public function findBySlug( $slug, $limit = null ) {
$whereClause = [ 'slug', '=', $slug ];
if ( empty( $limit ) ) {
$categories = self::$db->get( $this->tableName, $whereClause );
} else {
$categories = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
}
if ( !$categories->count() ) {
Debug::info( 'No categories found.' );
return false;
}
return $this->filter( $categories->first() );
}
public function simple() {
$categories = self::$db->get( $this->tableName, '*' );
if ( !$categories->count() ) {
Debug::warn( 'Could not find any categories' );
return false;
}
$categories = $categories->results();
$out = [];
foreach ( $categories as &$category ) {
$out[ $category->name ] = $category->ID;
}
return $out;
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* app/plugins/reviews/plugin.php
*
* This houses all of the main plugin info and functionality.
*
* @package TP Reviews
* @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 Reviews extends Plugin {
public $pluginName = 'TP Reviews';
public $pluginAuthor = 'JoeyK';
public $pluginWebsite = 'https://TheTempusProject.com';
public $modelVersion = '1.0';
public $pluginVersion = '3.0';
public $pluginDescription = 'A simple plugin which adds a site wide review system.';
public $permissionMatrix = [
'review' => [
'pretty' => 'Can create reviews',
'default' => false,
],
'createReviewCategory' => [
'pretty' => 'Can create review categories',
'default' => false,
],
];
public $admin_links = [
[
'text' => '<i class="fa fa-fw fa-copy"></i> Reviews',
'url' => '{ROOT_URL}admin/reviews',
],
];
public $footer_links = [
[
'text' => 'Reviews',
'url' => '{ROOT_URL}reviews/index/',
'filter' => 'loggedin',
],
];
}
// need a setting to allow reviewing a category from the dropdown
// if disabled, "I'm sorry but reviews are invite only. If you have been asked to review a product, double check the link and make sure its been entered correctly
// if you have not been invited to review a product, please feel free to leave any feedback in the feedback section.

View File

@ -0,0 +1,35 @@
<div class="container col-md-4 col-lg-4">
<div class="row">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Review Category</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="">
<table class="table table-user-primary">
<tbody>
<tr>
<td align="left" width="200"><b>Name</b></td>
<td align="right">{name}</td>
</tr>
<tr>
<td><b>Slug</b></td>
<td align="right">{slug}</td>
</tr>
<tr>
<td><b>Created</b></td>
<td align="right">{DTC}{createdAt}{/DTC}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="panel-footer">
<a href="{ROOT_URL}admin/reviews/categoryEdit/{ID}" class="btn btn-md btn-warning" role="button">Edit</a>
<a href="{ROOT_URL}admin/reviews/categoryDelete/{ID}" class="btn btn-md btn-danger" role="button">Delete</a>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,22 @@
<legend>Create Review Category</legend>
<form action="" method="post" class="form-horizontal">
<input type="hidden" name="token" value="{TOKEN}">
<div class="form-group">
<label for="name" class="col-lg-3 control-label">Name</label>
<div class="col-lg-3">
<input type="text" class="form-control" name="name" id="name">
</div>
</div>
<div class="form-group">
<label for="slug" class="col-lg-3 control-label">Slug (the public link for reviews would be {ROOT_URL}reviews/YOUR_SLUG_HERE)</label>
<div class="col-lg-3">
<input type="text" class="form-control" name="slug" id="slug">
</div>
</div>
<div class="form-group">
<label for="submit" class="col-lg-3 control-label"></label>
<div class="col-lg-3">
<button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary center-block ">Submit</button>
</div>
</div>
</form>

View File

@ -0,0 +1,22 @@
<legend>Edit Review Category</legend>
<form action="" method="post" class="form-horizontal">
<input type="hidden" name="token" value="{TOKEN}">
<div class="form-group">
<label for="name" class="col-lg-3 control-label">Name</label>
<div class="col-lg-3">
<input type="text" class="form-control" name="name" id="name" value="{name}">
</div>
</div>
<div class="form-group">
<label for="slug" class="col-lg-3 control-label">Slug (the public link for reviews would be {ROOT_URL}reviews/YOUR_SLUG_HERE)</label>
<div class="col-lg-3">
<input type="text" class="form-control" name="slug" id="slug" value="{slug}">
</div>
</div>
<div class="form-group">
<label for="submit" class="col-lg-3 control-label"></label>
<div class="col-lg-3">
<button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary center-block ">Submit</button>
</div>
</div>
</form>

View File

@ -0,0 +1,33 @@
<legend>Review Categories</legend>
<table class="table table-striped">
<thead>
<tr>
<th style="width: 10%">ID</th>
<th style="width: 30%">Name</th>
<th style="width: 30%">Slug</th>
<th style="width: 10%"></th>
<th style="width: 10%"></th>
<th style="width: 10%"></th>
</tr>
</thead>
<tbody>
{LOOP}
<tr>
<td align="center">{ID}</td>
<td>{name}</td>
<td>{slug}</td>
<td><a href="{ROOT_URL}admin/reviews/categoryView/{ID}" class="btn btn-sm btn-primary" role="button"><i class="glyphicon glyphicon-info-sign"></i></a></td>
<td><a href="{ROOT_URL}admin/reviews/categoryEdit/{ID}" class="btn btn-sm btn-warning" role="button"><i class="glyphicon glyphicon-edit"></i></a></td>
<td><a href="{ROOT_URL}admin/reviews/categoryDelete/{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>
<a href="{ROOT_URL}admin/reviews/categoryCreate" class="btn btn-sm btn-primary" role="button">Create</a>

View File

@ -0,0 +1,9 @@
<div class="row">
<div class="col-xlg-6 col-lg-6 col-md-6 col-sm-6 col-xs-6">
{reviews}
</div>
<div class="col-xlg-6 col-lg-6 col-md-6 col-sm-6 col-xs-6">
{reviewCategories}
</div>
</div>

View File

@ -0,0 +1,42 @@
<div class="container col-md-4 col-lg-4">
<div class="row">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Review</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="">
<table class="table table-user-primary">
<tbody>
<tr>
<td align="left" width="200"><b>Title</b></td>
<td align="right">{title}</td>
</tr>
<tr>
<td><b>Rating</b></td>
<td align="right">{rating}</td>
</tr>
<tr>
<td><b>Created</b></td>
<td align="right">{DTC}{createdAt}{/DTC}</td>
</tr>
<tr>
<td align="center" colspan="2"><b>Review</b></td>
</tr>
<tr>
<td colspan="2">{review}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="panel-footer">
<a href="{ROOT_URL}admin/reviews/reviewApprove/{ID}" class="btn btn-sm btn-success" role="button"><i class="glyphicon glyphicon-info-check"></i></a>
<a href="{ROOT_URL}admin/reviews/reviewHide/{ID}" class="btn btn-sm btn-info" role="button"><i class="glyphicon glyphicon-eye-closed"></i></a>
<a href="{ROOT_URL}admin/reviews/reviewDelete/{ID}" class="btn btn-sm btn-danger" role="button"><i class="glyphicon glyphicon-trash"></i></a>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,32 @@
<legend>Reviews</legend>
<table class="table table-striped">
<thead>
<tr>
<th style="width: 10%">ID</th>
<th style="width: 30%">Title</th>
<th style="width: 30%">Rating</th>
<th style="width: 10%"></th>
<th style="width: 10%"></th>
<th style="width: 10%"></th>
</tr>
</thead>
<tbody>
{LOOP}
<tr>
<td align="center">{ID}</td>
<td><a href="{ROOT_URL}admin/reviews/reviewView/{ID}" class="btn btn-sm btn-primary" role="button">{title}</a></td>
<td align="center">{rating}</td>
<td><a href="{ROOT_URL}admin/reviews/reviewApprove/{ID}" class="btn btn-sm btn-success" role="button"><i class="glyphicon glyphicon-info-check"></i></a></td>
<td><a href="{ROOT_URL}admin/reviews/reviewHide/{ID}" class="btn btn-sm btn-info" role="button"><i class="glyphicon glyphicon-eye-closed"></i></a></td>
<td><a href="{ROOT_URL}admin/reviews/reviewDelete/{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>

View File

@ -0,0 +1,29 @@
<div class="container mt-5">
<h2>Write a Review</h2>
<form id="review-form" method="post">
<div class="form-group">
<label for="review_category_id">Review Category:</label>
{reviewCategorySelect}
</div>
<div class="form-group">
<label for="title">Title your review:</label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="form-group">
<label>Rating:</label>
<div class="star-rating">
<span class="fa fa-star" data-rating="1"></span>
<span class="fa fa-star" data-rating="2"></span>
<span class="fa fa-star" data-rating="3"></span>
<span class="fa fa-star" data-rating="4"></span>
<span class="fa fa-star" data-rating="5"></span>
<input type="hidden" name="rating" class="rating-value" value="0">
</div>
</div>
<div class="form-group">
<label for="review">Your Review:</label>
<textarea class="form-control" id="review" name="review" 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 @@
{reviews}

View File

@ -0,0 +1,32 @@
<legend>Reviews</legend>
<table class="table table-striped">
<thead>
<tr>
<th style="width: 10%">ID</th>
<th style="width: 30%">Title</th>
<th style="width: 30%">Rating</th>
<th style="width: 10%"></th>
<th style="width: 10%"></th>
<th style="width: 10%"></th>
</tr>
</thead>
<tbody>
{LOOP}
<tr>
<td align="center">{ID}</td>
<td><a href="{ROOT_URL}admin/reviews/reviewView/{ID}" class="btn btn-sm btn-primary" role="button">{title}</a></td>
<td align="center">{rating}</td>
<td><a href="{ROOT_URL}admin/reviews/reviewApprove/{ID}" class="btn btn-sm btn-success" role="button"><i class="glyphicon glyphicon-info-check"></i></a></td>
<td><a href="{ROOT_URL}admin/reviews/reviewHide/{ID}" class="btn btn-sm btn-info" role="button"><i class="glyphicon glyphicon-eye-closed"></i></a></td>
<td><a href="{ROOT_URL}admin/reviews/reviewDelete/{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>

View File

@ -0,0 +1,119 @@
<?php
/**
* app/plugins/suggestions/controllers/admin/suggestions.php
*
* This is the suggestions admin controller.
*
* @package TP Suggest
* @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\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Classes\Forms;
use TheTempusProject\Classes\AdminController;
use TheTempusProject\Models\Suggestions as SuggestionsModel;
use TheTempusProject\Models\Comments;
use TheTempusProject\Houdini\Classes\Forms as TemplateForm;
class Suggestions extends AdminController {
protected static $suggestions;
protected static $comments;
public function __construct() {
parent::__construct();
self::$title = 'Admin - Suggestions';
self::$suggestions = new SuggestionsModel;
}
public function index( $data = null ) {
Views::view( 'suggestions.admin.list', self::$suggestions->list() );
}
public function view( $id = null ) {
$data = self::$suggestions->findById( $id );
if ( $data == false ) {
Issues::add( 'error', 'Suggestion not found.' );
return $this->index();
}
if ( empty( self::$comments ) ) {
self::$comments = new Comments;
}
Components::set( 'COMMENT_TYPE', 'suggestions' );
Components::set( 'count', self::$comments->count( 'suggestion', $id ) );
Components::set( 'COMMENTS', Views::simpleView( 'comments.list', self::$comments->display( 10, 'suggestion', $id ) ) );
Views::view( 'suggestions.admin.view', $data );
}
public function approve( $id = null ) {
$data = self::$suggestions->findById( $id );
if ( $data == false ) {
Issues::add( 'error', 'Suggestion not found.' );
return $this->index();
}
if ( !self::$suggestions->approve( $id ) ) {
Issues::add( 'error', 'Suggestion not approved.' );
return $this->index();
}
Issues::add( 'success', 'Suggestion Approved' );
return $this->index();
}
public function reject( $id = null ) {
$data = self::$suggestions->findById( $id );
if ( $data == false ) {
Issues::add( 'error', 'Suggestion not found.' );
return $this->index();
}
if ( !self::$suggestions->reject( $id ) ) {
Issues::add( 'error', 'Suggestion not rejected.' );
return $this->index();
}
Issues::add( 'success', 'Suggestion Rejected' );
return $this->index();
}
public function edit( $id = null ) {
$data = self::$suggestions->findById( $id );
if ( false == $data ) {
return $this->index();
}
TemplateForm::selectRadio( 'approved', $data->approved );
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'suggestions.admin.edit', $data );
}
if ( !Forms::check( 'editSuggestion' ) ) {
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
return Views::view( 'suggestions.admin.edit', $data );
}
if ( self::$suggestions->update( $id, Input::post( 'title' ), Input::post( 'suggestion' ), Input::post( 'approved' ) ) ) {
Issues::add( 'success', 'Suggestion updated' );
} else {
return Views::view( 'suggestions.edit', $data );
}
}
public function delete( $data = null ) {
if ( Input::exists( 'submit' ) ) {
$data = Input::post( 'S_' );
}
if ( !self::$suggestions->delete( $data ) ) {
Issues::add( 'error', 'There was an error with your request.' );
} else {
Issues::add( 'success', 'Suggestions has been deleted' );
}
$this->index();
}
public function clear( $data = null ) {
self::$suggestions->empty();
$this->index();
}
}

View File

@ -0,0 +1,133 @@
<?php
/**
* app/plugins/suggestions/controllers/suggestions.php
*
* This is the suggestions controller.
*
* @package TP Suggest
* @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\Bedrock\Functions\Check;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Hermes\Functions\Redirect;
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\Suggestions as SuggestionModel;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Models\Comments as CommentsModel;
use TheTempusProject\Plugins\Comments;
use TheTempusProject\Houdini\Classes\Components;
class Suggestions extends Controller {
protected static $suggestions;
protected static $comments;
public function __construct() {
parent::__construct();
if ( !App::$isLoggedIn ) {
Session::flash( 'notice', 'You must be logged in to view suggestions.' );
return Redirect::home();
}
self::$suggestions = new SuggestionModel;
self::$title = 'Suggestions - {SITENAME}';
self::$pageDescription = 'On this page you can view, submit, or comment-on suggestions for the site.';
}
public function index() {
Views::view( 'suggestions.list', self::$suggestions->recent() );
}
public function view( $id = null ) {
$data = self::$suggestions->findById( $id );
if ( $data == false ) {
Issues::add( 'error', 'Suggestion not found.' );
return $this->index();
}
if ( empty( self::$comments ) ) {
self::$comments = new CommentsModel;
}
if ( Input::exists( 'contentId' ) ) {
$this->comments( 'post', Input::post( 'contentId' ) );
}
Components::set( 'CONTENT_ID', $id );
Components::set( 'COMMENT_TYPE', 'suggestions' );
Components::set( 'NEWCOMMENT', Views::simpleView( 'comments.create' ) );
Components::set( 'count', self::$comments->count( 'suggestion', $id ) );
Components::set( 'COMMENTS', Views::simpleView( 'comments.list', self::$comments->display( 10, self::$suggestions->tableName, $id ) ) );
Views::view( 'suggestions.view', $data );
}
public function create() {
if ( !Input::exists() ) {
return Views::view( 'suggestions.create' );
}
if ( !Forms::check( 'newSuggestion' ) ) {
Issues::add( 'error', [ 'There was an error with your suggestion.' => Check::userErrors() ] );
return Views::view( 'suggestions.create' );
}
if ( !self::$suggestions->create( Input::post( 'title' ), Input::post( 'suggestion' ) ) ) {
Issues::add( 'error', [ 'There was an error with your suggestion.' => Check::userErrors() ] );
return Views::view( 'suggestions.create' );
}
Session::flash( 'success', 'Your Suggestion has been received. We must verify all suggestions before they are published, but as long as it doesn\'t violate our code of conduct, it should be available to view and comment on publicly within 24 hours.' );
Redirect::to( 'suggestions/index' );
}
public function edit( $data = null ) {
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'suggestions.edit', self::$suggestions->findById( $data ) );
}
if ( !Forms::check( 'editSuggestion' ) ) {
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
return Views::view( 'suggestions.edit', self::$suggestions->findById( $data ) );
}
if ( self::$suggestions->update( $data, Input::post( 'title' ), Input::post( 'suggestion' ) ) ) {
Issues::add( 'success', 'Suggestion updated' );
} else {
return Views::view( 'suggestions.edit', self::$suggestions->findById( $data ) );
}
$this->index();
}
public function comments( $sub = null, $data = null ) {
if ( empty( self::$comments ) ) {
self::$comments = new CommentsModel;
}
$commentsPlugin = new Comments;
if ( empty( $sub ) || empty( $data ) ) {
Session::flash( 'error', 'Whoops, try again.' );
Redirect::to( 'suggestions' );
}
switch ( $sub ) {
case 'post':
$content = self::$suggestions->findById( $data );
if ( empty( $content ) ) {
Session::flash( 'error', 'Unknown Content.' );
Redirect::to( 'suggestions' );
}
return $commentsPlugin->formPost( self::$suggestions->tableName, $content, 'suggestions/view/' );
case 'edit':
$content = self::$comments->findById( $data );
if ( empty( $content ) ) {
Session::flash( 'error', 'Unknown Comment.' );
Redirect::to( 'suggestions' );
}
return $commentsPlugin->formEdit( self::$suggestions->tableName, $content, 'suggestions/view/' );
case 'delete':
$content = self::$comments->findById( $data );
if ( empty( $content ) ) {
Session::flash( 'error', 'Unknown Comment.' );
Redirect::to( 'suggestions' );
}
return $commentsPlugin->formDelete( self::$suggestions->tableName, $content, 'suggestions/view/' );
}
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* app/plugins/suggestions/forms.php
*
* This houses all of the form checking functions for this plugin.
*
* @package TP Suggest
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Plugins\Suggestions;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Classes\Forms;
class SuggestionForms extends Forms {
/**
* Adds these functions to the form list.
*/
public function __construct() {
self::addHandler( 'newSuggestion', __CLASS__, 'newSuggestion' );
self::addHandler( 'editSuggestion', __CLASS__, 'editSuggestion' );
}
/**
* Validates the suggestion create form.
*
* @return {bool}
*/
public static function newSuggestion() {
if ( !Input::exists( 'title' ) ) {
self::addUserError( 'You must specify title' );
return false;
}
if ( !Input::exists( 'suggestion' ) ) {
self::addUserError( 'You must write a Suggestion' );
return false;
}
if ( !self::token() ) {
return false;
}
return true;
}
/**
* Validates the suggestion create form.
*
* @return {bool}
*/
public static function editSuggestion() {
if ( !Input::exists( 'title' ) ) {
self::addUserError( 'You must specify title' );
return false;
}
if ( !Input::exists( 'suggestion' ) ) {
self::addUserError( 'You must write a Suggestion' );
return false;
}
if ( !self::token() ) {
return false;
}
return true;
}
}
new SuggestionForms;

View File

@ -0,0 +1,183 @@
<?php
/**
* app/plugins/suggestions/models/suggestions.php
*
* This class is used for the manipulation of the suggestions database table.
*
* @package TP Suggest
* @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\Functions\Check;
use TheTempusProject\Bedrock\Classes\Config;
use TheTempusProject\Canary\Bin\Canary as Debug;
use TheTempusProject\Canary\Classes\CustomException;
use TheTempusProject\Classes\DatabaseModel;
use TheTempusProject\TheTempusProject as App;
class Suggestions extends DatabaseModel {
public $tableName = 'suggestions';
public $databaseMatrix = [
[ 'title', 'varchar', '86' ],
[ 'suggestion', 'text', '' ],
[ 'suggestedOn', 'int', '10' ],
[ 'approved', 'varchar', '5' ],
[ 'approvedOn', 'int', '10' ],
[ 'approvedBy', 'int', '11' ],
[ 'author', 'int', '11' ],
];
/**
* The model constructor.
*/
public function __construct() {
parent::__construct();
}
// @TODO: Add a config for some of these things
// public function enabled() {
// if ( true === parent::enabled() ) {
// return Config::getValue( $this->configName . '/enabled' ) === true;
// }
// return false;
// }
public function filter( $data, $params = [] ) {
foreach ( $data as $instance ) {
if ( !is_object( $instance ) ) {
$instance = $data;
$end = true;
}
if ( !empty($instance->approvedBy)) {
$instance->approvedByName = self::$user->getUsername( $instance->approvedBy );
} else {
$instance->approvedByName = '';
}
$instance->submittedBy = self::$user->getUsername( $instance->author );
$out[] = $instance;
if ( !empty( $end ) ) {
$out = $out[0];
break;
}
}
return $out;
}
/**
* Logs a Suggestion form.
*
* @param int $ID the user ID submitting the form
* @param string $url the url
* @param string $o_url the original url
* @param int $repeat is repeatable?
* @param string $description_ description of the event.
*
* @return null
*/
public function create( $title, $suggestion, $approved = 'false' ) {
if ( !$this->enabled() ) {
Debug::info( 'Suggestions are disabled in the config.' );
return false;
}
$fields = [
'author' => App::$activeUser->ID,
'suggestedOn' => time(),
'suggestion' => $suggestion,
'approved' => $approved,
'title' => $title,
];
if ( !self::$db->insert( $this->tableName, $fields ) ) {
new CustomException( $this->tableName );
return false;
}
return self::$db->lastId();
}
public function update( $ID, $title, $suggestion, $approved = 'false' ) {
if ( empty( self::$log ) ) {
self::$log = new Log;
}
if ( !Check::id( $ID ) ) {
Debug::info( 'Suggestion: illegal ID.' );
return false;
}
$fields = [
'suggestion' => $suggestion,
'approved' => $approved,
'title' => $title,
];
if ( !self::$db->update( $this->tableName, $ID, $fields ) ) {
new CustomException( $this->tableName );
Debug::error( "Suggestion: $ID not updated: $fields" );
return false;
}
self::$log->admin( "Updated Suggestion: $ID" );
return true;
}
public function approve( $ID ) {
if ( empty( self::$log ) ) {
self::$log = new Log;
}
if ( !Check::id( $ID ) ) {
Debug::info( 'Suggestion: illegal ID.' );
return false;
}
$fields = [
'approved' => 'true',
'approvedOn' => time(),
'approvedBy' => App::$activeUser->ID,
];
if ( !self::$db->update( $this->tableName, $ID, $fields ) ) {
new CustomException( $this->tableName );
Debug::error( "Suggestion: $ID not Rejected: $fields" );
return false;
}
self::$log->admin( "Suggestion Rejected: $ID" );
return true;
}
public function reject( $ID ) {
if ( empty( self::$log ) ) {
self::$log = new Log;
}
if ( !Check::id( $ID ) ) {
Debug::info( 'Suggestion: illegal ID.' );
return false;
}
$fields = [
'approved' => 'false',
'approvedOn' => null,
'approvedBy' => null,
];
if ( !self::$db->update( $this->tableName, $ID, $fields ) ) {
new CustomException( $this->tableName );
Debug::error( "Suggestion: $ID not Approved: $fields" );
return false;
}
self::$log->admin( "Suggestion Approved: $ID" );
return true;
}
public function recent( $approvedOnly = true, $limit = 0 ) {
if ( true === $approvedOnly ) {
$where = ['approved', '=', 'true'];
} else {
$where = ['ID', '>', '0'];
}
if ( empty( $limit ) ) {
$data = self::$db->getPaginated( $this->tableName, $where, 'suggestedOn', 'DESC' );
} else {
$data = self::$db->get( $this->tableName, $where, 'suggestedOn', 'DESC', [0, $limit] );
}
if ( !$data->count() ) {
Debug::info( 'No Suggestions found.' );
return false;
}
return $this->filter( $data->results() );
}
}

View File

@ -0,0 +1,47 @@
<?php
/**
* app/plugins/suggestions/plugin.php
*
* This houses all of the main plugin info and functionality.
*
* @package TP Suggest
* @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 ReflectionClass;
use TheTempusProject\Classes\Installer;
use TheTempusProject\Houdini\Classes\Navigation;
use TheTempusProject\Classes\Plugin;
use TheTempusProject\TheTempusProject as App;
class Suggestions extends Plugin {
public $pluginName = 'TP Suggest';
public $pluginAuthor = 'JoeyK';
public $pluginWebsite = 'https://TheTempusProject.com';
public $modelVersion = '1.0';
public $pluginVersion = '3.0';
public $pluginDescription = 'A simple plugin which adds a site wide suggestion system.';
public $permissionMatrix = [
'suggest' => [
'pretty' => 'Can create suggestions',
'default' => false,
],
];
public $admin_links = [
[
'text' => '<i class="fa fa-fw fa-copy"></i> Suggestions',
'url' => '{ROOT_URL}admin/suggestions',
],
];
public $footer_links = [
[
'text' => 'Suggestions',
'url' => '{ROOT_URL}suggestions/index',
'filter' => 'loggedin',
],
];
}

View File

@ -0,0 +1,22 @@
<form action="" method="post" class="form-horizontal">
<div class="form-group">
<div class="col-lg-4 col-lg-offset-4">
<label for="title" class="col-lg-3 control-label">Title</label>
<input type="text" class="form-check-input" name="title" id="title" value="{title}">
</div>
</div>
<div class="form-group">
<div class="col-lg-4 col-lg-offset-4">
<label for="suggestion">Suggestion</label>
<textarea class="form-control" name="suggestion" maxlength="2000" rows="10" cols="50" id="suggestion">{suggestion}</textarea>
</div>
</div>
<div class="form-group">
<div class="col-lg-4 col-lg-offset-4">
<input class="" type="checkbox" name="approved" id="approved" value="true" {CHECKED:approved=true}>
<label for="approved">Approved (Publicly available)?</label>
</div>
</div>
<button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary center-block">Save</button>
<input type="hidden" name="token" value="{TOKEN}">
</form>

View File

@ -0,0 +1,56 @@
<legend>Suggestions</legend>
{PAGINATION}
<form action="{ROOT_URL}admin/suggestions/delete" method="post">
<table class="table table-striped">
<thead>
<tr>
<th style="width: 5%">ID</th>
<th style="width: 30%">Suggestion</th>
<th style="width: 10%">Suggested On</th>
<th style="width: 10%">Suggested By</th>
<th style="width: 10%">Approved</th>
<th style="width: 10%">Approved On</th>
<th style="width: 10%">Approved By</th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%">
<INPUT type="checkbox" onchange="checkAll(this)" name="check.br" value="S_[]"/>
</th>
</tr>
</thead>
<tbody>
{LOOP}
<tr>
<td align="center">{ID}</td>
<td>{suggestion}</td>
<td align="center">{DTC}{suggestedOn}{/DTC}</td>
<td align="center">{submittedBy}</td>
<td>{approved}</td>
<td align="center">{DTC}{approvedOn}{/DTC}</td>
<td align="center">{approvedByName}</td>
<td>
<a href="{ROOT_URL}admin/suggestions/approve/{ID}" class="btn btn-sm btn-success" role="button"><i class="glyphicon glyphicon-ok"></i></a>
<a href="{ROOT_URL}admin/suggestions/reject/{ID}" class="btn btn-sm btn-danger" role="button"><i class="glyphicon glyphicon-remove"></i></a>
</td>
<td>
<a href="{ROOT_URL}admin/suggestions/view/{ID}" class="btn btn-sm btn-primary" role="button"><i class="glyphicon glyphicon-open"></i></a>
<a href="{ROOT_URL}admin/suggestions/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="BR_[]">
</td>
</tr>
{/LOOP}
{ALT}
<tr>
<td align="center" colspan="6">
No results to show.
</td>
</tr>
{/ALT}
</tbody>
</table>
<button name="submit" value="submit" type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>
<br />
<a href="{ROOT_URL}admin/suggestions/clear">clear all</a>

View File

@ -0,0 +1,17 @@
<div class="row">
<div class="col-lg-12 col-sm-12 blog-main">
<div class="blog-post">
<h2 class="blog-post-title">Suggestion</h2>
<hr>
<p class="blog-post-meta">{DTC date}{suggestedOn}{/DTC} by <a href="{ROOT_URL}home/profile/{author}">{submittedBy}</a></p>
{suggestion}
{ADMIN}
<hr>
<a href="{ROOT_URL}admin/suggestions/delete/{ID}" class="btn btn-md btn-danger" role="button">Delete</a>
<a href="{ROOT_URL}admin/suggestions/edit/{ID}" class="btn btn-md btn-warning" role="button">Edit</a>
<hr>
{/ADMIN}
</div><!-- /.suggestions-post -->
{COMMENTS}
</div><!-- /.suggestions-main -->
</div><!-- /.row -->

View File

@ -0,0 +1,16 @@
<form action="" method="post" class="form-horizontal">
<legend>Submit a Suggestion</legend>
<div class="form-group">
<label for="title" class="col-lg-3 control-label">Title</label>
<div class="col-lg-3">
<input type="text" class="form-check-input" name="title" id="title" value="{title}">
</div>
</div>
<div class="form-group center-block">
<div class="col-lg-8 col-lg-offset-2">
<textarea class="form-control" name="suggestion" maxlength="2000" rows="4" cols="50" id="suggestion"></textarea>
</div>
</div>
<button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary center-block">Submit</button>
<input type="hidden" name="token" value="{TOKEN}">
</form>

View File

@ -0,0 +1,15 @@
<form action="" method="post" class="form-horizontal">
<div class="form-group">
<label for="title" class="col-lg-3 control-label">Title</label>
<div class="col-lg-3">
<input type="text" class="form-check-input" name="title" id="title" value="{title}">
</div>
</div>
<div class="form-group center-block">
<div class="col-lg-4 col-lg-offset-4">
<textarea class="form-control" name="suggestion" maxlength="2000" rows="10" cols="50" id="suggestion">{suggestion}</textarea>
</div>
</div>
<button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary center-block">Save</button>
<input type="hidden" name="token" value="{TOKEN}">
</form>

View File

@ -0,0 +1,19 @@
<legend>Suggestions</legend>
{PAGINATION}
{LOOP}
<div class="blog-post">
<h2 class="blog-post-title"><a href="{ROOT_URL}suggestions/view/{ID}">{title}</a></h2>
<div class="well">
{suggestion}
<p class="blog-post-meta">
Suggested on <i>{DTC date}{suggestedOn}{/DTC}</i> by <a href="{ROOT_URL}home/profile/{author}"><strong>{submittedBy}</strong></a>
</p>
</div>
</div>
{/LOOP}
{ALT}
<div class="blog-post">
<p class="blog-post-meta">No Suggestions Found.</p>
</div>
{/ALT}
<a href="{ROOT_URL}suggestions/create" class="btn btn-sm btn-primary" role="button">Create</a>

View File

@ -0,0 +1,18 @@
<div class="row">
<div class="col-lg-12 col-sm-12 blog-main">
<div class="blog-post">
<h2 class="blog-post-title">{title}</h2>
<hr>
<p class="blog-post-meta">{DTC date}{suggestedOn}{/DTC} by <a href="{ROOT_URL}home/profile/{author}">{submittedBy}</a></p>
{suggestion}
{ADMIN}
<hr>
<a href="{ROOT_URL}admin/suggestions/delete/{ID}" class="btn btn-md btn-danger" role="button">Delete</a>
<a href="{ROOT_URL}admin/suggestions/edit/{ID}" class="btn btn-md btn-warning" role="button">Edit</a>
<hr>
{/ADMIN}
</div><!-- /.suggestions-post -->
{COMMENTS}
{NEWCOMMENT}
</div><!-- /.suggestions-main -->
</div><!-- /.row -->

View File

@ -0,0 +1,102 @@
<?php
/**
* app/plugins/wip/controllers/admin/wip.php
*
* This is the projects admin controller.
*
* @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\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\Projects;
class Wip extends AdminController {
public static $projects;
public function __construct() {
parent::__construct();
self::$projects = new Projects;
self::$title = 'Admin - Projects';
$view = Navigation::activePageSelect( 'nav.admin', '/admin/wip' );
Components::set( 'ADMINNAV', $view );
}
public function index( $data = null ) {
Views::view( 'wip.admin.list', self::$projects->listPaginated() );
}
public function create( $data = null ) {
if ( !Input::exists( 'submit' ) ) {
return Views::view( 'wip.admin.create' );
}
if ( !Forms::check( 'newProject' ) ) {
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
return $this->index();
}
$result = self::$projects->create( Input::post( 'title' ), Input::post( 'description' ), Input::post( 'progress' ), Input::post( 'startDate' ) );
if ( $result ) {
Issues::add( 'success', 'Your projects 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( 'wip.admin.edit', self::$projects->findById( $data ) );
}
if ( !Forms::check( 'editProject' ) ) {
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
return $this->index();
}
$fields = [
'title' => Input::post( 'title' ),
'description' => Input::post( 'description' ),
'progress' => Input::post( 'progress' ),
'startDate' => Input::post( 'startDate' ),
];
if ( self::$projects->update( $data, $fields ) ) {
Issues::add( 'success', 'Projects Updated.' );
return $this->index();
}
Issues::add( 'error', 'There was an error with your request.' );
$this->index();
}
public function view( $data = null ) {
$projectData = self::$projects->findById( $data );
if ( $projectData !== false ) {
return Views::view( 'wip.admin.view', $projectData );
}
Issues::add( 'error', 'Projects not found.' );
$this->index();
}
public function delete( $data = null ) {
if ( $data == null ) {
if ( Input::exists( 'P_' ) ) {
$data = Input::post( 'P_' );
}
}
if ( !self::$projects->delete( (array) $data ) ) {
Issues::add( 'error', 'There was an error with your request.' );
} else {
Issues::add( 'success', 'Projects has been deleted' );
}
$this->index();
}
}

View File

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

79
app/plugins/wip/forms.php Normal file
View File

@ -0,0 +1,79 @@
<?php
/**
* app/plugins/wip/forms.php
*
* This houses all of the form checking functions for this plugin.
*
* @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\Plugins\Wip;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Classes\Forms;
class WipForms extends Forms {
/**
* Adds these functions to the form list.
*/
public function __construct() {
self::addHandler( 'newProject', __CLASS__, 'newProject' );
self::addHandler( 'editProject', __CLASS__, 'editProject' );
}
/**
* Validates the new project post form.
*
* @return {bool}
*/
public static function newProject() {
if ( !Input::exists( 'title' ) ) {
self::addUserError( 'You must specify title' );
return false;
}
if ( !Input::exists( 'description' ) ) {
self::addUserError( 'You must specify description' );
return false;
}
if ( !Input::exists( 'progress' ) ) {
self::addUserError( 'You must specify progress' );
return false;
}
if ( !Input::exists( 'startDate' ) ) {
self::addUserError( 'You must specify startDate' );
return false;
}
return true;
}
/**
* Validates the edit project post form.
*
* @return {bool}
*/
public static function editProject() {
if ( !Input::exists( 'title' ) ) {
self::addUserError( 'You must specify title' );
return false;
}
if ( !Input::exists( 'description' ) ) {
self::addUserError( 'You must specify description' );
return false;
}
if ( !Input::exists( 'progress' ) ) {
self::addUserError( 'You must specify progress' );
return false;
}
if ( !Input::exists( 'startDate' ) ) {
self::addUserError( 'You must specify startDate' );
return false;
}
return true;
}
}
new WipForms;

View File

@ -0,0 +1,85 @@
<?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;
class Projects extends DatabaseModel {
public $tableName = 'projects';
public $databaseMatrix = [
[ 'title', 'varchar', '128' ],
[ 'description', 'text', '' ],
[ 'progress', 'int', '3' ],
[ 'startDate', '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;
}
$instance->prettyStart = $instance->startDate;
$out[] = $instance;
if ( !empty( $end ) ) {
$out = $out[0];
break;
}
}
return $out;
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* app/plugins/wip/plugin.php
*
* This houses all of the main plugin info and functionality.
*
* @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\Plugins;
use TheTempusProject\Classes\Plugin;
class Wip extends Plugin {
public $pluginName = 'TP Wip';
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 wip.';
public $configName = 'wip';
public $configMatrix = [
'enabled' => [
'type' => 'radio',
'pretty' => 'Enable the wip Feature.',
'default' => true,
],
];
public $main_links = [
[
'text' => 'WIP',
'url' => '{ROOT_URL}wip/index',
],
];
public $admin_links = [
[
'text' => '<i class="fa fa-fw fa-support"></i> Wip',
'url' => '{ROOT_URL}admin/wip',
],
];
}

View File

@ -0,0 +1,16 @@
<h2>Create Project</h2>
<form action="#" method="POST">
<label for="title">Title:</label><br>
<input type="text" id="title" name="title" required><br><br>
<label for="progress">Progress:</label><br>
<input type="text" id="progress" name="progress" required><br><br>
<label for="startDate">Start Month/Year:</label><br>
<input type="month" id="startDate" name="startDate" 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,16 @@
<h2>Edit Project</h2>
<form action="#" method="POST">
<label for="title">Title:</label><br>
<input type="text" id="title" name="title" value="{title}" required><br><br>
<label for="progress">Progress:</label><br>
<input type="text" id="progress" name="progress" value="{progress}" required><br><br>
<label for="startDate">Start Month/Year:</label><br>
<input type="month" id="startDate" name="startDate" value="{startDate}" 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>Works in Progress</legend>
{PAGINATION}
<form action="{ROOT_URL}admin/wip/delete" method="post">
<table class="table table-striped">
<thead>
<tr>
<th style="width: 30%">Title</th>
<th style="width: 20%">Progress</th>
<th style="width: 20%">Start Date</th>
<th style="width: 10%"></th>
<th style="width: 10%"></th>
<th style="width: 10%">
<INPUT type="checkbox" onchange="checkAll(this)" name="check.b" value="P_[]"/>
</th>
</tr>
</thead>
<tbody>
{LOOP}
<tr>
<td><a href="{ROOT_URL}admin/wip/view/{ID}">{title}</a></td>
<td>{progress}</td>
<td>{startDate}</td>
<td><a href="{ROOT_URL}admin/wip/edit/{ID}" class="btn btn-sm btn-warning" role="button"><i class="glyphicon glyphicon-edit"></i></a></td>
<td><a href="{ROOT_URL}admin/wip/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/wip/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,8 @@
<legend>WIP</legend>
<div class="wip-project">
<h3 class="wip-project-title">{name}</h3>
<p><b>{position}</b> from <i>{prettyStart}</i> to <i>{prettyEnd}</i></p>
<div class="well">
{details}
</div>
</div>

View File

@ -0,0 +1,19 @@
<h1>Work in Progress</h1>
<hr>
{LOOP}
<div class="wip-project">
<h3 class="wip-project-title">{title}</h3>
<p><b>Started: </b><i>{prettyStart}</i></p>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: {progress}%" aria-valuenow="{progress}" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="well">
{description}
</div>
</div>
{/LOOP}
{ALT}
<div class="wip-project">
<p>None Found</p>
</div>
{/ALT}