function refreshRecords($materia, $plan, $anio, $cuat) { /* Now to your question. I would create a function in the UsersRoles model named something like refreshRoles($user, $roles). Where $user is the user id you are selecting roles for, and $roles is an array of roles that should be set. The function would retrieve the list of Roles by id_users, and compare it to $roles, deleting roles that are missing from $roles, and adding roles that are missing from the UsersRoles table. */ /*$userRoles = $this->findAllByAttribute(array('id_users' => $user)); foreach ($userRoles as $userRole) { if (!in_array($userRole->id_roles, $roles)) { $userRole->delete(); } else { $key = array_search($userRole->id_roles, $roles)); unset($roles[$key]); }*/ $model = new MateriaPlan(); $model->Materia_id = $materia; $model->Plan_id = $plan; $model->anio = $anio; $model->cuatrimestre = $cuat; $model->save(false); }
protected function agregarMaterias($materiasArray, $planID) { /* Recibo un arreglo de 10 componentes. Cada uno con un arreglo asociativo con las materias de ese cuatrimestre [0]=> Codigo de materia [1]=> Codigo de materia */ for ($i = 0; $i < count($materiasArray); $i++) { $cuat = $this->getCuatrimestre($i); $anio = $this->getYear($i); $materias = $materiasArray[$i]; foreach ($materias as $materiaID) { if (strlen($materiaID) > 0) { $modeloMateriaPlan = new MateriaPlan(); $modeloMateriaPlan->Plan_id = $planID; $modeloMateriaPlan->Materia_id = $materiaID; $modeloMateriaPlan->anio = $anio; $modeloMateriaPlan->cuatrimestre = $cuat; $modeloMateriaPlan->save(); } } } }