public function afterUpdate($object, $line)
 {
     if (FleximportConfig::get("SEMIRO_SEND_MESSAGES")) {
         $messaging = new messaging();
         //Email an Dozenten:
         foreach ((array) $this->new_dozenten as $user_id) {
             $message = sprintf(_('Sie wurden von Semiro als DozentIn in die Veranstaltung **%s** eingetragen.'), $object->name);
             $messaging->insert_message($message, get_username($user_id), '____%system%____', FALSE, FALSE, '1', FALSE, sprintf('%s %s', _('Systemnachricht:'), _('Eintragung in Veranstaltung')), TRUE);
         }
     }
     $teilnehmergruppe = $line['teilnehmergruppe'];
     $import_type = "semiro_participant_import_" . $object->getId() . "_" . md5($teilnehmergruppe);
     $imported_items = array();
     if ($teilnehmergruppe && $object->getId()) {
         $seminar = new Seminar($object->getId());
         $datafield = Datafield::findOneByName(FleximportConfig::get("SEMIRO_USER_DATAFIELD_NAME"));
         $dilp_kennung_feld = FleximportConfig::get("SEMIRO_DILP_KENNUNG_FIELD");
         if (!$dilp_kennung_feld) {
             $dilp_kennung_feld = "dilp_teilnehmer";
         }
         if ($datafield) {
             $statement = DBManager::get()->prepare("\n                    SELECT `" . addslashes($dilp_kennung_feld) . "`\n                    FROM fleximport_semiro_participant_import\n                    WHERE teilnehmergruppe = ?\n                ");
             $statement->execute(array($teilnehmergruppe));
             while ($id_teilnehmer = $statement->fetch(PDO::FETCH_COLUMN, 0)) {
                 //$ids = $statement->fetchAll(PDO::FETCH_COLUMN, 0);
                 //foreach ($ids as $id_teilnehmer) {
                 $entry = DatafieldEntryModel::findOneBySQL("datafield_id = ? AND content = ? ", array($datafield->getId(), $id_teilnehmer));
                 if ($entry) {
                     $was_member = CourseMember::findOneBySQL("seminar_id = ? AND user_id = ?", array($object->getId(), $entry['range_id']));
                     $seminar->addMember($entry['range_id']);
                     if (!$was_member && FleximportConfig::get("SEMIRO_SEND_MESSAGES")) {
                         $message = sprintf(_('Sie wurden von Semiro als TeilnehmerIn in die Veranstaltung **%s** eingetragen.'), $seminar->name);
                         $messaging->insert_message($message, get_username($entry['range_id']), '____%system%____', FALSE, FALSE, '1', FALSE, sprintf('%s %s', _('Systemnachricht:'), _('Eintragung in Veranstaltung')), TRUE);
                     }
                     //Zu Statusgruppe hinzufügen:
                     $gruppe = Statusgruppen::findOneBySQL("range_id = ? AND name = ?", array($object->getId(), $teilnehmergruppe));
                     if (!$gruppe) {
                         $gruppe = new Statusgruppen();
                         $gruppe['range_id'] = $object->getId();
                         $gruppe['name'] = $teilnehmergruppe;
                         $gruppe->store();
                     }
                     if (!$gruppe->isMember($entry['range_id'])) {
                         $gruppe->addUser($entry['range_id']);
                     }
                     //$gruppe->updateFolder(true);
                     if (!$gruppe->hasFolder()) {
                         create_folder(_("Dateiordner der Gruppe:") . ' ' . $teilnehmergruppe, _("Ablage für Ordner und Dokumente dieser Gruppe"), $gruppe->id, 15, $object->getId());
                     }
                     $item_id = $entry['range_id'];
                     if (!in_array($item_id, $imported_items)) {
                         $mapped = FleximportMappedItem::findbyItemId($item_id, $import_type) ?: new FleximportMappedItem();
                         $mapped['import_type'] = $import_type;
                         $mapped['item_id'] = $item_id;
                         $mapped['chdate'] = time();
                         $mapped->store();
                         $imported_items[] = $item_id;
                     }
                 }
             }
         }
         //Dozent zu Statusgruppe hinzufügen:
         $gruppe = Statusgruppen::findOneBySQL("range_id = ? AND name = ?", array($object->getId(), $teilnehmergruppe));
         foreach ($object->members->filter(function ($member, $value) {
             return $member['status'] === "dozent";
         }) as $teacher) {
             if (!$gruppe->isMember($teacher->getId())) {
                 $gruppe->addUser($teacher->getId());
             }
         }
         $items = FleximportMappedItem::findBySQL("import_type = :import_type AND item_id NOT IN (:ids)", array('import_type' => $import_type, 'ids' => $imported_items ?: ""));
         foreach ($items as $item) {
             $user_id = $item['item_id'];
             //check if user is in another group of this course
             $statement = DBManager::get()->prepare("\n                    SELECT 1\n                    FROM fleximport_semiro_participant_import\n                        INNER JOIN fleximport_semiro_course_import ON (fleximport_semiro_course_import.teilnehmergruppe = fleximport_semiro_participant_import.teilnehmergruppe)\n                    WHERE `" . addslashes($dilp_kennung_feld) . "` = :user_dilp\n                        AND fleximport_semiro_course_import.name_veranstaltung = :name\n                ");
             $dilp_entry = DatafieldEntryModel::findOneBySQL("datafield_id = ? AND range_id = ? ", array($datafield->getId(), $user_id));
             $statement->execute(array('user_dilp' => $dilp_entry['content'], 'name' => $object['name']));
             $is_still_in_course = $statement->fetch(PDO::FETCH_COLUMN, 0);
             if (!$is_still_in_course) {
                 $seminar->deleteMember($user_id);
             }
             $item->delete();
         }
     }
 }
 /**
  * Import and update the dates
  */
 public function afterUpdate(SimpleORMap $object, $line)
 {
     $weekdays = array('so' => 0, 'su' => 0, 'mo' => 1, 'di' => 2, 'die' => 2, 'tue' => 2, 'mi' => 3, 'we' => 3, 'do' => 4, 'thu' => 4, 'fr' => 5, 'fri' => 5, 'sa' => 6);
     $zeiten = $line['zeit'];
     $zeiten = preg_split("/\\s*,\\s*/", $zeiten, null, PREG_SPLIT_NO_EMPTY);
     $singledates = array();
     $metadates = array();
     $import_type_dates = "karlsruhe_coursedates_import_" . $object->getId();
     $import_type_metadates = "karlsruhe_coursemetadates_import_" . $object->getId();
     foreach ($zeiten as $zeit) {
         if (!is_numeric(trim($zeit[0]))) {
             preg_match("/(\\w+) (\\d+):(\\d+)\\s*-\\s*(\\d+):(\\d+)/", $zeit, $matches);
             $day = strtolower($matches[1]);
             if (isset($weekdays[$day])) {
                 $statement = DBManager::get()->prepare("\n                        SELECT metadate_id \n                        FROM seminar_cycle_dates \n                        WHERE seminar_id = :course_id\n                            AND start_time = :start_time\n                            AND end_time = :end_time\n                            AND weekday = :weekday\n                    ");
                 $statement->execute(array('course_id' => $object->getId(), 'start_time' => $matches[2] . ":" . $matches[3] . ":00", 'end_time' => $matches[4] . ":" . $matches[5] . ":00", 'weekday' => $weekdays[$day]));
                 $found = false;
                 foreach ($statement->fetchAll(PDO::FETCH_COLUMN) as $cycle_id) {
                     if (FleximportMappedItem::findbyItemId($cycle_id, $import_type_metadates)) {
                         $found = $cycle_id;
                         break;
                     }
                 }
                 if (!$found) {
                     /*$semester = $object->end_semester;
                       $cycle = new SeminarCycleDate(); //Does not work yet
                       $cycle['seminar_id'] = $object->getId();
                       $cycle->start_hour = $matches[2];
                       $cycle->start_minute = $matches[3];
                       $cycle->end_hour = $matches[4];
                       $cycle->end_minute = $matches[5];
                       $cycle['weekday'] = $weekdays[$day];
                       $cycle['week_offset'] = 0;
                       $cycle['end_offset'] = floor(($semester->ende - $semester->beginn) / (7*24*60*60)) - 2;
                       $cycle['cycle'] = 0; //wöchentlich
                       $cycle->store();
                       $cycle_id = $cycle->getId();*/
                     $seminar = new Seminar($object->getId());
                     $cycle_id = $seminar->addCycle(array('day' => $weekdays[$day], 'start_stunde' => $matches[2], 'start_minute' => $matches[3], 'end_stunde' => $matches[4], 'end_minute' => $matches[5], 'week_offset' => 0, 'startWeek' => 0, 'turnus' => 0));
                     $mapped = new FleximportMappedItem();
                     $mapped['table_id'] = $import_type_metadates;
                     $mapped['item_id'] = $cycle_id;
                     $mapped->store();
                     $metadates[] = $cycle_id;
                 } else {
                     $seminar = new Seminar($object->getId());
                     $seminar->editCycle(array('cycle_id' => $found, 'day' => $weekdays[$day], 'start_stunde' => $matches[2], 'start_minute' => $matches[3], 'end_stunde' => $matches[4], 'end_minute' => $matches[5], 'week_offset' => 0, 'startWeek' => 0, 'turnus' => 0));
                     /*$semester = $object->end_semester;
                       $cycle = new SeminarCycleDate($found);
                       $cycle['seminar_id'] = $object->getId();
                       $cycle->start_hour = $matches[2];
                       $cycle->start_minute = $matches[3];
                       $cycle->end_hour = $matches[4];
                       $cycle->end_minute = $matches[5];
                       $cycle['weekday'] = $weekdays[$day];
                       $cycle['cycle'] = 0; //wöchentlich
                       $cycle['week_offset'] = 0;
                       $cycle['end_offset'] = floor(($semester->ende - $semester->beginn) / (7*24*60*60)) - 2;
                       $cycle->store();*/
                     $metadates[] = $found;
                 }
             }
         } else {
             //$zeit = explode("-", $zeit);
             preg_match("/(\\d{4}-\\d{1,2}-\\d{1,2}\\s+\\d{1,2}:\\d{1,2})\\s*-\\s(\\d{4}-\\d{1,2}-\\d{1,2}\\s+\\d{1,2}:\\d{1,2})/", $zeit, $matches);
             $begin = strtotime($matches[1]);
             $end = strtotime($matches[2]);
             $found = false;
             $dates = CourseDate::findBySQL("range_id = :course_id AND date = :begin AND end_time = :end", array('course_id' => $object->getId(), 'begin' => $begin, 'end' => $end));
             foreach ($dates as $date) {
                 if (FleximportMappedItem::findbyItemId($date->getId(), $import_type_dates)) {
                     $found = true;
                     $singledates[] = $date->getId();
                     break;
                 }
             }
             if (!$found) {
                 $date = new CourseDate();
                 $date['range_id'] = $object->getId();
                 $date['date'] = $begin;
                 $date['end_time'] = $end;
                 $date->store();
                 $mapped = new FleximportMappedItem();
                 $mapped['table_id'] = $import_type_dates;
                 $mapped['item_id'] = $date->getId();
                 $mapped->store();
                 $singledates[] = $date->getId();
             }
         }
     }
     $items = FleximportMappedItem::findBySQL("table_id = :table_id AND item_id NOT IN (:ids)", array('table_id' => $import_type_dates, 'ids' => $singledates ?: ""));
     foreach ($items as $item) {
         $date = new CourseDate($item['item_id']);
         $date->delete();
         $item->delete();
     }
     $items = FleximportMappedItem::findBySQL("table_id = :table_id AND item_id NOT IN (:ids)", array('table_id' => $import_type_metadates, 'ids' => $metadates ?: ""));
     foreach ($items as $item) {
         $cycle = new SeminarCycleDate($item['item_id']);
         $cycle->delete();
     }
 }
示例#3
0
 public function countDeletableItems($not = array())
 {
     return FleximportMappedItem::countBySQL("table_id = :table_id AND item_id NOT IN (:ids)", array('table_id' => $this->getId(), 'ids' => $not ?: ""));
 }