/** * Adds a resource to this attribute * @param AResource|CUploadedFile $item the resource, or an uploaded file * @return boolean whether the resource was added or not */ public function add($item) { if ($item instanceof CUploadedFile) { $item = AResource::fromUploadedFile($item); } $this->getResources(); $item->ownerModel = get_class($this->owner); $item->ownerId = $this->owner->primaryKey; $item->ownerAttribute = $this->name; if (!$item->save()) { return false; } if (!$this->multiple) { foreach ($this->_resources as $resource) { $resource->delete(); } } $this->_resources[] = $item; return true; }