172 lines
7.2 KiB
PHP
172 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use App\Http\Requests\LambdaRequest;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
class ForumTopicController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'forum';
|
|
$this->_module = 'forumtopic';
|
|
$this->_viewname = 'forumtopic';
|
|
$this->_title = 'Forum Topics';
|
|
$this->_base_url = '/forumtopic';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$forum_id = $request->session()->get('forum_id');
|
|
if($forum_id === 0) {
|
|
return redirect('/forums')->withError('Magazine not found!');
|
|
}
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all', ['forum_id' => $forum_id]);
|
|
//echo '<pre>'; print_r($response); exit;
|
|
$fields = $this->get_list_fields();
|
|
return $this->view('list')->with([
|
|
'title' => $this->_title,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $response->data->items,
|
|
'buttons' => $this->get_list_buttons()
|
|
]);
|
|
}
|
|
|
|
protected function get_list_buttons() {
|
|
return [ ['title' => 'Add New', 'link' => $this->_base_url.'/addnew' ], ['title' => 'Back to Forums', 'link' => '/forums'] ];
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete', 'comment' => ['icon' => 'comment', 'querystring' => 'id={ID}'] ] ],
|
|
// 'media_thumb' => ['title' => 'Media Thumb', 'type' => 'image'],
|
|
'title' => ['title' => 'Topic Name', 'type' => 'text'],
|
|
'description' => ['title' => 'Topic Description', 'type' => 'text'],
|
|
// 'points' => ['title' => 'Points', 'type' => 'text'],
|
|
// 'media_type' => ['title' => 'Media Type', 'type' => 'text'],
|
|
'up_votes' => ['title' => 'Up votes', 'type' => 'text'],
|
|
'down_votes' => ['title' => 'Down votes', 'type' => 'text'],
|
|
// 'comments_count' => ['title' => 'Comments', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$groups = $this->getlambda('get', 'ums', 'group', 'dropdown');
|
|
$groups_dd = [];
|
|
foreach($groups->data->items as $group){
|
|
$groups_dd[$group->id] = $group->name;
|
|
}
|
|
$fields = [
|
|
'title' => ['title' => 'Topic Name', 'type' => 'text', 'required' => true],
|
|
// 'points' => ['title' => 'Points', 'type' => 'text', 'required' => true],
|
|
'description' => ['title' => 'Topic Description', 'type' => 'textarea', 'required' => true, 'fullwidth' => true],
|
|
// 'media_type' => ['title' => 'Media Types', 'type' => 'select', 'required' => true, 'values' => ['image' => 'Image', 'video' => 'Video', 'pdf' => 'PDF', 'audio' => 'Audio', 'gallery' => 'Gallery', 'form' => 'Form', 'external' => 'External Url', 'scorm' => 'Scorm'] ],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
'attachment' => ['title' => 'Attachment', 'type' => 'text' ],
|
|
|
|
// 'media_thumb' => ['title' => 'Topic Thumb', 'type' => 'image', 'required' => true],
|
|
// 'media_url' => ['title' => 'Media File (image, video, pdf, audio, scorm) (for gallery, upload zip file with all images)', 'type' => 'file'],
|
|
// 'gallery' => ['title' => 'Multiple Media File (only for gallery)', 'type' => 'multiimage'],
|
|
// 'ext_url' => ['title' => 'Media Url (form, external)', 'type' => 'text'],
|
|
];
|
|
return $fields;
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
$data['forum_id'] = $request->session()->get('forum_id');
|
|
if($data['attachment'] == ""){
|
|
unset($data['attachment']);
|
|
}
|
|
// if( $request->file('media_thumb') ) {
|
|
// $data['media_thumb'] = $this->_uploadMedia($request, 'media_thumb', 'magazine_media_thumb');
|
|
// }
|
|
// if( $request->file('media_url') ) {
|
|
// $data['media_url'] = $this->_uploadMedia($request, 'media_url', 'magazine_media');
|
|
// }
|
|
// if($data['media_type'] == 'form' || $data['media_type'] == 'external') {
|
|
// $data['media_url'] = $data['ext_url'];
|
|
// }
|
|
// if($data['media_type'] == 'gallery') {
|
|
// $galleries = [];
|
|
// if($request->file('gallery')) {
|
|
// foreach($request->file('gallery') as $img) {
|
|
// $galleries[] = env('AWS_URL').'/'.$img->store('magazine_media', 's3');
|
|
// }
|
|
// }
|
|
// if(isset($data['gallery_existing'])) {
|
|
// foreach($data['gallery_existing'] as $gallery_existing) {
|
|
// $galleries[] = $gallery_existing;
|
|
// }
|
|
// }
|
|
// $data['media_url'] = json_encode($galleries);
|
|
// }
|
|
// unset($data['gallery_existing']);
|
|
// unset($data['gallery']);
|
|
// unset($data['ext_url']);
|
|
//echo '<pre>'; print_r($data); exit;
|
|
return $data;
|
|
}
|
|
|
|
protected function _beforeform($type, $values) {
|
|
// if($type == 'edit') {
|
|
// if($values->media_type == 'form' || $values->media_type == 'external') {
|
|
// $values->ext_url = $values->media_url;
|
|
// } else {
|
|
// $values->ext_url = '';
|
|
// }
|
|
// if($values->media_type == 'gallery' ) {
|
|
// $values->gallery = json_decode($values->media_url);
|
|
// }
|
|
// unset($values->user_info);
|
|
// unset($values->likes);
|
|
// unset($values->likes_users);
|
|
// unset($values->comments);
|
|
// unset($values->views);
|
|
// unset($values->comments_users);
|
|
// unset($values->likes_count);
|
|
// unset($values->comments_count);
|
|
|
|
// //echo '<pre>'; print_r($values); exit;
|
|
// }
|
|
return $values;
|
|
}
|
|
|
|
public function comment(Request $request) {
|
|
$topic_id = $request->input('id', 0);
|
|
// dd($forum_id);
|
|
if($topic_id === 0) {
|
|
return redirect('/forum')->withError('Forum Not found!');
|
|
} else {
|
|
$request->session()->put('topic_id', $topic_id);
|
|
return redirect('/comments');
|
|
}
|
|
|
|
}
|
|
|
|
public function form($type, $id = null) {
|
|
$values = [];
|
|
if($type == 'edit') {
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_one', ['id' => $id]);
|
|
// echo '<pre>'; print_r($response); exit;
|
|
$values = $response->data->item;
|
|
//echo '<pre>'; print_r($values); exit;
|
|
}
|
|
//echo '<pre>'; print_r($values); exit;
|
|
$data = $this->_beforeform($type, $values);
|
|
$fields = $this->get_form_fields($type, $values);
|
|
//echo '<pre>'; print_r($fields); exit;
|
|
return $this->view('form')->with([
|
|
'title' => $this->_title,
|
|
'mode' => $type,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'item' => $values,
|
|
]);
|
|
}
|
|
|
|
} |