예제 #1
0
 public static function getInstance()
 {
     if (null == self::$_objInstance) {
         self::$_objInstance = new TrainingCourse();
     }
     return self::$_objInstance;
 }
 /**
  * @param array $data
  * @return ICourse
  */
 public function buildTrainingCourse(array $data)
 {
     $course = new TrainingCourse();
     $course_id = intval(Convert::raw2sql(@$data['ID']));
     $training_id = intval(Convert::raw2sql(@$data['TrainingServiceID']));
     $type_id = intval(Convert::raw2sql(@$data['TypeID']));
     $level_id = intval(Convert::raw2sql(@$data['LevelID']));
     if ($course_id > 0) {
         $course->setField('ID', $course_id);
     }
     if ($training_id > 0) {
         $course->setField('TrainingServiceID', $training_id);
     }
     if ($type_id > 0) {
         $course->setField('TypeID', $type_id);
     }
     if ($level_id > 0) {
         $course->setField('LevelID', $level_id);
     }
     $course->setName($data['Name']);
     $course->setDescription($data['Description']);
     if (@$data['Online']) {
         $course->Online();
         $course->setOnlineLink($data['Link']);
     } else {
         $course->Offline();
         $course->setOnlineLink(null);
     }
     if (@$data['Paid']) {
         $course->Paid();
     } else {
         $course->Free();
     }
     return $course;
 }
 function up()
 {
     echo "Starting Migration Proc ...<BR>";
     //check if migration already had ran ...
     $migration = Migration::get()->filter('Name', $this->title)->first();
     if (!$migration) {
         $programs = DB::query('SELECT P.*,C.CompanyID from TrainingProgram P INNER JOIN Contract C on C.ID = P.TrainingContractID;');
         $service = new TrainingManager(new SapphireTrainingServiceRepository(), new SapphireMarketPlaceTypeRepository(), new MarketPlaceTypeAddPolicyStub(), null, new CacheServiceStub(), new MarketplaceFactory(), SapphireTransactionManager::getInstance());
         $factory = new TrainingFactory();
         foreach ($programs as $program) {
             $company_id = (int) $program['CompanyID'];
             $company = Company::get()->byID($company_id);
             $program_id = (int) $program['ID'];
             $training = $factory->buildTraining($program['Name'], $program['Description'], true, $company);
             $training->CompanyID = $company_id;
             $training->write();
             //get former courses and associate it with new entity
             $courses = TrainingCourse::get()->filter('ProgramID', $program_id);
             if ($courses && count($courses) > 0) {
                 foreach ($courses as $course) {
                     $course->TrainingServiceID = $training->getIdentifier();
                     $course->write();
                 }
             }
         }
         //db alter
         DB::query('DROP TABLE Training;');
         DB::query('ALTER TABLE `TrainingCourse` DROP COLUMN ProgramID;');
         DB::query('DROP TABLE TrainingProgram;');
         $new_training_group_slug = ITraining::MarketPlaceGroupSlug;
         DB::query("\n\t\t\tUPDATE `Company_Administrators`\n\t\t\tSET GroupID = (SELECT ID FROM `Group` WHERE code='{$new_training_group_slug}' LIMIT 1 )\n\t\t\tWHERE ID IN (\n\t\t\t\tSELECT tmp.id FROM\n\t\t\t\t(\n\t\t\t\t\tSELECT ID FROM `Company_Administrators`\n\t\t\t\t\tWHERE GroupID IN ( SELECT ID FROM `Group` where code='training-admins')\n\t\t\t\t) as tmp\n\t\t\t);\n\t\t\t");
         DB::query("\n\t\t\tDELETE Permission\n\t\t\tFROM Permission\n\t\t\tWHERE Code='MANAGE_COMPANY_TRAINING';\n\t\t\t");
         $migration = new Migration();
         $migration->Name = $this->title;
         $migration->Description = $this->description;
         $migration->Write();
     }
     echo "Ending  Migration Proc ...<BR>";
 }
예제 #4
0
<?php

require_once 'Repository/TrainingCourse.php';
$savedata['name'] = $_POST['name'];
$savedata['short_name'] = $_POST['short_name'];
TrainingCourse::getInstance()->saveOrUpdate($savedata, 'course');