PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý công ty du lịch khách sạn PHP/sgncnew/administrator/components/com_joomfish/models/ContentObject.php

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