/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Team::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'team_name', $this->team_name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
?> <?php echo $form->field($model, 'birthday')->widget(DatePicker::className(), ['name' => 'dp_2', 'type' => DatePicker::TYPE_COMPONENT_PREPEND, 'pluginOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]); ?> <?php echo $form->field($model, 'address')->textInput(['placeholder' => "Nhập địa chỉ", 'value' => $user->address]); ?> <?php echo $form->field($model, 'telephone')->textInput(['placeholder' => "Nhập số điện thoại", 'value' => $user->telephone]); ?> <?php echo $form->field($model, 'imageFile')->fileInput(['placeholder' => "Upload ảnh"]); ?> <?php echo $form->field($model, 'avatar')->textInput(['placeholder' => "Nhập a", 'value' => $user->avatar]); ?> <?php echo $form->field($model, 'team')->widget(Select2::classname(), ['data' => ArrayHelper::map(Team::find()->all(), 'id', 'team_name'), 'options' => ['placeholder' => 'Select a team ...', 'multiple' => true], 'pluginOptions' => []]); ?> <div class="form-group"> <?php echo Html::submitButton('Submit', ['class' => 'btn btn-primary']); ?> </div> <?php ActiveForm::end();
public function getTeamName($teamid) { return Team::findOne($teamid)->team_name; }
if (Yii::$app->session->hasFlash('updateOK')) { ?> <div class="alert alert-success"> Updated successfully! </div> <?php } ?> <br /> <?php $gridColumns = [['class' => '\\kartik\\grid\\SerialColumn'], ['label' => 'Work Time', 'attribute' => 'work_time', 'value' => function ($data) { return $data->work_time . ' hour(s)'; }, 'mergeHeader' => true, 'hAlign' => GridView::ALIGN_CENTER, 'mergeHeader' => true], ['label' => 'Team', 'attribute' => 'team.team_name', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Team::find()->orderBy('team_name')->asArray()->all(), 'team_name', 'team_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Team']], 'mergeHeader' => true], ['label' => 'Process', 'attribute' => 'process.process_name', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Process::find()->orderBy('process_name')->asArray()->all(), 'process_name', 'process_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Process']], 'mergeHeader' => true], ['label' => 'Work Details', 'attribute' => 'work_name', 'mergeHeader' => true], ['label' => 'Comment', 'attribute' => 'comment', 'mergeHeader' => true]]; ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $gridColumns, 'hover' => true, 'striped' => false, 'headerRowOptions' => ['style' => 'color: black; background: #eee; border-color: #337ab7;']]); ?> <?php if ($model->user_id === Yii::$app->user->identity->id) { ?> <div class="form-group" style="text-align: right;"> <?php echo Html::a('<span class="glyphicon glyphicon-pencil"></span> Edit', 'index.php?r=timesheet/update&id=' . $model->id, ['class' => $model->status ? 'btn btn-primary disabled' : 'btn btn-primary']); ?> <?php
use kartik\editable\Editable; use common\models\User; use frontend\models\Process; use frontend\models\Timesheet; use frontend\models\Team; /* @var $this yii\web\View */ /* @var $searchModel frontend\models\WorkSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Chấm điểm timesheet'; $this->params['breadcrumbs'][] = $this->title; $formatter = Yii::$app->formatter; ?> <div class="work-index container-fluid"> <h1 style="text-align: center;"><?php echo Html::encode($this->title); ?> </h1> <?php $gridColumns = [['attribute' => 'timesheet.date', 'format' => 'date', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'width' => '13em', 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => ['pluginOptions' => ['autoClose' => true, 'format' => 'yyyy-mm-dd'], 'removeButton' => false], 'hAlign' => GridView::ALIGN_CENTER], ['label' => 'User', 'attribute' => 'user.full_name', 'width' => '15em', 'group' => true, 'subGroupOf' => 0, 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(User::find()->orderBy('full_name')->asArray()->all(), 'full_name', 'full_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Full name']]], ['attribute' => 'work_time', 'value' => function ($data) { return $data->work_time . ' hour(s)'; }, 'width' => '2em', 'mergeHeader' => true, 'hAlign' => GridView::ALIGN_CENTER], ['label' => 'Team', 'attribute' => 'team.team_name', 'width' => '5em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Team::find()->orderBy('team_name')->asArray()->all(), 'team_name', 'team_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Team']]], ['label' => 'Process', 'attribute' => 'process.process_name', 'width' => '9em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Process::find()->orderBy('process_name')->asArray()->all(), 'process_name', 'process_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Process']]], ['label' => 'Work Details', 'attribute' => 'work_name', 'mergeHeader' => true], ['label' => 'Comment', 'attribute' => 'comment', 'mergeHeader' => true], ['class' => 'kartik\\grid\\EditableColumn', 'label' => 'Point', 'attribute' => 'timesheet.point', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'subGroupOf' => 1, 'width' => '2.2em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Timesheet::find()->orderBy('point')->asArray()->all(), 'point', 'point'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Point']], 'hAlign' => GridView::ALIGN_CENTER, 'editableOptions' => ['header' => 'điểm', 'inputType' => \kartik\editable\Editable::INPUT_TEXT, 'format' => Editable::FORMAT_BUTTON, 'valueIfNull' => '<em style="color:red">Chưa chấm !</em>', 'preHeader' => '<i class="glyphicon glyphicon-edit"></i> Chấm ', 'type' => 'danger', 'placement' => 'left', 'options' => ['placeholder' => 'Chấm điểm ở đây']]], ['class' => 'kartik\\grid\\EditableColumn', 'label' => 'Director Comment', 'attribute' => 'timesheet.director_comment', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'subGroupOf' => 1, 'mergeHeader' => true, 'editableOptions' => ['header' => 'comment', 'inputType' => \kartik\editable\Editable::INPUT_TEXTAREA, 'valueIfNull' => '<em style="color:red">Chưa comment !</em>', 'preHeader' => '<i class="glyphicon glyphicon-edit"></i> Viết ', 'editableValueOptions' => ['style' => 'color: blue'], 'type' => 'warning', 'size' => 'lg', 'placement' => 'left', 'options' => ['placeholder' => 'Viết comment vào đây']]]]; ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $gridColumns, 'hover' => TRUE, 'striped' => FALSE]); ?> </div>
/** * Finds the Team model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Team the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Team::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use kartik\grid\ExpandRowColumn; use common\models\User; use frontend\models\Process; use frontend\models\Timesheet; use frontend\models\Team; /* @var $this yii\web\View */ /* @var $searchModel frontend\models\WorkSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'HBLab Timesheets'; $this->params['breadcrumbs'][] = $this->title; $formatter = Yii::$app->formatter; ?> <div class="work-index container-fluid"> <h1 style="text-align: center; margin-bottom: 40px;"><?php echo Html::encode($this->title); ?> </h1> <?php $gridColumns = [['attribute' => 'timesheet.date', 'format' => 'date', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'width' => '13em', 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => ['pluginOptions' => ['autoClose' => true, 'format' => 'yyyy-mm-dd'], 'removeButton' => false], 'hAlign' => GridView::ALIGN_CENTER], ['label' => 'User', 'attribute' => 'user.full_name', 'width' => '15em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(User::find()->orderBy('full_name')->asArray()->all(), 'full_name', 'full_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Full name']], 'group' => true, 'subGroupOf' => 0], ['attribute' => 'work_time', 'value' => function ($data) { return $data->work_time . ' hour(s)'; }, 'width' => '2em', 'mergeHeader' => true, 'hAlign' => GridView::ALIGN_CENTER], ['label' => 'Team', 'attribute' => 'team.team_name', 'width' => '5em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Team::find()->orderBy('team_name')->asArray()->all(), 'team_name', 'team_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Team']]], ['label' => 'Process', 'attribute' => 'process.process_name', 'width' => '9em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Process::find()->orderBy('process_name')->asArray()->all(), 'process_name', 'process_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Process']]], ['label' => 'Work Details', 'attribute' => 'work_name', 'mergeHeader' => true], ['label' => 'Comment', 'attribute' => 'comment', 'mergeHeader' => true], ['label' => 'Point', 'attribute' => 'timesheet.point', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'subGroupOf' => 1, 'width' => '2.2em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Timesheet::find()->orderBy('point')->asArray()->all(), 'point', 'point'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Point']], 'hAlign' => GridView::ALIGN_CENTER], ['label' => 'Director Comment', 'attribute' => 'timesheet.director_comment', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'subGroupOf' => 1, 'mergeHeader' => true]]; ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $gridColumns, 'hover' => TRUE, 'striped' => FALSE, 'rowOptions' => function ($model, $key, $index, $grid) { return ['id' => $model['timesheet_id'], 'onclick' => 'window.location.href = "index.php?r=timesheet/view&id="+this.id;']; }, 'panel' => ['heading' => '<span class="glyphicon glyphicon-list-alt"></span>', 'type' => GridView::TYPE_DEFAULT], 'toolbar' => [['content' => Html::a('<i class="glyphicon glyphicon-plus"></i> Create', ['work/create2', 'id' => Yii::$app->user->identity->id], ['class' => 'btn btn-success'])], '{toggleData}', '{export}'], 'export' => ['fontAwesome' => false, 'label' => 'Export']]); ?> </div>
public function actionCreate2() { $formatter = Yii::$app->formatter; $work = new Work(); $timesheet = new Timesheet(); $isUpdated = false; $isCreated = false; if (Yii::$app->request->post()) { $formAttributes = Yii::$app->request->post('createForm'); $date = $formAttributes['date']; $availTimesheet = Timesheet::find()->where(['date' => $date, 'user_id' => Yii::$app->user->identity->id])->one(); if ($availTimesheet) { // timesheet is available if ($availTimesheet->status) { Yii::$app->session->setFlash('CreateTimesheetFailed'); return $this->render('create'); } $work->timesheet_id = $availTimesheet->id; $availTimesheet->updated_at = time(); if ($availTimesheet->update()) { $isUpdated = true; } } else { $timesheet->created_at = time(); $timesheet->updated_at = time(); $timesheet->date = $date; $timesheet->user_id = Yii::$app->user->identity->id; $timesheet->point = 0; $timesheet->director_comment = ''; $timesheet->status = 0; if ($timesheet->save()) { $isCreated = true; } } if ($isUpdated || $isCreated && ($work->timesheet_id = $timesheet->id)) { $process = Process::find()->where(['process_name' => $formAttributes['process_name']])->one(); $team = Team::find()->where(['team_name' => $formAttributes['team_name']])->one(); $work->process_id = $process->id; $work->team_id = $team->id; $work->work_time = $formAttributes['work_time']; $work->work_name = $formAttributes['work_name']; $work->comment = $formAttributes['comment']; $work->created_at = time(); $work->updated_at = time(); if ($work->save()) { return $this->goBack(); } else { return $this->render('create'); } } } return $this->render('create'); }
public static function getUserTeams($id) { // get all team-member relations of user $teams_member = \frontend\models\TeamMember::find()->where(['user_id' => $id])->all(); // for each relation... foreach ($teams_member as $team_member) { // ...store team name in an array $user_team[] = \frontend\models\Team::find()->where(['id' => $team_member['team_id']])->one(); } return $user_team; }
/** * @return \yii\db\ActiveQuery */ public function getTeam() { return $this->hasOne(Team::className(), ['id' => 'team_id']); }