Beispiel #1
0
function createAndSaveScenario(EiProjet $ei_project, EiNode $root_node)
{
    //On crée le noeud du scénario avant de créer le scénario en soit
    $ei_node = new EiNode();
    $ei_scenario = new EiScenario();
    $ei_node->setIsRoot(false);
    $ei_node->setProjectId($ei_project->getProjectId());
    $ei_node->setProjectRef($ei_project->getRefId());
    $ei_node->setName('testNomScenario');
    $ei_node->setPosition(Doctrine_Core::getTable('EiNode')->getLastPositionInNode($ei_project->getProjectId(), $ei_project->getRefId(), $root_node->getId()));
    $ei_node->setType('EiScenario');
    $ei_node->setRootId($root_node->getId());
    $ei_scenario->project_id = $ei_project->getProjectId();
    $ei_scenario->project_ref = $ei_project->getRefId();
    $ei_scenario->setNomScenario('testNomScenario');
    $ei_scenario->setEiNode($ei_node);
    $ei_scenario->save();
    $ei_node->setObjId($ei_scenario->getId());
    $ei_node->save();
    return $ei_scenario;
}
 /**
  * Action permettant de récupérer l'arbre des jeux de données.
  *
  * @param sfWebRequest $request
  */
 public function execute($request)
 {
     $this->logger = sfContext::getInstance()->getLogger();
     $this->logger->info("----------------------------------------------------------");
     $this->logger->info("---   DEBUT RECUPERATION ARBRE DATA SET");
     $this->getResponse()->setContentType('application/json');
     $this->setLayout(false);
     $response = array("error" => "An error occured when we try to create your directory.");
     try {
         $this->getUser()->signIn($this->user, true);
         /** @var EiNodeTable $tableEiNode */
         $tableEiNode = Doctrine_Core::getTable("EiNode");
         // Récupération des données.
         $nom = $request->getPostParameter("name");
         $parentNodeId = $request->getPostParameter("parent_node_id");
         if ($nom == null || $parentNodeId == null) {
             $response["error"] = "You have to select a parent directory and type a valid directory name";
         } else {
             /** @var EiNode $parentNode Récupération du noeud parent. */
             $parentNode = $tableEiNode->find($parentNodeId);
             if ($parentNode != null && $parentNode->getId() != "" && $parentNode->getEiScenarioNode()->getObjId() == $this->scenario->getId()) {
                 try {
                     $folder = new EiNode();
                     $folder->setName($nom);
                     $folder->setType(EiNode::$TYPE_DATASET_FOLDER);
                     $folder->setProjectId($parentNode->getProjectId());
                     $folder->setProjectRef($parentNode->getProjectRef());
                     $folder->setRootId($parentNode->getId());
                     $folder->save();
                     unset($response["error"]);
                     $response["id"] = $folder->getId();
                 } catch (Exception $exc) {
                     $response["error"] = "An error occured when we tried to create directory : " . $exc->getMessage();
                 }
             } else {
                 $response["error"] = "We are not able to accommodate your request.";
             }
         }
     } catch (Exception $e) {
         $response = array();
     }
     return $this->renderText(json_encode($response));
 }
 /**
  * Créer le noeud contenant les dataSetFolders et les dataSets du scenario.
  * @param Doctrine_Connection $conn
  * @return $folder Le dossier nouvelle créé.
  */
 public function createDefaultEiDataSetFolder(Doctrine_Connection $conn)
 {
     $folder = new EiNode();
     $folder->setIsRoot(false);
     $folder->setName('Data sets');
     $folder->setProjectId($this->getProjectId());
     $folder->setProjectRef($this->getProjectRef());
     $folder->setType('EiDataSetFolder');
     $folder->setPosition(1);
     $folder->save($conn);
     $folder->setObjId($folder->getId());
     $folder->setRootId($this->ei_node_id);
     $folder->save($conn);
     return $folder;
 }
 public function isAncestorOf(EiNode $new_parent, EiNode $current_node)
 {
     while ($new_parent->getRootId() != null) {
         if ($new_parent->getRootId() == $current_node->getId()) {
             return true;
         }
         $new_parent = $new_parent->getParent();
     }
     return false;
 }