existsSynonymByTerm() public static method

Check if a synonym exists
public static existsSynonymByTerm ( string $term, integer $exclude = null ) : boolean
$term string The term we're looking for.
$exclude integer Exclude a certain id.
return boolean
コード例 #1
0
ファイル: AddSynonym.php プロジェクト: forkcms/forkcms
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate field
         $this->frm->getField('synonym')->isFilled(BL::err('SynonymIsRequired'));
         $this->frm->getField('term')->isFilled(BL::err('TermIsRequired'));
         if (BackendSearchModel::existsSynonymByTerm($this->frm->getField('term')->getValue())) {
             $this->frm->getField('term')->addError(BL::err('TermExists'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item = array();
             $item['term'] = $this->frm->getField('term')->getValue();
             $item['synonym'] = $this->frm->getField('synonym')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             // insert the item
             $id = BackendSearchModel::insertSynonym($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_synonym', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Synonyms') . '&report=added-synonym&var=' . rawurlencode($item['term']) . '&highlight=row-' . $id);
         }
     }
 }