Example #1
0
 /**
  * Deletes the selected translations (only the translations of course)
  * @return string	message
  */
 public function removeTranslation($catid, $cid)
 {
     $message = '';
     $db = JFactory::getDBO();
     foreach ($cid as $cid_row) {
         list($translationid, $contentid, $language_id) = explode('|', $cid_row);
         $jfManager = JoomFishManager::getInstance();
         $contentElement = $jfManager->getContentElement($catid);
         if ($contentElement->getTarget() == "joomfish") {
             $contentTable = $contentElement->getTableName();
             $contentid = intval($contentid);
             $translationid = intval($translationid);
             // safety check -- complete overkill but better to be safe than sorry
             // get the translation details
             JLoader::import('tables.JFContent', JOOMFISH_ADMINPATH);
             $translation = new jfContent($db);
             $translation->load($translationid);
             if (!isset($translation) || $translation->id == 0) {
                 $this->setState('message', JText::sprintf('NO_SUCH_TRANSLATION', $translationid));
                 continue;
             }
             // make sure translation matches the one we wanted
             if ($contentid != $translation->reference_id) {
                 $this->setState('message', JText::_('SOMETHING_DODGY_GOING_ON_HERE'));
                 continue;
             }
             $sql = "DELETE from #__jf_content WHERE reference_table='{$catid}' and language_id={$language_id} and reference_id={$contentid}";
             $db->setQuery($sql);
             $db->query();
             if ($db->getErrorNum() != 0) {
                 $this->setError(JText::_('SOMETHING_DODGY_GOING_ON_HERE'));
                 JError::raiseWarning(400, JTEXT::_('No valid table information: ') . $db->getErrorMsg());
                 continue;
             } else {
                 $this->setState('message', JText::_('TRANSLATION_SUCCESSFULLY_DELETED'));
             }
         } else {
             $db = JFactory::getDbo();
             $contentElement = $jfManager->getContentElement($catid);
             $tableclass = $contentElement->getTableClass();
             if ($tableclass && intval($translationid) > 0) {
                 // load the translation and amend
                 $table = JTable::getInstance($tableclass);
                 $table->load(intval($translationid));
                 if (!$table->delete()) {
                     $this->setError(JText::_('SOMETHING_DODGY_GOING_ON_HERE'));
                     JError::raiseWarning(400, JTEXT::_('No valid table information: ') . $db->getErrorMsg());
                     continue;
                 } else {
                     $this->setState('message', JText::_('TRANSLATION_SUCCESSFULLY_DELETED'));
                 }
             }
         }
     }
     return $message;
 }
Example #2
0
 /**
  * Deletes the selected translations (only the translations of course)
  * @return string	message
  */
 function _removeTranslation($catid, $cid)
 {
     $message = '';
     $db = JFactory::getDBO();
     foreach ($cid as $cid_row) {
         list($translationid, $contentid, $language_id) = explode('|', $cid_row);
         $jfManager = JoomFishManager::getInstance();
         $contentElement = $jfManager->getContentElement($catid);
         $contentTable = $contentElement->getTableName();
         $contentid = intval($contentid);
         $translationid = intval($translationid);
         // safety check -- complete overkill but better to be safe than sorry
         // get the translation details
         JLoader::import('models.JFContent', JOOMFISH_ADMINPATH);
         $translation = new jfContent($db);
         $translation->load($translationid);
         if (!isset($translation) || $translation->id == 0) {
             $this->setState('message', JText::sprintf('NO_SUCH_TRANSLATION', $translationid));
             continue;
         }
         // make sure translation matches the one we wanted
         if ($contentid != $translation->reference_id) {
             $this->setState('message', JText::_('Something dodgy going on here'));
             continue;
         }
         $sql = "DELETE from #__jf_content WHERE reference_table='{$catid}' and language_id={$language_id} and reference_id={$contentid}";
         $db->setQuery($sql);
         $db->query();
         if ($db->getErrorNum() != 0) {
             $this->setError(JText::_('Something dodgy going on here'));
             JError::raiseWarning(400, JTEXT::_('No valid table information: ') . $db->getErrorMsg());
             continue;
         } else {
             $this->setState('message', JText::_('Translation successfully deleted'));
         }
     }
     return $message;
 }
Example #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);
     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;
     }
 }
 /** 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;
             }
         }
     }
 }
Example #5
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;
     }
 }