本文整理匯總了PHP中Attachments::findLastByObject方法的典型用法代碼示例。如果您正苦於以下問題:PHP Attachments::findLastByObject方法的具體用法?PHP Attachments::findLastByObject怎麽用?PHP Attachments::findLastByObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Attachments
的用法示例。
在下文中一共展示了Attachments::findLastByObject方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: attachments
/**
* List all attachments, and manage attachments
*
* @param void
* @return null
*/
function attachments()
{
if (!$this->active_object->canEdit($this->logged_user)) {
$this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall());
}
// if
$attachemts = $this->active_object->getAttachments();
$this->smarty->assign(array('attachments' => $attachemts));
if ($this->request->isSubmitted()) {
$async = (bool) $this->request->get('async');
db_begin_work();
$file = array_shift($_FILES);
$this->active_object->attachUploadedFile($file, $this->logged_user);
$save = $this->active_object->save();
if ($save && !is_error($save)) {
$attachment = Attachments::findLastByObject($this->active_object);
if (instance_of($attachment, 'Attachment')) {
db_commit();
if ($async) {
$this->smarty->assign(array('_attachment' => $attachment, '_object_attachments_cycle_name' => 'object_attachments_cycle_' . $attachment->getId()));
// jQuery acts a bit weird here. Insted of providing response as
// a string it tries to append it to the BODY so some markup
// (tr, td) gets discarded. That is why we need to use temp table
// in order to get properly marked-up row
die('<table style="display: none">' . $this->smarty->fetch(get_template_path('_object_attachments_row', 'attachments', RESOURCES_MODULE))) . '</table>';
} elseif ($this->request->isApiCall()) {
$this->serveData($attachment, 'attachment');
} else {
flash_success('File ":file" has been added', array('file' => $file['name']));
$this->redirectToUrl($this->active_object->getAttachmentsUrl());
}
// if
}
// if
}
// if
db_rollback();
if ($async) {
$this->httpError(HTTP_ERR_OPERATION_FAILED);
} elseif ($this->request->isApiCall()) {
$this->httpError(HTTP_ERR_OPERATION_FAILED, null, true, true);
} else {
flash_error('File ":file" has not been added', array('file' => $file['name']));
$this->redirectToUrl($this->active_object->getAttachmentsUrl());
}
// if
} else {
if ($this->request->isApiCall()) {
$this->serveData($attachemts, 'attachments');
}
// if
}
// if
}