public function update($fieldsCols = null) { $fields = parent::update(['beforeUpdate' => function ($fields, \app\models\Form\Chenneling $model) { if ($fields['description'] == '') { $fields['description'] = GsssHtml::getMiniText($fields['content']); } return $fields; }]); $item = \app\models\Chenneling::find($this->id); if ($this->is_add_image) { $content = Html::tag('p', Html::img(\cs\Widget\FileUpload2\FileUpload::getOriginal($item->getField('img')), ['class' => 'thumbnail', 'style' => 'width:100%;', 'alt' => $item->getField('header')])) . $item->getField('content'); $item->update(['content' => $content]); } return $fields; }
public static function chennelingItem($row) { if (!is_array($row)) { $id = $row; $item = \app\models\Chenneling::find($id); if (is_null($item)) { return ''; } $row = $item->getFields(); } // Заголовок $html[] = Html::tag('div', Html::tag('h4', $row['header']), ['class' => 'header']); // Дата $html[] = Html::tag('p', self::dateString($row['date']), Html::css(['font-size' => '70%', 'color' => '#808080'])); // картинка с ссылкой $year = substr($row['date'], 0, 4); $month = substr($row['date'], 5, 2); $day = substr($row['date'], 8, 2); $html[] = Html::tag('p', Html::a(Html::img($row['img'], ['width' => '100%', 'class' => 'thumbnail']), "/chenneling/{$year}/{$month}/{$day}/{$row['id_string']}")); // Описание $html[] = Html::tag('p', $row['description']); return Html::tag('div', join('', $html), ['class' => 'col-sm-4 chennelingItem']); }
public function actionChenneling_item($year, $month, $day, $id) { $date = $year . $month . $day; $pattern = '#^[a-z\\d_-]+$#'; if (!preg_match($pattern, $id)) { throw new BadRequestHttpException('Имеются запрещенные символы'); } $item = Chenneling::find(['date' => $date, 'id_string' => $id]); if (is_null($item)) { throw new HttpException(404, 'Нет такого послания'); } $item->incViewCounter(); $nearList = Chenneling::query()->select('id,header,id_string,img,view_counter,description,content, date_insert')->orderBy(['date_insert' => SORT_DESC])->andWhere(['not in', 'id', $item->getId()])->limit(3)->all(); return $this->render(['item' => $item->getFields(), 'nearList' => $nearList]); }
/** * AJAX * Добавляет site_update * Делает рассылку * * @param integer $id - идентификатор послания * * @return string */ public function actionChenneling_list_subscribe($id) { $item = Chenneling::find($id); if (is_null($item)) { return self::jsonError(101, 'Не найдено послание'); } Subscribe::add($item); SiteUpdate::add($item); $item->update(['is_added_site_update' => 1]); return self::jsonSuccess(); }