Initial commit
This commit is contained in:
153
app/plugins/polls/controllers/admin/polls.php
Normal file
153
app/plugins/polls/controllers/admin/polls.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/polls/controllers/admin/polls.php
|
||||
*
|
||||
* This is the Bug-Tracker admin controller.
|
||||
*
|
||||
* @package TP Polls
|
||||
* @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\Houdini\Classes\Forms as FormGen;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\Models\Poll as PollModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Models\Comments;
|
||||
|
||||
class Polls extends AdminController {
|
||||
protected static $polls;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$polls = new PollModel;
|
||||
self::$title = 'Admin - Polls';
|
||||
$view = Navigation::activePageSelect( 'nav.admin', '/admin/polls' );
|
||||
Components::set( 'ADMINNAV', $view );
|
||||
}
|
||||
|
||||
public function index( $data = null ) {
|
||||
Views::view( 'polls.admin.list', self::$polls->listSitePolls() );
|
||||
}
|
||||
|
||||
public function create( $data = null ) {
|
||||
Components::set( 'TRACKER_FORM', $form );
|
||||
if ( !Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'bugtracker.admin.create' );
|
||||
}
|
||||
if ( !Forms::check( 'newBugTracker' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'bugtracker.admin.create' );
|
||||
}
|
||||
$image = '';
|
||||
$result = self::$tracker->create(
|
||||
App::$activeUser->ID,
|
||||
Input::post( 'url' ),
|
||||
$image,
|
||||
Input::post( 'repeat' ),
|
||||
Input::post( 'description' ),
|
||||
Input::post( 'title' ),
|
||||
);
|
||||
if ( $result ) {
|
||||
Issues::add( 'success', 'Your tracker 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' ) ) {
|
||||
$bug = self::$tracker->findById( $data );
|
||||
$statusList = [
|
||||
TRACKER_STATUS_IN_PROGRESS => TRACKER_STATUS_IN_PROGRESS,
|
||||
TRACKER_STATUS_TESTING => TRACKER_STATUS_TESTING,
|
||||
TRACKER_STATUS_NEW => TRACKER_STATUS_NEW,
|
||||
TRACKER_STATUS_FIXED => TRACKER_STATUS_FIXED,
|
||||
TRACKER_STATUS_CLOSED => TRACKER_STATUS_CLOSED,
|
||||
];
|
||||
$form = '';
|
||||
$form .= FormGen::getFormFieldHtml( 'title', 'Title', 'text', $bug->title );
|
||||
$form .= FormGen::getFormFieldHtml( 'description', 'Description', 'block', $bug->description );
|
||||
$form .= FormGen::getFormFieldHtml( 'bugImage', 'Screenshot', 'file', $bug->image );
|
||||
$form .= FormGen::getFormFieldHtml( 'url', 'Page you were on', 'text', $bug->url );
|
||||
$form .= FormGen::getFormFieldHtml( 'repeat', 'Has this happened more than once', 'radio', $bug->repeatable );
|
||||
$form .= FormGen::getFormFieldHtml( 'status', 'Status', 'customSelect', $bug->status, $statusList );
|
||||
Components::set( 'TRACKER_FORM', $form );
|
||||
return Views::view( 'bugtracker.admin.edit', $bug );
|
||||
}
|
||||
$image = '';
|
||||
$tracker = self::$tracker->updateTracker(
|
||||
$data,
|
||||
Input::post( 'url' ),
|
||||
$image,
|
||||
Input::post( 'repeat' ),
|
||||
Input::post( 'description' ),
|
||||
Input::post( 'title' ),
|
||||
Input::post( 'status' )
|
||||
);
|
||||
if ( true === $tracker ) {
|
||||
Issues::add( 'success', 'Tracker Updated.' );
|
||||
return $this->index();
|
||||
}
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
if ( empty( self::$comments ) ) {
|
||||
self::$comments = new Comments;
|
||||
}
|
||||
$data = self::$tracker->findById( $id );
|
||||
if ( $data === false ) {
|
||||
Issues::add( 'error', 'Tracker not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
if ( Input::exists( 'contentId' ) ) {
|
||||
$this->comments( 'post', Input::post( 'contentId' ) );
|
||||
}
|
||||
if ( empty( self::$comments ) ) {
|
||||
self::$comments = new Comments;
|
||||
}
|
||||
Components::set( 'CONTENT_ID', $id );
|
||||
Components::set( 'COMMENT_TYPE', 'admin/bugtracker' );
|
||||
Components::set( 'count', self::$comments->count( 'tracker', $id ) );
|
||||
Components::set( 'NEWCOMMENT', Views::simpleView( 'comments.create' ) );
|
||||
Components::set( 'COMMENTS', Views::simpleView( 'comments.list', self::$comments->display( 10, 'tracker', $id ) ) );
|
||||
Views::view( 'bugtracker.admin.view', $data );
|
||||
}
|
||||
|
||||
public function delete( $data = null ) {
|
||||
if ( $data == null ) {
|
||||
if ( Input::exists( 'P_' ) ) {
|
||||
$data = Input::post( 'P_' );
|
||||
}
|
||||
}
|
||||
if ( !self::$polls->delete( $data ) ) {
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
} else {
|
||||
Issues::add( 'success', 'Poll has been deleted' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function close( $data = null ) {
|
||||
if ( !self::$polls->closeNow( $data ) ) {
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
} else {
|
||||
Issues::add( 'success', 'Poll has been ended' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
}
|
0
app/plugins/polls/controllers/polls.php
Normal file
0
app/plugins/polls/controllers/polls.php
Normal file
Reference in New Issue
Block a user