/**
  * Overrides Table::store to check unique fields.
  *
  * @param   boolean  $updateNulls  True to update fields even if they are null.
  *
  * @return  boolean  True on success.
  *
  * @since   11.4
  */
 public function store($updateNulls = false)
 {
     // Verify that the sef field is unique
     $table = Table::getInstance('Language', 'JTable');
     if ($table->load(array('sef' => $this->sef)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) {
         $this->setError(Text::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_SEF'));
         return false;
     }
     // Verify that the image field is unique
     if ($table->load(array('image' => $this->image)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) {
         $this->setError(Text::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_IMAGE'));
         return false;
     }
     // Verify that the language code is unique
     if ($table->load(array('lang_code' => $this->lang_code)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) {
         $this->setError(Text::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_LANG_CODE'));
         return false;
     }
     return parent::store($updateNulls);
 }
 /**
  * Method to delete a node and, optionally, its child nodes from the table.
  *
  * @param   integer  $pk        The primary key of the node to delete.
  * @param   boolean  $children  True to delete child nodes, false to move them up a level.
  *
  * @return  boolean  True on success.
  *
  * @since   11.1
  */
 public function delete($pk = null, $children = true)
 {
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     // Lock the table for writing.
     if (!$this->_lock()) {
         // Error message set in lock method.
         return false;
     }
     // If tracking assets, remove the asset first.
     if ($this->_trackAssets) {
         $name = $this->_getAssetName();
         $asset = Table::getInstance('Asset');
         // Lock the table for writing.
         if (!$asset->_lock()) {
             // Error message set in lock method.
             return false;
         }
         if ($asset->loadByName($name)) {
             // Delete the node in assets table.
             if (!$asset->delete(null, $children)) {
                 $this->setError($asset->getError());
                 $asset->_unlock();
                 return false;
             }
             $asset->_unlock();
         } else {
             $this->setError($asset->getError());
             $asset->_unlock();
             return false;
         }
     }
     // Get the node by id.
     $node = $this->_getNode($pk);
     if (empty($node)) {
         // Error message set in getNode method.
         $this->_unlock();
         return false;
     }
     // Should we delete all children along with the node?
     if ($children) {
         // Delete the node and all of its children.
         $query = $this->_db->getQuery(true);
         $query->delete()->from($this->_tbl)->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         // Compress the left values.
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl)->set('lft = lft - ' . (int) $node->width)->where('lft > ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         // Compress the right values.
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl)->set('rgt = rgt - ' . (int) $node->width)->where('rgt > ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
     } else {
         // Delete the node.
         $query = $this->_db->getQuery(true);
         $query->delete()->from($this->_tbl)->where('lft = ' . (int) $node->lft);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         // Shift all node's children up a level.
         $query->clear()->update($this->_tbl)->set('lft = lft - 1')->set('rgt = rgt - 1')->set('level = level - 1')->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         // Adjust all the parent values for direct children of the deleted node.
         $query->clear()->update($this->_tbl)->set('parent_id = ' . (int) $node->parent_id)->where('parent_id = ' . (int) $node->{$k});
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         // Shift all of the left values that are right of the node.
         $query->clear()->update($this->_tbl)->set('lft = lft - 2')->where('lft > ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         // Shift all of the right values that are right of the node.
         $query->clear()->update($this->_tbl)->set('rgt = rgt - 2')->where('rgt > ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
     }
     // Unlock the table for writing.
     $this->_unlock();
     return true;
 }
 /**
  * Method to get the user table object
  *
  * This function uses a static variable to store the table name of the user table to
  * instantiate. You can call this function statically to set the table name if
  * needed.
  *
  * @param   string  $type    The user table name to be used
  * @param   string  $prefix  The user table prefix to be used
  *
  * @return  object  The user table object
  *
  * @since   11.1
  */
 public static function getTable($type = null, $prefix = 'JTable')
 {
     static $tabletype;
     // Set the default tabletype;
     if (!isset($tabletype)) {
         $tabletype['name'] = 'user';
         $tabletype['prefix'] = 'JTable';
     }
     // Set a custom table type is defined
     if (isset($type)) {
         $tabletype['name'] = $type;
         $tabletype['prefix'] = $prefix;
     }
     // Create the user table object
     return Table::getInstance($tabletype['name'], $tabletype['prefix']);
 }