API15

JTable/canDelete

From Joomla! Documentation

< API15:JTable
Revision as of 13:51, 12 May 2013 by JoomlaWikiBot (talk | contribs) (removing red link to edit, no existant pages)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Generic check for whether dependancies exist for this object in the db schema

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

canDelete($oid=null, $joins=null)
Parameter Name Default Value Description
$oid null $msg Error message returned
$joins null Optional key index

Returns[edit]

true|false

Defined in[edit]

libraries/joomla/database/table.php

Importing[edit]

jimport( 'joomla.database.table' );

Source Body[edit]

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;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

<CodeExamplesForm />