/**
  * Method to bind the data.
  *
  * @param   array  $array   The data to bind.
  * @param   mixed  $ignore  An array or space separated list of fields to ignore.
  *
  * @return  boolean  True on success, false on failure.
  *
  * @since   11.1
  */
 public function bind($array, $ignore = '')
 {
     // Bind the rules as appropriate.
     if (isset($array['rules'])) {
         if (is_array($array['rules'])) {
             $array['rules'] = json_encode($array['rules']);
         }
     }
     return parent::bind($array, $ignore);
 }
 /**
  * Overloaded bind function
  *
  * @param   array  $array   Named array
  * @param   mixed  $ignore  An optional array or space separated list of properties
  *                          to ignore while binding.
  *
  * @return  mixed  Null if operation was satisfactory, otherwise returns an error
  *
  * @see     JTable::bind
  * @since   11.1
  */
 public function bind($array, $ignore = '')
 {
     if (isset($array['params']) && is_array($array['params'])) {
         $registry = new Registry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     if (isset($array['control']) && is_array($array['control'])) {
         $registry = new Registry();
         $registry->loadArray($array['control']);
         $array['control'] = (string) $registry;
     }
     return parent::bind($array, $ignore);
 }
 /**
  * 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 store a node in the database table.
  *
  * @param   boolean  $updateNulls  True to update null values as well.
  *
  * @return  boolean  True on success.
  *
  * @link    http://docs.joomla.org/JTableNested/store
  * @since   11.1
  */
 public function store($updateNulls = false)
 {
     $k = $this->_tbl_key;
     // @codeCoverageIgnoreStart
     if ($this->_debug) {
         echo "\n" . get_class($this) . "::store\n";
         $this->_logtable(true, false);
     }
     // @codeCoverageIgnoreEnd
     /*
      * If the primary key is empty, then we assume we are inserting a new node into the
      * tree.  From this point we would need to determine where in the tree to insert it.
      */
     if (empty($this->{$k})) {
         /*
          * We are inserting a node somewhere in the tree with a known reference
          * node.  We have to make room for the new node and set the left and right
          * values before we insert the row.
          */
         if ($this->_location_id >= 0) {
             // Lock the table for writing.
             if (!$this->_lock()) {
                 // Error message set in lock method.
                 return false;
             }
             // We are inserting a node relative to the last root node.
             if ($this->_location_id == 0) {
                 // Get the last root node as the reference node.
                 $query = $this->_db->getQuery(true);
                 $query->select($this->_tbl_key . ', parent_id, level, lft, rgt')->from($this->_tbl)->where('parent_id = 0')->order('lft DESC');
                 $this->_db->setQuery($query, 0, 1);
                 $reference = $this->_db->loadObject();
                 // @codeCoverageIgnoreStart
                 if ($this->_debug) {
                     $this->_logtable(false);
                 }
                 // @codeCoverageIgnoreEnd
             } else {
                 // Get the reference node by primary key.
                 if (!($reference = $this->_getNode($this->_location_id))) {
                     // Error message set in getNode method.
                     $this->_unlock();
                     return false;
                 }
             }
             // Get the reposition data for shifting the tree and re-inserting the node.
             if (!($repositionData = $this->_getTreeRepositionData($reference, 2, $this->_location))) {
                 // Error message set in getNode method.
                 $this->_unlock();
                 return false;
             }
             // Create space in the tree at the new location for the new node in left ids.
             $query = $this->_db->getQuery(true);
             $query->update($this->_tbl)->set('lft = lft + 2')->where($repositionData->left_where);
             $this->_runQuery($query, 'JLIB_DATABASE_ERROR_STORE_FAILED');
             // Create space in the tree at the new location for the new node in right ids.
             $query = $this->_db->getQuery(true);
             $query->update($this->_tbl)->set('rgt = rgt + 2')->where($repositionData->right_where);
             $this->_runQuery($query, 'JLIB_DATABASE_ERROR_STORE_FAILED');
             // Set the object values.
             $this->parent_id = $repositionData->new_parent_id;
             $this->level = $repositionData->new_level;
             $this->lft = $repositionData->new_lft;
             $this->rgt = $repositionData->new_rgt;
         } else {
             // Negative parent ids are invalid
             $e = new UnexpectedValueException(sprintf('%s::store() used a negative _location_id', get_class($this)));
             $this->setError($e);
             return false;
         }
     } else {
         // If the location has been set, move the node to its new location.
         if ($this->_location_id > 0) {
             if (!$this->moveByReference($this->_location_id, $this->_location, $this->{$k})) {
                 // Error message set in move method.
                 return false;
             }
         }
         // Lock the table for writing.
         if (!$this->_lock()) {
             // Error message set in lock method.
             return false;
         }
     }
     // Store the row to the database.
     if (!parent::store($updateNulls)) {
         $this->_unlock();
         return false;
     }
     // @codeCoverageIgnoreStart
     if ($this->_debug) {
         $this->_logtable();
     }
     // @codeCoverageIgnoreEnd
     // Unlock the table for writing.
     $this->_unlock();
     return true;
 }
 /**
  * Method to bind the user, user groups, and any other necessary data.
  *
  * @param   array  $array   The data to bind.
  * @param   mixed  $ignore  An array or space separated list of fields to ignore.
  *
  * @return  boolean  True on success, false on failure.
  *
  * @since   11.1
  */
 public function bind($array, $ignore = '')
 {
     if (array_key_exists('params', $array) && is_array($array['params'])) {
         $registry = new Registry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     // Attempt to bind the data.
     $return = parent::bind($array, $ignore);
     // Load the real group data based on the bound ids.
     if ($return && !empty($this->groups)) {
         // Set the group ids.
         ArrayHelper::toInteger($this->groups);
         // Get the titles for the user groups.
         $query = $this->_db->getQuery(true);
         $query->select($this->_db->quoteName('id'));
         $query->select($this->_db->quoteName('title'));
         $query->from($this->_db->quoteName('#__usergroups'));
         $query->where($this->_db->quoteName('id') . ' = ' . implode(' OR ' . $this->_db->quoteName('id') . ' = ', $this->groups));
         $this->_db->setQuery($query);
         // Set the titles for the user groups.
         $this->groups = $this->_db->loadAssocList('id', 'id');
     }
     return $return;
 }
 /**
  * Inserts a new row if id is zero or updates an existing row in the database table
  *
  * @param   boolean  $updateNulls  If false, null object variables are not updated
  *
  * @return  boolean  True if successful, false otherwise and an internal error message is set
  *
  * @since   11.1
  */
 public function store($updateNulls = false)
 {
     if ($result = parent::store($updateNulls)) {
         // Rebuild the nested set tree.
         $this->rebuild();
     }
     return $result;
 }
 /**
  * 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']);
 }