public function updatePosition($ids, $campaign_id)
 {
     if (!is_array($ids)) {
         return null;
     }
     //On reconstruit les relations de la table graph_has_graph
     $newStepTab = array();
     $ids = $ids[0];
     if (!is_array($ids)) {
         return null;
     }
     foreach ($ids as $i => $item) {
         if (array_key_exists($i + 1, $ids)) {
             $newStepTab[] = array($ids[$i], $ids[$i + 1]);
         }
     }
     //var_dump($newStepTab);
     if (!is_array($newStepTab)) {
         return null;
     }
     $conn = Doctrine_Manager::connection();
     try {
         $conn->beginTransaction();
         /*On vérifie qu'on est pas en accès concurrent */
         $nb = count(Doctrine_Core::getTable('EiCampaignGraph')->findByCampaignId($campaign_id));
         if ($nb != count($ids)) {
             throw new Exception('Concurrent Access. refresh page ...');
         }
         $conn->delete($this->getInstance(), array('campaign_id' => $campaign_id));
         $collection = new Doctrine_Collection($this->getInstance());
         foreach ($newStepTab as $item) {
             $newItem = new EiCampaignGraphHasGraph();
             $newItem->setParentId($item[0]);
             $newItem->setChildId($item[1]);
             $newItem->setCampaignId($campaign_id);
             $collection->add($newItem);
         }
         $collection->save($conn);
         $conn->commit();
         //  validation globale  de la création
         return 1;
     } catch (Exception $e) {
         $conn->rollback();
         //throw $e('An error occurred while trying to update nodes positions ');
         return -1;
     }
 }
 public static function createItem(array $item_fields, Doctrine_Connection $conn = null)
 {
     if ($conn == null) {
         $conn = Doctrine_Manager::connection();
     }
     if (isset($item_fields['parent_id']) && isset($item_fields['child_id']) && isset($item_fields['campaign_id'])) {
         $new_relation = new EiCampaignGraphHasGraph();
         $new_relation->setParentId($item_fields['parent_id']);
         $new_relation->setChildId($item_fields['child_id']);
         $new_relation->setCampaignId($item_fields['campaign_id']);
         $new_relation->save($conn);
         return $new_relation;
     } else {
         return null;
     }
 }
Beispiel #3
0
 public function executeCreate(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod(sfRequest::POST));
     $this->checkProject($request);
     //Récupération du projet
     $this->checkProfile($request, $this->ei_project);
     //Récupération du profil courant
     //Recherche de la campagne concernée
     $this->checkCampaign($request, $this->ei_project);
     $this->getNodeParent($request);
     //Récupération du noeud parent
     $this->position = $request->getParameter('position');
     //Récupération  de la position
     //Initialisation du formulaire
     $ei_campaign_graph = new EiCampaignGraph();
     $ei_campaign_graph->setEiCampaign($this->ei_campaign);
     $this->form = new EiCampaignGraphForm($ei_campaign_graph, array('ei_project' => $this->ei_project));
     $graphRelation = new EiCampaignGraphHasGraph();
     $graphRelation->setParentId($this->parent_id);
     $graphRelation->setCampaignChild($ei_campaign_graph);
     $graphRelation->setEiCampaign($this->ei_campaign);
     $graphRelation->setPosition($this->position);
     $this->form->embedForm('graphParent', new EiCampaignGraphHasGraphForm($graphRelation));
     $this->processForm($request, $this->form);
     //Récupération du root folder du projet
     $this->root_folder = Doctrine_Core::getTable('EiNode')->getRootFolder($this->project_ref, $this->project_id);
     //Récupération des noeuds enfants du dossier
     $this->ei_nodes = $this->root_folder->getNodes(false, false);
     //Récupération du chemin firefox dans les settings utilisateur
     /** @var EiUser $user */
     $user = $this->getUser()->getGuardUser()->getEiUser();
     $this->user_settings = Doctrine_Core::getTable('EiUserSettings')->findOneByUserRefAndUserId($user->getRefId(), $user->getUserId());
     $firefoxPath = $this->user_settings == null ?: $this->user_settings->getFirefoxPath();
     if ($this->success) {
         $this->campaignGraphBlockType = Doctrine_Core::getTable('EiBlockType')->findAll();
         $campaignGraphLine = $this->urlParameters;
         $campaignGraphLine['ei_campaign_graph'] = Doctrine_Core::getTable('EiCampaignGraph')->getCampaignGraphStep($this->ei_campaign_graph->getId());
         $campaignGraphLine['project_name'] = $this->ei_project->getName();
         $campaignGraphLine['firefox_path'] = $firefoxPath;
         $campaignGraphLine['campaignGraphBlockType'] = $this->campaignGraphBlockType;
         $campaign_graph_new = $this->urlParameters;
         $campaign_graph_new['campaign_id'] = $this->ei_campaign_graph->getId();
         $campaign_graph_new['parent_id'] = $this->ei_campaign_graph->getId();
         return $this->renderText(json_encode(array('html' => $this->getPartial('eicampaigngraph/campaignGraphLine', $campaignGraphLine), 'new_create_url' => $this->generateUrl('campaign_graph_new', $campaign_graph_new), 'updateMode' => false, 'success' => true)));
     } else {
         $uri_form = $this->urlParameters;
         $uri_form['form'] = $this->form;
         $uri_form['ei_nodes'] = $this->ei_nodes;
         $uri_form['campaign_id'] = $this->campaign_id;
         $uri_form['root_folder'] = $this->root_folder;
         $uri_form['parent_id'] = $this->parent_id;
         return $this->renderText(json_encode(array('html' => $this->getPartial('eicampaigngraph/form', $uri_form), 'success' => false)));
     }
     //Retour de la réponse json en cas de succès
     return sfView::NONE;
 }
 public function addStepAsNextOf(EiCampaignGraph $step_before, EiCampaignGraph $new_step, Doctrine_Connection $conn = null)
 {
     if ($conn == null) {
         $conn = Doctrine_Manager::connection();
     }
     try {
         $conn->beginTransaction();
         $new_step->save($conn);
         //Ajout de la relation père fils
         $child_of_step_before = Doctrine_Core::getTable('EiCampaignGraphHasGraph')->findOneByParentId($step_before->getId());
         if ($child_of_step_before != null) {
             //L'élément a bien un fils, on intercale le nouveau step entre les deux
             $new_relation = new EiCampaignGraphHasGraph();
             $new_relation->setParentId($new_step->getId());
             $new_relation->setChildId($child_of_step_before->getChildId());
             $new_relation->setCampaignId($step_before->getCampaignId());
             $new_relation->save($conn);
             //Modification de l'ancienne relation
             $child_of_step_before->setChildId($new_step->getId());
             $child_of_step_before->save($conn);
             $conn->commit();
             return $new_step;
         } else {
             //L'élément est root
             $new_relation = new EiCampaignGraphHasGraph();
             $new_relation->setParentId($step_before->getId());
             $new_relation->setChildId($new_step->getId());
             $new_relation->setCampaignId($step_before->getCampaignId());
             $new_relation->save($conn);
             $conn->commit();
             return $new_step;
         }
         $conn->close();
         return null;
     } catch (Exception $e) {
         $conn->rollback();
         throw $e;
     }
 }