本文整理汇总了PHP中Media::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Media::setAttributes方法的具体用法?PHP Media::setAttributes怎么用?PHP Media::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Media
的用法示例。
在下文中一共展示了Media::setAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveAndDeleteMedia
private function saveAndDeleteMedia($type)
{
/** @var $model Media [ ] */
$model = new Media();
$mockRecord = $this->getMockRecord();
$instruction = Deal::model()->findByPk($mockRecord['med_row']);
$this->assertNotEmpty($instruction, "instruction not exist");
$property = Property::model()->findByPk($instruction->dea_prop);
$this->assertNotEmpty($property, "property not exist");
$this->assertNotNull($property->addressId, "property has no address");
$address = Address::model()->findByPk($property->addressId);
$this->assertNotEmpty($address, " Address not exist");
$model->setAttributes($this->getMockRecord());
$model->file = $this->getMockCuploadedImage('image/jpeg', 1);
if ($type == Media::TYPE_PHOTO) {
$model->setCropFactor($this->getCropFactor());
} elseif ($type == Media::TYPE_EPC || $type == Media::TYPE_FLOORPLAN) {
$model->otherMedia = $type;
}
$this->assertTrue($model->validate(), "record not validated");
$this->assertTrue($model->save(), "record not saved");
foreach ($model->getImageSizes() as $imageSize) {
$this->assertFileExists($model->getFullPath($imageSize), $imageSize . " does not exist");
}
$this->deleteMedia($model->med_id);
}
示例2: saveAssociatedMedia
/**
* Save uploaded file and add associated media object
*/
public function saveAssociatedMedia($file)
{
if (!$file instanceof CUploadedFile) {
return;
}
$fileAttribute = $this->fileAttribute;
$media = new Media();
$username = Yii::app()->user->getName();
// file uploaded through form
$tempName = $file->getTempName();
$media->setAttributes(array('associationType' => $this->associationType, 'associationId' => $this->getAssociationId(), 'uploadedBy' => $username, 'createDate' => time(), 'lastUpdated' => time(), 'fileName' => preg_replace('/ /', '_', $file->getName()), 'mimetype' => $file->type), false);
$media->resolveNameConflicts();
if (!$media->save()) {
throw new CException(implode(';', $media->getAllErrorMessages()));
}
if (!FileUtil::ccopy($tempName, "uploads/protected/media/{$username}/{$media->fileName}")) {
throw new CException();
}
}
示例3: save
public function save($runValidation = true, $attributes = null)
{
if ($this->photo) {
// save related photo record
$transaction = Yii::app()->db->beginTransaction();
try {
// save the event
$ret = parent::save($runValidation, $attributes);
if (!$ret) {
throw new CException(implode(';', $this->getAllErrorMessages()));
}
// add media record for file
$media = new Media();
$media->setAttributes(array('fileName' => $this->photo->getName(), 'mimetype' => $this->photo->type), false);
$media->resolveNameConflicts();
if (!$media->save()) {
throw new CException(implode(';', $media->getAllErrorMessages()));
}
// save the file
$tempName = $this->photo->getTempName();
$username = Yii::app()->user->getName();
if (!FileUtil::ccopy($tempName, "uploads/protected/media/{$username}/{$media->fileName}")) {
throw new CException();
}
// relate file to event
$join = new RelationshipsJoin('insert', 'x2_events_to_media');
$join->eventsId = $this->id;
$join->mediaId = $media->id;
if (!$join->save()) {
throw new CException(implode(';', $join->getAllErrorMessages()));
}
$transaction->commit();
return $ret;
} catch (CException $e) {
$transaction->rollback();
return false;
}
} else {
return parent::save($runValidation, $attributes);
}
}
示例4: convertToMedia
public function convertToMedia(array $attributes = array())
{
$username = Yii::app()->user->getName();
$name = $this->name;
$tempFilename = 'uploads/protected/media/temp/' . $this->folder . '/' . $this->name;
if (FileUtil::ccopy($tempFilename, "uploads/protected/media/{$username}/{$name}")) {
$model = new Media();
$model->name = $model->fileName = $name;
$model->uploadedBy = $username;
$model->createDate = time();
$model->lastUpdated = time();
$model->resolveType();
$model->resolveSize();
$model->setAttributes($attributes, false);
if ($model->save()) {
return $model;
}
}
return false;
}
示例5: actionUpload
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionUpload()
{
$model = new Media();
if (isset($_POST['Media'])) {
$temp = TempFile::model()->findByPk($_POST['TempFileId']);
$userFolder = Yii::app()->user->name;
// place uploaded files in a folder named with the username of the user that uploaded the file
$userFolderPath = 'uploads/protected/media/' . $userFolder;
// if user folder doesn't exit, try to create it
if (!(file_exists($userFolderPath) && is_dir($userFolderPath))) {
if (!@mkdir('uploads/protected/media/' . $userFolder, 0777, true)) {
// make dir with edit permission
// ERROR: Couldn't create user folder
var_dump($userFolder);
exit;
}
}
rename($temp->fullpath(), $userFolderPath . '/' . $temp->name);
// save media info
$model->fileName = $temp->name;
$model->createDate = time();
$model->lastUpdated = time();
$model->uploadedBy = Yii::app()->user->name;
$model->setAttributes($_POST['Media']);
$model->path;
// File type setter is embedded in the magic getter for path
if (empty($model->name)) {
$model->name = $model->fileName;
}
if (empty($model->associationType)) {
$model->associationType = 'none';
}
if ($model->save()) {
$this->createAttachmentAction($model);
$this->redirect(array('view', 'id' => $model->id));
}
}
/*
uncomment when media module supports custom forms
if(isset($_POST['x2ajax'])){
$this->renderInlineCreateForm ($model, isset ($ajaxErrors) ? $ajaxErrors : false);
} else { */
$this->render('upload', array('model' => $model));
//}
}