public function import(CFormModel $source) { $data = $source->getData(); $markIds = array(); $isFirstRow = true; foreach ($data as $row) { if ($isFirstRow) { // это первая строка - в не идентификаторы оценок $isFirstRow = false; $markIds = $row; } else { // это все остальные строки - здесь уже студенты $student = CStaffManager::getStudent($row[0]); if (!is_null($student)) { $isFirstCol = true; foreach ($row as $id => $cell) { if (!$isFirstCol) { if ($cell != "") { // если не пустая, то берем дисциплину $subjectId = $markIds[$id]; $subject = CTaxonomyManager::getDiscipline($subjectId); if (!is_null($subject)) { // если дисциплина есть, то происходит маппинг оценок $marks = array("2" => "4", "3" => "3", "4" => "2", "5" => "1"); // создаем запись об оценке $activity = new CStudentActivity(); $activity->subject_id = $subject->getId(); $activity->kadri_id = $source->person; $activity->student_id = $student->getId(); $activity->date_act = date("Y-m-d", strtotime($source->created)); if (mb_strlen($cell) == 2 || strlen($cell) == 2) { // это курсовой $cell = mb_substr($cell, 0, 1); $activity->study_act_id = 43; if (array_key_exists($cell, $marks)) { $activity->study_mark = $marks[$cell]; } } elseif (array_key_exists($cell, $marks)) { // это экзамен $activity->study_act_id = 1; $activity->study_mark = $marks[$cell]; } else { // это зачет $activity->study_act_id = 2; $activity->study_mark = 5; } $activity->save(); } } } else { // пропускаем первую ячейку - в ней идентификатор студента $isFirstCol = false; } } } } } return true; }
public function actionSaveGroup() { $activity = new CStudentActivitiesList(); $activity->setAttributes(CRequest::getArray($activity::getClassName())); if ($activity->validate()) { // если стоит флаг запоминания данных, то пишем их в куки на месяц if (CRequest::getString("saveValues") == "1") { setcookie("gradebook[multiple][date_act]", $activity->date_act, time() + 1209600); setcookie("gradebook[multiple][subject_id]", $activity->subject_id, time() + 1209600); setcookie("gradebook[multiple][kadri_id]", $activity->kadri_id, time() + 1209600); setcookie("gradebook[multiple][group_id]", $activity->group_id, time() + 1209600); setcookie("gradebook[multiple][study_act_id]", $activity->study_act_id, time() + 1209600); setcookie("gradebook[multiple][study_act_comment]", $activity->study_act_comment, time() + 1209600); setcookie("gradebook[multiple][comment]", $activity->comment, time() + 1209600); } foreach ($activity->student as $key => $value) { if ($value != 0) { $a = new CStudentActivity(); $a->date_act = date("Y-m-d", strtotime($activity->date_act)); $a->subject_id = $activity->subject_id; $a->kadri_id = $activity->kadri_id; $a->study_act_id = $activity->study_act_id; $a->study_act_comment = $activity->study_act_comment; $a->comment = $activity->comment; $a->student_id = $key; $a->study_mark = $value; $a->save(); if (CRequest::getString("saveValues") == "1") { setcookie("gradebook[multiple][student_" . $key . "]", $value, time() + 1209600); } } } $this->redirect("?action=index"); return true; } $this->addJSInclude("_core/jquery-ui-1.8.20.custom.min.js"); $this->addCSSInclude("_core/jUI/jquery-ui-1.8.2.custom.css"); $this->addJSInclude("_core/personTypeFilter.js"); $groups = array(); foreach (CStaffManager::getStudentGroupsByYear(CUtils::getCurrentYear())->getItems() as $group) { if ($group->getStudents()->getCount() > 0) { $groups[$group->getId()] = $group->getName(); } } $this->setData("groups", $groups); $this->setData("activity", $activity); $this->renderView("_gradebook/addGroup.tpl"); }