本文整理汇总了PHP中Attachment::setName方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachment::setName方法的具体用法?PHP Attachment::setName怎么用?PHP Attachment::setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attachment
的用法示例。
在下文中一共展示了Attachment::setName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: body
protected function body()
{
$inputs = array('lecture' => 'isIndex', 'name' => array('isName', 'isNotEmpty'), 'type' => array('isEnum' => array('text', 'code', 'image')));
if (!$this->isInputValid($inputs)) {
return false;
}
$lectureId = $this->getParams('lecture');
/** @var \Lecture $lecture */
$lecture = Repositories::findEntity(Repositories::Lecture, $lectureId);
$name = $this->getParams('name');
$type = $this->getParams('type');
$id = $this->getParams('id');
$isIdSet = $id !== null && $id !== '';
$originalName = $this->getUploadedFileName('file');
if (!$originalName) {
return false;
}
$extensionStart = strrpos($originalName, '.');
$extension = $extensionStart === false ? '' : substr($originalName, strrpos($originalName, '.'));
$attachmentFolder = Config::get('paths', 'attachments');
$filename = $id . '_' . $name . $extension;
if (!$this->checkTestGenerationPrivileges($lecture)) {
return $this->death(StringID::InsufficientPrivileges);
}
/**
* @var $attachment \Attachment
*/
$attachment = null;
if (!$this->saveUploadedFile('file', $attachmentFolder . $filename)) {
return $this->death(StringID::InsufficientPrivileges);
}
/** @var \Attachment[] $attachmentsWithThisName */
$attachmentsWithThisName = Repositories::getRepository(Repositories::Attachment)->findBy(['lecture' => $lectureId, 'name' => $name]);
if ($isIdSet) {
$attachment = Repositories::findEntity(Repositories::Attachment, $id);
if (count($attachmentsWithThisName) > 0) {
if ($attachmentsWithThisName[0]->getId() !== $attachment->getId()) {
return $this->death(StringID::AttachmentExists);
}
}
} else {
if (count($attachmentsWithThisName) > 0) {
return $this->death(StringID::AttachmentExists);
}
$attachment = new \Attachment();
}
$attachment->setType($type);
$attachment->setLecture($lecture);
$attachment->setName($name);
$attachment->setFile($filename);
Repositories::persistAndFlush($attachment);
return true;
}
示例2: edit
/**
* Show and process edit attachment form
*
* @param void
* @return null
*/
function edit()
{
$this->wireframe->print_button = false;
if ($this->active_attachment->isNew()) {
$this->httpError(HTTP_ERR_NOT_FOUND);
}
// if
$parent = $this->active_attachment->getParent();
if (!instance_of($parent, 'ProjectObject')) {
$this->httpError(HTTP_ERR_NOT_FOUND);
}
// if
$attachment_data = $this->request->post('attachment');
if (!is_array($attachment_data)) {
$attachment_data = array('name' => $this->active_attachment->getName());
}
// if
$this->smarty->assign('attachment_data', $attachment_data);
if ($this->request->isSubmitted()) {
db_begin_work();
$old_name = $this->active_attachment->getName();
$this->active_attachment->setName(array_var($attachment_data, 'name'));
$save = $this->active_attachment->save();
if ($save && !is_error($save)) {
db_commit();
$this->active_attachment->ready();
if ($this->request->getFormat() == FORMAT_HTML) {
flash_success('File :filename has been updated', array('filename' => $old_name));
$this->redirectToUrl($parent->getViewUrl());
} else {
$this->serveData($this->active_attachment);
}
// if
} else {
db_rollback();
if ($this->request->getFormat() == FORMAT_HTML) {
flash_error('Failed to update :filename', array('filename' => $old_name));
$this->redirectToUrl($parent->getViewUrl());
} else {
$this->serveData($save);
}
// if
}
// if
}
// if
}
示例3: save
/**
* Save this object into the database
*
* @param void
* @return boolean
* @throws DBQueryError
* @throws ValidationErrors
*/
function save()
{
$is_new = $this->isNew();
$modified_fields = $this->modified_fields;
$old_values = $this->old_values;
if ($is_new) {
$this->setType(get_class($this));
}
// if
if ($this->isModified()) {
$this->setVersion($this->getVersion() + 1);
// increment object version on save...
}
// if
db_begin_work();
$save = parent::save();
if (!$save || is_error($save)) {
db_rollback();
return $save;
}
// if
// Log activities...
if ($this->log_activities) {
if ($is_new) {
if ($this->log_creation) {
if (instance_of($this, 'File')) {
$activity_log = new NewFileActivityLog();
} else {
$activity_log = new ObjectCreatedActivityLog();
}
// if
$activity_log->log($this, $this->getCreatedBy());
}
// if
} else {
if ($this->log_update || $this->log_move_to_trash || $this->log_restore_from_trash) {
$trashed = false;
$restored = false;
if (is_array($this->modified_fields) && in_array('state', $modified_fields)) {
if (isset($old_values['state']) && $old_values['state'] == STATE_DELETED && $this->getState() == STATE_VISIBLE) {
$restored = true;
}
// if
if (isset($old_values['state']) && $old_values['state'] == STATE_VISIBLE && $this->getState() == STATE_DELETED) {
$trashed = true;
}
// if
}
// if
if ($trashed) {
if ($this->log_move_to_trash) {
$activity_log = new ObjectTrashedActivityLog();
$activity_log->log($this);
}
// if
} elseif ($restored) {
if ($this->log_restore_from_trash) {
$activity_log = new ObjectRestoredActivityLog();
$activity_log->log($this);
}
// if
} else {
if ($this->log_update) {
$activity_log = new ObjectUpdatedActivityLog();
$activity_log->log($this);
}
// if
}
// if
}
// if
}
// if
}
// if
// Pending files
if ($this->can_have_attachments && is_foreachable($this->pending_files)) {
foreach ($this->pending_files as $pending_file) {
$attachment = new Attachment();
$attachment->setParent($this);
if (isset($pending_file['created_by']) && (instance_of($pending_file['created_by'], 'User') || instance_of($pending_file['created_by'], 'AnonymousUser'))) {
$attachment->setCreatedBy($pending_file['created_by']);
} else {
$attachment->setCreatedBy($this->getCreatedBy());
}
// if
$attachment->setName($pending_file['name']);
$attachment->setLocation(substr($pending_file['location'], strlen(UPLOAD_PATH) + 1));
$attachment->setMimeType($pending_file['type']);
$attachment->setSize($pending_file['size']);
if (instance_of($this, 'File')) {
$attachment->setAttachmentType(ATTACHMENT_TYPE_FILE_REVISION);
//.........这里部分代码省略.........
示例4: Error
/**
* Creates attachment from uploaded file
*
* @param array $file
* @param ApplicationObject $parent
* @return Attachment
*/
function &make_attachment($file, $parent = null)
{
if (!isset($file) || !isset($file['tmp_name'])) {
return new Error(lang('File is not uploaded'));
}
// if
$destination_file = get_available_uploads_filename();
if (!move_uploaded_file($file['tmp_name'], $destination_file)) {
return new Error(lang('Could not move uploaded file to uploads directory'));
}
// if
$attachment = new Attachment();
$attachment->setName($file['name']);
$attachment->setLocation(basename($destination_file));
$attachment->setMimeType(array_var($file, 'type', 'application/octet-stream'));
$attachment->setSize(array_var($file, 'size', 0));
if (instance_of($parent, 'ApplicationObject')) {
$attachment->setParent($parent);
}
// if
$save = $attachment->save();
if (!$save || is_error($save)) {
@unlink($destination_file);
return $save;
}
// if
return $attachment;
}
示例5: Project
/**
* Provides logic for image picker dialog
*
* @param void
* @return null
*/
function image_picker()
{
$project_id = $this->request->get('project_id');
if ($project_id) {
$this->active_project = Projects::findById($project_id);
}
// if
if (!instance_of($this->active_project, 'Project')) {
$this->active_project = new Project();
}
// if
$image_picker_url = assemble_url('image_picker', array('project_id' => $this->active_project->getId()));
$this->smarty->assign(array('image_picker_url' => $image_picker_url, 'disable_upload' => (bool) $this->request->get('disable_upload')));
if ($this->request->isSubmitted()) {
$action = $this->request->post('widget_action');
switch ($action) {
case 'upload':
// check if any file is uploaded
$uploaded_file = array_var($_FILES, 'image', null);
if (!is_array($uploaded_file)) {
$this->httpError(HTTP_ERR_OPERATION_FAILED, lang('You did not uploaded any file'), true, true);
}
// if
// we are setting base attributes
$attachment = new Attachment();
$attachment->setName($uploaded_file['name']);
$attachment->setMimeType($uploaded_file['type']);
$attachment->setSize($uploaded_file['size']);
$attachment->setAttachmentType(ATTACHMENT_TYPE_ATTACHMENT);
$attachment->setCreatedBy($this->logged_user);
$attachment->setCreatedOn(new DateTimeValue());
// check if uploaded file is image
if (!$attachment->isImage()) {
$this->httpError(HTTP_ERR_OPERATION_FAILED, lang('Uploaded file is not image'), true, true);
}
// if
$destination_file = get_available_uploads_filename();
if (!move_uploaded_file($uploaded_file['tmp_name'], $destination_file)) {
$this->httpError(HTTP_ERR_OPERATION_FAILED, lang('Could not copy uploaded image to work folder'), true, true);
}
// if
if (FIX_UPLOAD_PERMISSION !== false) {
@chmod($destination_file, FIX_UPLOAD_PERMISSION);
}
// if
$attachment->setLocation(basename($destination_file));
$save = $attachment->save();
if (!$save || is_error($save)) {
@unlink($destination_file);
$this->httpError(HTTP_ERR_OPERATION_FAILED, $save->getMessage(), true, true);
}
// if
echo "<img attachment_id='" . $attachment->getId() . "' src='" . $attachment->getViewUrl($this->active_project->getId()) . "' />";
die;
break;
default:
break;
}
// switch
}
// if
}