本文整理汇总了PHP中Notifier::newFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Notifier::newFile方法的具体用法?PHP Notifier::newFile怎么用?PHP Notifier::newFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notifier
的用法示例。
在下文中一共展示了Notifier::newFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_file
/**
* Add file
*
* @access public
* @param void
* @return null
*/
function add_file() {
if (!ProjectFile::canAdd(logged_user(), active_project())) {
flash_error(lang('no access permissions'));
$this->redirectToReferer(get_url('files'));
} // if
$file = new ProjectFile();
$file_data = array_var($_POST, 'file');
if (!is_array($file_data)) {
$file_data = array(
'folder_id' => get_id('folder_id'),
'is_private' => config_option('default_private', false)
); // array
} // if
tpl_assign('file', $file);
tpl_assign('file_data', $file_data);
if (is_array(array_var($_POST, 'file'))) {
try {
DB::beginWork();
$uploaded_file = array_var($_FILES, 'file_file');
// move uploaded file to folder where I can read and write
move_uploaded_file($uploaded_file['tmp_name'], ROOT . '/tmp/' . $uploaded_file['name']);
$uploaded_file['tmp_name'] = ROOT . '/tmp/' . $uploaded_file['name'];
$file->setFromAttributes($file_data);
if (!logged_user()->isMemberOfOwnerCompany()) {
$file->setIsPrivate(false);
$file->setIsImportant(false);
$file->setCommentsEnabled(true);
$file->setAnonymousCommentsEnabled(false);
} // if
$file->setFilename(array_var($uploaded_file, 'name'));
$file->setProjectId(active_project()->getId());
$file->setIsVisible(true);
$file->save();
if (plugin_active('tags')) {
$file->setTagsFromCSV(array_var($file_data, 'tags'));
}
$revision = $file->handleUploadedFile($uploaded_file, true); // handle uploaded file
ApplicationLogs::createLog($file, active_project(), ApplicationLogs::ACTION_ADD);
DB::commit();
// Try to send notifications but don't break submission in case of an error
// define all the users to be notified - here all project users, from all companies.
// Restrictions if comment is private is taken into account in newOtherComment()
try {
$notify_people = array();
$project_companies = active_project()->getCompanies();
foreach ($project_companies as $project_company) {
$company_users = $project_company->getUsersOnProject(active_project());
if (is_array($company_users)) {
foreach ($company_users as $company_user) {
if ((array_var($file_data, 'notify_company_' . $project_company->getId()) == 'checked') || (array_var($file_data, 'notify_user_' . $company_user->getId()))) {
$notify_people[] = $company_user;
} // if
} // if
} // if
} // if
Notifier::newFile($file, $notify_people); // send notification email...
} catch(Exception $e) {
Logger::log("Error: Notification failed, " . $e->getMessage(), Logger::ERROR);
} // try
flash_success(lang('success add file', $file->getFilename()));
$this->redirectToUrl($file->getDetailsUrl());
} catch(Exception $e) {
DB::rollback();
tpl_assign('error', $e);
tpl_assign('file', new ProjectFile()); // reset file
// If we uploaded the file remove it from repository
if (isset($revision) && ($revision instanceof ProjectFileRevision) && FileRepository::isInRepository($revision->getRepositoryId())) {
FileRepository::deleteFile($revision->getRepositoryId());
} // if
} // try
} // if
} // add_file