english/libraries/joomla/database/table/content.php
/**
	 * Method to set the publishing state for a row or list of rows in the database
	 * table. The method respects checked out rows by other users and will attempt
	 * to checkin rows that it can after adjustments are made.
	 *
	 * @param   mixed    $pks      An optional array of primary key values to update.  If not
	 *                            set the instance property value is used.
	 * @param   integer  $state   The publishing state. eg. [0 = unpublished, 1 = published]
	 * @param   integer  $userId  The user id of the user performing the operation.
	 *
	 * @return  boolean  True on success.
	 *
	 * @since   11.1
	 */
Method to set the publishing state for a row or list of rows in the database
table. The method respects checked out rows by other users and will attempt
to checkin rows that it can after adjustments are made.

@param   mixed    $pks      An optional array of primary key values to update.  If not
set the instance property value is used.
@param   integer  $state   The publishing state. eg. [0 = unpublished, 1 = published]
@param   integer  $userId  The user id of the user performing the operation.

@return  boolean  True on success.


Method to set the publishing state for a row or list of rows in the database table . The method respects checked out rows by other users and will attempt to checkin rows that it can after adjustments are made . @param mixed $pks An optional array of primary key values to update . If not set the instance property value is used . @param integer $state The publishing state . eg . [ 0 = unpublished 1 = published ] @param integer $userId The user id of the user performing the operation . @return boolean True on success .
public function publish($pks = null, $state = 1, $userId = 0)
	{
		$k = $this->_tbl_key;
		JArrayHelper::toInteger($pks);
		$userId = (int) $userId;
		$state  = (int) $state;
		if (empty($pks)) {
			if ($this->$k) {
				$pks = array($this->$k);
			}
			else {
				$this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
				return false;
			}
		}
		$where = $k.'='.implode(' OR '.$k.'=', $pks);
		if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time')) {
			$checkin = '';
		} else {
			$checkin = ' AND (checked_out = 0 OR checked_out = '.(int) $userId.')';
		}
		$this->_db->setQuery(
			'UPDATE '.$this->_db->quoteName($this->_tbl).
			' SET '.$this->_db->quoteName('state').' = '.(int) $state .
			' WHERE ('.$where.')' .
			$checkin
		);
		$this->_db->query();
		if ($this->_db->getErrorNum()) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}
		if ($checkin && (count($pks) == $this->_db->getAffectedRows())) {
			foreach($pks as $pk) {
				$this->checkin($pk);
			}
		}
		if (in_array($this->$k, $pks)) {
			$this->state = $state;
		}
		$this->setError('');
		return true;
	}
public function publish ( $ pks = null , $ state = 1 , $ userId = 0 ) { $ k = $ this -> _tbl_key ; JArrayHelper :: toInteger ( $ pks ) ; $ userId = ( int ) $ userId ; $ state = ( int ) $ state ; if ( empty ( $ pks ) ) { if ( $ this -> $ k ) { $ pks = array ( $ this -> $ k ) ; } else { $ this -> setError ( JText :: _ ( 'JLIB_DATABASE_ERROR_NO_ROWS_SELECTED' ) ) ; return false ; } } $ where = $ k . '=' . implode ( ' OR ' . $ k . '=' , $ pks ) ; if ( ! property_exists ( $ this , 'checked_out' ) || ! property_exists ( $ this , 'checked_out_time' ) ) { $ checkin = '' ; } else { $ checkin = ' AND (checked_out = 0 OR checked_out = ' . ( int ) $ userId . ')' ; } $ this -> _db -> setQuery ( 'UPDATE ' . $ this -> _db -> quoteName ( $ this -> _tbl ) . ' SET ' . $ this -> _db -> quoteName ( 'state' ) . ' = ' . ( int ) $ state . ' WHERE (' . $ where . ')' . $ checkin ) ; $ this -> _db -> query ( ) ; if ( $ this -> _db -> getErrorNum ( ) ) { $ this -> setError ( $ this -> _db -> getErrorMsg ( ) ) ; return false ; } if ( $ checkin && ( count ( $ pks ) == $ this -> _db -> getAffectedRows ( ) ) ) { foreach ( $ pks as $ pk ) { $ this -> checkin ( $ pk ) ; } } if ( in_array ( $ this -> $ k , $ pks ) ) { $ this -> state = $ state ; } $ this -> setError ( '' ) ; return true ; }
Method to set the publishing state for a row or list of rows in the database
 table.
Method to set the publishing state for a row or list of rows in the database table .
// Initialise variables. // Sanitize input. // If there are no primary keys set check to see if the instance key is set. // Nothing to set publishing state on, return false. // Build the WHERE clause for the primary keys. // Determine if there is checkin support for the table. // Update the publishing state for rows with the given primary keys. // Check for a database error. // If checkin is supported and all rows were adjusted, check them in. // Checkin the rows. // If the JTable instance value is in the list of primary keys that were set, set the instance.