Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17249 | Rev 17261 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 17249 Rev 17260
Línea 65... Línea 65...
65
use LeadersLinked\Cache\CacheInterface;
65
use LeadersLinked\Cache\CacheInterface;
66
use LeadersLinked\Cache\CacheImpl;
66
use LeadersLinked\Cache\CacheImpl;
67
use PhpOffice\PhpSpreadsheet\IOFactory;
67
use PhpOffice\PhpSpreadsheet\IOFactory;
68
use LeadersLinked\Mapper\MicrolearningTopicUserMapper;
68
use LeadersLinked\Mapper\MicrolearningTopicUserMapper;
69
use LeadersLinked\Model\MicrolearningTopicUser;
69
use LeadersLinked\Model\MicrolearningTopicUser;
-
 
70
use LeadersLinked\Library\Storage;
Línea 70... Línea 71...
70
 
71
 
71
class MicrolearningAccessForStudentsController extends AbstractActionController
72
class MicrolearningAccessForStudentsController extends AbstractActionController
72
{
73
{
73
    /**
74
    /**
Línea 685... Línea 686...
685
                $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
686
                $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
Línea 686... Línea 687...
686
                
687
                
Línea 687... Línea 688...
687
                $form->setData($dataPost);
688
                $form->setData($dataPost);
-
 
689
                
-
 
690
                if($form->isValid()) {
-
 
691
                    $storage = Storage::getInstance($this->config, $this->adapter);
-
 
692
 
-
 
693
                    $storage->setFiles($dataPost);
-
 
694
 
-
 
695
                    if(!$storage->setCurrentFilename('file')) {
-
 
696
                        return new JsonModel([
-
 
697
                            'success' => false,
-
 
698
                            'data' => 'ERROR_UPLOAD_FILE'
-
 
699
                        ]);
-
 
700
                    }
-
 
701
 
-
 
702
                    $tmp_filename = $storage->getTmpFilename();
-
 
703
                    $filename =   $storage->getFilename();
-
 
704
                    $target_filename = $storage->composePathToFilename(
-
 
705
                        Storage::TYPE_MICROLEARNING_ACCESS_FOR_STUDENTS,
-
 
706
                        $topic->uuid,
Línea 688... Línea -...
688
                
-
 
689
                if($form->isValid()) {
-
 
690
                    
-
 
691
                    $file = $_FILES['file'];
-
 
692
                    $tmp_filename = $file['tmp_name'];
707
                        $filename
693
                    $final_filename =  'data/' . $file['name'];
708
                    );
694
                    
709
                    
695
                    if(!move_uploaded_file($tmp_filename, $final_filename)) {
710
                    if(!$storage->putFile($tmp_filename, $target_filename)) {
696
                        return new JsonModel([
711
                        return new JsonModel([
697
                            'success' => false,
712
                            'success' => false,
Línea 703... Línea 718...
703
                    $count_users = 0;
718
                    $count_users = 0;
704
                    $users = [];
719
                    $users = [];
705
                    $count_errors = 0;
720
                    $count_errors = 0;
706
                    $errors = [];
721
                    $errors = [];
Línea 707... Línea -...
707
                    
-
 
-
 
722
                    
708
                    
723
                    try {
709
                    $spreadsheet = IOFactory::load($final_filename);
724
                        $spreadsheet = IOFactory::load($target_filename);
-
 
725
                        $records = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
-
 
726
                    } catch (\Exception $e) {
-
 
727
                        return new JsonModel([
-
 
728
                            'success' => false,
-
 
729
                            'data' => 'ERROR_UPLOAD_FILE' . $e->getMessage()
-
 
730
                        ]);
Línea 710... Línea 731...
710
                    $records = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
731
                    }
711
                    
732
                    
Línea 712... Línea 733...
712
                    $emails = [];
733
                    $emails = [];
Línea 746... Línea 767...
746
                        $partner = isset($record['J']) ? Functions::sanitizeFilterString($record['J']) : '';
767
                        $partner = isset($record['J']) ? Functions::sanitizeFilterString($record['J']) : '';
747
                        $sector = isset($record['K']) ? Functions::sanitizeFilterString($record['K']) : '';
768
                        $sector = isset($record['K']) ? Functions::sanitizeFilterString($record['K']) : '';
748
                        $studentType = isset($record['L']) ? Functions::sanitizeFilterString($record['L']) : '';
769
                        $studentType = isset($record['L']) ? Functions::sanitizeFilterString($record['L']) : '';
749
                        $country =  isset($record['M']) ? Functions::sanitizeFilterString($record['M']) : '';
770
                        $country =  isset($record['M']) ? Functions::sanitizeFilterString($record['M']) : '';
750
                        $isAdult = isset($record['N']) ? Functions::sanitizeFilterString($record['N']) : '';
771
                        $isAdult = isset($record['N']) ? Functions::sanitizeFilterString($record['N']) : '';
751
 
-
 
Línea 752... Línea 772...
752
                        
772
                        
753
                        if($row == 1) {
773
                        if($row == 1) {
754
                            continue;
774
                            continue;
Línea 755... Línea 775...
755
                        }
775
                        }
756
                        
776
                        
757
                        //||  empty($password)
-
 
758
                        if(empty($first_name) || empty($last_name) || !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
-
 
759
                           
-
 
760
                            
777
                        //||  empty($password)
761
                            
-
 
762
                            continue;
778
                        if(empty($first_name) || empty($last_name) || !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
Línea 763... Línea 779...
763
                            
779
                            continue;                            
Línea 764... Línea 780...
764
                        }
780
                        }
Línea 805... Línea 821...
805
                            ]);
821
                            ]);
806
                        }
822
                        }
807
                    }
823
                    }
Línea 808... Línea 824...
808
 
824
 
-
 
825
                    // cache the users
809
                    // cache the users
826
                    try {
810
                    $key = md5($currentUser->id . '-' . $topic->uuid . '-' . $topic->uuid);
827
                        $key = md5($currentUser->id . '-' . $topic->uuid . '-' . $topic->uuid);
-
 
828
                        $this->cache->setItem($key, serialize($users));
-
 
829
                    } catch (\Exception $e) {
-
 
830
                        return new JsonModel([
-
 
831
                            'success' => false,
-
 
832
                            'data' => 'ERROR_CACHE_SET_ITEM' . $e->getMessage()
-
 
833
                        ]);
Línea 811... Línea 834...
811
                    $this->cache->setItem($key, serialize($users));
834
                    }
812
 
835
 
813
                    // return the key
836
                    // return the key
814
                    return new JsonModel([
837
                    return new JsonModel([