当前位置: 首页>>代码示例>>PHP>>正文


PHP ElggFile::addRelationship方法代码示例

本文整理汇总了PHP中ElggFile::addRelationship方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggFile::addRelationship方法的具体用法?PHP ElggFile::addRelationship怎么用?PHP ElggFile::addRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ElggFile的用法示例。


在下文中一共展示了ElggFile::addRelationship方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: projects_upload_attachments

/**
 *
 * upload attachments for a project
 * @param ElggEntity 
 *
*/
function projects_upload_attachments($attachments, $project)
{
    $count = count($attachments['name']);
    for ($i = 0; $i < $count; $i++) {
        if ($attachments['error'][$i] || !$attachments['name'][$i]) {
            continue;
        }
        $name = $attachments['name'][$i];
        $file = new ElggFile();
        $file->container_guid = $project->guid;
        $file->title = $name;
        $file->access_id = (int) $project->access_id;
        $prefix = "file/";
        $filestorename = elgg_strtolower(time() . $name);
        $file->setFilename($prefix . $filestorename);
        $file->open("write");
        $file->close();
        move_uploaded_file($attachments['tmp_name'][$i], $file->getFilenameOnFilestore());
        $saved = $file->save();
        if ($saved) {
            $mime_type = ElggFile::detectMimeType($attachments['tmp_name'][$i], $attachments['type'][$i]);
            $info = pathinfo($name);
            $office_formats = array('docx', 'xlsx', 'pptx');
            if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) {
                switch ($info['extension']) {
                    case 'docx':
                        $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                        break;
                    case 'xlsx':
                        $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                        break;
                    case 'pptx':
                        $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                        break;
                }
            }
            // check for bad ppt detection
            if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") {
                $mime_type = "application/vnd.ms-powerpoint";
            }
            //add_metastring("projectId");
            //$file->projectId = $project_guid;
            $file->setMimeType($mime_type);
            $file->originalfilename = $name;
            if (elgg_is_active_plugin('file')) {
                $file->simpletype = file_get_simple_type($mime_type);
            }
            $saved = $file->save();
            if ($saved) {
                $file->addRelationship($project->guid, 'attachment');
            }
        }
    }
}
开发者ID:amcfarlane1251,项目名称:ongarde,代码行数:60,代码来源:projects.php

示例2: hj_framework_edit_object_action


//.........这里部分代码省略.........
                $file->close();
                move_uploaded_file($attachments['tmp_name'][$i], $file->getFilenameOnFilestore());
                $saved = $file->save();
                if ($saved) {
                    $mime_type = ElggFile::detectMimeType($attachments['tmp_name'][$i], $attachments['type'][$i]);
                    $info = pathinfo($name);
                    $office_formats = array('docx', 'xlsx', 'pptx');
                    if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) {
                        switch ($info['extension']) {
                            case 'docx':
                                $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                                break;
                            case 'xlsx':
                                $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                                break;
                            case 'pptx':
                                $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                                break;
                        }
                    }
                    // check for bad ppt detection
                    if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") {
                        $mime_type = "application/vnd.ms-powerpoint";
                    }
                    //add_metastring("projectId");
                    //$file->projectId = $project_guid;
                    $file->setMimeType($mime_type);
                    $file->originalfilename = $name;
                    if (elgg_is_active_plugin('file')) {
                        $file->simpletype = file_get_simple_type($mime_type);
                    }
                    $saved = $file->save();
                    if ($saved) {
                        $file->addRelationship($guid, 'attachment');
                    }
                }
            }
        }
        $accesslevel = get_input('accesslevel', false);
        $params = array('entity' => $entity);
        $form = hj_framework_prepare_form($form_name, $params);
        $fields = $form['form']['fields'];
        $ignore_fields = array('guid', 'type', 'subtype', 'owner_guid', 'container_guid', 'access_id', 'title', 'description');
        foreach ($fields as $name => $options) {
            if (in_array($name, $ignore_fields)) {
                continue;
            }
            if (!$options) {
                continue;
            }
            $type = elgg_extract('input_type', $options, 'text');
            $accesslevel_id = isset($accesslevel[$name]) ? $accesslevel[$name] : $entity->access_id;
            $params = array('name' => $name, 'form_name' => $form_name, 'field' => $options, 'access_id' => $accesslevel_id, 'entity' => $entity, 'event' => $event);
            if (!elgg_trigger_plugin_hook('process:input', "form:input:name:{$name}", $params, false) && !elgg_trigger_plugin_hook('process:input', "form:input:type:{$type}", $params, false)) {
                $value = get_input($name);
                set_input($name, null);
                //				if (!$value) {
                //					elgg_delete_metadata(array(
                //						'guid' => $entity->guid,
                //						'metadata_name' => $name
                //					));
                //
                //					continue;
                //				}
                //
                //				if (is_array($value) && count($value) > 1) {
开发者ID:amcfarlane1251,项目名称:ongarde,代码行数:67,代码来源:actions.php


注:本文中的ElggFile::addRelationship方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。