/** * Add a model to the list of models that should be included in all cases * * @param \Model $model The model to include * @throws \Exception When a model is of an unsupported type */ public function addInclude(\Model $model) { $type = strtolower($model->getType()); if (!in_array($type, $this->types)) { throw new \Exception("Objects of type \"{$model->getTypeForHumans()}\" are not supported"); } $this->included[$type][] = $model; }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { if (isset($options['include'])) { $this->include = $options['include']; } if (isset($options['multiple'])) { $this->multiple = $options['multiple']; } if ($this->include && !$this->multiple) { throw new \LogicException("You can't include an object in a single selection!"); } $builderName = ucfirst($builder->getName()); // TODO: Use a more accurate placeholder $placeholder = $this->multiple ? 'brad, kierra, ...' : null; if ($this->include) { $exclude = $this->include->getType() . ':' . $this->include->getId(); } else { $exclude = null; } // Model IDs that will be manipulated by javascript $builder->add('ids', 'hidden', array('attr' => array('class' => 'select2-compatible', 'data-exclude' => $exclude, 'data-label' => $builderName, 'data-multiple' => $this->multiple, 'data-required' => $options['required']))); // Model name inputs that will be edited by users if javascript is // disabled foreach ($this->types as $type) { $pluralType = $this->multiple ? Inflector::pluralize($type) : $type; $label = count($this->types) > 1 ? "{$builderName} {$pluralType}" : $builderName; $builder->add($builder->create($type, 'text', array('attr' => array('class' => 'model-select', 'data-type' => $type, 'placeholder' => $placeholder), 'label' => $label, 'required' => false))); } if ($this->multiple) { $transformer = new MultipleAdvancedModelTransformer($this->types); if ($this->include) { $transformer->addInclude($this->include); } } else { $transformer = new SingleAdvancedModelTransformer($this->types); } $builder->addViewTransformer($transformer); // Make sure we can change the values provided by the user $builder->setDataLocked(false); }
public function __construct($util, $get = null) { parent::__construct($util); $this->model(); $model = new Model(); $this->setViewMenu(); if (isset($get["vers"])) { $vers = $get["vers"]; } else { $vers = 1; } if (isset($get["depuis"])) { $depuis = $get["depuis"]; } else { $depuis = 1; } if (isset($get["numsitu"])) { $numsitu = $get["numsitu"]; } else { $numsitu = 0; } if (isset($get["commenter"])) { $commenter = $get["commenter"]; } else { $commenter = "N"; } if (isset($get["modif"])) { $modif = $get["modif"]; } else { $modif = "n"; } //debut enregistrements if (isset($get["enregistrer"]) || $modif == "o") { //cliqué bouton enregistrer ou changement onglet switch ($depuis) { case 1: //écran description if ($this->util->estEtudiant()) { $lc = $this->ha($get["libcourt"]); $de = $this->ha($get["description"]); $pa = $this->ha($get["lieu"]); $lo = $this->ha($get["localisation"]); $so = $this->ha($get["source"]); $ca = $this->ha($get["cadre"]); $dd = $this->dteusa($this->ha($get["datedebut"])); $df = $this->dteusa($this->ha($get["datefin"])); if ($this->nbJ($dd, $df) < 0) { $df = $dd; } $ty = $this->ha($get["typedecrit"]); $te = $this->ha($get["techno"]); $ac = $this->ha($get["acteur"]); $sg = $this->ha($get["situoblig"]); $to = array(); if ($sg == "O" && isset($get["typologie"])) { $to = $get["typologie"]; } $av = $this->ha($get["avisperso"]); $ideleve = $this->util->getId(); if ($numsitu == 0) { //enregistrer données $numsitu = $model->setDescription($lc, $de, $pa, $lo, $so, $ca, $to, $dd, $df, $ty, $te, $ac, $av, $ideleve); } else { //modifier les données $model->updateDescription($numsitu, $lc, $de, $pa, $lo, $so, $ca, $to, $dd, $df, $ty, $te, $ac, $av); } } break; case 2: //écran caractérisation if ($this->util->estEtudiant()) { $activchoisies = $get["lesactivschoisies"]; $model->gereActivChoisie($numsitu, $activchoisies); } break; case 3: //saisie reformulation if ($this->util->estEtudiant()) { $lescom = $get["comm"]; $idact = $get["idact"]; for ($i = 0; $i < count($lescom); $i++) { $model->enregReformul($numsitu, $this->ha($lescom[$i]), $idact[$i]); } } break; case 4: // productions if ($this->util->estEtudiant()) { $de = $get["designation"]; // tableau de désignations $ad = $get["adresse"]; // tableau des adresses $codeP = $get["codeP"]; //tableau des codes productions if (isset($get["chksup"])) { $chksup = $get["chksup"]; } else { $chksup = null; } //les tableaux ont la même taille, sauf chksup $nb = count($de); for ($i = 0; $i < $nb - 1; $i++) { $model->updateProduction($numsitu, $codeP[$i], $this->ha($de[$i]), $this->ha($ad[$i])); } if ($de[$nb - 1] != "") { $model->ajouteProduction($numsitu, $this->ha($de[$nb - 1]), $this->ha($ad[$i])); } for ($i = 0; $i < count($chksup); $i++) { $model->supprProduction($numsitu, $chksup[$i]); } } break; case 5: //commentaires prof(s) if ($commenter == "P" && $this->util->estProf()) { if ($numsitu > 0) { $txt = $this->ha($get["commnew"]); if ($txt != '') { $model->setCommentaire($numsitu, $txt, $this->util->getId()); } if (isset($get["chksup"])) { $model->supprCommentaire($get["chksup"]); } if (isset($get["comm"])) { $model->majCommentaire($get["commref"], $get["comm"]); } } } break; } } //fin gestion du bouton enregistrer //pr�paration donn�es ihm � afficher switch ($vers) { case 1: //donn�es situation $data = array("typesitu" => $model->getTypeSitu(), "localisation" => $model->getLocalisation(), "source" => $model->getSource(), "cadre" => $model->getCadre(), "type" => $model->getType(), "typologie" => $model->getTypologie()); if ($numsitu != 0) { $data["lasitu"] = $model->getSitu1($numsitu); } break; case 2: //s�lection activit�s $data = array("typeactiv" => $model->getActivites(), "lescomp" => $model->getCompetences()); if ($numsitu != 0) { $data["lasitu"] = $model->getSitu3($numsitu); $data["lesactiv"] = $model->getSitu2($numsitu); } break; case 3: //ecran reformulation activit�(s) par �l�ve if ($numsitu != 0) { $data["lasitu"] = $model->getSitu3($numsitu); } $data["lesactiv"] = $model->getSitu4($numsitu); break; case 4: //saisie productions $data = array(); if ($numsitu != 0) { $data["lasitu"] = $model->getSitu3($numsitu); $data["lesprod"] = $model->getProd($numsitu); } break; case 5: //saisie ou affichage commentaires profs $data = array(); if ($numsitu != 0) { $data["lasitu"] = $model->getSitu3($numsitu); $data["lescomm"] = $model->getCommentaire($numsitu); $data["idprof"] = $this->util->getId(); } break; } //fin pr�parations sp�cifiques //pour toutes les ihm : $data["etudiant"] = $model->getAuteurSitu($numsitu); $model->close(); $data["numsitu"] = $numsitu; $data["commenter"] = $commenter; $data["auth"] = $this->util->estAuthent(); //appel page sp�cifique avec $data $this->view->init('saisie' . $vers . '.php', $data); $this->setViewBas(); }
/** * Dynamically get the form to show to the user * * @param \Model|null $model The model being edited, `null` if we're creating one * @return ModelFormCreator */ private function getFormCreator($model = null) { $type = $model instanceof Model ? $model->getType() : $this->getName(); $type = ucfirst($type); $creatorClass = "\\BZIon\\Form\\Creator\\{$type}FormCreator"; $creator = new $creatorClass($model, $this->getMe(), $this); return $creator; }
public static function invalid(Model $model, $message = null) { return new self(sprintf('Oops! The requested action for model type "%s" is invalid. %s', $model->getType(), $message), 400, __FUNCTION__); }