/**
  * @throws class_exception
  * @return void
  */
 public function updateForeignElement()
 {
     $objAnnotations = new class_reflection($this);
     $arrTargetTables = $objAnnotations->getAnnotationValuesFromClass(class_orm_base::STR_ANNOTATION_TARGETTABLE);
     if (count($arrTargetTables) != 0) {
         $objORM = new class_orm_objectupdate($this);
         $objORM->updateStateToDb();
     }
     //legacy code
     $strElementTableColumns = $this->getArrModule("tableColumns");
     if ($strElementTableColumns != "") {
         //open new tx
         class_carrier::getInstance()->getObjDB()->transactionBegin();
         $arrElementParams = $this->getArrParamData();
         $arrTableRows = explode(",", $strElementTableColumns);
         if (count($arrTableRows) > 0) {
             $arrInserts = array();
             $arrParams = array();
             foreach ($arrTableRows as $strTableColumnName) {
                 $strColumnValue = "";
                 if (isset($arrElementParams[$strTableColumnName])) {
                     $strColumnValue = $arrElementParams[$strTableColumnName];
                 }
                 $arrParams[] = $strColumnValue;
                 $arrInserts[] = " " . class_carrier::getInstance()->getObjDB()->encloseColumnName($strTableColumnName) . " = ? ";
             }
             $strRowUpdates = implode(", ", $arrInserts);
             $strUpdateQuery = " UPDATE " . $this->getTable() . " SET " . $strRowUpdates . " WHERE content_id= ? ";
             $arrParams[] = $this->getSystemid();
             if (!class_carrier::getInstance()->getObjDB()->_pQuery($strUpdateQuery, $arrParams)) {
                 class_carrier::getInstance()->getObjDB()->transactionRollback();
             } else {
                 class_carrier::getInstance()->getObjDB()->transactionCommit();
             }
         } else {
             throw new class_exception("Element has invalid tableRows value!!!", class_exception::$level_ERROR);
         }
     } else {
         //To remain backwards-compatible:
         //Call the save-method of the element instead or if the element wants to update its data specially
         if (method_exists($this, "actionSave") && !$this->actionSave($this->getSystemid())) {
             throw new class_exception("Element returned error saving to database!!!", class_exception::$level_ERROR);
         }
     }
 }
Example #2
0
 /**
  * Called whenever a update-request was fired.
  * Use this method to synchronize the current object with the database.
  * Use only updates, inserts are not required to be implemented.
  * Provides a default implementation based on the current objects column mappings.
  * Override this method whenever you want to perform additional actions or escaping.
  *
  * @throws class_exception
  * @return bool
  */
 protected function updateStateToDb()
 {
     $objORMMapper = new class_orm_objectupdate($this);
     return $objORMMapper->updateStateToDb();
 }