english/administrator/components/com_modules/models/module.php
/**
	 * Method to duplicate modules.
	 *
	 * @param	array	$pks	An array of primary key IDs.
	 *
	 * @return	boolean	True if successful.
	 * @since	1.6
	 * @throws	Exception
	 */
Method to duplicate modules.
@param       array   $pks    An array of primary key IDs.

@return      boolean True if successful.
Method to duplicate modules . @param array $pks An array of primary key IDs . @return boolean True if successful .
public function duplicate(&$pks)
	{
		$user	= JFactory::getUser();
		$db		= $this->getDbo();
		if (!$user->authorise('core.create', 'com_modules')) {
			throw new Exception(JText::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
		}
		$table = $this->getTable();
		foreach ($pks as $pk)
		{
			if ($table->load($pk, true)) {
				$table->id = 0;
				$m = null;
				if (preg_match('#\((\d+)\)$#', $table->title, $m)) {
					$table->title = preg_replace('#\(\d+\)$#', '('.($m[1] + 1).')', $table->title);
				}
				else {
					$table->title .= ' (2)';
				}
				$table->published = 0;
				if (!$table->check() || !$table->store()) {
					throw new Exception($table->getError());
				}
				$query	= $db->getQuery(true);
				$query->select('menuid');
				$query->from('#__modules_menu');
				$query->where('moduleid='.(int)$pk);
				$this->_db->setQuery((string)$query);
				$rows = $this->_db->loadResultArray();
				foreach ($rows as $menuid)
				{
					$tuples[] = '('.(int) $table->id.','.(int) $menuid.')';
				}
			}
			else {
				throw new Exception($table->getError());
			}
		}
		if (!empty($tuples)) {
			$query = 'INSERT INTO #__modules_menu (moduleid,menuid) VALUES '.implode(',', $tuples);
			$this->_db->setQuery($query);
			if (!$this->_db->query()) {
				return JError::raiseWarning(500, $row->getError());
			}
		}
		$this->cleanCache();
		return true;
	}
public function duplicate ( & $ pks ) { $ user = JFactory :: getUser ( ) ; $ db = $ this -> getDbo ( ) ; if ( ! $ user -> authorise ( 'core.create' , 'com_modules' ) ) { throw new Exception ( JText :: _ ( 'JERROR_CORE_CREATE_NOT_PERMITTED' ) ) ; } $ table = $ this -> getTable ( ) ; foreach ( $ pks as $ pk ) { if ( $ table -> load ( $ pk , true ) ) { $ table -> id = 0 ; $ m = null ; if ( preg_match ( '#\((\d+)\)$#' , $ table -> title , $ m ) ) { $ table -> title = preg_replace ( '#\(\d+\)$#' , '(' . ( $ m [ 1 ] + 1 ) . ')' , $ table -> title ) ; } else { $ table -> title .= ' (2)' ; } $ table -> published = 0 ; if ( ! $ table -> check ( ) || ! $ table -> store ( ) ) { throw new Exception ( $ table -> getError ( ) ) ; } $ query = $ db -> getQuery ( true ) ; $ query -> select ( 'menuid' ) ; $ query -> from ( '#__modules_menu' ) ; $ query -> where ( 'moduleid=' . ( int ) $ pk ) ; $ this -> _db -> setQuery ( ( string ) $ query ) ; $ rows = $ this -> _db -> loadResultArray ( ) ; foreach ( $ rows as $ menuid ) { $ tuples [ ] = '(' . ( int ) $ table -> id . ',' . ( int ) $ menuid . ')' ; } } else { throw new Exception ( $ table -> getError ( ) ) ; } } if ( ! empty ( $ tuples ) ) { $ query = 'INSERT INTO #__modules_menu (moduleid,menuid) VALUES ' . implode ( ',' , $ tuples ) ; $ this -> _db -> setQuery ( $ query ) ; if ( ! $ this -> _db -> query ( ) ) { return JError :: raiseWarning ( 500 , $ row -> getError ( ) ) ; } } $ this -> cleanCache ( ) ; return true ; }
Method to duplicate modules.
Method to duplicate modules .
// Initialise variables. // Access checks. // Reset the id to create a new record. // Alter the title. // Unpublish duplicate module // $query = 'SELECT menuid' //	. ' FROM #__modules_menu' //	. ' WHERE moduleid = '.(int) $pk //	; // Module-Menu Mapping: Do it in one query // Clear modules cache