public function canDelete($pk = null, $joins = null)
	{
		// Deprecation warning.
		Log::debug('Hubzero\Database\Table::canDelete() is deprecated.');

		// Initialise variables.
		$k = $this->_tbl_key;
		$pk = (is_null($pk)) ? $this->$k : $pk;

		// If no primary key is given, return false.
		if ($pk === null)
		{
			return false;
		}

		if (is_array($joins))
		{
			// Get a query object.
			$query = $this->_db->getQuery();

			// Setup the basic query.
			$query->select($this->_tbl_key);
			$query->from($this->_tbl);
			$query->whereEquals($this->_tbl_key, $this->$k);
			$query->group($this->_tbl_key);

			// For each join add the select and join clauses to the query object.
			foreach ($joins as $table)
			{
				$query->select('COUNT(DISTINCT ' . $table['idfield'] . ')', $table['idfield']);
				$query->join($table['name'], $table['joinfield'], $k, 'left');
			}

			// Get the row object from the query.
			$this->_db->setQuery((string) $query->toString(), 0, 1);
			$row = $this->_db->loadObject();

			// Check for a database error.
			if ($this->_db->getErrorNum())
			{
				$this->setError($this->_db->getErrorMsg());

				return false;
			}

			$msg = array();
			$i = 0;

			foreach ($joins as $table)
			{
				$k = $table['idfield'] . $i;

				if ($row->$k)
				{
					$msg[] = Lang::txt($table['label']);
				}

				$i++;
			}

			if (count($msg))
			{
				$this->setError("noDeleteRecord" . ": " . implode(', ', $msg));

				return false;
			}
			else
			{
				return true;
			}
		}

		return true;
	}
public function canDelete($pk = null, $joins = null)
	{
		// Deprecation warning.
		Log::debug('Hubzero\Database\Table::canDelete() is deprecated.');

		// Initialise variables.
		$k = $this->_tbl_key;
		$pk = (is_null($pk)) ? $this->$k : $pk;

		// If no primary key is given, return false.
		if ($pk === null)
		{
			return false;
		}

		if (is_array($joins))
		{
			// Get a query object.
			$query = $this->_db->getQuery();

			// Setup the basic query.
			$query->select($this->_tbl_key);
			$query->from($this->_tbl);
			$query->whereEquals($this->_tbl_key, $this->$k);
			$query->group($this->_tbl_key);

			// For each join add the select and join clauses to the query object.
			foreach ($joins as $table)
			{
				$query->select('COUNT(DISTINCT ' . $table['idfield'] . ')', $table['idfield']);
				$query->join($table['name'], $table['joinfield'], $k, 'left');
			}

			// Get the row object from the query.
			$this->_db->setQuery((string) $query->toString(), 0, 1);
			$row = $this->_db->loadObject();

			// Check for a database error.
			if ($this->_db->getErrorNum())
			{
				$this->setError($this->_db->getErrorMsg());

				return false;
			}

			$msg = array();
			$i = 0;

			foreach ($joins as $table)
			{
				$k = $table['idfield'] . $i;

				if ($row->$k)
				{
					$msg[] = Lang::txt($table['label']);
				}

				$i++;
			}

			if (count($msg))
			{
				$this->setError("noDeleteRecord" . ": " . implode(', ', $msg));

				return false;
			}
			else
			{
				return true;
			}
		}

		return true;
	}
public function canDelete ( $ pk = null , $ joins = null ) { // Deprecation warning. Log :: debug ( 'Hubzero\Database\Table::canDelete() is deprecated.' ) ; // Initialise variables. $ k = $ this -> _tbl_key ; $ pk = ( is_null ( $ pk ) ) ? $ this -> $ k : $ pk ; // If no primary key is given, return false. if ( $ pk === null ) { return false ; } if ( is_array ( $ joins ) ) { // Get a query object. $ query = $ this -> _db -> getQuery ( ) ; // Setup the basic query. $ query -> select ( $ this -> _tbl_key ) ; $ query -> from ( $ this -> _tbl ) ; $ query -> whereEquals ( $ this -> _tbl_key , $ this -> $ k ) ; $ query -> group ( $ this -> _tbl_key ) ; // For each join add the select and join clauses to the query object. foreach ( $ joins as $ table ) { $ query -> select ( 'COUNT(DISTINCT ' . $ table [ 'idfield' ] . ')' , $ table [ 'idfield' ] ) ; $ query -> join ( $ table [ 'name' ] , $ table [ 'joinfield' ] , $ k , 'left' ) ; } // Get the row object from the query. $ this -> _db -> setQuery ( ( string ) $ query -> toString ( ) , 0 , 1 ) ; $ row = $ this -> _db -> loadObject ( ) ; // Check for a database error. if ( $ this -> _db -> getErrorNum ( ) ) { $ this -> setError ( $ this -> _db -> getErrorMsg ( ) ) ; return false ; } $ msg = array ( ) ; $ i = 0 ; foreach ( $ joins as $ table ) { $ k = $ table [ 'idfield' ] . $ i ; if ( $ row -> $ k ) { $ msg [ ] = Lang :: txt ( $ table [ 'label' ] ) ; } $ i ++ ; } if ( count ( $ msg ) ) { $ this -> setError ( "noDeleteRecord" . ": " . implode ( ', ' , $ msg ) ) ; return false ; } else { return true ; } } return true ; }
Generic check for whether dependencies exist for this object in the database schema

Can be overloaded/supplemented by the child class

@param   mixed  $pk     An optional primary key value check the row for.  If not
set the instance property value is used.
@param   array  $joins  An optional array to compiles standard joins formatted like:
[label => 'Label', name => 'table name' , idfield => 'field', joinfield => 'field']
@return  boolean  True on success.
@deprecated    2.1.12
@since  2.1.12
Generic check for whether dependencies exist for this object in the database schema