protected function importimagefromstr($media, $path, $flag) { $mediaIds = []; yii::info($media, __METHOD__); $hash = md5($media); if (($armodel = Asset::findOne(['mediahash' => $hash])) !== null) { return [$armodel->Id]; } $media_doc = ['filename' => $media, 'path' => '@media/' . $path . '/' . $media, 'uri' => $path . '/' . $media, 'description' => '', 'mimetype' => '', 'source' => '', 'embedcode' => '', 'mediahash' => $hash, 'metainfo' => '', 'createdBy' => 40, 'updatedBy' => 40, 'status' => 1]; $assetmodel = new Asset(); $assetmodel->load($media_doc, ''); $assetmodel->save(false); $mediaIds[] = $assetmodel->Id; try { $tag = Asset::loadTagmodel($flag, true); Asset::saveAssetTag($assetmodel, $tag); } catch (\yii\base\ErrorException $error) { Yii::info(print_r($error, true), __METHOD__); } return $mediaIds; }
/** * Save Asset with Tag * * @param Integer $assetId the Asset Id. * @return ActiveRecord Asset Model */ public function loadAsset($assetId) { if (($model = Asset::findOne($assetId)) !== null) { return $model; } else { //throw new NotFoundHttpException('The requested page does not exist.'); yii::warning('asset id= ' . $assetId . ' not found'); } }
/** * Save Asset with Tag * * @param Integer $assetId the Asset Id. * @return ActiveRecord Asset Model */ public function loadAsset($assetId) { if (($model = Asset::findOne($assetId)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * * @param integer $id media asset Id * @param string $table asset Table * @return \common\models\Asset */ public static function loadAssetmodel($id, $table) { if (($model = Asset::findOne(['remoteId' => $id, 'table' => $table])) !== null) { } else { $model = new Asset(); } return $model; }
/** * Finds the Asset model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Asset the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Asset::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }