本文整理汇总了PHP中Attachments::findByObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachments::findByObject方法的具体用法?PHP Attachments::findByObject怎么用?PHP Attachments::findByObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attachments
的用法示例。
在下文中一共展示了Attachments::findByObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cloneAttachments
/**
* Clone attachments
*
* @param ProjectObject $from
* @param ProjectObject $to
* @return boolean
*/
function cloneAttachments($original, $copy)
{
$attachments = Attachments::findByObject($original);
if (is_foreachable($attachments)) {
$new_files = array();
$to_insert = array();
foreach ($attachments as $attachment) {
$source_file = $attachment->getFilePath();
$target_file = get_available_uploads_filename();
if (copy($source_file, $target_file)) {
$new_files[] = $target_file;
$to_insert[] = db_prepare_string("(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array($copy->getId(), get_class($copy), $attachment->getName(), $attachment->getMimeType(), $attachment->getSize(), basename($target_file), $attachment->getAttachmentType(), $attachment->getCreatedOn(), $attachment->getCreatedById(), $attachment->getCreatedByName(), $attachment->getCreatedByEmail()));
}
// if
}
// foreach
if (is_foreachable($to_insert)) {
$insert = db_execute("INSERT INTO " . TABLE_PREFIX . 'attachments (parent_id, parent_type, name, mime_type, size, location, attachment_type, created_on, created_by_id, created_by_name, created_by_email) VALUES ' . implode(', ', $to_insert));
if ($insert && !is_error($insert)) {
return true;
} else {
foreach ($new_files as $new_file) {
@unlink($new_file);
}
// if
return $insert;
}
// if
}
// if
}
// if
return true;
}
示例2: getAttachments
/**
* Return file attachments
*
* @param void
* @return array
*/
function getAttachments()
{
return Attachments::findByObject($this, $this->getState(), $this->getVisibility());
}