教学活动扩展

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

1.执行创建插件命令

  1. app/console plugin:create GroupTask

2.执行插件注册命令

  1. app/console plugin:register GroupTask

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

  1. <?php
  2. namespace GroupTaskPlugin\Biz\Activity\Type;
  3. use Biz\Activity\Config\Activity;
  4. class Group extends Activity
  5. {
  6. protected function registerListeners()
  7. {
  8. return array();
  9. }
  10. public function get($targetId)
  11. {
  12. // code
  13. }
  14. public function find($ids)
  15. {
  16. // code
  17. }
  18. public function copy($activity, $config = array())
  19. {
  20. // 计划被复制时调用
  21. }
  22. public function sync($sourceActivity, $activity)
  23. {
  24. // 计划被复制到班级时,源计划任务新增修改删除时调用
  25. }
  26. public function update($targetId, &$fields, $activity)
  27. {
  28. // code
  29. }
  30. public function isFinished($activityId)
  31. {
  32. // code
  33. }
  34. public function delete($targetId)
  35. {
  36. // code
  37. }
  38. public function create($fields)
  39. {
  40. // code
  41. }
  42. /**
  43. * @return TextActivityDao
  44. */
  45. protected function getXXXDao()
  46. {
  47. return $this->getBiz()->dao('GroupPlugin:XXX:XXXDao');
  48. }
  49. /**
  50. * @return ActivityService
  51. */
  52. protected function getXXXService()
  53. {
  54. return $this->getBiz()->service('GroupPlugin:XXX:XXXService');
  55. }
  56. }

注意

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

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

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

  1. <?php
  2. namespace GroupTaskPlugin\Extension;
  3. use AppBundle\Extension\Extension;
  4. use Pimple\Container;
  5. use Pimple\ServiceProviderInterface;
  6. use GroupTaskPlugin\Biz\Activity\Type\Group;
  7. class ActivityExtension extends Extension implements ServiceProviderInterface
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function register(Container $container)
  13. {
  14. $container['activity_type.group'] = function ($biz) {
  15. return new Group($biz);
  16. };
  17. }
  18. public function getActivities()
  19. {
  20. $biz = $this->biz;
  21. return array(
  22. 'group' => array(
  23. 'meta' => array(
  24. 'name' => '小组', //任务类型名称
  25. 'icon' => 'es-icon es-icon-graphicclass', //任务类型图片
  26. ),
  27. 'controller' => 'GroupTaskPlugin:Activity/Group', //任务控制器
  28. 'visible' => function ($courseSet, $course) { //是否可见
  29. return true;
  30. },
  31. )
  32. );
  33. }
  34. }

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

  1. services:
  2. plugin.activity.extension:
  3. class: GroupTaskPlugin\Extension\ActivityExtension
  4. calls:
  5. - [setBiz, ['@biz']]
  6. tags:
  7. - { name: extension }

注意

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

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

  1. <?php
  2. namespace GroupTaskPlugin\Controller\Activity;
  3. use AppBundle\Controller\BaseController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. class GroupController extends BaseController implements ActivityActionInterface
  6. {
  7. public function showAction(Request $request, $activity)
  8. {
  9. // code
  10. return $this->render('GroupTaskPlugin:Activity/Group/index.html.twig', array(
  11. 'activity' => $activity,
  12. // other params
  13. ));
  14. }
  15. public function previewAction(Request $request, $task)
  16. {
  17. $activity = $this->getActivityService()->getActivity($task['activityId']);
  18. // code
  19. return $this->render('GroupTaskPlugin:Activity/Group/preview.html.twig', array(
  20. 'activity' => $activity,
  21. // other params
  22. ));
  23. }
  24. public function editAction(Request $request, $id, $courseId)
  25. {
  26. $activity = $this->getActivityService()->getActivity($id);
  27. // code
  28. return $this->render('GroupTaskPlugin:Activity/Group/modal.html.twig', array(
  29. 'activity' => $activity,
  30. // other params
  31. ));
  32. }
  33. public function createAction(Request $request, $courseId)
  34. {
  35. //code
  36. return $this->render('GroupTaskPlugin:Activity/Group/modal.html.twig', array(
  37. 'courseId' => $courseId,
  38. // other params
  39. ));
  40. }
  41. public function finishConditionAction(Request $request, $activity)
  42. {
  43. $media = $this->getActivityService()->getActivityConfig('group')->get($activity['mediaId']);
  44. return $this->render('GroupTaskPlugin:Activity/Group/finish-condition.html.twig', array(
  45. 'media' => $media,
  46. ));
  47. }
  48. protected function getActivityService()
  49. {
  50. return $this->createService('Activity:ActivityService');
  51. }
  52. public function getXXXService()
  53. {
  54. return $this->createService('GroupTaskPlugin:XXX:XXXService');
  55. }
  56. }

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