I created a tabular data array as shown below
7136
7137
The problem is that it save every other thing to the table apart from the comment column as marked with yellow in the picture.
The attribute is scored_comment
Controller
<?php
namespace app\modules\inspection\controllers;
use Yii;
use app\modules\inspection\models\Inspection;
use app\modules\inspection\models\InspectionSearch;
use app\modules\inspection\models\ScoredItem;
use app\modules\inspection\models\ScoredEquipment;
use app\modules\inspection\models\ScoredItemScore;
use app\modules\inspection\models\ScoredEquipmentScore;
use app\modules\inspection\models\InspectionComment;
use app\modules\inspection\models\InspectionScore;
use app\modules\inspection\models\InspectionRatingScale;
use app\modules\inspection\models\InspectionBooking;
use app\modules\inspection\models\InspectionBookingSearch;
use app\modules\contractors\models\Inspector;
use app\modules\consumers\models\Building;
use app\modules\billing\models\Fee;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
//use yii\ArrayDataProvider;
use yii\helpers\ArrayHelper;
/**
* InspectorController implements the CRUD actions for Inspector model.
*/
class InspectionController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Creates a new Inspector model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionUpdate($building_id, $bip_id, $inspector_id)
{
$model = new InspectionBooking();
$rating = new InspectionRatingScale();
$scoreditem = new Scoreditem();
$scoreditems=$scoreditem->getBuildingScoreditem($building_id);
$scoreditemscore = new ScoredItemScore();
$scoreditemscore1=$scoreditemscore->getScore($building_id,$bip_id);
if(!isset($inspectioncomment))
$inspectioncomment = new InspectionComment();
if(isset($_POST['InspectionRatingScale'])){
foreach ($_POST['InspectionRatingScale']['scoreditem'] as $key=>$value)
{
$scoreditemscore = ScoredItemScore::find()->andWhere(['building_id' => $building_id, 'bookinspection_id' => $bip_id, 'item_id' => $key])->one();
if(!isset($scoreditemscore))
$scoreditemscore = new ScoredItemScore();
// die(var_dump($scoreditemscore));
$scoreditemscore->item_id=$key;
$scoreditemscore->rating=$value['rating_text'];
$scoreditemscore->date_inspected=Date("Y/m/d");
$scoreditemscore->date_updated= Date("Y/m/d");
$scoreditemscore->scored_comment= $_POST['ScoredItemScore']['scored_comment'];
$scoreditemscore->building_id=$building_id;
$scoreditemscore->bookinspection_id=$bip_id;
$scoreditemscore->inspector_id=$inspector_id;
$scoreditemscore->save();
}
if(isset($_POST['continue']))
{
$this->redirect(['view', 'building_id' => $building_id, 'bookinspection_id' => $bip_id, 'inspector_id' => $inspector_id ]);
}
}
return $this->render('update', [
'rating' => $rating,
'scoreditems' => $scoreditems,
'scoreditemscore'=>$scoreditemscore1,
]);
}
}
public static function getScore($id,$bookinspection_id)
{
$conection=Yii::$app()->db;
$sql="select b.rating_text, a.rating,a.building_rating, t.item_category, t.item_name,t.item_id from scored_item t left join inspection_score a on (t.item_id=a.scoreitem_id and a.building_id=$id) join inspection_rating_scale b on b.rating_id=a.rating where a.building_id=$id and a.bookinspection_id=$bookinspection_id";
$command=$conection->createCommand($sql);
$vappcom=$command->queryAll();
return $vappcom;
// return new CArrayDataProvider($vapp);
}
View
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\jui\DatePicker;
use kartik\grid\GridView;
use kartik\builder\TabularForm;
use kartik\widgets\Select2;
use kartik\depdrop\DepDrop;
use app\modules\inspection\models\Inspection;
use app\modules\inspection\models\ScoredItemScore;
use app\modules\inspection\models\ScoredEquipmentScore;
use app\modules\inspection\models\InspectionRatingScale;
use app\modules\inspection\models\InspectionBooking;
use app\modules\inspection\models\InspectionComment;
use app\modules\consumers\models\Building;
use app\modules\contractors\models\Inspector;
/* @var $this yii\web\View */
/* @var $model app\models\Inspector */
/*
$this->title = 'Update Inspection: ' . ' ' . $model->inspectionsheet_id;
$this->params['breadcrumbs'][] = ['label' => 'Inspectors', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->inspectionsheet_id, 'url' => ['view', 'id' => $model->inspectionsheet_id]];
$this->params['breadcrumbs'][] = 'Update';
*/
//$this->title = 'Building Inspection';
//$title = 'Inspection Sheet';
$this->title = 'Building Inspection';
$this->params['breadcrumbs'][] = $this->title;
?>
<style type="text/css">
/* tbody#special td+td+td {
background:red;
*/
tr.group,
tr.group:hover {
background-color: #ddd !important;
}
</style>
<div class="col-xs-12 col-lg-12">
<!--<div class="inspector-update"> -->
<!--</div>-->
<!--</div>-->
<div class="inspection-form">
<?php $form = ActiveForm::begin(['id' => 'inspection-form']); ?>
<h1>Inspection Sheet</h1>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">Scoring Items</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<!-- <th><input type="checkbox" id="check_all" /></th> -->
<th>#</th>
<th>Activity</th>
<th>Building Rating</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
<?php //$competencies=$competency->findAll();
$i = 1;
if(count($scoreditemscore)>=1){
foreach ($scoreditemscore as $cvalue)
{
?>
<tr>
<td><?php echo $i++;?></td>
<td><?php echo $cvalue['item_name'] ?></td>
<td>
<?php
$name="InspectionRatingScale[scoreditem][$cvalue[item_id]][rating_text]";
$yn=array("$cvalue[rating]"=>array('selected'=>true));
//echo $form->dropDownList($rating, 'rating_text', ArrayHelper::map($rating->findAll(),'rating_value','rating_text'),array('class'=>'form-control','name'=>$name,'options'=>$yn))->label(false);
echo $form->field($rating, 'rating_text')->dropDownList(ArrayHelper::map(\app\modules\inspection\models\InspectionRatingScale::find()->all(),'rating_value','rating_text'), ['name'=>$name,'options'=>$yn])->label(false);
?>
</td>
<td>
<?php echo $form->field($scoreditemscore, 'scored_comment')->textInput() ?>
</td>
</tr>
<?php
}
}
else{
foreach ($scoreditems as $cvalue)
{
?>
<tr>
<td><?php echo $i++;?></td>
<td><?php echo $cvalue['item_name'] ?></td>
<td>
<?php
$name="InspectionRatingScale[scoreditem][$cvalue[item_id]][rating_text]";
// echo $form->dropDownList($rating, 'rating_text', ArrayHelper::map($rating->findAll(''),'rating_value','rating_text'),array('class'=>'form-control','name'=>$name));
echo $form->field($rating, 'rating_text')->dropDownList(ArrayHelper::map(\app\modules\inspection\models\InspectionRatingScale::find()->all(),'rating_value','rating_text'), ['name'=>$name])->label(false);
// $listData=ArrayHelper::map($countries,'code','name');
// echo $form->field($model, 'name')->dropDownList($listData, ['prompt'=>'Choose...']);
// $name="InspectionRatingScale[scoreditem][$cvalue[rating_id]][rating_text]";
// echo $form->dropDownList($rating, 'rating_text', ArrayHelper::map($rating->findAll(),'rating_value','rating_text'),array('class'=>'form-control','name'=>$name));
?>
</td>
<td>
<?php
// die(var_dump($scoreditem));
$sc=new ScoredItemScore();
echo $form->field($sc, 'scored_comment')->textInput()->label(false);;
?>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->
<div class="form-group">
<div class="col-xs-12 col-sm-2 col-lg-2">
<button id="but" class="btn btn-primary btn-block btn-lg" name="cancel" type="submit">Cancel</button>
</div>
<div class="col-xs-12 col-sm-2 col-lg-2">
<button id="but1" class="btn btn-primary btn-block btn-lg" name="continue" type="submit">Continue >></button>
</div>
</div>
<?php ActiveForm::end(); ?>
</div> <!-- /.End of Inspection Sheet -->
</div> <!-- /.End of col-xs-12 col-lg-12 -->
<!-- page script -->
<script>
$(function () {
$("#example1").DataTable(
function groupTable($rows, startIndex, total){
if (total === 0){
return;
}
var i , currentIndex = startIndex, count=1, lst=[];
var tds = $rows.find('td:eq('+ currentIndex +')');
var ctrl = $(tds[0]);
lst.push($rows[0]);
for (i=1;i<=tds.length;i++){
if (ctrl.text() == $(tds[i]).text()){
count++;
$(tds[i]).addClass('deleted');
lst.push($rows[i]);
}
else{
if (count>1){
ctrl.attr('rowspan',count);
groupTable($(lst),startIndex+1,total-1)
}
count=1;
lst = [];
ctrl=$(tds[i]);
lst.push($rows[i]);
}
}
}
groupTable($('#example1 tr:has(td)'),0,3);
$('#example1 .deleted').remove();
);
$('#example2').DataTable({
"paging": true,
"lengthChange": false,
"searching": true, ///"searching": false,
"ordering": true,
"info": true,
"autoWidth": false
});
});
</script>