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;
     }
 }
 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;
     }
 }
示例#3
0
 public function addManyStepProcess(EiCampaign $ei_campaign, array $selectStepTab, EiCampaignGraph $firstStep, EiCampaignGraph $lastStep = null)
 {
     $bef = $firstStep;
     $this->collection_step = new Doctrine_Collection('EiCampaignGraph');
     foreach ($selectStepTab as $i => $stepId) {
         if ($this->before_step_id == 0 && $i == 0) {
             $step = $bef->copy();
             $step->setCampaignId($ei_campaign->getId());
             $step->save($this->conn);
             $this->collection_step->add($step);
             //Enregistrement du step dans la collection à retourner
             $bef = $step;
         } else {
             $step = Doctrine_Core::getTable('EiCampaignGraph')->findOneById($stepId);
             $step = $step->copy();
             $step->setCampaignId($ei_campaign->getId());
             $step->save($this->conn);
             $this->collection_step->add($step);
             //Enregistrement du step dans la collection à retourner
             //Création de la relation
             $new_relation = new EiCampaignGraphHasGraph();
             $new_relation->setParentId($bef->getId());
             $new_relation->setChildId($step->getId());
             $new_relation->setCampaignId($ei_campaign->getId());
             $new_relation->save($this->conn);
             //Changement du bef
             $bef = $step;
         }
     }
     //On vérifie s'il existait un élément après le curseur
     if ($lastStep != null) {
         //Création de la relation
         $new_relation = new EiCampaignGraphHasGraph();
         $new_relation->setParentId($bef->getId());
         $new_relation->setChildId($lastStep->getId());
         $new_relation->setCampaignId($ei_campaign->getId());
         $new_relation->save($this->conn);
     }
 }
 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;
     }
 }