| Current Path : /var/www/html/project/controllers/ |
| Current File : /var/www/html/project/controllers/TaskslogController.php |
<?php
namespace app\controllers;
use Yii;
use app\models\TasksLog;
use app\models\TasksLogSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use app\models\User;
/**
* TaskslogController implements the CRUD actions for TasksLog model.
*/
class TaskslogController extends Controller {
/**
* {@inheritdoc}
*/
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all TasksLog models.
* @return mixed
*/
public function actionIndex() {
$searchModel = new TasksLogSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single TasksLog model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new TasksLog model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($task_id) {
$model = new TasksLog();
$model->task_id = $task_id;
$model->created_dt = date("Y-m-d H:i:s");
$model->created_by = Yii::$app->user->identity->id;
if ($model->load(Yii::$app->request->post())) {
$model->file_url = UploadedFile::getInstance($model, 'file_url');
if (!empty($model->file_url)) {
$file_name = 'uploads/' . date("YmdHis") . '.' . $model->file_url->extension;
if ($model->file_url->saveAs($file_name))
$model->file_url = $file_name;
}
if ($model->save())
return $this->goBack();
}
return $this->render('create', ['model' => $model,]);
}
/**
* Updates an existing TasksLog model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id) {
$model = $this->findModel($id);
$original_file = $model->file_url;
if ($model->load(Yii::$app->request->post())) {
$model->file_url = UploadedFile::getInstance($model, 'file_url');
if (!empty($model->file_url)) {
$file_name = 'uploads/' . date("YmdHis") . '.' . $model->file_url->extension;
if ($model->file_url->saveAs($file_name))
$model->file_url = $file_name;
} else {
$model->file_url = $original_file;
}
if ($model->save())
return $this->goBack();
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing TasksLog model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete() {
if (($model = TasksLog::findOne($_POST['id'])) !== null) {
$model->delete();
return 'success';
}
}
/**
* Finds the TasksLog model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return TasksLog the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = TasksLog::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionGetlog() {
$output = '';
$User = new User();
$model = TasksLog::find()->where(['task_id' => $_POST['task_id']])->orderBy(['id' => SORT_DESC])->all();
if (!empty($model)) {
foreach ($model as $row) {
$attachment = '';
if (!empty($row->file_url)) {
$attachment = '<span class="ml-2 mr-2">|</span><a href="' . $row->file_url . '" class="kt-link kt-link--dark kt-timeline-v3__item-link kt-font-primary" target="_blank">
Download attachment
</a>';
}
$output .= '<div class="kt-timeline-v3__item kt-timeline-v3__item--info">
<span class="kt-timeline-v3__item-time text-nowrap">' . date("d M", strtotime($row->created_dt)) . '</span>
<div class="kt-timeline-v3__item-desc">
<span class="kt-timeline-v3__item-user-name kt-font-bold mr-5">By ' . $User->getusername($row->created_by) . '</span>
<a href="index.php?r=taskslog/update&id=' . $row->id . '">Update Log</a>
<span class="ml-2 mr-2">|</span>
<a href="#" onclick="deletelog(' . $row->id . ','.$row->task_id.')">Delete Log</a>
' . $attachment . '
<span class="kt-timeline-v3__item-text">' . $row->remarks . '</span>
</div>
</div>';
}
} else {
$output = 'No record found';
}
return $output;
}
public function actionGetlog2($task_id) {
$output = '';
$User = new User();
$model = TasksLog::find()->where(['task_id' => $task_id])->orderBy(['id' => SORT_DESC])->all();
if (!empty($model)) {
foreach ($model as $row) {
$attachment = '';
if (!empty($row->file_url)) {
$attachment = '<a href="' . $row->file_url . '" class="ml-5 kt-link kt-link--dark kt-timeline-v3__item-link kt-font-primary" target="_blank">
Download attachment
</a>';
}
$output .= '<div class="kt-timeline-v3__item kt-timeline-v3__item--info">
<span class="kt-timeline-v3__item-time text-nowrap">' . date("d M", strtotime($row->created_dt)) . '</span>
<div class="kt-timeline-v3__item-desc">
<span class="kt-timeline-v3__item-user-name kt-font-bold">By ' . $User->getusername($row->created_by) . '</span>
' . $attachment . '
<span class="kt-timeline-v3__item-text">' . $row->remarks . '</span>
</div>
</div>';
}
} else {
$output = 'No record found';
}
return $output;
}
}