private function buildItems() { $tpl = $this->_config['itemTemplate']; $hasParams = preg_match('/@\\d+@/', $tpl) != false; Yii::trace('hasParams=' . $hasParams); $cats = Categories::findAll(array_keys($this->_config['filterCategories'])); foreach ($cats as $c) { if (!$c->isEmpty) { foreach ($c->resources as $r) { $t = $tpl; if ($hasParams) { $params = $r->getParams(); if ($params !== null) { $search = $replace = []; foreach ($params as $p) { $search[] = '@' . $p->type_id . '@'; $replace[] = $p->value; } $t = str_replace($search, $replace, $t); $t = preg_replace('/@\\d+@/', '', $t); //удаление лишних/не найденных } } $this->_items[] = str_replace($this->_ph, [$r->id, $r->created, $r->alias, $r->title, $r->description, '/' . $r->route], $t); } } } return implode('', $this->_items); }
public function getCategoryList($id = 0, $l = 0) { $cat = Categories::findAll(['parent_id' => $id]); $list = []; $level = $l; foreach ($cat as $c) { //$title = $t.$c->title; $t = $this->getCategoryList($c->id, $level + 1); $list[] = ['id' => $c->id, 'title' => $c->title, 'level' => $level, 'parent' => $id, 'child_count' => count($t)]; $list = array_merge($list, $t); } return $list; }
private function getChilds($item_id) { $node = true; $childs = Categories::findAll(['parent_id' => $item_id]); Yii::trace('Categories count: ' . count($childs)); if (!count($childs)) { $node = false; $childs = Resources::findAll(['category_id' => $item_id]); Yii::trace('Resources count: ' . count($childs)); } if (!count($childs)) { $_items = []; return; } foreach ($childs as $item) { $this->_items[] = ['id' => $item->id, 'title' => $item->title, 'url' => '/' . $item->route, 'node' => $node]; } }
public function actionCategories($id) { $categories = Categories::findAll(['race_id' => $id]); echo "<option>Selecciona una categoría</option>"; if ($categories) { foreach ($categories as $category) { echo "<option value='" . $category->category_id . "'>" . $category->category->name . "</option>"; } } }
$form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'header')->label('Заголовок:'); ?> <?php echo $form->field($model, 'text')->label('Текст:')->widget(\dosamigos\tinymce\TinyMce::className(), ['options' => ['rows' => 14], 'language' => 'ru', 'clientOptions' => ['plugins' => ["advlist autolink lists link charmap print preview anchor", "searchreplace visualblocks code fullscreen", "insertdatetime media table contextmenu paste image"], 'file_browser_callback' => new yii\web\JsExpression("function(field_name, url, type, win) {\n if(type=='image') \$('#file_upload_input').click();\n }"), 'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"]]); ?> <div class="form-group"> <label>Категория: </label> <?php echo Html::activeDropDownList($model, 'category_id', \yii\helpers\ArrayHelper::map(\app\models\Categories::findAll(['active' => true]), 'id', 'name'), ['class' => 'form-control']); ?> </div> <?php echo $form->field($model, 'date')->label('Дата:')->widget(DatePicker::className(), ['model' => $model, 'attribute' => 'date', 'language' => 'ru', 'options' => ['class' => 'form-control']]); ?> <?php echo $form->field($model, 'url')->label('Url:'); ?> <div class="form-group"> <div class="pull-right"> <?php