PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/vendor/schmunk42/yii2-giiant/src/generators/crud/default/views/index.php

https://gitlab.com/I-NOZex/quiz
PHP | 255 lines | 199 code | 37 blank | 19 comment | 18 complexity | cf3ef0eba801962d664c576fe2a6aa93 MD5 | raw file
  1. <?php
  2. use yii\helpers\Inflector;
  3. use yii\helpers\StringHelper;
  4. /*
  5. * @var yii\web\View $this
  6. * @var schmunk42\giiant\generators\crud\Generator $generator
  7. */
  8. $urlParams = $generator->generateUrlParams();
  9. $nameAttribute = $generator->getNameAttribute();
  10. /** @var \yii\db\ActiveRecord $model */
  11. $model = new $generator->modelClass();
  12. $model->setScenario('crud');
  13. $modelName = Inflector::pluralize(StringHelper::basename($model::className()));
  14. $safeAttributes = $model->safeAttributes();
  15. if (empty($safeAttributes)) {
  16. /** @var \yii\db\ActiveRecord $model */
  17. $model = new $generator->modelClass();
  18. $safeAttributes = $model->safeAttributes();
  19. if (empty($safeAttributes)) {
  20. $safeAttributes = $model->getTableSchema()->columnNames;
  21. }
  22. }
  23. echo "<?php\n";
  24. ?>
  25. use yii\helpers\Html;
  26. use yii\helpers\Url;
  27. use <?= $generator->indexWidgetType === 'grid' ? 'yii\\grid\\GridView' : 'yii\\widgets\\ListView' ?>;
  28. /**
  29. * @var yii\web\View $this
  30. * @var yii\data\ActiveDataProvider $dataProvider
  31. <?php if ($generator->searchModelClass !== ''): ?>
  32. * @var <?= ltrim($generator->searchModelClass, '\\') ?> $searchModel
  33. <?php endif; ?>
  34. */
  35. <?php
  36. $this->title = Yii::t($generator->messageCategory, $modelName);
  37. $this->params['breadcrumbs'][] = $this->title;
  38. ?>
  39. <?php
  40. if($generator->accessFilter):
  41. ?>
  42. /**
  43. * create action column template depending acces rights
  44. */
  45. $actionColumnTemplates = [];
  46. if (\Yii::$app->user->can('<?=$permisions['view']['name']?>')) {
  47. $actionColumnTemplates[] = '{view}';
  48. }
  49. if (\Yii::$app->user->can('<?=$permisions['update']['name']?>')) {
  50. $actionColumnTemplates[] = '{update}';
  51. }
  52. if (\Yii::$app->user->can('<?=$permisions['delete']['name']?>')) {
  53. $actionColumnTemplates[] = '{delete}';
  54. }
  55. <?php
  56. endif;
  57. ?>
  58. if (isset($actionColumnTemplates)) {
  59. $actionColumnTemplate = implode(' ', $actionColumnTemplates);
  60. $actionColumnTemplateString = $actionColumnTemplate;
  61. } else {
  62. Yii::$app->view->params['pageButtons'] = Html::a('<span class="glyphicon glyphicon-plus"></span> ' . <?= $generator->generateString('New') ?>, ['create'], ['class' => 'btn btn-success']);
  63. $actionColumnTemplateString = "{view} {update} {delete}";
  64. }
  65. <?php
  66. echo '?>';
  67. ?>
  68. <div class="giiant-crud <?= Inflector::camel2id(StringHelper::basename($generator->modelClass), '-', true) ?>-index">
  69. <?=
  70. '<?php '.($generator->indexWidgetType === 'grid' ? '// ' : '') ?>
  71. <?php if ($generator->searchModelClass !== ''): ?>
  72. echo $this->render('_search', ['model' =>$searchModel]);
  73. <?php endif; ?>
  74. ?>
  75. <?php if ($generator->indexWidgetType === 'grid'): ?>
  76. <?= "<?php \yii\widgets\Pjax::begin(['id'=>'pjax-main', 'enableReplaceState'=> false, 'linkSelector'=>'#pjax-main ul.pagination a, th a', 'clientOptions' => ['pjax:success'=>'function(){alert(\"yo\")}']]) ?>\n"; ?>
  77. <h1>
  78. <?= "<?= Yii::t('{$generator->messageCategory}', '{$modelName}') ?>" ?>
  79. <small>
  80. List
  81. </small>
  82. </h1>
  83. <div class="clearfix crud-navigation">
  84. <?php
  85. if($generator->accessFilter){
  86. echo "<?php\n"
  87. ?>
  88. if(\Yii::$app->user->can('<?=$permisions['create']['name']?>')){
  89. <?php
  90. echo "?>\n"
  91. ?>
  92. <div class="pull-left">
  93. <?= '<?= ' ?>Html::a('<span class="glyphicon glyphicon-plus"></span> ' . <?= $generator->generateString(
  94. 'New'
  95. ) ?>, ['create'], ['class' => 'btn btn-success']) ?>
  96. </div>
  97. <?php
  98. echo "<?php\n}\n?>";
  99. }else{
  100. ?>
  101. <div class="pull-left">
  102. <?= '<?= ' ?>Html::a('<span class="glyphicon glyphicon-plus"></span> ' . <?= $generator->generateString(
  103. 'New'
  104. ) ?>, ['create'], ['class' => 'btn btn-success']) ?>
  105. </div>
  106. <?php
  107. }
  108. ?>
  109. <div class="pull-right">
  110. <?php
  111. $items = '';
  112. $model = new $generator->modelClass();
  113. ?>
  114. <?php foreach ($generator->getModelRelations($model) as $relation): ?>
  115. <?php
  116. // relation dropdown links
  117. $iconType = ($relation->multiple) ? 'arrow-right' : 'arrow-left';
  118. if ($generator->isPivotRelation($relation)) {
  119. $iconType = 'random';
  120. }
  121. $controller = $generator->pathPrefix.Inflector::camel2id(
  122. StringHelper::basename($relation->modelClass),
  123. '-',
  124. true
  125. );
  126. $route = $generator->createRelationRoute($relation, 'index');
  127. $label = Inflector::titleize(StringHelper::basename($relation->modelClass), '-', true);
  128. $items .= <<<PHP
  129. [
  130. 'url' => ['{$route}'],
  131. 'label' => '<i class="glyphicon glyphicon-arrow-right">&nbsp;' . {$generator->generateString($label)} . '</i>',
  132. ],
  133. PHP;
  134. ?>
  135. <?php endforeach; ?>
  136. <?= "<?= \n" ?>
  137. \yii\bootstrap\ButtonDropdown::widget(
  138. [
  139. 'id' => 'giiant-relations',
  140. 'encodeLabel' => false,
  141. 'label' => '<span class="glyphicon glyphicon-paperclip"></span> ' . <?= $generator->generateString(
  142. 'Relations'
  143. ) ?>,
  144. 'dropdown' => [
  145. 'options' => [
  146. 'class' => 'dropdown-menu-right'
  147. ],
  148. 'encodeLabels' => false,
  149. 'items' => [<?= $items ?>]
  150. ],
  151. 'options' => [
  152. 'class' => 'btn-default'
  153. ]
  154. ]
  155. );
  156. <?= '?>' ?>
  157. </div>
  158. </div>
  159. <hr />
  160. <div class="table-responsive">
  161. <?= '<?= ' ?>GridView::widget([
  162. 'layout' => '{summary}{pager}{items}{pager}',
  163. 'dataProvider' => $dataProvider,
  164. 'pager' => [
  165. 'class' => yii\widgets\LinkPager::className(),
  166. 'firstPageLabel' => <?= $generator->generateString('First') ?>,
  167. 'lastPageLabel' => <?= $generator->generateString('Last') ?>
  168. ],
  169. <?php if ($generator->searchModelClass !== ''): ?>
  170. 'filterModel' => $searchModel,
  171. <?php endif; ?>
  172. 'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'],
  173. 'headerRowOptions' => ['class'=>'x'],
  174. 'columns' => [
  175. <?php
  176. $actionButtonColumn = <<<PHP
  177. [
  178. 'class' => '{$generator->actionButtonClass}',
  179. 'template' => \$actionColumnTemplateString,
  180. 'urlCreator' => function(\$action, \$model, \$key, \$index) {
  181. // using the column name as key, not mapping to 'id' like the standard generator
  182. \$params = is_array(\$key) ? \$key : [\$model->primaryKey()[0] => (string) \$key];
  183. \$params[0] = \Yii::\$app->controller->id ? \Yii::\$app->controller->id . '/' . \$action : \$action;
  184. return Url::toRoute(\$params);
  185. },
  186. 'contentOptions' => ['nowrap'=>'nowrap']
  187. ],
  188. PHP;
  189. // action buttons first
  190. echo $actionButtonColumn;
  191. $count = 0;
  192. echo "\n"; // code-formatting
  193. foreach ($safeAttributes as $attribute) {
  194. $format = trim($generator->columnFormat($attribute, $model));
  195. if ($format == false) {
  196. continue;
  197. }
  198. if (++$count < $generator->gridMaxColumns) {
  199. echo "\t\t\t" . str_replace("\n", "\n\t\t\t", $format) . ",\n";
  200. } else {
  201. echo "\t\t\t/*" . str_replace("\n", "\n\t\t\t", $format) . ",*/\n";
  202. }
  203. }
  204. ?>
  205. ],
  206. ]); ?>
  207. </div>
  208. </div>
  209. <?= "<?php \yii\widgets\Pjax::end() ?>\n"; ?>
  210. <?php else: ?>
  211. <?= '<?= ' ?> ListView::widget([
  212. 'dataProvider' => $dataProvider,
  213. 'itemOptions' => ['class' => 'item'],
  214. 'itemView' => function ($model, $key, $index, $widget) {
  215. return Html::a(Html::encode($model-><?= $nameAttribute ?>), ['view', <?= $urlParams ?>]);
  216. },
  217. ]); ?>
  218. <?php endif; ?>