/** * extracts tags from the provided text and connects them to this question. If a tag is deleted it * will be deleted from the relation * * @return void * @author The Young Shepherd **/ public function save(Doctrine_Connection $conn = null) { $currentTags = array(); foreach ($this->Tags as $tag) { $currentTags[] = $tag->name; } $newTags = array_keys(Toolkit::extractTags($this->Best->question . ' ' . $this->Best->answer)); $deleteTags = array_diff($currentTags, $newTags); foreach ($deleteTags as $name) { foreach ($this->Tags as $index => $tag) { if ($tag->name === $name) { unset($this->Tags[$index]); break; // go to next name to delete } } } $addTags = array_diff($newTags, $currentTags); foreach ($addTags as $name) { if (!($tag = Doctrine::getTable('Tag')->findOneByName($name))) { $tag = new Tag(); $tag->name = $name; } $this->Tags[] = $tag; } return parent::save($conn); }
public function save(Doctrine_Connection $conn = null) { $new = $this->isNew() ? true : false; $question = parent::save($conn); if ($new) { $traitement = new TraitementAgent(); $traitement->setQuestion($this); $traitement->save(); } return $question; }
public function save($con = null) { $con = Propel::getConnection(); try { $con->begin(); $ret = parent::save(); $this->updateSearchIndex(); $con->commit(); return $ret; } catch (Exception $e) { $con->rollback(); throw $e; } }