API15:JTable/canDelete
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Generic check for whether dependancies exist for this object in the db schema
Syntax
canDelete($oid=null, $joins=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $oid | null | $msg Error message returned |
| $joins | null | Optional key index |
Returns
true|false
Defined in
libraries/joomla/database/table.php
Importing
jimport( 'joomla.database.table' );
Source Body
function canDelete( $oid=null, $joins=null ) { $k = $this->_tbl_key; if ($oid) { $this->$k = intval( $oid ); } if (is_array( $joins )) { $select = "$k"; $join = ""; foreach( $joins as $table ) { $select .= ', COUNT(DISTINCT '.$table['idfield'].') AS '.$table['idfield']; $join .= ' LEFT JOIN '.$table['name'].' ON '.$table['joinfield'].' = '.$k; } $query = 'SELECT '. $select . ' FROM '. $this->_tbl . $join . ' WHERE '. $k .' = '. $this->_db->Quote($this->$k) . ' GROUP BY '. $k ; $this->_db->setQuery( $query ); if (!$obj = $this->_db->loadObject()) { $this->setError($this->_db->getErrorMsg()); return false; } $msg = array(); $i = 0; foreach( $joins as $table ) { $k = $table['idfield'] . $i; if ($obj->$k) { $msg[] = JText::_( $table['label'] ); } $i++; } if (count( $msg )) { $this->setError("noDeleteRecord" . ": " . implode( ', ', $msg )); return false; } else { return true; } } return true; }
[Edit See Also] SeeAlso:JTable/canDelete
Examples
<CodeExamplesForm />
