/** * @inheritdoc */ public function contentTemplate($model) { $template = ['descriptor' => ['class' => 'list-group-item-heading', 'tag' => 'h5'], 'description' => ['class' => 'list-group-item-text']]; $row = ['settings' => ['class' => 'expanded-only list-group-label-block']]; $context = $this->getContext(); $row[] = function ($widget, $model, $settings) { $parts = []; $parent = null; foreach ($model->objectTypeItem->parents as $parentRelationship) { if ($parentRelationship->parent->systemId === 'Individual') { continue; } if ($parentRelationship->parent->systemId === 'Invoice') { continue; } $parent = $model->getForeignField('parent:' . $parentRelationship->parent->systemId, [], $this->getContext()); if (!empty($parent)) { break; } } if (!empty($parent)) { $parts[] = Html::tag('span', $parent->model->objectType->title->upperSingular, ['class' => 'list-group-sub-label']); $parts[] = Html::tag('span', $parent->model->viewLink, ['class' => 'list-group-sub-value']); } else { $parts[] = Html::tag('span', 'Contributor', ['class' => 'list-group-sub-label']); $contributor = $widget->getItemFieldValue($model, 'parent:Individual:viewLink:contributor', []); if (empty($contributor)) { $parts[] = Html::tag('span', '<span class="empty">no one</span>', ['class' => 'list-group-sub-value']); } else { $parts[] = Html::tag('span', $contributor, ['class' => 'list-group-sub-value']); } } return implode($parts); }; if (!isset($context['relation']) || !in_array('parent:Invoice', $context['relation'])) { $row[] = function ($widget, $model, $settings) { $parts = []; $parts[] = Html::tag('span', 'Invoice', ['class' => 'list-group-sub-label']); $invoice = $widget->getItemFieldValue($model, 'parent:Invoice:viewLink', []); if (empty($invoice)) { $parts[] = Html::tag('span', '<span class="empty">none</span>', ['class' => 'list-group-sub-value']); } else { $parts[] = Html::tag('span', $invoice, ['class' => 'list-group-sub-value']); } return implode($parts); }; } else { $row[] = function ($widget, $model, $settings) { $parts = []; $parts[] = Html::tag('span', 'Contributor', ['class' => 'list-group-sub-label']); $contributor = $widget->getItemFieldValue($model, 'parent:Individual:viewLink:contributor', []); if (empty($contributor)) { $parts[] = Html::tag('span', '<span class="empty">none</span>', ['class' => 'list-group-sub-value']); } else { $parts[] = Html::tag('span', $contributor, ['class' => 'list-group-sub-value']); } return implode($parts); }; } $template[] = $row; if ($model->can('read')) { return $template; } else { return ['descriptor' => ['class' => 'list-group-item-heading', 'tag' => 'h5']]; } }
/** * @inheritdoc */ public function renderItemContent($model, $key, $index) { $descriptorContent = parent::renderItemContent($model, $key, $index); $parts = []; $parts[] = Html::beginTag('div', ['class' => 'ic-task-item row']); $parts[] = Html::beginTag('div', ['class' => 'col-xs-1']); $fields = $model->getFields(); $radioOptions = []; $relatedObject = null; if (isset(Yii::$app->request->object) && Yii::$app->request->object->primaryKey !== $model->primaryKey) { $relatedObject = Yii::$app->request->object; } if (!$model->can('update')) { $radioOptions['disabled'] = true; } elseif (!Html::prepareEditInPlace($radioOptions, $model, 'completedStatus', $relatedObject)) { $radioOptions['disabled'] = true; } $radioOptions['uncheckedValue'] = 0; $title = 'Task has not been completed'; if (!empty($model->completed)) { $title = 'Task was completed on ' . $model->completed; } $radioOptions['title'] = $title; Html::addCssClass($radioOptions, 'taskCompletedStatus'); $parts[] = Html::checkbox($fields['completedStatus']->formField->getModelFieldName(), !empty($model->completedStatus), $radioOptions); $parts[] = Html::endTag('div'); $parts[] = Html::beginTag('div', ['class' => 'col-xs-10 expandable-child']); $parts[] = $descriptorContent; $parts[] = Html::endTag('div'); $parts[] = Html::endTag('div'); return implode("", $parts); }