/** * Lists all Articlecomment models. * @return mixed */ public function actionIndex() { $list = ''; $post = Yii::$app->request->post(); if ($post['id']) { $mod = new Query(); $comment = $mod->select(['a.id', 'a.parentId', 'a.articleId', 'a.content', 'a.createTime', 'b.username'])->from('articlecomment as a')->leftJoin('user as b', 'a.userId = b.id')->where(['commentId' => $post['id']])->orderBy(['createTime' => 'DESC', 'id' => 'DESC'])->createCommand()->queryAll(); if ($comment) { foreach ($comment as $v) { $content = '回复@' . Articlecomment::getCommentByParId($v['parentId']) . ':' . $v['content']; $ahtml = html::a(html::tag("i", "", ["class" => "fa fa-thumbs-o-up"]) . html::tag("span", "回复"), ["/main/viewart", "id" => $v["articleId"], "parId" => $v['id']]); $list .= '<div class="infos small-comment' . $post['id'] . '" style="border:1px solid;"> <div class="media-body markdown-reply content-body"> <p>' . $content . '</p> <span class="opts pull-right"> <a class="author" >' . $v["username"] . '</a> • <addr title="' . $v["createTime"] . '">' . Html::tag("span", Yii::$app->formatter->asRelativeTime($v["createTime"])) . '</addr> ' . $ahtml . ' </span> </div> </div>'; } } } $result = array('success' => true, 'message' => $list); echo json_encode($result); die; return $this->renderAjax('index', ['success' => true, 'message' => '']); }
public static function defaultColumns() { return ['fqdn' => ['attribute' => 'fqdn', 'value' => function ($model) { return $model->fqdn; }], 'type' => ['value' => function ($model) { return strtoupper($model->type); }], 'value' => ['value' => function ($model) { return $model->getValueText(); }], 'zone' => ['class' => MainColumn::className(), 'label' => Yii::t('hipanel:dns', 'Zone'), 'attribute' => 'name'], 'actions' => ['class' => ActionColumn::className(), 'template' => '{update} {delete}', 'visibleButtonsCount' => 2, 'options' => ['style' => 'width: 15%'], 'buttons' => ['update' => function ($url, $model, $key) { if ($model->is_system) { return Html::tag('div', Html::a('<i class="fa fa-pencil"></i> ' . Yii::t('hipanel', 'Update'), null, ['class' => 'btn btn-default btn-xs disabled']), ['data-placement' => 'top', 'data-toggle' => 'tooltip', 'title' => Yii::t('hipanel:dns', 'This record was created by hosting panel automatically and cannot be updated'), 'style' => 'display: inline-block; cursor: not-allowed;']); } $data = Html::a('<i class="fa fa-pencil"></i> ' . Yii::t('hipanel', 'Update'), null, ['class' => 'btn btn-default btn-xs edit-dns-toggle', 'data' => ['record_id' => $model->id, 'hdomain_id' => $model->hdomain_id, 'load-url' => Url::to(['@dns/record/update', 'hdomain_id' => $model->hdomain_id, 'id' => $model->id])]]); $progress = Json::htmlEncode("<tr><td colspan='5'>" . Progress::widget(['id' => 'progress-bar', 'percent' => 100, 'barOptions' => ['class' => 'active progress-bar-striped', 'style' => 'width: 100%']]) . '</td></tr>'); Yii::$app->view->registerJs("\n \$('.edit-dns-toggle').click(function () {\n var record_id = \$(this).data('id');\n var hdomain_id = \$(this).data('hdomain_id');\n\n var currentRow = \$(this).closest('tr');\n var newRow = \$({$progress});\n\n \$(newRow).data({'record_id': record_id, hdomain_id: hdomain_id});\n \$('tr').filter(function () { return \$(this).data('id') == record_id; }).find('.btn-cancel').click();\n \$(newRow).insertAfter(currentRow);\n\n jQuery.ajax({\n url: \$(this).data('load-url'),\n type: 'GET',\n timeout: 0,\n error: function() {\n\n },\n success: function(data) {\n newRow.find('td').html(data);\n newRow.find('.btn-cancel').on('click', function (event) {\n event.preventDefault();\n newRow.remove();\n });\n }\n });\n\n });\n "); return $data; }, 'delete' => function ($url, $model, $key) { if ($model->type === 'ns' && $model->is_system) { return Html::tag('div', Html::a('<i class="fa text-danger fa-trash-o"></i> ' . Yii::t('hipanel', 'Delete'), null, ['class' => 'btn btn-default btn-xs disabled']), ['data-placement' => 'top', 'data-toggle' => 'tooltip', 'title' => Yii::t('hipanel:dns', 'This record is important for the domain zone viability and can not be deleted'), 'style' => 'display: inline-block; cursor: not-allowed;']); } return ModalButton::widget(['model' => $model, 'scenario' => 'delete', 'submit' => ModalButton::SUBMIT_PJAX, 'form' => ['action' => Url::to('@dns/record/delete')], 'button' => ['class' => 'btn btn-default btn-xs', 'label' => '<i class="fa text-danger fa-trash-o"></i> ' . Yii::t('hipanel', 'Delete')], 'modal' => ['header' => Html::tag('h4', Yii::t('hipanel:dns', 'Confirm DNS record deleting')), 'headerOptions' => ['class' => 'label-danger'], 'footer' => ['label' => Yii::t('hipanel:dns', 'Delete record'), 'data-loading-text' => Yii::t('hipanel:dns', 'Deleting record...'), 'class' => 'btn btn-danger']], 'body' => function ($model) { echo Html::activeHiddenInput($model, 'hdomain_id'); echo Yii::t('hipanel:dns', 'Are you sure, that you want to delete record {name}?', ['name' => $model->fqdn]); }]); }]]]; }
/** * @inheritdoc */ public function run() { $view = $this->getView(); $kcfinder = KCFinderAsset::register($view); if ($this->hasModel()) { if (!empty($this->model->icon)) { $this->src = $this->model->icon; } } //$this->options = array_merge($this->options, ['onclick'=>'openKCFinder(this);']); echo Html::tag('div', Html::img($this->src, ['id' => $this->widget['id'] . '-preview', 'class' => 'img-responsive']), ['class' => 'well well-sm text-center', 'style' => 'margin:5px;']); echo '<div class="input-group">'; if ($this->hasModel()) { echo Html::activeTextInput($this->model, $this->attribute, $this->options); } else { echo Html::textInput($this->name, $this->value, $this->options); } echo '<span class="input-group-btn"><button type="button" class="btn btn-default btn-flat" id="' . $this->widget['id'] . '-btn-clear"><i class="glyphicon glyphicon-remove"></i></button></span>'; echo '<span class="input-group-btn"><button type="button" class="btn btn-default btn-flat" id="' . $this->widget['id'] . '-btn-browse"><i class="glyphicon glyphicon-folder-open"></i></button></span>'; echo '</div>'; $session = Yii::$app->session; if (!$session->has('KCFINDER')) { $session->set('KCFINDER', ['disabled' => false, 'uploadDir' => $this->uploadDir, 'uploadURL' => $this->uploadURL]); $htSource = __DIR__ . '/upload.htaccess'; $htDest = $kcfinder->basePath . '/conf/upload.htaccess'; copy($htSource, $htDest); } $this->registerJs(); }
public function run() { BowerAssets::register($this->getView()); $this->jsOption = \yii\helpers\Json::encode($this->jsOption); $this->getView()->registerJs("\$('#{$this->getId()}').highcharts({$this->jsOption});"); return \yii\helpers\Html::tag('div', '', \yii\helpers\ArrayHelper::merge($this->option, ['id' => $this->getId()])); }
public static function renderOp($op) { $map = ['add' => 'success', 'replace' => 'warning', 'remove' => 'danger']; $class = isset($map[$op]) ? $map[$op] : 'default'; $content = $op; return Html::tag('span', $content, ['class' => 'label label-' . $class]); }
public function run() { if (empty($this->name) && (!empty($this->model) && !empty($this->attribute))) { $this->name = Html::getInputName($this->model, $this->attribute); } if (empty($this->url)) { $this->url = Url::toRoute(['site/upload']); } $options = ['url' => $this->url, 'paramName' => $this->name, 'params' => []]; if (Yii::$app->request->enableCsrfValidation) { $options['params'][Yii::$app->request->csrfParam] = Yii::$app->request->getCsrfToken(); } if (!empty($this->message)) { $message = Html::tag('div', $this->message, $this->messageOptions); } else { $message = ''; } $this->htmlOptions['id'] = $this->id; $this->options = ArrayHelper::merge($this->options, $options); echo Html::tag('div', $message, $this->htmlOptions); $this->registerAssets(); $this->createDropzone(); foreach ($this->eventHandlers as $event => $handler) { $handler = new \yii\web\JsExpression($handler); $this->getView()->registerJs($this->dropzoneName . ".on('{$event}', {$handler})"); } $this->addFiles($this->storedFiles); $this->decrementMaxFiles(count($this->storedFiles)); if ($this->sortable) { $options = Json::encode($this->sortableOptions); $this->getView()->registerJs("jQuery('#{$this->id}').sortable(" . $options . ");"); } }
public function run() { if ($this->hasModel()) { $replace['{input}'] = Html::activeHiddenInput($this->model, $this->attribute, $this->options); $attributeId = Html::getInputId($this->model, $this->attribute); $id = Html::getInputId($this->model, 'hydra_' . $this->attribute); $name = Html::getInputName($this->model, 'hydra_' . $this->attribute); $this->value = $this->model[$this->attribute]; } else { $replace['{input}'] = Html::hiddenInput($this->name, $this->value, $this->options); $name = $id = 'hydra_' . $this->name; $attributeId = $this->name; } $fileInputName = empty($this->fileInputName) ? $name : $this->fileInputName; $replace['{preview}'] = 'Файл еще не загружен'; if (!empty($this->value)) { $replace['{preview}'] = $this->value; $extension = Yii::$app->hydra->getExtension($this->value); if (Yii::$app->hydra->isImage($extension)) { $replace['{preview}'] = Html::img(Yii::$app->hydra->getCacheUrl($this->value, $this->resolution), ['id' => $id . '_image']); } $replace['{reset-button}'] = Html::tag($this->resetButton['tag'], $this->resetButton['label'], ArrayHelper::merge(['onClick' => '$("#' . $attributeId . '").val("");$("#' . $id . '_image' . '").remove();$(this).remove();'], $this->resetButton['options'])); } $replace['{input}'] .= Html::fileInput($fileInputName, null, ArrayHelper::merge(['id' => $id], $this->fileInput['options'])); return strtr($this->template, $replace); }
/** * @inheritdoc */ public function run() { echo Html::tag('div', null, ['id' => $this->containerId, 'style' => 'display:none']); $view = $this->getView(); PushStreamAsset::register($view); $options = Json::encode($this->pluginOptions); $channels = ''; foreach ((array) $this->channels as $channel) { $channels .= $this->pusher . ".addChannel('{$channel}');"; } $js = <<<JS var {$this->pusher} = new PushStream({$options}); {$channels} {$this->pusher}.onmessage = function (text, id, channel) { \$.each(text.events, function (index, event) { \$('#{$this->containerId}').trigger({ channel: channel, type: event.name, body: event.body }); }); }; JS; if ($this->connect) { $js .= $this->pusher . '.connect();'; } $view->registerJs($js); }
public function renderItem($model, $key, $index) { if ($this->itemView === null) { $content = $key; } elseif (is_string($this->itemView)) { $content = $this->getView()->render($this->itemView, array_merge(['model' => $model, 'key' => $key, 'index' => $index, 'widget' => $this, 'user' => $this->user], $this->viewParams)); } else { $content = call_user_func($this->itemView, $model, $key, $index, $this); } $options = $this->itemOptions; $tag = ArrayHelper::remove($options, 'tag', 'div'); if ($tag !== false) { $options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string) $key; $options['data-contact'] = $model['contact_id']; if (isset($this->clientOptions['unreadCssClass'])) { if ($model['new_messages'] > 0) { Html::addCssClass($options, $this->clientOptions['unreadCssClass']); } } if (isset($this->clientOptions['currentCssClass'])) { if ($model['contact_id'] == \Yii::$app->request->get('contactId')) { Html::addCssClass($options, $this->clientOptions['currentCssClass']); } } return Html::tag($tag, $content, $options); } else { return $content; } }
public function run() { // Get the JSON string $jsonstring = $_GET['jsonstring']; // Decode it into an array $jsonDecoded = json_decode($jsonstring, true, 64); // Run the function above $readbleArray = $this->parseJsonArray($jsonDecoded); // Loop through the "readable" array and save changes to DB foreach ($readbleArray as $key => $value) { // $value should always be an array, but we do a check if (is_array($value)) { $modelclass = $this->modelclass; $pks = (array) $modelclass::primaryKey(); $model = $modelclass::find()->where([join(',', $pks) => $value['id']])->one(); if ($this->scenario) { $model->setScenario($this->scenario); } $model->{$this->orderBy} = $key; $model->{$this->parentId} = $value['parentID']; $model->save(false); } } // Echo status message for the update echo Html::tag('div', Yii::t('claudejanz', "Order Updated on {date}", ['date' => Yii::$app->formatter->asDatetime(time())]), ['class' => 'alert alert-success']); }
/** * @inheritdoc */ public function run() { echo Html::beginTag('div', $this->options); echo Html::tag('div', $this->content, ['class' => 'ui sticky']); echo Html::endTag('div'); $this->registerPlugin('sticky'); }
/** * @return string */ public function run() { if (YII_ENV == 'prod') { try { \Yii::beginProfile("Run: " . $this->_token); $content = $this->_run(); \Yii::endProfile("Run: " . $this->_token); } catch (\Exception $e) { $content = \Yii::t('app', 'Error widget {class}', ['class' => $this->className()]) . " (" . $this->descriptor->name . "): " . $e->getMessage(); } } else { \Yii::beginProfile("Run: " . $this->_token); $content = $this->_run(); \Yii::endProfile("Run: " . $this->_token); } \Yii::$app->cmsToolbar->initEnabled(); if (\Yii::$app->cmsToolbar->editWidgets == Cms::BOOL_Y && \Yii::$app->cmsToolbar->enabled) { $pre = ""; /*$pre = Html::tag('pre', Json::encode($this->attributes), [ 'style' => 'display: none;' ]);*/ $id = 'sx-infoblock-' . $this->getId(); $this->getView()->registerJs(<<<JS new sx.classes.toolbar.EditViewBlock({'id' : '{$id}'}); JS ); return Html::tag('div', $pre . (string) $content, ['class' => 'skeeks-cms-toolbar-edit-view-block', 'id' => $id, 'title' => \Yii::t('app', "Double-click on the block will open the settings manager"), 'data' => ['id' => $this->getId(), 'config-url' => $this->getEditUrl()]]); } return $content; }
public function run() { $blockId = 'block_' . $this->id; $this->view->beginBlock($blockId); $inputFile = InputFile::begin(ArrayHelper::merge(['model' => $this->model, 'attribute' => $this->attribute, 'name' => $this->name, 'value' => $this->value], $this->fileInputOptions)); $inputId = $inputFile->options['id']; $previewId = 'media-' . $inputId; InputFile::end(); $this->view->endBlock(); $replace['{input}'] = $this->view->blocks[$blockId]; $replace['{img}'] = Html::tag('div', '', ['class' => 'form-media-preview', 'id' => $previewId]); echo strtr($this->template, $replace); $this->view->registerJs(<<<JS \$('#{$inputId}').change(function() { var src = \$(this).val(); if (src != '') { var img = \$('<img/>').attr('src', src); \$('#{$previewId}').wrapInner(img); } else { \$('#{$previewId}').empty(); } }).change(); JS ); }
protected function renderReloader() { $text = Html::tag('p', 'На изображении плохо видно буквы?'); $link = Html::tag('p', 'Нажмите сюда для обновления.', ['id' => 'verifycode-hint', 'class' => 'captcha-hint-link']); Html::addCssClass($options, 'captcha-hint'); return Html::tag('div', $text . $link, $options); }
protected function renderItem($item) { $this->validateItems($item); $template = ArrayHelper::getValue($item, 'template', $this->linkTemplate); $url = Url::to(ArrayHelper::getValue($item, 'url', '#')); $linkOptions_ar = ArrayHelper::getValue($item, 'linkOptions'); $linkOptions = ''; if (!empty($linkOptions_ar)) { foreach ($linkOptions_ar as $key => $value) { $linkOptions .= ' ' . $key . '="' . $value . '"'; } } if (empty($item['top'])) { if (empty($item['items'])) { $template = str_replace('{icon}', $this->indItem . '{icon}', $template); } else { $template = isset($item['template']) ? $item['template'] : '<a href="{url}" class="kv-toggle">{icon}{label}</a>'; $openOptions = $item['active'] ? ['class' => 'opened'] : ['class' => 'opened', 'style' => 'display:none']; $closeOptions = $item['active'] ? ['class' => 'closed', 'style' => 'display:none'] : ['class' => 'closed']; $indicator = Html::tag('span', $this->indMenuOpen, $openOptions) . Html::tag('span', $this->indMenuClose, $closeOptions); $template = str_replace('{icon}', $indicator . '{icon}', $template); } } $icon = empty($item['icon']) ? '' : '<span class="' . $this->iconPrefix . $item['icon'] . '"></span> '; unset($item['icon'], $item['top']); return strtr($template, ['{url}' => $url, '{label}' => $item['label'], '{icon}' => $icon, '{linkOptions}' => $linkOptions]); }
/** * @param null $key * * @return string */ public static function showFlash($key = null) { $session = \Yii::$app->getSession(); if (!$key) { $out = ''; foreach ($session->getAllFlashes(false) as $key => $value) { $out .= self::showFlash($key); } return $out; } else { switch ($key) { case "success": $htmlOptions = ["class" => "alert alert-success"]; break; case "error": $htmlOptions = ["class" => "alert alert-danger"]; break; case "info": $htmlOptions = ["class" => "alert alert-info"]; break; case "warning": $htmlOptions = ["class" => "alert alert-warning"]; break; default: $htmlOptions = ["class" => "alert alert-info"]; } if ($session->hasFlash($key)) { return Html::tag('div', $session->getFlash($key), $htmlOptions); } } }
function run() { foreach ($this->data as $n => $v) { if (isset($this->{$n})) { $this->{$n} = $v; } } $this->view->registerCssFile('http://code.ionicframework.com/ionicons/1.5.2/css/ionicons.min.css'); $link = $this->link; if (is_array($link)) { $link = Url::to($link); } if ($this->link_text === null) { $this->link_text = \Yii::t('app', 'More info'); } $html = "<!-- small box -->\n"; $html .= "<div class=\"col-lg-3 col-xs-6\">\n"; $html .= " <div class=\"small-box {$this->color}\">\n"; $html .= " <div class=\"inner\">"; $html .= Html::tag('h3', $this->count . Html::tag('sup', $this->count_type, ['style' => "font-size: 20px"])); $html .= Html::tag('p', $this->text); $html .= "</div>\n"; $html .= " <div class=\"icon\">"; $html .= Html::tag('i', '', ['class' => 'ion ' . $this->icon]); $html .= "</div>\n"; $html .= " "; $html .= Html::a($this->link_text . " <i class=\"fa fa-arrow-circle-right\"></i>", $link, ['class' => 'small-box-footer']); $html .= " </div>"; $html .= "</div>"; return $html; }
public static function show($name, $framework = 'glyphicon', $options = []) { new self(); $class = $framework . ' ' . $framework . '-' . $name; $options['class'] = empty($options['class']) ? $class : $class . ' ' . $options['class']; return Html::tag('span', null, $options) . ' '; }
/** * Renders the widget. */ public function run() { $contents = []; if ($this->inline) { if ($this->hasModel()) { $contents[] = Html::activeHiddenInput($this->model, $this->attribute, $this->options); } else { $contents[] = Html::hiddenInput($this->name, $this->value, $this->options); } $contents[] = Html::tag('div', '', $this->containerOptions); } else { if ($this->hasModel()) { $contents[] = Html::activeTextInput($this->model, $this->attribute, $this->options); } else { $contents[] = Html::textInput($this->name, $this->value, $this->options); } } echo implode("\n", $contents); if ($this->language) { DatePickerAsset::$extraJs[] = 'plugins/bootstrap-datepicker-extended/js/locales/bootstrap-datepicker.' . $this->language . '.js'; $this->clientOptions['language'] = $this->language; } DatePickerAsset::register($this->view); $this->registerPlugin('datepicker'); if ($this->inline) { $this->view->registerJs("\n !(function(\$){\n var el = \$('#{$this->options['id']}'),\n val = el.val(),\n container = \$('#{$this->containerOptions['id']}');\n container.on('changeDate', function(e){\n el.val(e.format());\n });\n if(val) {\n container.datepicker('update', new Date(Date.parse(val)));\n }\n })(jQuery);\n ", View::POS_READY); } }
protected function renderItems($items, $options = []) { $lines = []; foreach ($items as $i => $item) { if (isset($item['visible']) && !$item['visible']) { continue; } if (is_string($item)) { $lines[] = $item; continue; } if (!array_key_exists('label', $item)) { throw new InvalidConfigException("The 'label' option is required."); } $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels; $label = $encodeLabel ? Html::encode($item['label']) : $item['label']; $itemOptions = ArrayHelper::getValue($item, 'options', []); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []); $linkOptions['tabindex'] = '-1'; $url = array_key_exists('url', $item) ? $item['url'] : null; if (empty($item['items'])) { if ($url === null) { $content = $label; } else { $content = Html::a($label, $url, $linkOptions); } } else { $submenuOptions = $options; unset($submenuOptions['id']); $content = Html::a($label, $url === null ? '#' : $url, $linkOptions) . $this->renderItems($item['items'], $submenuOptions); } $lines[] = Html::tag('li', $content, $itemOptions); } return Html::tag('ul', implode("\n", $lines), $options); }
public function run() { return Html::ul($this->flatPageList, ['class' => $this->htmlClass, 'item' => function ($flatPage, $index) { $class = $flatPage->url == Yii::$app->controller->action->id ? $this->activeLiClass : null; return Html::tag('li', Html::a($flatPage->anchor, [$flatPage->url]), ['class' => $class]); }]); }
/** * Recursively renders the menu items (without the container tag). * @param array $items the menu items to be rendered recursively * @return string the rendering result */ protected function renderItems($items) { $n = count($items); $lines = []; foreach ($items as $i => $item) { $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', [])); $tag = ArrayHelper::remove($options, 'tag', 'li'); $class = []; if ($item['active']) { $class[] = $this->activeCssClass; } if ($i === 0 && $this->firstItemCssClass !== null) { $class[] = $this->firstItemCssClass; } if ($i === $n - 1 && $this->lastItemCssClass !== null) { $class[] = $this->lastItemCssClass; } if (!empty($class)) { if (empty($options['class'])) { $options['class'] = implode(' ', $class); } else { $options['class'] .= ' ' . implode(' ', $class); } } $menu = $this->renderItem($item); if (!empty($item['items'])) { $menu .= strtr($this->submenuTemplate, ['{show}' => $item['active'] ? "style='display: block'" : '', '{items}' => $this->renderItems($item['items'])]); } $lines[] = Html::tag($tag, $menu, $options); } return implode("\n", $lines); }
public function testCommon() { $url = 'https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=1K5pS0Rz6KrM0n-ju_CBm0DZxFkKyoyJd3Orhhk3MYz4&exportFormat=xlsx'; $path = Yii::getAlias('@tests/_output/AdvancedImporter.xlsx'); file_put_contents($path, file_get_contents($url)); $importer = new Importer(['filePath' => $path, 'sheetNames' => ['Data'], 'standardModelsConfig' => [['className' => Test::className(), 'labels' => ['Test', 'Tests'], 'standardAttributesConfig' => [['name' => 'type', 'valueReplacement' => Test::getTypesList()], ['name' => 'description', 'valueReplacement' => function ($value) { return $value ? Html::tag('p', $value) : ''; }], ['name' => 'author_id', 'valueReplacement' => function ($value) { return Author::find()->select('id')->where(['name' => $value]); }]]], ['className' => Question::className(), 'labels' => ['Question', 'Questions']], ['className' => Answer::className(), 'labels' => ['Answer', 'Answers']]]]); $result = $importer->run(); $this->assertEquals($importer->error, null); $this->assertEquals($result, true); $this->assertEquals(Test::find()->count(), 5); $this->assertEquals(Test::findOne(1)->attributes, ['id' => 1, 'name' => 'Basic test', 'type' => 2, 'description' => '<p>This is the basic test</p>', 'author_id' => 2]); $this->assertEquals(Test::findOne(2)->attributes, ['id' => 2, 'name' => 'Common test', 'type' => 1, 'description' => '', 'author_id' => 1]); $this->assertEquals(Test::findOne(3)->attributes, ['id' => 3, 'name' => 'Programming test', 'type' => 2, 'description' => '', 'author_id' => 2]); $this->assertEquals(Test::findOne(4)->attributes, ['id' => 4, 'name' => 'Language test', 'type' => 1, 'description' => '', 'author_id' => 1]); $this->assertEquals(Test::findOne(5)->attributes, ['id' => 5, 'name' => 'Science test', 'type' => 1, 'description' => '', 'author_id' => 1]); $this->assertEquals(Question::find()->count(), 5); $this->assertEquals(Question::findOne(1)->attributes, ['id' => 1, 'test_id' => 1, 'content' => "What's your name?", 'sort' => 1]); $this->assertEquals(Question::findOne(2)->attributes, ['id' => 2, 'test_id' => 1, 'content' => 'How old are you?', 'sort' => 2]); $this->assertEquals(Question::findOne(3)->attributes, ['id' => 3, 'test_id' => 5, 'content' => "What's your name?", 'sort' => 1]); $this->assertEquals(Question::findOne(4)->attributes, ['id' => 4, 'test_id' => 5, 'content' => 'How old are you?', 'sort' => 2]); $this->assertEquals(Question::findOne(5)->attributes, ['id' => 5, 'test_id' => 1, 'content' => 'Yes or no?', 'sort' => 1]); $this->assertEquals(Answer::find()->count(), 2); $this->assertEquals(Answer::findOne(1)->attributes, ['id' => 1, 'question_id' => 5, 'content' => 'Yes', 'sort' => 1]); $this->assertEquals(Answer::findOne(2)->attributes, ['id' => 2, 'question_id' => 5, 'content' => 'No', 'sort' => 2]); }
public function run() { $chatModel = new \nitm\widgets\models\Replies(['constrain' => ['type' => 'chat']]); $notificationModel = new \nitm\widgets\models\Notification(['constrain' => ['user_id' => \Yii::$app->user->getId()], 'queryOptions' => ['read' => 0]]); $uniqid = uniqid(); $chatWidget = Nav::widget(['encodeLabels' => false, 'options' => ['id' => 'communication-center-messages-wrapper' . $uniqid, 'class' => 'nav navbar-right navbar-nav'], 'items' => [['label' => Icon::show('comment') . Html::tag('span', $chatModel->hasNew(), ['class' => 'badge']), 'options' => ['class' => !$chatModel->hasNew() ? 'text-disabled' : 'text-success'], 'linkOptions' => ['id' => 'communication-center-messages-button' . $uniqid, 'title' => 'Click here again to refresh the info', 'role' => 'dynamicValue', 'data-run-once' => 1, 'data-animation-target' => '#chat' . $uniqid, 'data-animation-start-only' => 1, 'data-type' => 'html', 'data-id' => '#chat' . $uniqid, 'data-url' => \Yii::$app->urlManager->createUrl(['/reply/index/chat/0', '__format' => 'html', \nitm\widgets\models\Replies::FORM_PARAM => true])], 'items' => [['label' => Html::tag('div', Html::tag('h2', 'Loading Messages...', ['class' => 'text-center']) . Html::script('$("#communication-center-messages-button' . $uniqid . '").one("mouseover", function (event) { $(this).trigger("click"); })', ['type' => 'text/javascript']), ['role' => 'chatParent', 'id' => 'chat' . $uniqid, 'class' => '']), 'options' => $this->contentOptions]]]]]); $alertWidget = Nav::widget(['encodeLabels' => false, 'options' => ['id' => 'communication-center-notifications-wrapper' . $uniqid, 'class' => 'nav navbar-right navbar-nav'], 'items' => [['label' => Icon::show('bell') . Html::tag('span', $notificationModel->count(), ['class' => 'badge']), 'options' => ['class' => !$notificationModel->count() ? 'bg-disabled' : 'bg-success'], 'linkOptions' => ['id' => 'communication-center-notifications-button' . $uniqid, 'title' => 'Click here again to refresh the info', 'role' => 'dynamicValue', 'data-run-once' => 1, 'data-animation-target' => '#communication-center-notifications' . $uniqid, 'data-animation-start-only' => 1, 'data-type' => 'html', 'data-id' => '#communication-center-notifications' . $uniqid, 'data-url' => \Yii::$app->urlManager->createUrl(['/alerts/notifications', '__format' => 'html'])], 'items' => [['label' => Html::tag('div', Html::tag('h2', 'Loading Alerts...', ['class' => 'text-center']) . Html::script('$("#communication-center-notifications-button' . $uniqid . '").one("mouseover", function (event) { $(this).trigger("click"); })', ['type' => 'text/javascript']), ['id' => 'communication-center-notifications' . $uniqid, 'class' => '']), 'options' => $this->contentOptions]]]]]); $widget = $alertWidget . $chatWidget; //$js = "\$nitm.onModuleLoad('communication-center', function (module) { // module.initChatTabs('#".$this->options['id']."'); //});"; $js = ""; if ($this->chatUpdateOptions['enabled']) { $js .= "\$nitm.onModuleLoad('polling', function (module) {\r\n\t\t\t\tmodule.initPolling('chat', {\r\n\t\t\t\t\tenabled: true,\r\n\t\t\t\t\turl: '" . $this->chatUpdateOptions['url'] . "', \r\n\t\t\t\t\tinterval: " . $this->chatUpdateOptions['interval'] . ",\r\n\t\t\t\t\tcontainer: '#nitm-communication-center-widget" . $uniqid . "'\r\n\t\t\t\t}, {object: \$nitm.module('replies'), method: 'chatStatus'});\r\n\t\t\t});"; } if ($this->notificationUpdateOptions['enabled']) { $js .= "\r\n\t\t\t\$nitm.onModuleLoad('polling', function (module) {\r\n\t\t\t\tmodule.initPolling('notifications', {\r\n\t\t\t\t\tenabled: true,\r\n\t\t\t\t\tinterval: " . $this->notificationUpdateOptions['interval'] . ",\r\n\t\t\t\t\turl: '" . $this->notificationUpdateOptions['url'] . "',\r\n\t\t\t\t\tcontainer: '#nitm-communication-center-widget" . $uniqid . "'\r\n\t\t\t\t}, {object: \$nitm.module('notifications'), method: 'notificationStatus'});\r\n\t\t\t});"; } if ($js) { $js = Html::script($js, ['type' => 'text/javascript']); } return $widget . $js; }
/** * Inits pager */ protected function initPager() { $this->pager['firstPageLabel'] = Html::tag('i', '', ['class' => 'fa fa-angle-double-left']); $this->pager['lastPageLabel'] = Html::tag('i', '', ['class' => 'fa fa-angle-double-right']); $this->pager['prevPageLabel'] = Html::tag('i', '', ['class' => 'fa fa-angle-left']); $this->pager['nextPageLabel'] = Html::tag('i', '', ['class' => 'fa fa-angle-right']); }
protected function renderButtonAdd() { Html::addCssClass($this->buttonOptions, 'btn'); $this->buttonOptions = ArrayHelper::merge($this->buttonOptions, ['role' => 'area.add', 'data-tmpl' => $this->options['id']]); $templateButtonAdding = strtr($this->templateButtonAdding, ['{button}' => Html::button('+', $this->buttonOptions), '{label}' => Html::tag('label', $this->label)]); echo Html::tag('div', $templateButtonAdding, ['class' => 'form-group']); }
public function init() { $url = is_array($this->route) ? Url::to($this->route) : Url::to([$this->route, 'term' => 'QUERY']); $this->dataset = [['remote' => ['url' => $url, 'wildcard' => 'QUERY'], 'templates' => ['empty' => Html::tag('span', Yii::t('app', 'Hit enter to search'), ['class' => 'empty-search']), 'suggestion' => new JsExpression("Handlebars.compile('{$this->template}')")]]]; $this->pluginOptions = ['hint' => false]; parent::init(); }
/** * @return string */ protected function renderItems() { $html = ''; $textAlign = 'c-font-right'; $align = 'right'; foreach ($this->items as $item) { if ('right' == $align) { $html .= Html::beginTag('ul', ['class' => 'c-list']); } $html .= Html::beginTag('li'); $html .= Html::beginTag('div', ['class' => "c-card c-bg-white {$textAlign}", 'data-height' => 'height']); $html .= Html::tag('i', '', ['class' => "{$item['icon']} c-font-white c-font-27 c-theme-bg c-float-{$align}"]); $html .= Html::beginTag('div', ['class' => "c-content c-content-{$align}"]); $html .= Html::tag('h3', $item['title'], ['class' => "c-font-uppercase c-font-bold"]); $html .= Html::tag('p', $item['content']); $html .= Html::endTag('div'); $html .= Html::endTag('div'); $html .= Html::endTag('li'); if ('right' != $align) { $html .= Html::endTag('ul'); } $textAlign = 'c-font-right' == $textAlign ? '' : 'c-font-right'; $align = 'right' == $align ? 'left' : 'right'; } return $html; }
/** * Renders the hint tag. * @param string $content the hint content. It will NOT be HTML-encoded. * @param array $options the tag options in terms of name-value pairs. These will be rendered as * the attributes of the hint tag. The values will be HTML-encoded using [[Html::encode()]]. * * The following options are specially handled: * * - tag: this specifies the tag name. If not set, "div" will be used. * * @return static the field object itself */ public function hint($content, $options = []) { $options = array_merge($this->hintOptions, $options, ['id' => 'hint-' . Html::getInputId($this->model, $this->attribute)]); $tag = ArrayHelper::remove($options, 'tag', 'p'); $this->parts['{hint}'] = Html::tag($tag, $content, $options); return $this; }
public function renderItem($item) { $label = null; $url = $item['url']; $urlOptions = isset($item['urlOptions']) ? $item['urlOptions'] : null; $options = []; // Check whether label is required if ($this->label) { if (!isset($item['label'])) { throw new InvalidConfigException("The 'label' option is required."); } $label = $item['label']; } // Check whether icon is required if ($this->icon) { if (!isset($item['icon'])) { throw new InvalidConfigException("The 'icon' option is required."); } $icon = Html::tag('i', null, ['class' => $item['icon']]); $label = "<span class='wrap-icon'>{$icon}</span><span class='wrap-text'>{$label}</span>"; } if (isset($item['options'])) { $options = $item['options']; } return Html::tag('li', Html::a($label, $url, $urlOptions), $options); }