plugin wip

This commit is contained in:
Joey Kimsey
2024-12-17 22:45:47 -05:00
parent 0955fb4175
commit e537771708
42 changed files with 1043 additions and 693 deletions

View File

@ -51,17 +51,24 @@ class Suggestions extends Controller {
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 ) ) );
$plugin = new Comments;
if ( ! $plugin->checkEnabled() ) {
Components::set( 'NEWCOMMENT', '' );
Components::set( 'count', '' );
Components::set( 'COMMENTS', '' );
} else {
$comments = new CommentsModel;
Components::set( 'count', $comments->count( 'suggestion', $id ) );
Components::set( 'COMMENTS', Views::simpleView( 'comments.list', $comments->display( 10, self::$suggestions->tableName, $id ) ) );
Components::set( 'NEWCOMMENT', Views::simpleView( 'comments.create' ) );
}
Views::view( 'suggestions.view', $data );
}
@ -98,36 +105,40 @@ class Suggestions extends Controller {
}
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' );
Issues::add( 'error', 'There was an issue with your request. Please check the url and try again.' );
return $this->index();
}
$plugin = new Comments;
if ( ! $plugin->checkEnabled() ) {
Issues::add( 'error', 'Comments are disabled.' );
return $this->index();
}
switch ( $sub ) {
case 'post':
$content = self::$suggestions->findById( $data );
if ( empty( $content ) ) {
Session::flash( 'error', 'Unknown Content.' );
Redirect::to( 'suggestions' );
Issues::add( 'error', 'Unknown Content.' );
return $this->index();
}
return $commentsPlugin->formPost( self::$suggestions->tableName, $content, 'suggestions/view/' );
Redirect::to( 'suggestions' );
return $plugin->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' );
Issues::add( 'error', 'Unknown Comment.' );
return $this->index();
}
return $commentsPlugin->formEdit( self::$suggestions->tableName, $content, 'suggestions/view/' );
return $plugin->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' );
Issues::add( 'error', 'Unknown Comment.' );
return $this->index();
}
return $commentsPlugin->formDelete( self::$suggestions->tableName, $content, 'suggestions/view/' );
return $plugin->formDelete( self::$suggestions->tableName, $content, 'suggestions/view/' );
}
}
}