This commit is contained in:
afornerot 2019-06-19 17:00:21 +02:00
parent ee2732d329
commit c8c5d85e47
14 changed files with 881 additions and 11 deletions

View File

@ -8,7 +8,7 @@ INSERT IGNORE INTO `niveau01` (`id`, `label`, `siren`) VALUES
(-100, 'DRAAF', '130007107'); (-100, 'DRAAF', '130007107');
INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES
(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}9d5GfmZGEHAUq0E4rrULoubrbYBrUL0F (-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}AI3soJCege5aUkKULnotDIMTBrJowKYU
', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple'); ', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple');

View File

@ -162,6 +162,27 @@ class InitDataCommand extends ContainerAwareCommand
$this->entityManager->remove($entity); $this->entityManager->remove($entity);
} }
// Job de récupération des cours Moodle
// Toute les 6h
$activate_widmoodle = $this->getContainer()->getParameter('activate_widmoodle');
$entity = $this->entityManager->getRepository('CadolesCronBundle:Cron')->find(1020);
if(!$entity&&$activate_widmoodle) {
$entity = new Cron;
$nextdate=$entity->getSubmitdate();
$nextdate->setTime(1,0);
$entity->setCommand("Portal:GetMoodle");
$entity->setDescription("Récupération des cours Moodle ");
$entity->setId(1020);
$entity->setStatut(2);
$entity->setRepeatcall(0);
$entity->setRepeatexec(0);
$entity->setRepeatinterval(21600);
$entity->setNextexecdate($nextdate);
$this->entityManager->persist($entity);
}
elseif($entity&&!$activate_widmoodle) {
$this->entityManager->remove($entity);
}
$this->entityManager->flush(); $this->entityManager->flush();
} }

View File

@ -351,7 +351,6 @@ class GetLimesurveyCommand extends Command
->setHelp('Synchronize Limesurvey') ->setHelp('Synchronize Limesurvey')
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job') ->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron') ->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
->addArgument('idcalendar', InputArgument::OPTIONAL, 'ID Calendar to synchronize')
; ;
} }

View File

@ -0,0 +1,764 @@
<?php
namespace Cadoles\PortalBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpKernel\KernelInterface;
use Doctrine\DBAL\Connection as DBALConnection;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Validator\Constraints\DateTime;
class curl {
/** @var bool */
public $cache = false;
public $proxy = false;
/** @var array */
public $response = array();
public $header = array();
/** @var string */
public $info;
public $error;
/** @var array */
private $options;
/** @var string */
private $proxy_host = '';
private $proxy_auth = '';
private $proxy_type = '';
/** @var bool */
private $debug = false;
private $cookie = false;
public $count=0;
/**
* @param array $options
*/
public function __construct($options = array()){
if (!function_exists('curl_init')) {
$this->error = 'cURL module must be enabled!';
trigger_error($this->error, E_USER_ERROR);
return false;
}
// the options of curl should be init here.
$this->resetopt();
if (!empty($options['debug'])) {
$this->debug = true;
}
if(!empty($options['cookie'])) {
if($options['cookie'] === true) {
$this->cookie = 'curl_cookie.txt';
} else {
$this->cookie = $options['cookie'];
}
}
if (!empty($options['cache'])) {
if (class_exists('curl_cache')) {
$this->cache = new curl_cache();
}
}
}
/**
* Resets the CURL options that have already been set
*/
public function resetopt(){
$this->options = array();
$this->options['CURLOPT_USERAGENT'] = 'MoodleBot/1.0';
// True to include the header in the output
$this->options['CURLOPT_HEADER'] = 0;
// True to Exclude the body from the output
$this->options['CURLOPT_NOBODY'] = 0;
// TRUE to follow any "Location: " header that the server
// sends as part of the HTTP header (note this is recursive,
// PHP will follow as many "Location: " headers that it is sent,
// unless CURLOPT_MAXREDIRS is set).
//$this->options['CURLOPT_FOLLOWLOCATION'] = 1;
$this->options['CURLOPT_MAXREDIRS'] = 10;
$this->options['CURLOPT_ENCODING'] = '';
// TRUE to return the transfer as a string of the return
// value of curl_exec() instead of outputting it out directly.
$this->options['CURLOPT_RETURNTRANSFER'] = 1;
$this->options['CURLOPT_BINARYTRANSFER'] = 0;
$this->options['CURLOPT_SSL_VERIFYPEER'] = 0;
$this->options['CURLOPT_SSL_VERIFYHOST'] = 2;
$this->options['CURLOPT_CONNECTTIMEOUT'] = 30;
}
/**
* Reset Cookie
*/
public function resetcookie() {
if (!empty($this->cookie)) {
if (is_file($this->cookie)) {
$fp = fopen($this->cookie, 'w');
if (!empty($fp)) {
fwrite($fp, '');
fclose($fp);
}
}
}
}
/**
* Set curl options
*
* @param array $options If array is null, this function will
* reset the options to default value.
*
*/
public function setopt($options = array()) {
if (is_array($options)) {
foreach($options as $name => $val){
if (stripos($name, 'CURLOPT_') === false) {
$name = strtoupper('CURLOPT_'.$name);
}
$this->options[$name] = $val;
}
}
}
/**
* Reset http method
*
*/
public function cleanopt(){
unset($this->options['CURLOPT_HTTPGET']);
unset($this->options['CURLOPT_POST']);
unset($this->options['CURLOPT_POSTFIELDS']);
unset($this->options['CURLOPT_PUT']);
unset($this->options['CURLOPT_INFILE']);
unset($this->options['CURLOPT_INFILESIZE']);
unset($this->options['CURLOPT_CUSTOMREQUEST']);
}
/**
* Set HTTP Request Header
*
* @param array $headers
*
*/
public function setHeader($header) {
if (is_array($header)){
foreach ($header as $v) {
$this->setHeader($v);
}
} else {
$this->header[] = $header;
}
}
/**
* Set HTTP Response Header
*
*/
public function getResponse(){
return $this->response;
}
/**
* private callback function
* Formatting HTTP Response Header
*
* @param mixed $ch Apparently not used
* @param string $header
* @return int The strlen of the header
*/
private function formatHeader($ch, $header)
{
$this->count++;
if (strlen($header) > 2) {
list($key, $value) = explode(" ", rtrim($header, "\r\n"), 2);
$key = rtrim($key, ':');
if (!empty($this->response[$key])) {
if (is_array($this->response[$key])){
$this->response[$key][] = $value;
} else {
$tmp = $this->response[$key];
$this->response[$key] = array();
$this->response[$key][] = $tmp;
$this->response[$key][] = $value;
}
} else {
$this->response[$key] = $value;
}
}
return strlen($header);
}
/**
* Set options for individual curl instance
*
* @param object $curl A curl handle
* @param array $options
* @return object The curl handle
*/
private function apply_opt($curl, $options) {
// Clean up
$this->cleanopt();
// set cookie
if (!empty($this->cookie) || !empty($options['cookie'])) {
$this->setopt(array('cookiejar'=>$this->cookie,
'cookiefile'=>$this->cookie
));
}
// set proxy
if (!empty($this->proxy) || !empty($options['proxy'])) {
$this->setopt($this->proxy);
}
$this->setopt($options);
// reset before set options
curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this,'formatHeader'));
// set headers
if (empty($this->header)){
$this->setHeader(array(
'User-Agent: MoodleBot/1.0',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Connection: keep-alive'
));
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->header);
if ($this->debug){
echo '<h1>Options</h1>';
var_dump($this->options);
echo '<h1>Header</h1>';
var_dump($this->header);
}
// set options
foreach($this->options as $name => $val) {
if (is_string($name)) {
$name = constant(strtoupper($name));
}
curl_setopt($curl, $name, $val);
}
return $curl;
}
/**
* Download multiple files in parallel
*
* Calls {@link multi()} with specific download headers
*
* <code>
* $c = new curl;
* $c->download(array(
* array('url'=>'http://localhost/', 'file'=>fopen('a', 'wb')),
* array('url'=>'http://localhost/20/', 'file'=>fopen('b', 'wb'))
* ));
* </code>
*
* @param array $requests An array of files to request
* @param array $options An array of options to set
* @return array An array of results
*/
public function download($requests, $options = array()) {
$options['CURLOPT_BINARYTRANSFER'] = 1;
$options['RETURNTRANSFER'] = false;
return $this->multi($requests, $options);
}
/*
* Mulit HTTP Requests
* This function could run multi-requests in parallel.
*
* @param array $requests An array of files to request
* @param array $options An array of options to set
* @return array An array of results
*/
protected function multi($requests, $options = array()) {
$count = count($requests);
$handles = array();
$results = array();
$main = curl_multi_init();
for ($i = 0; $i < $count; $i++) {
$url = $requests[$i];
foreach($url as $n=>$v){
$options[$n] = $url[$n];
}
$handles[$i] = curl_init($url['url']);
$this->apply_opt($handles[$i], $options);
curl_multi_add_handle($main, $handles[$i]);
}
$running = 0;
do {
curl_multi_exec($main, $running);
} while($running > 0);
for ($i = 0; $i < $count; $i++) {
if (!empty($options['CURLOPT_RETURNTRANSFER'])) {
$results[] = true;
} else {
$results[] = curl_multi_getcontent($handles[$i]);
}
curl_multi_remove_handle($main, $handles[$i]);
}
curl_multi_close($main);
return $results;
}
/**
* Single HTTP Request
*
* @param string $url The URL to request
* @param array $options
* @return bool
*/
protected function request($url, $options = array()){
// create curl instance
$curl = curl_init($url);
$options['url'] = $url;
$this->apply_opt($curl, $options);
if ($this->cache && $ret = $this->cache->get($this->options)) {
return $ret;
} else {
$ret = curl_exec($curl);
if ($this->cache) {
$this->cache->set($this->options, $ret);
}
}
$this->info = curl_getinfo($curl);
$this->error = curl_error($curl);
if ($this->debug){
echo '<h1>Return Data</h1>';
var_dump($ret);
echo '<h1>Info</h1>';
var_dump($this->info);
echo '<h1>Error</h1>';
var_dump($this->error);
}
curl_close($curl);
if (empty($this->error)){
return $ret;
} else {
return $this->error;
// exception is not ajax friendly
//throw new moodle_exception($this->error, 'curl');
}
}
/**
* HTTP HEAD method
*
* @see request()
*
* @param string $url
* @param array $options
* @return bool
*/
public function head($url, $options = array()){
$options['CURLOPT_HTTPGET'] = 0;
$options['CURLOPT_HEADER'] = 1;
$options['CURLOPT_NOBODY'] = 1;
return $this->request($url, $options);
}
/**
* Recursive function formating an array in POST parameter
* @param array $arraydata - the array that we are going to format and add into &$data array
* @param string $currentdata - a row of the final postdata array at instant T
* when finish, it's assign to $data under this format: name[keyname][][]...[]='value'
* @param array $data - the final data array containing all POST parameters : 1 row = 1 parameter
*/
function format_array_postdata_for_curlcall($arraydata, $currentdata, &$data) {
foreach ($arraydata as $k=>$v) {
$newcurrentdata = $currentdata;
if (is_object($v)) {
$v = (array) $v;
}
if (is_array($v)) { //the value is an array, call the function recursively
$newcurrentdata = $newcurrentdata.'['.urlencode($k).']';
$this->format_array_postdata_for_curlcall($v, $newcurrentdata, $data);
} else { //add the POST parameter to the $data array
$data[] = $newcurrentdata.'['.urlencode($k).']='.urlencode($v);
}
}
}
/**
* Transform a PHP array into POST parameter
* (see the recursive function format_array_postdata_for_curlcall)
* @param array $postdata
* @return array containing all POST parameters (1 row = 1 POST parameter)
*/
function format_postdata_for_curlcall($postdata) {
if (is_object($postdata)) {
$postdata = (array) $postdata;
}
$data = array();
foreach ($postdata as $k=>$v) {
if (is_object($v)) {
$v = (array) $v;
}
if (is_array($v)) {
$currentdata = urlencode($k);
$this->format_array_postdata_for_curlcall($v, $currentdata, $data);
} else {
$data[] = urlencode($k).'='.urlencode($v);
}
}
$convertedpostdata = implode('&', $data);
return $convertedpostdata;
}
/**
* HTTP POST method
*
* @param string $url
* @param array|string $params
* @param array $options
* @return bool
*/
public function post($url, $params = '', $options = array()){
$options['CURLOPT_POST'] = 1;
if (is_array($params)) {
$params = $this->format_postdata_for_curlcall($params);
}
$options['CURLOPT_POSTFIELDS'] = $params;
return $this->request($url, $options);
}
/**
* HTTP GET method
*
* @param string $url
* @param array $params
* @param array $options
* @return bool
*/
public function get($url, $params = array(), $options = array()){
$options['CURLOPT_HTTPGET'] = 1;
if (!empty($params)){
$url .= (stripos($url, '?') !== false) ? '&' : '?';
$url .= http_build_query($params, '', '&');
}
return $this->request($url, $options);
}
/**
* HTTP PUT method
*
* @param string $url
* @param array $params
* @param array $options
* @return bool
*/
public function put($url, $params = array(), $options = array()){
$file = $params['file'];
if (!is_file($file)){
return null;
}
$fp = fopen($file, 'r');
$size = filesize($file);
$options['CURLOPT_PUT'] = 1;
$options['CURLOPT_INFILESIZE'] = $size;
$options['CURLOPT_INFILE'] = $fp;
if (!isset($this->options['CURLOPT_USERPWD'])){
$this->setopt(array('CURLOPT_USERPWD'=>'anonymous: noreply@moodle.org'));
}
$ret = $this->request($url, $options);
fclose($fp);
return $ret;
}
/**
* HTTP DELETE method
*
* @param string $url
* @param array $params
* @param array $options
* @return bool
*/
public function delete($url, $param = array(), $options = array()){
$options['CURLOPT_CUSTOMREQUEST'] = 'DELETE';
if (!isset($options['CURLOPT_USERPWD'])) {
$options['CURLOPT_USERPWD'] = 'anonymous: noreply@moodle.org';
}
$ret = $this->request($url, $options);
return $ret;
}
/**
* HTTP TRACE method
*
* @param string $url
* @param array $options
* @return bool
*/
public function trace($url, $options = array()){
$options['CURLOPT_CUSTOMREQUEST'] = 'TRACE';
$ret = $this->request($url, $options);
return $ret;
}
/**
* HTTP OPTIONS method
*
* @param string $url
* @param array $options
* @return bool
*/
public function options($url, $options = array()){
$options['CURLOPT_CUSTOMREQUEST'] = 'OPTIONS';
$ret = $this->request($url, $options);
return $ret;
}
public function get_info() {
return $this->info;
}
}
/**
* This class is used by cURL class, use case:
*
* <code>
*
* $c = new curl(array('cache'=>true), 'module_cache'=>'repository');
* $ret = $c->get('http://www.google.com');
* </code>
*
* @package core
* @subpackage file
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class curl_cache {
/** @var string */
public $dir = '';
/**
*
* @param string @module which module is using curl_cache
*
*/
function __construct() {
$this->dir = '/tmp/';
if (!file_exists($this->dir)) {
mkdir($this->dir, 0700, true);
}
$this->ttl = 1200;
}
/**
* Get cached value
*
* @param mixed $param
* @return bool|string
*/
public function get($param){
$this->cleanup($this->ttl);
$filename = 'u_'.md5(serialize($param));
if(file_exists($this->dir.$filename)) {
$lasttime = filemtime($this->dir.$filename);
if(time()-$lasttime > $this->ttl)
{
return false;
} else {
$fp = fopen($this->dir.$filename, 'r');
$size = filesize($this->dir.$filename);
$content = fread($fp, $size);
return unserialize($content);
}
}
return false;
}
/**
* Set cache value
*
* @param mixed $param
* @param mixed $val
*/
public function set($param, $val){
$filename = 'u_'.md5(serialize($param));
$fp = fopen($this->dir.$filename, 'w');
fwrite($fp, serialize($val));
fclose($fp);
}
/**
* Remove cache files
*
* @param int $expire The number os seconds before expiry
*/
public function cleanup($expire){
if($dir = opendir($this->dir)){
while (false !== ($file = readdir($dir))) {
if(!is_dir($file) && $file != '.' && $file != '..') {
$lasttime = @filemtime($this->dir.$file);
if(time() - $lasttime > $expire){
@unlink($this->dir.$file);
}
}
}
}
}
/**
* delete current user's cache file
*
*/
public function refresh(){
if($dir = opendir($this->dir)){
while (false !== ($file = readdir($dir))) {
if(!is_dir($file) && $file != '.' && $file != '..') {
if(strpos($file, 'u_')!==false){
@unlink($this->dir.$file);
}
}
}
}
}
}
class GetMoodleCommand extends Command
{
private $container;
private $em;
private $output;
private $filesystem;
private $rootlog;
private $widmoodle_url;
private function format_array_postdata_for_curlcall($arraydata, $currentdata, &$data) {
foreach ($arraydata as $k=>$v) {
$newcurrentdata = $currentdata;
if (is_object($v)) {
$v = (array) $v;
}
if (is_array($v)) { //the value is an array, call the function recursively
$newcurrentdata = $newcurrentdata.'['.urlencode($k).']';
$this->format_array_postdata_for_curlcall($v, $newcurrentdata, $data);
} else { //add the POST parameter to the $data array
$data[] = $newcurrentdata.'['.urlencode($k).']='.urlencode($v);
}
}
}
private function format_postdata_for_curlcall($postdata) {
if (is_object($postdata)) {
$postdata = (array) $postdata;
}
$data = array();
foreach ($postdata as $k=>$v) {
if (is_object($v)) {
$v = (array) $v;
}
if (is_array($v)) {
$currentdata = urlencode($k);
$this->format_array_postdata_for_curlcall($v, $currentdata, $data);
} else {
$data[] = urlencode($k).'='.urlencode($v);
}
}
$convertedpostdata = implode('&', $data);
return $convertedpostdata;
}
private function moodleAPI($client, $functionname,$params) {
$url=$this->widmoodle_url."&wsfunction=".$functionname."&moodlewsrestformat=json";
$output = $client->post($url, $params);
return json_decode($output);
}
protected function configure()
{
$this
->setName('Portal:GetMoodle')
->setDescription('Get Datas from Moodle')
->setHelp('Synchronize Moodle')
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->container = $this->getApplication()->getKernel()->getContainer();
$this->em = $this->container->get('doctrine')->getEntityManager();
$this->output = $output;
$this->filesystem = new Filesystem();
$this->moodlefile = $this->container->get('kernel')->getRootDir()."/../uploads/moodle";
$this->rootlog = $this->container->get('kernel')->getRootDir()."/../var/logs/";
$alias = $this->container->getParameter('alias');
$activate_widmoodle = $this->container->getParameter('activate_widmoodle');
if(!$activate_widmoodle) {
$this->writeln('Widget Moodle désactivé');
return 1;
}
$PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYactivate"])->getValue();
$PROXYserver = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYserver"])->getValue();
$PROXYport = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYport"])->getValue();
$this->writelnred('');
$this->writelnred('== Portal:GetMoodle');
$this->writelnred('==========================================================================================================');
$now=new \DateTime('now');
$fgdebug = false;
// Filesystem
$fs = new Filesystem();
// On supprime les potentiels yml.new restant
$fs->remove($this->moodlefile.'-new');
// Instance Moodle
$weburl=$this->container->getParameter('weburl');
$widmoodle_apikey = $this->container->getParameter('widmoodle_apikey');
$this->widmoodle_url = $this->container->getParameter('widmoodle_url')."/webservice/rest/server.php?wstoken=$widmoodle_apikey";
if(stripos($this->widmoodle_url,"/moodle")==0) {
$this->writeln("URL = ".$this->widmoodle_url);
$weburl=$this->container->getParameter('weburl');
$this->widmoodle_url="https://".$weburl.$this->widmoodle_url;
$PROXYactivate=false;
}
if(stripos($this->widmoodle_url,"https://".$weburl)===0) $PROXYactivate=false;
if(stripos($this->widmoodle_url,"http://".$weburl)===0) $PROXYactivate=false;
$client= new curl();
// Pour chaque cours
$courses=$this->moodleAPI($client,"core_course_get_courses",[]);
foreach($courses as $course) {
// Si le cours est visible
if($course->visible) {
/*
$capbs=["mod/lesson:grade","mod/feedback:receivemail"];
$coursecapabilities[] = array('courseid'=> $course->id, 'capabilities' => $capbs);
$eleves=$this->moodleAPI($client,"core_enrol_get_enrolled_users_with_capability",["coursecapabilities"=>$coursecapabilities]);
*/
// Pour chaque eleve du cours
$eleves=$this->moodleAPI($client,"core_enrol_get_enrolled_users",["courseid"=>$course->id]);
foreach($eleves as $eleve) {
$student=false;
$teacher=false;
foreach($eleve->roles as $role ) {
if($role->shortname=="student") $student=true;
if($role->shortname=="editingteacher") $teacher=true;
}
$user = $this->em->getRepository('CadolesCoreBundle:User')->findOneBy(["username"=>$eleve->username]);
if($user) {
$url=$this->container->getParameter('widmoodle_url')."/course/view.php?id=".$course->id;
$string ='"'.$course->id.'": {';
$string.='"title": '.json_encode($course->fullname).',';
$string.='"url": "'.$url.'",';
$string.='"date": "'.$course->startdate.'",';
$string.='"description": '.json_encode($course->summary);
$string.='},';
if($student)
$this->filesystem->appendToFile($this->moodlefile.'-new/'.$user->getId().'/invitation.json', $string."\n");
elseif($teacher)
$this->filesystem->appendToFile($this->moodlefile.'-new/'.$user->getId().'/course.json', $string."\n");
}
}
}
}
// On supprime les encours pour le remplacer le new
if($fs->exists($this->moodlefile.'-new')) {
$fs->remove($this->moodlefile);
$fs->rename($this->moodlefile.'-new',$this->moodlefile);
}
$this->writeln('');
return 1;
}
private function writelnred($string) {
$this->output->writeln('<fg=red>'.$string.'</>');
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
private function writeln($string) {
$this->output->writeln($string);
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
}

View File

@ -34,6 +34,7 @@ class InitDataCommand extends ContainerAwareCommand
$em = $this->getContainer()->get('doctrine')->getEntityManager(); $em = $this->getContainer()->get('doctrine')->getEntityManager();
$alias =$this->getContainer()->getParameter('alias'); $alias =$this->getContainer()->getParameter('alias');
$activate_widlimesurvey =$this->getContainer()->getParameter('activate_widlimesurvey'); $activate_widlimesurvey =$this->getContainer()->getParameter('activate_widlimesurvey');
$activate_widmoodle =$this->getContainer()->getParameter('activate_widmoodle');
$output->writeln('PORTAL = Default Data'); $output->writeln('PORTAL = Default Data');
@ -63,6 +64,18 @@ class InitDataCommand extends ContainerAwareCommand
$em->flush(); $em->flush();
} }
$entity = $em->getRepository('CadolesPortalBundle:Appexternal')->findoneby(["name"=>"Moodle"]);
if(!$entity&&$activate_widmoodle) {
$entity=new Appexternal;
$entity->setName("Moodle");
$em->persist($entity);
$em->flush();
}
elseif($entity&&!$activate_widmoodle) {
$em->remove($entity);
$em->flush();
}
// Creation des icons // Creation des icons
$output->writeln(' > Creation Icons'); $output->writeln(' > Creation Icons');
$finder = new Finder(); $finder = new Finder();
@ -100,6 +113,26 @@ class InitDataCommand extends ContainerAwareCommand
$em->flush(); $em->flush();
} }
$entityFlux = $em->getRepository('CadolesPortalBundle:Flux')->find(-2010);
if(!$entityFlux&&($activate_widmoodle)) {
$entityFlux = new Flux();
$entityFlux->setRowOrder(0);
$entityFlux->setColor("f77f11");
}
elseif($entityFlux&&!($activate_widmoodle)) {
$em->remove($entityFlux);
$em->flush();
$entityWidget=null;
}
if($entityFlux) {
$entityFlux->setId(-2010);
$entityFlux->setTitle("Moodle");
$entityFlux->setUrl("/".$alias."/feed/moodle/##userid##");
$entityFlux->setMaxread(0);
$em->persist($entityFlux);
$em->flush();
}
// Creation des pagecategory // Creation des pagecategory
$output->writeln(' > Creation Pagecategory'); $output->writeln(' > Creation Pagecategory');
$entityPagecategory = $em->getRepository('CadolesPortalBundle:Pagecategory')->find(-100); $entityPagecategory = $em->getRepository('CadolesPortalBundle:Pagecategory')->find(-100);
@ -378,8 +411,8 @@ class InitDataCommand extends ContainerAwareCommand
// Widget Applications Externe // Widget Applications Externe
$entityWidget = $em->getRepository('CadolesPortalBundle:Widget')->find(-1870); $entityWidget = $em->getRepository('CadolesPortalBundle:Widget')->find(-1870);
if(!$entityWidget&&($activate_widlimesurvey)) $entityWidget = new Widget(); if(!$entityWidget&&($activate_widlimesurvey||$activate_widmoodle)) $entityWidget = new Widget();
elseif($entityWidget&&!($activate_widlimesurvey)) { elseif($entityWidget&&!($activate_widlimesurvey||$activate_widmoodle)) {
$pagewidgets=$entityWidget->getPagewidgets(); $pagewidgets=$entityWidget->getPagewidgets();
foreach($pagewidgets as $pagewidget) { foreach($pagewidgets as $pagewidget) {
$em->remove($pagewidget); $em->remove($pagewidget);

View File

@ -39,4 +39,34 @@ class FeedController extends Controller
$response->headers->set('Content-Type', 'application/xml; charset=utf-8'); $response->headers->set('Content-Type', 'application/xml; charset=utf-8');
return $response; return $response;
} }
public function moodleAction($id)
{
$directory=$this->get('kernel')->getRootDir()."/../uploads/moodle/".$id;
$feeds=[];
$fs = new Filesystem();
if($fs->exists($directory."/invitation.json")) {
$file=file_get_contents($directory."/invitation.json");
$json = substr($file, 0, -2); // sup dernier ,
$surveys = json_decode("{".$json."}", true);
foreach($surveys as $id => $survey) {
array_push($feeds,[
"id"=>$id,
"title"=>$survey["title"],
"url"=>$survey["url"],
"date"=>$survey["date"],
"description"=>$survey["description"],
"category"=>"moodle"]);
}
}
$response = new Response($this->renderView('CadolesPortalBundle:Feed:index.xml.twig',array(
"feeds" => $feeds,
)));
$response->headers->set('Content-Type', 'application/xml; charset=utf-8');
return $response;
}
} }

View File

@ -1541,6 +1541,27 @@ class PagewidgetController extends Controller
} }
} }
break;
case "Moodle":
$category=["id"=>1,"label"=>"Moodle"];
array_push($itemcategorys,$category);
$directory=$this->get('kernel')->getRootDir()."/../uploads/moodle/".$user->getId();
$files=[];
$fs = new Filesystem();
if($fs->exists($directory."/course.json")) {
$file=file_get_contents($directory."/course.json");
$json = substr($file, 0, -2); // sup dernier ,
$courses = json_decode("{".$json."}", true);
if(is_array($courses)) {
foreach($courses as $id => $course) {
array_push($items,["id"=>$id,"title"=>$course["title"],"subtitle"=>"Sondage","url"=>$course["url"],"itemcategory"=>$category,"color"=>"f77f11","icon"=>"icon_moodle.png"]);
}
}
}
break; break;
} }
} }

View File

@ -600,7 +600,9 @@ cadoles_portal_user_feed_limesurvey:
path: /feed/limesurvey/{id} path: /feed/limesurvey/{id}
defaults: { _controller: CadolesPortalBundle:Feed:limesurvey } defaults: { _controller: CadolesPortalBundle:Feed:limesurvey }
cadoles_portal_user_feed_moodle:
path: /feed/moodle/{id}
defaults: { _controller: CadolesPortalBundle:Feed:moodle }
#== TOOL ================================================================================================================================================= #== TOOL =================================================================================================================================================

View File

@ -5,7 +5,7 @@
{% block pagewrapper %} {% block pagewrapper %}
{% if access=="config" %} {% if access=="config" %}
<div class="pagemenu"> <div class="pagemenu">
<a href="{{ path('cadoles_portal_config_blog_view', {id:entity.id})}}">{{ entity.name }}</a>> <a href="{{ path('cadoles_portal_config_blog_view', {id:entity.id})}}">{{ entity.name }}</a>
<a href='{{ path('cadoles_portal_config_blog_update', {id:entity.id}) }}' title='Modifier'><i class='fa fa-file fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_blog_update', {id:entity.id}) }}' title='Modifier'><i class='fa fa-file fa-fw'></i></a>
<a href='{{ path('cadoles_portal_config_blog_writer', {id:entity.id}) }}' title='Permission'><i class='fa fa-users fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_blog_writer', {id:entity.id}) }}' title='Permission'><i class='fa fa-users fa-fw'></i></a>
<a href='{{ path('cadoles_portal_config_blog_delete', { id: entity.id }) }}' data-method='delete' data-confirm='Êtes-vous sûr de vouloir supprimer ?' title='Supprimer'><i class='fa fa-trash fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_blog_delete', { id: entity.id }) }}' data-method='delete' data-confirm='Êtes-vous sûr de vouloir supprimer ?' title='Supprimer'><i class='fa fa-trash fa-fw'></i></a>

View File

@ -5,7 +5,7 @@
{% block pagewrapper %} {% block pagewrapper %}
{% if access=="config" %} {% if access=="config" %}
<div class="pagemenu"> <div class="pagemenu">
<a href="{{ path('cadoles_portal_config_calendar_view', {id:entity.id})}}">{{ entity.name }}</a>> <a href="{{ path('cadoles_portal_config_calendar_view', {id:entity.id})}}">{{ entity.name }}</a>
<a href='{{ path('cadoles_portal_config_calendar_update', {id:entity.id}) }}' title='Modifier le panel'><i class='fa fa-file fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_calendar_update', {id:entity.id}) }}' title='Modifier le panel'><i class='fa fa-file fa-fw'></i></a>
<a href='{{ path('cadoles_portal_config_calendar_delete', { id: entity.id }) }}' data-method='delete' data-confirm='Êtes-vous sûr de vouloir supprimer ?' title='Supprimer le panel'><i class='fa fa-trash fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_calendar_delete', { id: entity.id }) }}' data-method='delete' data-confirm='Êtes-vous sûr de vouloir supprimer ?' title='Supprimer le panel'><i class='fa fa-trash fa-fw'></i></a>
</div> </div>

View File

@ -4,7 +4,7 @@
{% block pagewrapper %} {% block pagewrapper %}
{% if access=="config" %} {% if access=="config" %}
<div class="pagemenu"> <div class="pagemenu">
<a href="{{ path('cadoles_portal_config_page_view', {id:entity.id})}}">{{ entity.name }}</a>> <a href="{{ path('cadoles_portal_config_page_view', {id:entity.id})}}">{{ entity.name }}</a>
<a href='{{ path('cadoles_portal_config_page_update', {id:entity.id}) }}' title='Modifier le panel'><i class='fa fa-file fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_page_update', {id:entity.id}) }}' title='Modifier le panel'><i class='fa fa-file fa-fw'></i></a>
<a href='{{ path('cadoles_portal_config_page_delete', { id: entity.id }) }}' data-method='delete' data-confirm='Êtes-vous sûr de vouloir supprimer ?' title='Supprimer le panel'><i class='fa fa-trash fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_page_delete', { id: entity.id }) }}' data-method='delete' data-confirm='Êtes-vous sûr de vouloir supprimer ?' title='Supprimer le panel'><i class='fa fa-trash fa-fw'></i></a>

View File

@ -8,7 +8,7 @@
{% block pagewrapper %} {% block pagewrapper %}
{% if access=="config" %} {% if access=="config" %}
<div class="pagemenu"> <div class="pagemenu">
<a href="{{ path('cadoles_portal_config_page_view', {id:entity.id})}}">{{ entity.name }}</a>> <a href="{{ path('cadoles_portal_config_page_view', {id:entity.id})}}">{{ entity.name }}</a>
<a href='{{ path('cadoles_portal_config_page_update', {id:entity.id}) }}' title='Modifier le panel'><i class='fa fa-file fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_page_update', {id:entity.id}) }}' title='Modifier le panel'><i class='fa fa-file fa-fw'></i></a>
<a href='{{ path('cadoles_portal_config_page_delete', { id: entity.id }) }}' data-method='delete' data-confirm='Êtes-vous sûr de vouloir supprimer ?' title='Supprimer le panel'><i class='fa fa-trash fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_page_delete', { id: entity.id }) }}' data-method='delete' data-confirm='Êtes-vous sûr de vouloir supprimer ?' title='Supprimer le panel'><i class='fa fa-trash fa-fw'></i></a>

View File

@ -5,7 +5,7 @@
{% block pagewrapper %} {% block pagewrapper %}
{% if access=="config" %} {% if access=="config" %}
<div class="pagemenu"> <div class="pagemenu">
<a href="{{ path('cadoles_portal_config_page_view', {id:entity.id})}}">{{ entity.name }}</a>> <a href="{{ path('cadoles_portal_config_page_view', {id:entity.id})}}">{{ entity.name }}</a>
<a href='{{ path('cadoles_portal_config_page_update', {id:entity.id}) }}' title='Modifier le panel'><i class='fa fa-file fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_page_update', {id:entity.id}) }}' title='Modifier le panel'><i class='fa fa-file fa-fw'></i></a>
<a href='{{ path('cadoles_portal_config_page_delete', { id: entity.id }) }}' data-method='delete' data-confirm='Êtes-vous sûr de vouloir supprimer ?' title='Supprimer le panel'><i class='fa fa-trash fa-fw'></i></a> <a href='{{ path('cadoles_portal_config_page_delete', { id: entity.id }) }}' data-method='delete' data-confirm='Êtes-vous sûr de vouloir supprimer ?' title='Supprimer le panel'><i class='fa fa-trash fa-fw'></i></a>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB