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,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/' );
}
}
}