/** * 发送Notice */ private function sendNotice($courseId, $announcementId, $entityType = 'announcement_added') { $courseMember = new CourseMember(); $members = $courseMember->findAllByAttributes(array('courseId' => $courseId)); foreach ($members as $k => $v) { $entity = new Entity(); $eData['type'] = 'announcement'; $entity->attributes = $eData; $entity->save(); $notice = new Notice(); $nData['userId'] = $v->userId; $nData['type'] = $entityType; $nData['addTime'] = time(); $nData['data'] = serialize(Announcement::model()->findByPk($announcementId)->id); $notice->attributes = $nData; $notice->save(); } }
private function findMembershipsByUserId($user_id, $semester) { $memberships = \SimpleORMapCollection::createFromArray(\CourseMember::findBySQL('user_id = ? ORDER BY mkdate ASC', array($user_id))); // filter by semester if ($semester) { $memberships = $memberships->filter(function ($m) use($semester) { $course = $m->course; return $course->start_time == $semester->beginn || $course->start_time <= $semester->beginn && ($course->duration_time == -1 || $semester->beginn <= $course->end_time); }); } return $memberships; }
public function actionDeleteMember($id, $userId) { $member = CourseMember::model()->findByAttributes(array('courseId' => $id, 'userId' => $userId)); if ($member && $member->delete()) { Yii::app()->user->setFlash('success', Yii::t('app', '删除成功!')); } else { Yii::app()->user->setFlash('error', Yii::t('app', '删除失败!')); } $this->redirect(array('members', 'id' => $id)); }
/** * * @param type $user_id * @return type */ public static function GetCoursesActivatedCalendar($user_id) { $courses_user = SimpleCollection::createFromArray(CourseMember::findByUser($user_id)); $modules = new Modules(); $courses = $courses_user->filter(function ($c) use($modules) { if ($modules->isBit($c->course->modules, $modules->registered_modules['calendar']['id'])) { return $c; } }); return $courses->pluck('course'); }
/** * Retrieves the number of all members of a status * * @param String|Array $status the status to filter with * * @return int the number of all those members. */ function countMembersWithStatus($status) { return CourseMember::countByCourseAndStatus($this->id, $status); }
public function switchdeputy_action($course_id, $newstatus) { $course = Seminar::getInstance($course_id); switch ($newstatus) { case 'dozent': $dozent = new CourseMember(); $dozent->seminar_id = $course_id; $dozent->user_id = $GLOBALS['user']->id; $dozent->status = 'dozent'; $dozent->comment = ''; if ($dozent->store()) { deleteDeputy($GLOBALS['user']->id, $course_id); PageLayout::postSuccess(sprintf(_('Sie wurden als %s eingetragen.'), get_title_for_status('dozent', 1))); } else { PageLayout::postError(sprintf(_('Sie konnten nicht als %s eingetragen werden.'), get_title_for_status('dozent', 1))); } break; case 'deputy': $dozent = Course::find($course_id)->members->findOneBy('user_id', $GLOBALS['user']->id); if (addDeputy($GLOBALS['user']->id, $course_id)) { $dozent->delete(); PageLayout::postSuccess(_('Sie wurden als Vertretung eingetragen.')); } else { PageLayout::postError(_('Sie konnten nicht als Vertretung eingetragen werden.')); } break; } $this->flash['open'] = "bd_personal"; $this->redirect($this->url_for('course/basicdata/view/' . $course_id)); }
/** * Returns the teacher for a given cours * * @param String $course_id Id of the course * @return array of user infos [user_id, username, Nachname, fullname] */ private function getTeacher($course_id) { $teachers = CourseMember::findByCourseAndStatus($course_id, 'dozent'); $collection = SimpleCollection::createFromArray($teachers); return $collection->map(function (CourseMember $teacher) { return array('user_id' => $teacher->user_id, 'username' => $teacher->username, 'Nachname' => $teacher->nachname, 'fullname' => $teacher->getUserFullname('no_title_rev')); }); }
/** * adds user with given id on waitinglist * * @param string $user_id * @param string $which_end 'last' or 'first' * @return integer 1 if successfull */ public function addToWaitlist($user_id, $which_end = 'last') { if (AdmissionApplication::exists(array($user_id, $this->id)) || CourseMember::find(array($this->id, $user_id))) { return false; } switch ($which_end) { // Append users to waitlist end. case 'last': $maxpos = DBManager::get()->fetchColumn("SELECT MAX(`position`) FROM `admission_seminar_user` WHERE `seminar_id`=? AND `status`='awaiting'", array($this->id)); $waitpos = $maxpos+1; break; // Prepend users to waitlist start. case 'first': default: // Move all others on the waitlist up by the number of people to add. DBManager::get()->execute("UPDATE `admission_seminar_user` SET `position`=`position`+1 WHERE `seminar_id`=? AND `status`='awaiting'", array($this->id)); $waitpos = 1; } $new_admission_member = new AdmissionApplication(); $new_admission_member->user_id = $user_id; $new_admission_member->position = $waitpos; $new_admission_member->status = 'awaiting'; $new_admission_member->seminar_id = $this->id; if ($new_admission_member->store()) { StudipLog::log('SEM_USER_ADD', $this->id, $user_id, 'awaiting', 'Auf Warteliste gesetzt, Position: ' . $waitpos); $this->course->resetRelation('admission_applicants'); return 1; } return false; }
public function actionAddComment($id) { $model = $this->loadModel($id); $comment = new Comment(); if (isset($_POST['Comment'])) { $comment->attributes = $_POST['Comment']; if ($model->addComment($comment)) { $model->upTime = time(); $model->save(); //发送消息 if ($model->asa('followable')) { $follows = $model->getAllFollows(); foreach ($follows as $follow) { if ($follow->userId != $comment->userId && $follow->userId != $comment->referId) { Notice::send($follow->userId, $model->entity->type . "_comment_added", array('commentId' => $comment->id)); } } } //更新回复统计 $member = CourseMember::model()->findByAttributes(array('userId' => Yii::app()->user->id, 'courseId' => $model->courseId)); if ($member) { $criteria = new CDbCriteria(); $criteria->join = "inner join {{course_post}} p on p.entityId=t.commentableEntityId"; $criteria->condition = "p.courseId=" . intval($model->courseId) . " and t.userId=" . Yii::app()->user->id; // Comment::model()->count($criteria); $member->commentNum = Comment::model()->count($criteria); $member->save(); } Yii::app()->user->setFlash('success', '回复成功!'); } else { Yii::app()->user->setFlash('error', '抱歉,回复失败!'); } } $this->redirect(array('view', 'id' => $model->id)); }
/** * Get the visibility of a user in a seminar * @param String $user_id * @param String $seminar_id * @return Array */ private function getUserVisibility() { $member = CourseMember::find(array($this->course_id, $this->user_id)); $visibility = $member->visible; $status = $member->status; #echo "<pre>"; var_dump($member); echo "</pre>"; $result['visible_mode'] = false; if ($visibility) { $result['iam_visible'] = $visibility == 'yes' || $visibility == 'unknown'; if ($status == 'user' || $status == 'autor') { $result['visible_mode'] = 'participant'; } else { $result['iam_visible'] = true; $result['visible_mode'] = false; } } return $result; }
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(); } } }
public function actionAlipayNotify() { // error_log("ok"); // error_log(print_r($_POST,true)); //ali验证不允许有多余参数 if (isset($_GET['r'])) { unset($_GET['r']); } global $sysSettings; $alipay = new Alipay($sysSettings['payment']['aliPartner'], $sysSettings['payment']['aliKey']); if ($alipay->verifyNotify()) { //验证成功 //商户订单号 $out_trade_no = $_POST['out_trade_no']; //支付宝交易号 $trade_no = $_POST['trade_no']; //交易状态 $trade_status = $_POST['trade_status']; $order = Order::model()->findByPk($out_trade_no); $course = Course::model()->findByAttributes(array('entityId' => $order->produceEntityId)); $user = UserInfo::model()->findByPk($order->userId); if ($trade_status == 'WAIT_BUYER_PAY') { //该判断表示买家已在支付宝交易管理中产生了交易记录,但没有付款 echo "success"; //请不要修改或删除 } else { if ($trade_status == 'WAIT_BUYER_CONFIRM_GOODS' || $trade_status == 'WAIT_BUYER_CONFIRM_GOODS' || $trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') { $order->status = Order::ORDER_PAID; $order->tradeNo = $trade_no; $order->save(); $member = CourseMember::model()->findByAttributes(array('userId' => Yii::app()->user->id, 'courseId' => $course->id)); if (!$member) { $member = new CourseMember(); $member->userId = $user->id; $member->courseId = $course->id; $member->arrRoles = array('student'); $member->startTime = time(); $member->save(); } else { $member->startTime = time(); $member->save(); } echo "success"; //请不要修改或删除 } else { //其他状态判断 echo "success"; } } } else { //验证失败 echo "fail"; } }
/** * Adds the given users to the target course. * @param array $users users to add * @param string $target_course which course to add users to * @param bool $move move users (=delete in source course) or just add to target course? * @return array success and failure statuses */ public function sendToCourse($users, $target_course_id, $move = false) { $msg = array(); foreach ($users as $user) { if (!CourseMember::exists(array($target_course_id, $user))) { $target_course = new Seminar($target_course_id); if ($target_course->addMember($user)) { if ($move) { $remove_from = Seminar::getInstance($this->course_id); $remove_from->deleteMember($user); } $msg['success'][] = $user; } else { $msg['failed'][] = $user; } } else { $msg['existing'][] = $user; } } return $msg; }
static function storeSingleDate($termin) { $table = 'termine'; if ($termin->isExTermin()) { $table = 'ex_termine'; $query = "SELECT assign_id FROM resources_assign WHERE assign_user_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($termin->getTerminID())); $assign_id = $statement->fetchColumn(); if ($assign_id) { // delete resource-request, if any if ($request_id = self::getRequestID($termin->getTerminID())) { $rr = new RoomRequest($request_id); $rr->delete(); } // delete resource assignment, if any AssignObject::Factory($assign_id)->delete(); } } $issueIDs = $termin->getIssueIDs(); if (is_array($issueIDs)) { $query = "REPLACE INTO themen_termine (termin_id, issue_id)\n VALUES (?, ?)"; $statement = DBManager::get()->prepare($query); foreach ($issueIDs as $val) { $statement->execute(array($termin->getTerminID(), $val)); } } if ($termin->isUpdate()) { $query = "UPDATE :table\n SET metadate_id = :metadate_id, date_typ = :date_typ,\n date = :date, end_time = :end_time,\n range_id = :range_id, autor_id = :autor_id,\n raum = :raum, content = :content\n WHERE termin_id = :termin_id"; $statement = DBManager::get()->prepare($query); $statement->bindValue(':table', $table, StudipPDO::PARAM_COLUMN); $statement->bindValue(':metadate_id', $termin->getMetaDateID() ?: null); $statement->bindValue(':date_typ', $termin->getDateType()); $statement->bindValue(':date', $termin->getStartTime()); $statement->bindValue(':end_time', $termin->getEndTime()); $statement->bindValue(':range_id', $termin->getRangeID()); $statement->bindValue(':autor_id', $termin->getAuthorID()); $statement->bindValue(':raum', $termin->getFreeRoomText()); $statement->bindValue(':content', $termin->getComment()); $statement->bindValue(':termin_id', $termin->getTerminID()); $statement->execute(); if ($statement->rowCount() > 0) { $query = "UPDATE :table SET chdate = :chdate WHERE termin_id = :termin_id"; $statement = DBManager::get()->prepare($query); $statement->bindValue(':table', $table, StudipPDO::PARAM_COLUMN); $statement->bindValue(':chdate', $termin->getChDate()); $statement->bindValue(':termin_id', $termin->getTerminID()); $statement->execute(); } } else { $query = "REPLACE INTO :table\n (metadate_id, date_typ, date, end_time, mkdate, chdate,\n termin_id, range_id, autor_id, raum, content)\n VALUES\n (:metadate_id, :date_typ, :date, :end_time, :mkdate, :chdate,\n :termin_id, :range_id, :autor_id, :raum, :content)"; $statement = DBManager::get()->prepare($query); $statement->bindValue(':table', $table, StudipPDO::PARAM_COLUMN); $statement->bindValue(':metadate_id', $termin->getMetaDateID()); $statement->bindValue(':date_typ', $termin->getDateType()); $statement->bindValue(':date', $termin->getStartTime()); $statement->bindValue(':end_time', $termin->getEndTime()); $statement->bindValue(':mkdate', $termin->getMkDate()); $statement->bindValue(':chdate', $termin->getChDate()); $statement->bindValue(':termin_id', $termin->getTerminID()); $statement->bindValue(':range_id', $termin->getRangeID()); $statement->bindValue(':autor_id', $termin->getAuthorID()); $statement->bindValue(':raum', $termin->getFreeRoomText()); $statement->bindValue(':content', $termin->getComment()); $statement->execute(); } $query = "DELETE FROM termin_related_persons WHERE range_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($termin->getTerminId())); if (count($termin->related_persons) && count($termin->related_persons) < CourseMember::countBySQL("Seminar_id = ? AND status = 'dozent'", array($termin->range_id))) { $query = "INSERT IGNORE INTO termin_related_persons (range_id, user_id) VALUES (?, ?)"; $statement = DBManager::get()->prepare($query); foreach ($termin->getRelatedPersons() as $user_id) { $statement->execute(array($termin->getTerminId(), $user_id)); } } $query = "DELETE FROM termin_related_groups WHERE termin_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($termin->getTerminId())); if (count($termin->related_groups) && count($termin->related_groups) < Statusgruppen::countBySQL("range_id = ?", array($termin->range_id))) { $query = "INSERT IGNORE INTO termin_related_groups (termin_id, statusgruppe_id) VALUES (?, ?)"; $statement = DBManager::get()->prepare($query); foreach ($termin->getRelatedGroups() as $statusgruppe_id) { $statement->execute(array($termin->getTerminId(), $statusgruppe_id)); } } return true; }
public function findMember($c = array()) { $c = array_merge_recursive($c, array('courseId' => $this->owner->id)); return CourseMember::model()->findByAttributes($c); //'userId'=>Yii::app()->user->id }