/** Reads all translation information from the database
  *
  */
 private function _loadContent($row = false)
 {
     $db = JFactory::getDBO();
     $elementTable = $this->getTable();
     if ($this->contentElement->getTarget() == "joomfish") {
         $sql = "select * " . "\n  from #__jf_content" . "\n where reference_id='" . $this->id . "'" . "\n   and reference_table='" . $elementTable->Name . "'";
         if (isset($this->language_id) && $this->language_id != "") {
             $sql .= "\n   and language_id=" . $this->language_id;
         }
         //echo "load sql=>$sql<<br />";
         $db->setQuery($sql);
         $rows = $db->loadObjectList('', 'stdClass', false);
         if ($db->getErrorNum() != 0) {
             JError::raiseWarning(400, JTEXT::_('No valid table information: ') . $db->getErrorMsg());
         }
         $translationFields = null;
         if (count($rows) > 0) {
             foreach ($rows as $trow) {
                 $fieldContent = new jfContent($db);
                 if (!$fieldContent->bind($trow)) {
                     JError::raiseWarning(200, JText::_('Problems binding object to fields: ' . $fieldContent->getError()));
                 }
                 $translationFields[$fieldContent->reference_field] = $fieldContent;
             }
         }
         // Check fields and their state
         for ($i = 0; $i < count($elementTable->Fields); $i++) {
             $field = $elementTable->Fields[$i];
             if ($field->prehandlertranslation != "") {
                 if (method_exists($this, $field->prehandlertranslation)) {
                     $handler = $field->prehandlertranslation;
                     $this->{$handler}($field, $translationFields);
                 }
             }
             if (isset($translationFields[$field->Name])) {
                 $fieldContent = $translationFields[$field->Name];
             } else {
                 $fieldContent = null;
             }
             if ($field->Translate) {
                 if (isset($fieldContent)) {
                     $field->changed = md5($field->originalValue) != $fieldContent->original_value;
                     if ($field->changed) {
                         $this->_numChangedFields++;
                     } else {
                         $this->_numUnchangedFields++;
                     }
                 } else {
                     $fieldContent = new jfContent($db);
                     $fieldContent->reference_id = $this->id;
                     $fieldContent->reference_table = $elementTable->Name;
                     $fieldContent->reference_field = $field->Name;
                     $fieldContent->language_id = $this->language_id;
                     $fieldContent->original_value = $field->originalValue;
                     $field->changed = false;
                     if ($field->originalValue != '') {
                         $this->_numNewAndNotNullFields++;
                     }
                 }
             }
             $field->translationContent = $fieldContent;
         }
         // Checking the record state based on the fields. If one field is changed the record is modifed
         if ($this->_numChangedFields == 0 && $this->_numNewAndNotNullFields == 0) {
             $this->state = 1;
         } elseif ($this->_numChangedFields == 0 && $this->_numNewAndNotNullFields > 0 && $this->_numUnchangedFields == 0) {
             $this->state = -1;
         } else {
             $this->state = 0;
         }
     } else {
         if (isset($row)) {
             $noprehandlerrow = clone $row;
             // Check fields and their state
             for ($i = 0; $i < count($elementTable->Fields); $i++) {
                 $field = $elementTable->Fields[$i];
                 if ($field->prehandlertranslation != "") {
                     if (method_exists($this, $field->prehandlertranslation)) {
                         $handler = $field->prehandlertranslation;
                         $this->{$handler}($field, $row);
                     }
                 }
                 $fieldname = $field->Name;
                 $transfieldname = "jfc_" . $field->Name;
                 $fieldContent = null;
                 if (isset($row->{$fieldname})) {
                     $fieldContent = new jfContent($db);
                     // id for translation
                     $fieldContent->id = intval($row->jfc_id);
                     $fieldContent->language_id = $this->language_id;
                     $fieldContent->reference_id = $row->id;
                     $fieldContent->reference_table = $elementTable->Name;
                     $fieldContent->reference_field = $fieldname;
                     if (isset($row->{$transfieldname})) {
                         $fieldContent->value = $row->{$transfieldname};
                         if (!empty($row->{$fieldname}) && empty($row->{$transfieldname}) && empty($noprehandlerrow->{$transfieldname})) {
                             $this->_untraslatedFields++;
                         }
                     } else {
                         $this->_untraslatedFields++;
                     }
                     $fieldContent->original_value = $row->{$fieldname};
                     $fieldContent->original_text = $row->{$fieldname};
                     // TODO check published is a valid field !
                     $fieldContent->published = $row->published;
                 } else {
                     $fieldContent = null;
                 }
                 $field->translationContent = $fieldContent;
             }
             $modifiedcompare = isset($row->modified) && isset($row->jfc_modified) && $row->modified > $row->jfc_modified ? 1 : 0;
             /*
              * Checking the record state based on existance of translated entry in database,
              * the fields translations (are all translatable fields not empty?) 
              * and modified dates. If original modified date is later than transaltion modified date, original was modified after translation.
              */
             if (!empty($row->jfc_id) && $this->_untraslatedFields == 0 && $modifiedcompare == 0) {
                 $this->state = 1;
             } elseif (empty($row->jfc_id)) {
                 $this->state = -1;
             } else {
                 $this->state = 0;
             }
         }
     }
 }
Exemplo n.º 2
0
 /** Reads all translation information from the database
  *
  */
 function _loadContent()
 {
     $db = JFactory::getDBO();
     $elementTable = $this->getTable();
     $sql = "select * " . "\n  from #__jf_content" . "\n where reference_id='" . $this->id . "'" . "\n   and reference_table='" . $elementTable->Name . "'";
     if (isset($this->language_id) && $this->language_id != "") {
         $sql .= "\n   and language_id=" . $this->language_id;
     }
     //echo "load sql=>$sql<<br />";
     $db->setQuery($sql);
     $rows = $db->loadObjectList(false);
     if ($db->getErrorNum() != 0) {
         JError::raiseWarning(400, JTEXT::_('No valid table information: ') . $db->getErrorMsg());
     }
     $translationFields = null;
     if (count($rows) > 0) {
         foreach ($rows as $row) {
             $fieldContent = new jfContent($db);
             if (!$fieldContent->bind($row)) {
                 JError::raiseWarning(200, JText::_('Problems binding object to fields: ' . $fieldContent->getError()));
             }
             $translationFields[$fieldContent->reference_field] = $fieldContent;
         }
     }
     // Check fields and their state
     for ($i = 0; $i < count($elementTable->Fields); $i++) {
         $field = $elementTable->Fields[$i];
         if ($field->prehandlertranslation != "") {
             if (method_exists($this, $field->prehandlertranslation)) {
                 $handler = $field->prehandlertranslation;
                 $this->{$handler}($field, $translationFields);
             }
         }
         if (isset($translationFields[$field->Name])) {
             $fieldContent = $translationFields[$field->Name];
         } else {
             $fieldContent = null;
         }
         if ($field->Translate) {
             if (isset($fieldContent)) {
                 $field->changed = md5($field->originalValue) != $fieldContent->original_value;
                 if ($field->changed) {
                     $this->_numChangedFields++;
                 } else {
                     $this->_numUnchangedFields++;
                 }
             } else {
                 $fieldContent = new jfContent($db);
                 $fieldContent->reference_id = $this->id;
                 $fieldContent->reference_table = $elementTable->Name;
                 $fieldContent->reference_field = $field->Name;
                 $fieldContent->language_id = $this->language_id;
                 $fieldContent->original_value = $field->originalValue;
                 $field->changed = false;
                 if ($field->originalValue != '') {
                     $this->_numNewAndNotNullFields++;
                 }
             }
         }
         $field->translationContent = $fieldContent;
     }
     // Checking the record state based on the fields. If one field is changed the record is modifed
     if ($this->_numChangedFields == 0 && $this->_numNewAndNotNullFields == 0) {
         $this->state = 1;
     } elseif ($this->_numChangedFields == 0 && $this->_numNewAndNotNullFields > 0 && $this->_numUnchangedFields == 0) {
         $this->state = -1;
     } else {
         $this->state = 0;
     }
 }
Exemplo n.º 3
0
 /** Reads all translation information from the database
  *
  */
 function _loadContent()
 {
     $db =& JFactory::getDBO();
     $elementTable = $this->getTable();
     $sql = "select * " . "\n  from #__jf_content" . "\n where reference_id='" . $this->id . "'" . "\n   and reference_table='" . $elementTable->Name . "'";
     if (isset($this->language_id) && $this->language_id != "") {
         $sql .= "\n   and language_id=" . $this->language_id;
     }
     //echo "load sql=>$sql<<br />";
     $db->setQuery($sql);
     $rows = $db->loadObjectList(false);
     echo $db->getErrorMsg();
     $translationFields = null;
     if (count($rows) > 0) {
         foreach ($rows as $row) {
             $fieldContent = new jfContent($db);
             if (!$fieldContent->bind($row)) {
                 echo $fieldContent->getError();
             }
             $translationFields[$fieldContent->reference_field] = $fieldContent;
         }
     }
     // Check fields and their state
     for ($i = 0; $i < count($elementTable->Fields); $i++) {
         $field =& $elementTable->Fields[$i];
         if (isset($translationFields[$field->Name])) {
             $fieldContent = $translationFields[$field->Name];
         } else {
             $fieldContent = null;
         }
         if ($field->Translate) {
             if (isset($fieldContent)) {
                 $field->changed = md5($field->originalValue) != $fieldContent->original_value;
                 if ($field->changed) {
                     $this->_numChangedFields++;
                 } else {
                     $this->_numUnchangedFields++;
                 }
             } else {
                 $fieldContent = new jfContent($db);
                 $fieldContent->reference_id = $this->id;
                 $fieldContent->reference_table = $elementTable->Name;
                 $fieldContent->reference_field = $field->Name;
                 $fieldContent->language_id = $this->language_id;
                 $fieldContent->original_value = $field->originalValue;
                 $field->changed = false;
                 if ($field->originalValue != '') {
                     $this->_numNewAndNotNullFields++;
                 }
             }
         }
         $field->translationContent = $fieldContent;
     }
     // Checking the record state based on the fields. If one field is changed the record is modifed
     if ($this->_numChangedFields == 0 && $this->_numNewAndNotNullFields == 0) {
         $this->state = 1;
     } elseif ($this->_numChangedFields == 0 && $this->_numNewAndNotNullFields > 0 && $this->_numUnchangedFields == 0) {
         $this->state = -1;
     } else {
         $this->state = 0;
     }
 }