EduSoho下的教学活动是指教学内容的展现方式,系统默认提供了图文、视频、音频、直播、讨论、flash、文档、PPT、考试、作业、练习、下载资料等12中教学活动,开发者可对教学活动进行扩展。现要新增一种教学活动—小组,以下是开发步骤:
php app/console plugin:create GroupTask
php app/console plugin:register GroupTask
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');
}
}
Biz/Activity/Type
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;
},
)
);
}
}
services:
plugin.activity.extension:
class: GroupTaskPlugin\Extension\ActivityExtension
calls:
- [setBiz, ['@biz']]
tags:
- { name: extension }
注意 :plugin.activity.extension
这个code的名字取与EduSoho系统activity.extension
不一样的名字,避免因加载优先级问题被覆盖。
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');
}
}