PageRenderTime 278ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_joomfish/models/ContentObject.php

https://github.com/Shigaru/shigaru
PHP | 716 lines | 445 code | 94 blank | 177 comment | 125 complexity | 9222f42b78bcb481b2a0c0c5f89985a9 MD5 | raw file
  1. <?php
  2. /**
  3. * Joom!Fish - Multi Lingual extention and translation manager for Joomla!
  4. * Copyright (C) 2003 - 2012, Think Network GmbH, Munich
  5. *
  6. * All rights reserved. The Joom!Fish project is a set of extentions for
  7. * the content management system Joomla!. It enables Joomla!
  8. * to manage multi lingual sites especially in all dynamic information
  9. * which are stored in the database.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
  24. *
  25. * The "GNU General Public License" (GPL) is available at
  26. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  27. * -----------------------------------------------------------------------------
  28. * $Id: ContentObject.php 1592 2012-01-20 12:51:08Z akede $
  29. * @package joomfish
  30. * @subpackage Models
  31. *
  32. */
  33. JLoader::register('jfContent', JOOMFISH_ADMINPATH .DS. 'models' .DS. 'JFContent.php' );
  34. JLoader::register('iJFTranslatable', JOOMFISH_ADMINPATH .DS. 'models' .DS. 'iJFTranslatable.php' );
  35. /**
  36. * Representation of one content with his translation.
  37. * The object includes information from the original object and
  38. * the refering translation. Based on that information it is
  39. * able to handle all necessary interactions with the tranlsation.
  40. * Each instance of this object represents only one translation in
  41. * on specified language, but it handles all the fields within the
  42. * ContentElement.
  43. *
  44. * @package joomfish
  45. * @subpackage administrator
  46. * @copyright 2003 - 2012, Think Network GmbH, Munich
  47. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
  48. * @version $Revision: 1592 $
  49. * @author Alex Kempkens
  50. */
  51. class ContentObject implements iJFTranslatable {
  52. /** @var _contentElement Reference to the ContentElement definition of the instance */
  53. private $_contentElement;
  54. /** @var id ID of the based content */
  55. public $id;
  56. /** @var translation_id translation id value */
  57. public $translation_id=0;
  58. /** @var checked_out User who checked out this content if any */
  59. public $checked_out;
  60. /** @var title Title of the object; used from the field configured as titletext */
  61. public $title;
  62. /** @var titleTranslation the actual translation of the title */
  63. public $titleTranslation;
  64. /** @var language_id language for the translation */
  65. public $language_id;
  66. /** @var language Language name of the content */
  67. public $language;
  68. /** @var lastchanged Date when the translation was last modified */
  69. public $lastchanged;
  70. /** @var modified_date Date of the last modification of the content - if existing */
  71. public $modified_date;
  72. /** @var state State of the translation
  73. * -1 := for at least one field of the content the translation is missing
  74. * 0 := the translation exists but the original content was changed
  75. * 1 := the translation is valid
  76. */
  77. public $state=-1;
  78. /** @var int Number of changed fields */
  79. private $_numChangedFields=0;
  80. /** @var int Number of new fields, with an original other than NULL */
  81. private $_numNewAndNotNullFields=0;
  82. /** @var int Number for fields unchanged */
  83. private $_numUnchangedFields=0;
  84. /** published Flag if the translation is published or not */
  85. public $published=false;
  86. /** Standard constructor
  87. *
  88. * @param languageID ID of the associated language
  89. * @param elementTable Reference to the ContentElementTable object
  90. */
  91. public function __construct( $languageID,& $contentElement, $id=-1 ) {
  92. $db = JFactory::getDBO();
  93. if($id>0) $this->id = $id;
  94. $this->language_id = $languageID;
  95. $jfManager = JoomFishManager::getInstance();
  96. $lang = $jfManager->getLanguageByID($languageID);
  97. $this->language = $lang->name;
  98. $this->_contentElement = $contentElement;
  99. }
  100. /** Loads the information based on a certain content ID
  101. */
  102. public function loadFromContentID( $id=null ) {
  103. $db = JFactory::getDBO();
  104. if( $id!=null && isset($this->_contentElement) && $this->_contentElement!==false ) {
  105. $db->setQuery( $this->_contentElement->createContentSQL( $this->language_id, $id ) );
  106. $row=null;
  107. $row = $db->loadObject( );
  108. $this->id = $id;
  109. $this->readFromRow( $row );
  110. }
  111. }
  112. /** Reads the information from the values of the form
  113. * The content element will be loaded first and then the values of the override
  114. * what is actually in the element
  115. *
  116. * @param array The values which should be bound to the object
  117. * @param string The field prefix
  118. * @param string An optional field
  119. * @param boolean try to bind the values to the object
  120. * @param boolean store original values too
  121. */
  122. public function bind( $formArray, $prefix="", $suffix="", $tryBind=true, $storeOriginalText=false ) {
  123. $user = JFactory::getUser();
  124. $db = JFactory::getDBO();
  125. if( $tryBind ) {
  126. $this->_jfBindArrayToObject( $formArray, $this );
  127. }
  128. if( $this->published=="" ) $this->published=0;
  129. // Go thru all the fields of the element and try to copy the content values
  130. $elementTable = $this->_contentElement->getTable();
  131. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  132. $field = $elementTable->Fields[$i];
  133. $fieldName=$field->Name;
  134. if( isset($formArray[$prefix ."refField_". $fieldName .$suffix]) ) {
  135. // Handle magic quotes compatability
  136. if (get_magic_quotes_gpc() && $field->Type !== 'htmltext') {
  137. $formArray[$prefix ."refField_". $fieldName .$suffix] = JRequest::_stripSlashesRecursive( $formArray[$prefix ."refField_". $fieldName .$suffix] );
  138. $formArray[$prefix ."origText_". $fieldName .$suffix] = JRequest::_stripSlashesRecursive( $formArray[$prefix ."origText_". $fieldName .$suffix] );
  139. }
  140. else {
  141. $formArray[$prefix ."refField_". $fieldName .$suffix] = JRequest::getVar( $prefix ."refField_". $fieldName .$suffix, '', 'post', 'string', JREQUEST_ALLOWRAW );
  142. $formArray[$prefix ."origText_". $fieldName .$suffix] = JRequest::getVar( $prefix ."origText_". $fieldName .$suffix, '', 'post', 'string', JREQUEST_ALLOWRAW );
  143. }
  144. $translationValue = $formArray[$prefix ."refField_". $fieldName .$suffix];
  145. $fieldContent = new jfContent($db);
  146. // code cleaner for xhtml transitional compliance
  147. if( $field->Type == 'titletext' || $field->Type == 'text') {
  148. jimport('joomla.filter.output');
  149. //$translationValue = JFilterOutput::ampReplace( $translationValue );
  150. }
  151. if( $field->Type == 'htmltext' ) {
  152. $translationValue = str_replace( '<br>', '<br />', $translationValue );
  153. // remove <br /> take being automatically added to empty fulltext
  154. $length = strlen( $translationValue ) < 9;
  155. $search = strstr( $translationValue, '<br />');
  156. if ( $length && $search ) {
  157. $translationValue = NULL;
  158. }
  159. }
  160. if ($field->Type == "params" && is_array($translationValue)){
  161. $registry = new JRegistry();
  162. $registry->loadArray($translationValue);
  163. $translationValue = $registry->toString();
  164. }
  165. if ($field->posthandler!=""){
  166. if (method_exists($this,$field->posthandler)){
  167. $handler = $field->posthandler;
  168. $this->$handler($translationValue,$elementTable->Fields,$formArray,$prefix,$suffix,$storeOriginalText);
  169. }
  170. }
  171. $originalValue = $formArray[$prefix ."origValue_". $fieldName .$suffix];
  172. $originalText = ($storeOriginalText) ? $formArray[$prefix ."origText_". $fieldName .$suffix] : "";
  173. $fieldContent->id=$formArray[$prefix . "id_" .$fieldName .$suffix];
  174. $fieldContent->reference_id = (intval($formArray[$prefix . "reference_id" .$suffix]) > 0) ? intval($formArray[$prefix . "reference_id" .$suffix]) : $this->id;
  175. $fieldContent->language_id = $this->language_id;
  176. $fieldContent->reference_table= $db->getEscaped( $elementTable->Name );
  177. $fieldContent->reference_field= $db->getEscaped( $fieldName );
  178. $fieldContent->value = $translationValue;
  179. // original value will be already md5 encoded - based on that any encoding isn't needed!
  180. $fieldContent->original_value = $originalValue;
  181. $fieldContent->original_text = !is_null($originalText)?$originalText:"";
  182. $datenow =& JFactory::getDate();
  183. $fieldContent->modified = $datenow->toMySQL();
  184. $fieldContent->modified_by = $user->id;
  185. $fieldContent->published=$this->published;
  186. $field->translationContent = $fieldContent;
  187. }
  188. }
  189. }
  190. // Post handlers
  191. public function filterTitle(&$alias){
  192. if($alias=="") {
  193. $alias = JRequest::getString("refField_title");
  194. }
  195. $alias = JFilterOutput::stringURLSafe($alias);
  196. }
  197. public function filterName(&$alias){
  198. if($alias=="") {
  199. $alias = JRequest::getString("refField_name");
  200. }
  201. $alias = JFilterOutput::stringURLSafe($alias);
  202. }
  203. public function saveUrlParams(&$link){
  204. $urlparams = JRequest::getVar("urlparams",array(),'post',"array");
  205. if (is_array($urlparams) && count($urlparams)>0){
  206. $pos = strpos( $link, '?' );
  207. if ($pos !== false)
  208. {
  209. $prefix = substr( $link, 0, $pos );
  210. $query = substr( $link, $pos+1 );
  211. $temp = array();
  212. if(strpos($query, '&amp;') !== false) {
  213. $query = str_replace('&amp;', '&', $query);
  214. }
  215. parse_str( $query, $temp );
  216. $temp2 = array_merge( $temp, $urlparams );
  217. $temp3 = array();
  218. foreach ($temp2 as $k => $v)
  219. {
  220. $temp3[] = $k.'='.$v;
  221. }
  222. $url = null;
  223. $link = $prefix . '?' . implode( '&', $temp3 );
  224. }
  225. }
  226. else {
  227. $menuid = JRequest::getInt("reference_id",0);
  228. if ($menuid==0) return;
  229. include_once( JPATH_SITE.DS.'includes'.DS.'application.php');
  230. $menu = JSite::getMenu();
  231. $item = $menu->getItem($menuid);
  232. if ($item->type=="menulink"){
  233. $urlparams = JRequest::getVar("refField_params",array(),'post',"array");
  234. if (is_array($urlparams) && count($urlparams)>0 && array_key_exists("menu_item",$urlparams)){
  235. $pos = strpos( $link, '?' );
  236. if ($pos !== false)
  237. {
  238. $prefix = substr( $link, 0, $pos );
  239. $link = $prefix . '?Itemid=' .$urlparams["menu_item"];
  240. }
  241. }
  242. }
  243. }
  244. }
  245. /**
  246. * Special pre translation handler for content text to combine intro and full text
  247. *
  248. * @param unknown_type $row
  249. */
  250. public function fetchArticleText($row){
  251. /*
  252. * We need to unify the introtext and fulltext fields and have the
  253. * fields separated by the {readmore} tag, so lets do that now.
  254. */
  255. if (JString::strlen($row->fulltext) > 1) {
  256. return $row->introtext . "<hr id=\"system-readmore\" />" . $row->fulltext;
  257. } else {
  258. return $row->introtext;
  259. }
  260. }
  261. /**
  262. * Special pre translation handler for content text to combine intro and full text
  263. *
  264. * @param unknown_type $row
  265. */
  266. public function fetchArticleTranslation($field, &$translationFields){
  267. if (is_null($translationFields)) return;
  268. /*
  269. * We need to unify the introtext and fulltext fields and have the
  270. * fields separated by the {readmore} tag, so lets do that now.
  271. */
  272. if (array_key_exists("fulltext",$translationFields)){
  273. if (isset($translationFields["introtext"])){
  274. $fulltext = $translationFields["fulltext"]->value;
  275. $introtext = $translationFields["introtext"]->value;
  276. }
  277. else {
  278. $translationFields["introtext"] = clone $translationFields["fulltext"];
  279. $translationFields["fulltext"]->value = "";
  280. $fulltext = "";
  281. }
  282. if (JString::strlen($fulltext) > 1) {
  283. $translationFields["introtext"]->value = $introtext . "<hr id=\"system-readmore\" />" . $fulltext;
  284. $translationFields["fulltext"]->value = "";
  285. }
  286. }
  287. }
  288. /**
  289. * Special post translation handler for content text to split intro and full text
  290. *
  291. * @param unknown_type $row
  292. */
  293. public function saveArticleText(&$introtext, $fields,&$formArray,$prefix,$suffix,$storeOriginalText) {
  294. // Search for the {readmore} tag and split the text up accordingly.
  295. $pattern = '#<hr\s+id=("|\')system-readmore("|\')\s*\/*>#i';
  296. $tagPos = preg_match($pattern, $introtext);
  297. if ( $tagPos > 0 ) {
  298. list($introtext, $fulltext) = preg_split($pattern, $introtext, 2);
  299. JRequest::setVar($prefix ."refField_fulltext" .$suffix,$fulltext,"post");
  300. $formArray[$prefix ."refField_fulltext" .$suffix] = $fulltext;
  301. }
  302. else {
  303. JRequest::setVar($prefix ."refField_fulltext" .$suffix,"","post");
  304. $formArray[$prefix ."refField_fulltext" .$suffix] = "";
  305. }
  306. }
  307. /** Reads the information out of an existing mosDBTable object into the contentObject.
  308. *
  309. * @param object instance of an mosDBTable object
  310. */
  311. public function updateMLContent( &$dbObject ) {
  312. $db = JFactory::getDBO();
  313. if( $dbObject === null ) return;
  314. if( $this->published=="" ) $this->published=0;
  315. // retriev the original untranslated object for references
  316. // this MUST be copied by value and not by reference!
  317. $origObject = clone($dbObject);
  318. $key = $dbObject->get( '_tbl_key' );
  319. $db->setQuery( "SELECT * FROM " .$dbObject->get('_tbl'). " WHERE " .$key. "='" .$dbObject->$key. "'" );
  320. $origObject = $db->loadObject( false );
  321. $this->copyContentToTranslation( $dbObject, $origObject );
  322. }
  323. /**
  324. * This method copies a currect database object into the translations
  325. * The original object might be the same kind of object and it is not required that
  326. * both objects are of the type mosDBTable!
  327. *
  328. * @param object $dbObject new values for the translation
  329. * @param object $origObject original values based on the db for reference
  330. */
  331. public function copyContentToTranslation( &$dbObject, $origObject ) {
  332. $user = JFactory::getUser();
  333. // Go thru all the fields of the element and try to copy the content values
  334. $elementTable = $this->_contentElement->getTable();
  335. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  336. $field = $elementTable->Fields[$i];
  337. $fieldName=$field->Name;
  338. if( isset($dbObject->$fieldName) && $field->Translate ) {
  339. $translationValue = $dbObject->$fieldName;
  340. $fieldContent = $field->translationContent;
  341. $fieldContent->value = $translationValue;
  342. $dbObject->$fieldName = $origObject->$fieldName;
  343. $fieldContent->original_value = md5( $origObject->$fieldName );
  344. // ToDo: Add handling of original text!
  345. $datenow =& JFactory::getDate();
  346. $fieldContent->modified = $datenow->toMySQL();
  347. $fieldContent->modified_by = $user->id;
  348. }
  349. }
  350. }
  351. /** Reads some of the information from the overview row
  352. */
  353. public function readFromRow( $row ) {
  354. $this->id = $row->id;
  355. $this->translation_id = $row->jfc_id;
  356. $this->title = $row->title;
  357. $this->titleTranslation = $row->titleTranslation;
  358. if( !isset($this->language_id) || $this->language_id == -1 ) {
  359. $this->language_id = $row->language_id;
  360. $this->language = $row->language;
  361. }
  362. $this->lastchanged = $row->lastchanged;
  363. $this->published = $row->published;
  364. if( isset($row->modified_date) ) $this->modified_date = $row->modified_date;
  365. if( isset($row->checked_out) ) $this->checked_out = $row->checked_out;
  366. // Go thru all the fields of the element and try to copy the content values
  367. $elementTable = $this->_contentElement->getTable();
  368. $fieldContent = new jfContent($db);
  369. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  370. $field = $elementTable->Fields[$i];
  371. $fieldName = $field->Name;
  372. if( isset($row->$fieldName) ) {
  373. $field->originalValue = $row->$fieldName;
  374. if ($field->prehandleroriginal!=""){
  375. if (method_exists($this,$field->prehandleroriginal)){
  376. $handler = $field->prehandleroriginal;
  377. $field->originalValue = $this->$handler($row);
  378. }
  379. }
  380. }
  381. }
  382. $this->_loadContent();
  383. }
  384. /** Reads all translation information from the database
  385. *
  386. */
  387. private function _loadContent() {
  388. $db = JFactory::getDBO();
  389. $elementTable = $this->getTable();
  390. $sql = "select * "
  391. ."\n from #__jf_content"
  392. ."\n where reference_id='" .$this->id."'"
  393. ."\n and reference_table='" .$elementTable->Name. "'";
  394. if( isset($this->language_id) && $this->language_id!="" ) {
  395. $sql .= "\n and language_id=" .$this->language_id;
  396. }
  397. //echo "load sql=>$sql<<br />";
  398. $db->setQuery( $sql );
  399. $rows = $db->loadObjectList(false);
  400. if($db->getErrorNum() != 0) {
  401. JError::raiseWarning( 400,JTEXT::_('No valid table information: ') .$db->getErrorMsg());
  402. }
  403. $translationFields=null;
  404. if( count($rows) > 0 ) {
  405. foreach( $rows as $row ) {
  406. $fieldContent = new jfContent($db);
  407. if( !$fieldContent->bind( $row ) ) {
  408. JError::raiseWarning( 200, JText::_('Problems binding object to fields: ' .$fieldContent->getError()));
  409. }
  410. $translationFields[$fieldContent->reference_field] = $fieldContent;
  411. }
  412. }
  413. // Check fields and their state
  414. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  415. $field = $elementTable->Fields[$i];
  416. if ($field->prehandlertranslation!=""){
  417. if (method_exists($this,$field->prehandlertranslation)){
  418. $handler = $field->prehandlertranslation;
  419. $this->$handler($field, $translationFields);
  420. }
  421. }
  422. if( isset($translationFields[$field->Name]) ) {
  423. $fieldContent = $translationFields[$field->Name];
  424. } else {
  425. $fieldContent = null;
  426. }
  427. if( $field->Translate) {
  428. if(isset($fieldContent) ) {
  429. $field->changed= (md5($field->originalValue) != $fieldContent->original_value);
  430. if( $field->changed ) {
  431. $this->_numChangedFields ++;
  432. }
  433. else $this->_numUnchangedFields++;
  434. }
  435. else{
  436. $fieldContent = new jfContent($db);
  437. $fieldContent->reference_id = $this->id;
  438. $fieldContent->reference_table = $elementTable->Name;
  439. $fieldContent->reference_field = $field->Name;
  440. $fieldContent->language_id = $this->language_id;
  441. $fieldContent->original_value = $field->originalValue;
  442. $field->changed =false;
  443. if ( $field->originalValue != '' ) {
  444. $this->_numNewAndNotNullFields ++;
  445. }
  446. }
  447. }
  448. $field->translationContent = $fieldContent;
  449. }
  450. // Checking the record state based on the fields. If one field is changed the record is modifed
  451. if( $this->_numChangedFields == 0 && $this->_numNewAndNotNullFields == 0 ) {
  452. $this->state = 1;
  453. } elseif ( $this->_numChangedFields == 0 && $this->_numNewAndNotNullFields > 0 && $this->_numUnchangedFields==0) {
  454. $this->state = -1;
  455. } else {
  456. $this->state = 0;
  457. }
  458. }
  459. /** Returns the content element fields which are text and can be translated
  460. *
  461. * @param boolean onle translateable fields?
  462. * @return array of fieldnames
  463. */
  464. public function getTextFields( $translation = true ) {
  465. $elementTable = $this->_contentElement->getTable();
  466. $textFields = null;
  467. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  468. $field = $elementTable->Fields[$i];
  469. $fieldType = $field->Type;
  470. if( $field->Translate == $translation && ($fieldType=="htmltext" || $fieldType=="text") ) {
  471. $textFields[] = $field->Name;
  472. }
  473. }
  474. return $textFields;
  475. }
  476. /**
  477. * Returns the field type of a field
  478. *
  479. * @param string $fieldname
  480. */
  481. public function getFieldType($fieldname){
  482. $elementTable = $this->_contentElement->getTable();
  483. $textFields = null;
  484. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  485. if ($elementTable->Fields[$i]->Name == $fieldname) return $elementTable->Fields[$i]->Type;
  486. }
  487. return "text";
  488. }
  489. /** Sets all fields of this content object to a certain published state
  490. */
  491. public function setPublished( $published ) {
  492. $elementTable = $this->_contentElement->getTable();
  493. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  494. $field = $elementTable->Fields[$i];
  495. $fieldContent = $field->translationContent;
  496. $fieldContent->published = $published;
  497. }
  498. }
  499. /** Updates the reference id of all included fields. This
  500. * Happens e.g when the reference object was created new
  501. *
  502. * @param referenceID new reference id
  503. */
  504. public function updateReferenceID( $referenceID ) {
  505. if( intval($referenceID) <= 0 ) return;
  506. $elementTable = $this->_contentElement->getTable();
  507. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  508. $field = $elementTable->Fields[$i];
  509. $fieldContent = $field->translationContent;
  510. $fieldContent->reference_id = $referenceID;
  511. }
  512. }
  513. /** Stores all fields of the content element
  514. */
  515. public function store() {
  516. $elementTable = $this->_contentElement->getTable();
  517. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  518. $field = $elementTable->Fields[$i];
  519. $fieldContent = $field->translationContent;
  520. if( $field->Translate ) {
  521. if( isset($fieldContent->reference_id) ) {
  522. if ( isset($fieldContent->value) && $fieldContent->value!='' ) {
  523. $fieldContent->store(true);
  524. }
  525. // special case to handle readmore in original when there is none in the translation
  526. else if (isset($fieldContent->value) && $fieldContent->reference_table=="content" && $fieldContent->reference_field=="fulltext"){
  527. $fieldContent->store(true);
  528. }
  529. else {
  530. $fieldContent->delete();
  531. }
  532. }
  533. }
  534. }
  535. }
  536. /** Checkouts all fields of this content element
  537. */
  538. public function checkout( $who, $oid=null ) {
  539. $elementTable = $this->_contentElement->getTable();
  540. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  541. $field = $elementTable->Fields[$i];
  542. $fieldContent = $field->translationContent;
  543. if( $field->Translate ) {
  544. if( isset($fieldContent->reference_id) ) {
  545. $fieldContent->checkout( $who, $oid );
  546. JError::raiseWarning( 200, JText::_('Problems binding object to fields: ' .$fieldContent->getError()));
  547. }
  548. }
  549. }
  550. }
  551. /** Checkouts all fields of this content element
  552. */
  553. public function checkin( $oid=null ) {
  554. $elementTable = $this->_contentElement->getTable();
  555. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  556. $field = $elementTable->Fields[$i];
  557. $fieldContent = $field->translationContent;
  558. if( $field->Translate ) {
  559. if( isset($fieldContent->reference_id) ) {
  560. $fieldContent->checkin( $oid );
  561. JError::raiseWarning( 200, JText::_('Problems binding object to fields: ' .$fieldContent->getError()));
  562. }
  563. }
  564. }
  565. }
  566. /** Delets all translations (fields) of this content element
  567. */
  568. public function delete( $oid=null ) {
  569. $elementTable = $this->_contentElement->getTable();
  570. for( $i=0; $i<count($elementTable->Fields); $i++ ) {
  571. $field = $elementTable->Fields[$i];
  572. $fieldContent = $field->translationContent;
  573. if( $field->Translate ) {
  574. if( isset($fieldContent->reference_id) ) {
  575. if( !$fieldContent->delete( $oid ) ) {
  576. echo $fieldContent->getError() ."<br />";
  577. }
  578. }
  579. }
  580. }
  581. }
  582. /** Returns the content element table this content is based on
  583. */
  584. public function getTable() {
  585. return $this->_contentElement->getTable();
  586. }
  587. /**
  588. * Temporary legacy function copied from Joomla
  589. *
  590. * @param unknown_type $array
  591. * @param unknown_type $obj
  592. * @param unknown_type $ignore
  593. * @param unknown_type $prefix
  594. * @return unknown
  595. */
  596. private function _jfBindArrayToObject( $array, &$obj, $ignore='', $prefix=NULL )
  597. {
  598. if (!is_array( $array ) || !is_object( $obj )) {
  599. return (false);
  600. }
  601. foreach (get_object_vars($obj) as $k => $v)
  602. {
  603. if( substr( $k, 0, 1 ) != '_' )
  604. {
  605. // internal attributes of an object are ignored
  606. if (strpos( $ignore, $k) === false)
  607. {
  608. if ($prefix) {
  609. $ak = $prefix . $k;
  610. } else {
  611. $ak = $k;
  612. }
  613. if (isset($array[$ak])) {
  614. $obj->$k = $array[$ak];
  615. }
  616. }
  617. }
  618. }
  619. return true;
  620. }
  621. }
  622. ?>