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;
     }
 }
示例#2
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;
     }
 }