function up()
 {
     echo "Starting Migration Proc ...<BR>";
     //check if migration already had ran ...
     $migration = DataObject::get_one("Migration", "Name='{$this->title}'");
     if (!$migration) {
         //first we add the platform InteropProgramType
         $platform = InteropProgramType::get("InteropProgramType", "ShortName = 'Platform'")->first();
         if (!$platform) {
             $platform = new InteropProgramType();
             $platform->Name = 'OpenStack Powered Platform';
             $platform->ShortName = 'Platform';
             $platform->HasCapabilities = true;
             $platform->Order = 1;
             $platform->write();
             $platform = InteropProgramType::get("InteropProgramType", "ShortName = 'Platform'")->first();
         }
         //then migrate the old InteropProgramType relations with capability and designated sections
         $relations = DB::query('SELECT cap.ID AS capID, pt.ID AS ptID, pv.ID AS pvID, cap.Order AS capOrder
                                 FROM InteropCapability AS cap
                                 LEFT JOIN InteropProgramType AS pt ON cap.ProgramID = pt.ID
                                 LEFT JOIN InteropProgramVersion AS pv ON cap.VersionID = pv.ID');
         foreach ($relations as $relation) {
             $capability = InteropCapability::get_by_id('InteropCapability', $relation['capID']);
             $program = InteropProgramType::get_by_id('InteropProgramType', $relation['ptID']);
             $version = InteropProgramVersion::get_by_id('InteropProgramVersion', $relation['pvID']);
             $capability->Program()->add($program);
             $capability->Program()->add($platform);
             $capability->Version()->add($version, array('Order' => $relation['capOrder']));
             $capability->write();
         }
         $relations = DB::query('SELECT ds.ID AS dsID, pt.ID AS ptID, pv.ID AS pvID, ds.Order AS dsOrder
                                 FROM InteropDesignatedSection AS ds
                                 LEFT JOIN InteropProgramType AS pt ON ds.ProgramID = pt.ID
                                 LEFT JOIN InteropProgramVersion AS pv ON ds.VersionID = pv.ID');
         foreach ($relations as $relation) {
             $dsection = InteropDesignatedSection::get_by_id('InteropDesignatedSection', $relation['dsID']);
             $program = InteropProgramType::get_by_id('InteropProgramType', $relation['ptID']);
             $version = InteropProgramVersion::get_by_id('InteropProgramVersion', $relation['pvID']);
             $dsection->Program()->add($program);
             $dsection->Program()->add($platform);
             $dsection->Version()->add($version, array('Order' => $relation['dsOrder']));
             $dsection->write();
         }
         //finally remove ProgramID and VersionID column from capability and designatedsection
         DB::query('ALTER TABLE InteropCapability DROP COLUMN ProgramID');
         DB::query('ALTER TABLE InteropDesignatedSection DROP COLUMN ProgramID');
         DB::query('ALTER TABLE InteropCapability DROP COLUMN VersionID');
         DB::query('ALTER TABLE InteropDesignatedSection DROP COLUMN VersionID');
         DB::query('ALTER TABLE InteropCapability DROP COLUMN `Order`');
         DB::query('ALTER TABLE InteropDesignatedSection DROP COLUMN `Order`');
         $migration = new Migration();
         $migration->Name = $this->title;
         $migration->Description = $this->description;
         $migration->Write();
     }
     echo "Ending  Migration Proc ...<BR>";
 }
 function getCMSFields()
 {
     $fields = new FieldList();
     $fields->add(new TextField('Name', 'Name'));
     $fields->add(new HtmlEditorField('Comment', 'Comment'));
     $fields->add(new HtmlEditorField('Guidance', 'Guidance'));
     $fields->add(new DropdownField('Status', 'Status', $this->dbObject('Status')->enumValues()));
     $fields->add($ddl_program = new CheckboxsetField('Program', 'Program', InteropProgramType::get()->filter('HasCapabilities', true)->sort('Order')->map("ID", "ShortName")));
     $fields->add($ddl_version = new CheckboxsetField('Version', 'Version', InteropProgramVersion::get()->map("ID", "Name")));
     if ($this->ID > 0) {
         $ddl_program->setValue('ID', $this->Program());
         $ddl_version->setValue('ID', $this->Version());
     }
     return $fields;
 }
 function getCMSFields()
 {
     $fields = new FieldList();
     $fields->add(new TextField('Name', 'Name'));
     $fields->add(new HtmlEditorField('Description', 'Description'));
     $fields->add(new DropdownField('Status', 'Status', $this->dbObject('Status')->enumValues()));
     $fields->add($ddl_program = new CheckboxsetField('Program', 'Program', InteropProgramType::get()->filter('HasCapabilities', true)->sort('Order')->map("ID", "ShortName")));
     $fields->add($ddl_version = new CheckboxsetField('Version', 'Version', InteropProgramVersion::get()->map("ID", "Name")));
     $fields->add($ddl_type = new DropdownField('TypeID', 'Type', Dataobject::get("InteropCapabilityType")->map("ID", "Name", "Please Select")));
     if ($this->ID > 0) {
         $ddl_program->setValue('ID', $this->Program());
         $ddl_version->setValue('ID', $this->Version());
         $ddl_type->setValue($this->TypeID);
     }
     return $fields;
 }
 public function getDesignatedSectionsByProgramType($program_type)
 {
     if ($program_type) {
         $program_type = InteropProgramType::get('InteropProgramType')->filter('Name', $program_type);
         return $this->DesignatedSections()->filter('Program.ID', $program_type->First()->ID)->sort('Order');
     } else {
         return $this->DesignatedSections()->sort('Order');
     }
 }