API15:JTable/publish
From Joomla! Documentation
Description
Generic Publish/Unpublish function
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
publish($cid=null, $publish=1, $user_id=0)
| Parameter Name | Default Value | Description |
|---|---|---|
| $cid | null | An array of id numbers |
| $publish | 1 | 0 if unpublishing, 1 if publishing |
| $user_id | 0 | The id of the user performnig the operation |
Defined in
libraries/joomla/database/table.php
Importing
jimport( 'joomla.database.table' );
Source Body
function publish( $cid=null, $publish=1, $user_id=0 )
{
JArrayHelper::toInteger( $cid );
$user_id = (int) $user_id;
$publish = (int) $publish;
$k = $this->_tbl_key;
if (count( $cid ) < 1)
{
if ($this->$k) {
$cid = array( $this->$k );
} else {
$this->setError("No items selected.");
return false;
}
}
$cids = $k . '=' . implode( ' OR ' . $k . '=', $cid );
$query = 'UPDATE '. $this->_tbl
. ' SET published = ' . (int) $publish
. ' WHERE ('.$cids.')'
;
$checkin = in_array( 'checked_out', array_keys($this->getProperties()) );
if ($checkin)
{
$query .= ' AND (checked_out = 0 OR checked_out = '.(int) $user_id.')';
}
$this->_db->setQuery( $query );
if (!$this->_db->query())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
if (count( $cid ) == 1 && $checkin)
{
if ($this->_db->getAffectedRows() == 1) {
$this->checkin( $cid[0] );
if ($this->$k == $cid[0]) {
$this->published = $publish;
}
}
}
$this->setError('');
return true;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples