private static function _entityDecoder($attributes) { /* check social facebook instagram twitter */ $itemNo = NULL; switch ($attributes['type']) { case 'document': $itemNo = $attributes['itemno']; $entityType = Entity::mapType($attributes['type']); $entity = Document::findOne(['type' => 5, 'refId' => $attributes['id'], 'itemNo' => $itemNo]); break; default: $entityType = Entity::mapType($attributes['type']); $entity = Entity::getInstance($entityType, $attributes['id']); break; } if (empty($entity)) { return; } switch ($attributes['type']) { case 'document': $arr = explode(".", $entity->srcPath); $extension = $arr[count($arr) - 1]; $thumbnail = $extension . ".png"; $thumbnailUrl = Url::toRoute(['/global/img/' . $thumbnail]); $str = "<entity type=\"{$attributes['type']}\" data-itemno=\"{$attributes['itemno']}\" data-id=\"{$attributes['id']}\">"; $str .= '<img src="' . $thumbnailUrl . '" alt="" width="30" height="30">'; break; default: $str = "<entity type=\"{$attributes['type']}\" data-id=\"{$attributes['id']}\">" . $entity->getPreview(array(Media::ENCODE_WIDTH => 100)); break; } switch ($entityType) { case Entity::TYPE_PERSON: $caption = $entity->getDisplayName(); break; case Entity::TYPE_DOCUMENT: $caption = $entity->caption; break; default: $caption = $entity->title; } $str .= "<p class=\"caption\">" . Entity::$arrTitle[$entityType] . ": {$caption}</p></entity>"; return $str; }
private static function _entityDecoder($attributes, $matches) { if (isset($attributes['type'])) { switch ($attributes['type']) { case 'document': $entityType = Entity::mapType($attributes['type']); $itemNo = $attributes['data-itemno']; $entityType = Entity::mapType($attributes['type']); $entity = Document::findOne(['type' => 5, 'refId' => $attributes['data-id'], 'itemNo' => $itemNo]); break; default: $entityType = Entity::mapType($attributes['type']); $entity = Entity::getInstance($entityType, $attributes['data-id']); break; } } if (empty($entity)) { return; } switch ($entityType) { case Entity::TYPE_DOCUMENT: $result = self::_documentReplace($entity, $attributes); break; case Entity::TYPE_GALLERY: $result = self::_galleryReplace($entity, $attributes); break; case Entity::TYPE_FEED: $result = self::_feedReplace($entity, $attributes); break; case Entity::TYPE_QUOTE: $result = self::_quoteReplace($entity, $attributes); break; default: $result = $entity->getPreview(array(Media::ENCODE_WIDTH => 532)); break; } return $result; }
/** * @param $id - ID документа источника * @param bool $children true - дочерние, false - потомки * @return array * Вывод всех дочерних документов / потомков с ID массивом * Используются методы компонента Nested Intervals */ public static function getChilds($id, $children = true) { $childs = []; /** @var \paulzi\nestedintervals\NestedIntervalsBehavior $model */ $model = Document::findOne($id); if ($model) { if ($children) { $ch = $model->getChildren()->all(); } else { $ch = $model->getDescendants()->all(); } if ($ch) { foreach ($ch as $c) { $childs[$c->id] = $c->name . " (" . $c->id . ")"; } } } return $childs; }
/** * ให้ค่า instance ของ model ที่ระบุด้วย entity type และ $refId * @param int $type * @param int $refId * @return ActiveRecord */ public static function getInstance($type, $refId, $orderNo = NULL) { $instance = null; switch ($type) { case self::TYPE_ACTIVITY: $instance = Activity::findOne($refId); break; case self::TYPE_BLOG: $instance = Blogs::findOne($refId); break; case self::TYPE_CARTOON: $arr = preg_split('/-/', $refId); $instance = CartoonChapter::findOne(array('cartoonId' => $arr[0], 'chapter' => $arr[1])); break; case self::TYPE_CONTENT: $instance = Content::findOne($refId); break; case self::TYPE_DOCUMENT: $instance = Document::findOne(array('type' => $type, 'refId' => $refId, 'itemNo' => $orderNo)); break; case self::TYPE_FAQ: $instance = Faq::findOne($refId); break; case self::TYPE_FEEDCONTENT: $instance = FeedContent::findOne($refId); break; case self::TYPE_FEED: $instance = Feed::findOne($refId); break; case self::TYPE_GALLERY: $instance = Gallery::findOne($refId); break; case self::TYPE_INFOGRAPHIC: $instance = InfoGraphic::findOne($refId); break; case self::TYPE_LIVEREPORT: $instance = LiveReport::findOne($refId); break; case self::TYPE_LOTTERY: $instance = Lottery::findOne($refId); break; case self::TYPE_BUNNY: case self::TYPE_MEDIA_COLLECTION: $instance = MediaCollection::findOne($refId); break; case self::TYPE_NEWSPAPER: // temporary class for media upload $instance = new stdClass(); $instance->createTime = date('Y-m-d H:i:s'); break; case self::TYPE_NOVEL: $instance = Novel::findOne($refId); break; case self::TYPE_PERSON: $instance = Person::findOne($refId); break; case self::TYPE_SPORT_PLAYER: $instance = Player::findOne($refId); break; case self::TYPE_SPORT_TEAM: $instance = Team::findOne($refId); break; case self::TYPE_QUOTE: $instance = Quote::findOne($refId); break; case self::TYPE_WIDGET: $instance = Widget::findOne($refId); break; case self::TYPE_TV_ANCHOR: $instance = TvAnchor::findOne($refId); break; case self::TYPE_TV_PROGRAM: $instance = TvProgram::findOne($refId); break; case self::TYPE_TV_HIGHLIGHT: $instance = TvHighlight::findOne($refId); break; case self::TYPE_TV_SCHEDULE: $instance = TvSchedule::findOne($refId); break; case self::TYPE_USER: $instance = User::findOne($refId); break; case self::TYPE_VIDEO: $instance = Video::findOne($refId); break; case self::TYPE_VIDEO_PLAYLIST: $instance = VideoPlaylist::findOne($refId); break; case self::TYPE_WATCHTOPIC: $instance = WatchTopic::findOne($refId); break; case self::TYPE_WEATHER: $instance = WeatherForecast::findOne($refId); break; } return $instance; }
/** * Finds the Document model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Document the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Document::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Finds the Document model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Document the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { /** @var \common\models\Document $model */ $model = Document::findOne($id); if ($model !== null) { $model->last_parent_id = $model->parent_id; $model->last_template_id = $model->template_id; $model->initialization(); return $model; } else { throw new NotFoundHttpException('Страница не найдена.'); } }
private function saveData() { $request = \Yii::$app->request; $arrParams = $request->bodyParams; $arrPimaryKey = []; //type if (!empty($arrParams[1])) { $arrPimaryKey['type'] = $arrParams[1]; } //refId if (!empty($arrParams[2])) { $arrPimaryKey['refId'] = $arrParams[2]; } //itemNo if (!empty($arrParams[3])) { $arrPimaryKey['itemNo'] = $arrParams[3]; } $document = Document::findOne($arrPimaryKey); if ($document == null) { throw new HttpException(404); } $document->caption = $request->post('caption'); $document->tags = $request->post('tags'); if ($document->save()) { return 'บันทึกข้อมูลเอกสารแล้ว'; } else { throw new HttpException(500, join("\n", $document->getErrors())); } }