public function insert() { /** @var \app\services\GetArticle\ExtractorInterface $extractor */ $extractor = null; switch ($this->provider) { case 'verhosvet': $extractor = new \app\services\GetArticle\Verhosvet($this->url); break; case 'youtube': $extractor = new \app\services\GetArticle\YouTube($this->url); break; } if (is_null($extractor)) { throw new Exception('Не верный extractor'); } $row = $extractor->extract(); $articleObject = Article::insert(['header' => $row['header'], 'content' => $row['content'], 'description' => $row['description'], 'source' => $this->url, 'id_string' => Str::rus2translit($row['header']), 'date_insert' => gmdate('YmdHis'), 'tree_node_id_mask' => (new BitMask($this->tree_node_id_mask))->getMask()]); $this->id = $articleObject->getId(); $image = $row['image']; $imageContent = file_get_contents($image); $imageUrl = parse_url($image); $pathInfo = pathinfo($imageUrl['path']); $pathInfo['extension']; $fields = \cs\Widget\FileUpload2\FileUpload::save(File::content($imageContent), $pathInfo['extension'], ['image', 'Картинка', 0, 'string', 'widget' => [FileUpload::className(), ['options' => ['small' => \app\services\GsssHtml::$formatIcon]]]], $this); $articleObject->update($fields); return true; }
public function insert($fieldsCols = null) { return parent::insert(['beforeInsert' => function ($fields) { $fields['date_insert'] = gmdate('YmdHis'); $fields['id_string'] = Str::rus2translit($fields['header']); return $fields; }]); }
public function insert($fieldsCols = null) { $row = parent::insert(['beforeInsert' => function ($fields) { $fields['date_insert'] = time(); $fields['id_string'] = Str::rus2translit($fields['header']); return $fields; }]); $item = new \app\models\Service($row); $fields = []; if ($row['description'] == '') { $fields['description'] = GsssHtml::getMiniText($row['content']); } $item->update($fields); return $item; }
public function insert($fieldsCols = null) { $row = parent::insert(['beforeInsert' => function ($fields) { $fields['date_insert'] = time(); $fields['id_string'] = Str::rus2translit($fields['header']); $fields['date'] = gmdate('Y-m-d'); return $fields; }]); $item = new \app\models\Praktice($row); $fields = ['content' => Html::tag('p', Html::img(\cs\Widget\FileUpload2\FileUpload::getOriginal($item->getField('image')), ['class' => 'thumbnail', 'style' => 'width:100%;'])) . $item->getField('content')]; if ($row['description'] == '') { $item = new NewsItem($row); $fields['description'] = GsssHtml::getMiniText($row['content']); } $item->update($fields); return $item; }
public function insert($fieldsCols = null) { $row = parent::insert(['beforeInsert' => function ($fields) { $fields['date_insert'] = gmdate('YmdHis'); $fields['id_string'] = Str::rus2translit($fields['header']); return $fields; }]); $item = \app\models\Article::find($row['id']); $fields = []; if ($item->getField('description') == '') { $fields['description'] = GsssHtml::getMiniText($item->getField('content')); } if (count($fields) > 0) { $item->update($fields); } return $item; }
public function insert($fieldsCols = null) { $row = parent::insert(['beforeInsert' => function ($fields) { $fields['date_insert'] = gmdate('YmdHis'); $fields['id_string'] = Str::rus2translit($fields['header']); $fields['date'] = gmdate('Y-m-d'); return $fields; }]); $item = new \app\models\Article($row); $fields = []; if ($this->is_add_image) { $fields = ['content' => Html::tag('p', Html::img(\cs\Widget\FileUpload2\FileUpload::getOriginal($item->getImage()), ['class' => 'thumbnail', 'style' => 'width:100%;', 'alt' => $item->getField('header')])) . $item->getField('content')]; } if ($item->getField('description', '') == '') { $fields['description'] = GsssHtml::getMiniText($item->getField('content', '')); } $item->update($fields); return $item; }
public function insert($fieldsCols = null) { return parent::insert(['beforeInsert' => function ($fields) { if (Str::pos('<', $fields['content']) === false) { $rows = explode("\r", $fields['content']); $rows2 = []; foreach ($rows as $row) { if (trim($row) != '') { $rows2[] = Html::tag('p', trim($row)); } } $fields['content'] = join("\r\r", $rows2); } $fields['date_insert'] = gmdate('YmdHis'); $fields['id_string'] = Str::rus2translit($fields['header']); $fields['date'] = gmdate('Y-m-d'); return $fields; }]); }
/** * Добавить послание из GetArticle * * @param \app\services\GetArticle\ExtractorInterface $extractor * * @return static * @throws \yii\base\Exception */ public static function insertExtractorInterface($extractor) { $row = $extractor->extract(); if (is_null($row['header'])) { throw new Exception('Нет заголовка'); } if ($row['header'] == '') { throw new Exception('Нет заголовка'); } if (is_null($row['description'])) { throw new Exception('Нет описания'); } if ($row['description'] == '') { throw new Exception('Нет описания'); } $fields = ['header' => $row['header'], 'content' => $row['content'], 'description' => $row['description'], 'source' => $extractor->getUrl(), 'id_string' => Str::rus2translit($row['header']), 'date_insert' => gmdate('YmdHis'), 'date' => gmdate('Ymd'), 'img' => '']; $articleObject = self::insert($fields); $model = new \app\models\Form\Chenneling(); $model->id = $articleObject->getId(); $image = $row['image']; if ($image) { try { $imageContent = file_get_contents($image); $imageUrl = parse_url($image); $pathInfo = pathinfo($imageUrl['path']); $pathInfo['extension']; $fields = FileUpload::save(File::content($imageContent), $pathInfo['extension'], ['img', 'Картинка', 0, 'string', 'widget' => [FileUpload::className(), ['options' => ['small' => \app\services\GsssHtml::$formatIcon]]]], $model); $articleObject->update($fields); } catch (\Exception $e) { } } return $articleObject; }