/** * @param Gallery $gallery * @param CmgFile $item * @return boolean */ public static function createItem($gallery, $item) { // Find User and Slider $modelFile = new ModelFile(); // Save Gallery Image FileService::saveImage($item, ['model' => $modelFile, 'attribute' => 'fileId']); // Save Gallery Item if ($item->id > 0) { $modelFile->parentType = CoreGlobal::TYPE_GALLERY; $modelFile->parentId = $gallery->id; $modelFile->save(); } return $item; }
/** * @return array - ModelFile associated with parent */ public function getModelFilesByType($type) { $parentType = $this->metaType; return $this->hasMany(ModelFile::className(), ['parentId' => 'id'])->where("parentType=:ptype AND type=:type", [':ptype' => $parentType, ':type' => $type])->all(); }