教学活动扩展

EduSoho下的教学活动是指教学内容的展现方式,系统默认提供了图文、视频、音频、直播、讨论、flash、文档、PPT、考试、作业、练习、下载资料等12中教学活动,开发者可对教学活动进行扩展。现要新增一种教学活动--小组,以下是开发步骤:

1.执行创建插件命令

app/console plugin:create GroupTask

2.执行插件注册命令

app/console plugin:register GroupTask

3.创建教学活动的扩展类Group,该类需要继承Biz\Activity\Config\Activity,并且实现相关接口。文件内容如下:

<?php

namespace GroupTaskPlugin\Biz\Activity\Type;

use Biz\Activity\Config\Activity;

class Group extends Activity
{
    protected function registerListeners()
    {
        return array();
    }

    public function get($targetId)
    {
        // code
    }

    public function find($ids)
    {
        // code
    }

    public function copy($activity, $config = array())
    {
        // 计划被复制时调用
    }

    public function sync($sourceActivity, $activity)
    {
        // 计划被复制到班级时,源计划任务新增修改删除时调用
    }

    public function update($targetId, &$fields, $activity)
    {
        // code
    }

    public function isFinished($activityId)
    {
        // code
    }

    public function delete($targetId)
    {
        // code
    }

    public function create($fields)
    {
        // code
    }

    /**
     * @return TextActivityDao
     */
    protected function getXXXDao()
    {
        return $this->getBiz()->dao('GroupPlugin:XXX:XXXDao');
    }

    /**
     * @return ActivityService
     */
    protected function getXXXService()
    {
        return $this->getBiz()->service('GroupPlugin:XXX:XXXService');
    }
}

注意

教学活动的扩展类文件目录要与EduSoho系统内教学活动类保持一致。EduSoho的教学活动类目录Biz/Activity/Type

5. 具体的业务逻辑请先完善ServiceDaoService类可继承EduSoho下的Biz\BaseService类。

6. 新建GroupTaskPlugin/Extension目录,该目录下创建ActivityExtension.php文件,具体内容:

<?php

namespace GroupTaskPlugin\Extension;

use AppBundle\Extension\Extension;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use GroupTaskPlugin\Biz\Activity\Type\Group;

class ActivityExtension extends Extension implements ServiceProviderInterface
{
    /**
     * {@inheritdoc}
     */
    public function register(Container $container)
    {
        $container['activity_type.group'] = function ($biz) {
            return new Group($biz);
        };
    }

    public function getActivities()
    {
        $biz = $this->biz;

        return array(
            'group' => array(
                'meta' => array(
                    'name' => '小组',                              //任务类型名称
                    'icon' => 'es-icon es-icon-graphicclass',     //任务类型图片
                ),
                'controller' => 'GroupTaskPlugin:Activity/Group', //任务控制器
                'visible' => function ($courseSet, $course) {        //是否可见
                    return true;
                },
            )
        );
    }
}

7. 在GroupTaskPlugin/Resources/config/services.yml文件下注入服务:

services:
    plugin.activity.extension:
        class: GroupTaskPlugin\Extension\ActivityExtension
        calls:
            - [setBiz, ['@biz']]
        tags:
            - { name: extension }

注意

plugin.activity.extension这个code的名字取与EduSoho系统activity.extension不一样的名字,避免因加载优先级问题被覆盖。

8. 任务控制器Controller,在GroupTaskPlugin/Controller目录创建Activity目录,并创建GroupController.php文件,该文件需要继承AppBundle\Controller\BaseController,具体内容如下:

<?php

namespace GroupTaskPlugin\Controller\Activity;

use AppBundle\Controller\BaseController;
use Symfony\Component\HttpFoundation\Request;

class GroupController extends BaseController implements ActivityActionInterface
{
    public function showAction(Request $request, $activity)
    {
        // code

        return $this->render('GroupTaskPlugin:Activity/Group/index.html.twig', array(
            'activity' => $activity,
            // other params
        ));
    }

    public function previewAction(Request $request, $task)
    {
        $activity = $this->getActivityService()->getActivity($task['activityId']);

        // code

        return $this->render('GroupTaskPlugin:Activity/Group/preview.html.twig', array(
            'activity' => $activity,
            // other params
        ));
    }

    public function editAction(Request $request, $id, $courseId)
    {
        $activity = $this->getActivityService()->getActivity($id);

        // code

        return $this->render('GroupTaskPlugin:Activity/Group/modal.html.twig', array(
            'activity' => $activity,
            // other params
        ));
    }

    public function createAction(Request $request, $courseId)
    {
        //code

        return $this->render('GroupTaskPlugin:Activity/Group/modal.html.twig', array(
            'courseId' => $courseId,
            // other params
        ));
    }

    public function finishConditionAction(Request $request, $activity)
    {
        $media = $this->getActivityService()->getActivityConfig('group')->get($activity['mediaId']);

        return $this->render('GroupTaskPlugin:Activity/Group/finish-condition.html.twig', array(
            'media' => $media,
        ));
    }

    protected function getActivityService()
    {
        return $this->createService('Activity:ActivityService');
    }

    public function getXXXService()
    {
        return $this->createService('GroupTaskPlugin:XXX:XXXService');
    }
}

9. 创建相关视图文件,具体可参考EduSoho系统下的默认任务类型的视图文件,例:app/Resources/views/activity/text/modal.html.twig。

results matching ""

    No results matching ""