public function createByName($name) { print_r('[' . $name . ']'); $document = new Division(); $document->setName($name); $document->setSlug(); $document->save(); $document = $this->findOneBySlug($document->getSlug()); return $document; }
public function load() { $this->clear(); $division = new Division('D1'); $level = $this->CI->_level->findOneBySlug('college'); $division->setLevel($level); $league = $this->CI->_league->findOneBySlug('ncaa'); $division->setLeague($league); $division->save(); print_r(sprintf("Created Division: %s (%s)\n", $division->getName(), $division->getId())); }
public function save() { $divisionId = $this->getValue('divisionId'); if (!empty($divisionId)) { $division = $this->getDivisionService()->getDivisionById($divisionId); } else { $division = new Division(); } $division->setDivisionName($this->getValue('division_name')); $division->setDivisionCode($this->getValue('division_code')); $division->setCouCode($this->getValue('country')); $division->save(); }
public function agregar() { $data = array(); if ($_POST) { $division = new Division(elements(array('division'), $_POST)); if ($division->is_valid()) { $division->save(); $this->session->set_flashdata('msg', '<div class="success">La División se guardó correctamente.</div>'); redirect('divisiones'); } else { $data['errors'] = $division->errors; } } $data['titulo'] = "Agregar División"; $data['action'] = "divisiones/agregar"; $this->template->write_view('content', 'divisiones/agregar', $data); $this->template->render(); }
protected function saveCiclolectivo($ciclolectivo) { //si se guarda el ciclo y se marca como actual //los demas ciclo del establecimiento tiene que quedar como ACUAL = false $con = Propel::getConnection(); try { $con->beginTransaction(); if ($ciclolectivo->getActual()) { $c1 = new Criteria(); $c1->add(CiclolectivoPeer::FK_ESTABLECIMIENTO_ID, $this->getUser()->getAttribute('fk_establecimiento_id')); $c2 = new Criteria(); $c2->add(CiclolectivoPeer::ACTUAL, false); BasePeer::doUpdate($c1, $c2, $con); } $ciclolectivo->setFkEstablecimientoId($this->getUser()->getAttribute('fk_establecimiento_id')); $isNew = $ciclolectivo->isNew(); $ciclolectivo->save(); if ($isNew) { # Codigo para copiar las divisiones del ciclo lectivo actual al nuevo # La consulta debe contemplar que lo haga desde el ciclo lectivo actual if ($this->getRequestParameter('importar')) { $ciclo_actual = CiclolectivoPeer::retrieveByPk($this->getUser()->getAttribute('fk_ciclolectivo_id')); if ($ciclo_actual) { $this->logMessage('ciclo_actual: ' . $ciclo_actual, 'debug'); //clonar turnos foreach ($ciclo_actual->getTurnos() as $turno) { $nt = new Turno(); $nt->setFkCiclolectivoId($ciclolectivo->getId()); $nt->setHoraInicio($turno->getHoraInicio()); $nt->setHoraFin($turno->getHoraFin()); $nt->setDescripcion($turno->getDescripcion()); $nt->save(); //clonar las divisiones foreach ($turno->getDivisions() as $division) { $this->logMessage('division: ' . $division, 'debug'); $nd = new Division(); $nd->setFkAnioId($division->getFkAnioId()); $nd->setDescripcion($division->getDescripcion()); $nd->setFkTurnoId($nt->getId()); $nd->setFkOrientacionId($division->getFkOrientacionId()); $nd->setOrden($division->getOrden()); $nd->save(); } } } else { //no existe el ciclo actual $this->getUser()->setFlash('error', 'No hay un ciclo actual seleccionado'); } } } $con->commit(); if ($ciclolectivo->getActual()) { //cambio el attributo porque se cambio el ciclo actual $this->getUser()->setAttribute('fk_ciclolectivo_id', $ciclolectivo->getId()); $this->getUser()->setAttribute('ciclolectivo_descripcion', $ciclolectivo->getDescripcion()); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); // add your code here $courses = CoursePeer::doSelect(new Criteria()); foreach ($courses as $course) { $division = new Division(); $division->setName($course->getName()); $division->setSchoolYearId($course->getSchoolYearId()); foreach ($course->getCourseSubjects() as $course_subject) { $course_students = $course->getCourseStudents(); if (isset($course_students[0])) { $division->setCareerId($course_students[0]->getCareerSubject()->getCareerId()); } else { $division->setCareerId(1); } $new_course = new Course(); $course->copyInto($new_course); $new_course->setName($course_subject->getSubject() . ' - ' . $course->getName()); $new_course->save(); $new_course_subject = new CourseSubject(); $course_subject->copyInto($new_course_subject); $new_course_subject->setCourseId($new_course->getId()); $new_course_subject->setCourseId($new_course->getId()); $new_course_subject->save(); $course_subject->delete(); $c = new Criteria(); $c->add(CourseStudentPeer::COURSE_ID, $course->getId()); $c->addJoin(CourseStudentPeer::CAREER_SUBJECT_ID, CareerSubjectPeer::ID); $c->add(CareerSubjectPeer::SUBJECT_ID, $new_course_subject->getSubjectId()); $course_students = CourseStudentPeer::doSelect($c); foreach ($course_students as $course_student) { $new_course_student = new CourseStudent(); $course_student->copyInto($new_course_student); $new_course_student->setCourseId($new_course->getId()); $new_course_student->save(); $course_student->delete(); } $division_course = new DivisionCourse(); $division_course->setCourse($new_course); $division->addDivisionCourse($division_course); } try { $course->delete(); } catch (Exception $e) { } try { $division->save(); } catch (Exception $e) { } $this->logSection('division+', 'Division ' . $division . ' created'); } }
function division_save($office_id = '', $id = '') { $data['page_name'] = '<b>Save Division</b>'; $data['msg'] = ''; $divisions = new Division(); $data['division'] = $divisions->get_by_id($id); $data['office_id'] = $office_id; if (Input::get('op')) { $divisions->name = Input::get('name'); $divisions->description = Input::get('description'); $divisions->office_id = $office_id; $divisions->order = Input::get('order'); $divisions->save(); Session::flash('msg', 'Division has been saved!'); return Redirect::to('office_manage/divisions/' . $office_id, 'refresh'); } $data['main_content'] = 'division_save'; return View::make('includes/template', $data); }
public function createCopyForSchoolYear(PropelPDO $con = null, $career_school_year) { $copy_division = new Division(); $copy_division->setDivisionTitle($this->getDivisionTitle()); $copy_division->setCareerSchoolYear($career_school_year); $copy_division->setShift($this->getShift()); $copy_division->setYear($this->getYear()); $copy_division->save($con); $this->copyPreceptorsToDivision($con, $copy_division); $this->copyCoursesToDivision($con, $copy_division, $career_school_year); if ($this->getYear() <= $career_school_year->getCareer()->getQuantityYears() && $this->getYear() > 1) { $copy_division->createStudentsForNextYear($con, $this->getCareerSchoolYear()); } $copy_division->clearAllReferences(true); unset($copy_division); $career_school_year->clearAllReferences(true); unset($career_school_year); $this->clearAllReferences(true); }