/** * Save user and check if it has a subscription key * * @param array|object $data * @return boolean */ public function save($data = array(), $isJUser = false) { // Load state if data not loaded yet and $data has sid but does NOT have uid. // Need to determine if this is a J! user if (!$this->getId() && !empty($data['subscriber_id']) && !isset($data['user_id'])) { if (!$this->load($data['subscriber_id'])) { return false; } } // Check if this should be a J! user entity. if (!empty($data['user_id'])) { $uid = $data['user_id']; } else { $uid = !empty($this->_data->user_id) ? $this->_data->user_id : null; } // If this is a J! user or need to create it if (!empty($uid) || $isJUser) { $jUser = JTable::getInstance('user'); if (!$jUser->load($uid)) { $data['username'] = $data['name']; $data['password'] = ''; $data['sendEmail'] = '1'; $data['block'] = '0'; $data['groups'] = array('2'); $data['params'] = array(); } else { // Dont touch the nick and pass!!! unset($data['username']); unset($data['password']); } $jUser->bind($data); if (!$jUser->store()) { return false; } // Sanitize model $data['name'] = ''; $data['email'] = ''; $data['created_on'] = 0; $data['modified_on'] = date('Y-m-d H:i:s'); $data['modified_by'] = JFactory::getUser()->id; $data['user_id'] = $jUser->id; } // Check if this is a new record if (!$this->getId()) { $data['created_by'] = JFactory::getUser()->id; $data['modified_on'] = 0; $data['modified_by'] = 0; $data['locked_on'] = 0; $data['locked_by'] = 0; } // Save the rest or all if (!parent::save($data)) { return false; } $this->_createSubscriptionKey(); return parent::save(); return true; }