本文整理汇总了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
}