public function save() { $modified = $this->isModified('enabled'); $result = parent::save(); if ($this->getStatus() == Library\Database::STATUS_UPDATED && $modified && $this->enabled) { $database = $this->getTable()->getAdapter(); $languages = $this->getObject('application.languages'); $primary = $languages->getPrimary(); foreach ($languages as $language) { if ($language->id != $primary->id) { $table = strtolower($language->iso_code) . '_' . $this->name; // Create language specific table. $query = 'CREATE TABLE ' . $database->quoteIdentifier($table) . ' LIKE ' . $database->quoteIdentifier($this->name); $database->execute($query); // Copy content of original table into the language specific one. $query = $this->getObject('lib:atabase.query.insert')->table($table)->values($this->getObject('lib:database.query.select')->table($this->name)); $database->execute($query); $status = DatabaseRowTranslation::STATUS_MISSING; $original = 0; } else { $status = DatabaseRowTranslation::STATUS_COMPLETED; $original = 1; } // Add items to the translations table. $select = $this->getObject('lib:database.query.select')->columns(array('iso_code' => ':iso_code', 'table' => ':table', 'row' => $this->unique_column, 'status' => ':status', 'original' => ':original'))->table($this->name)->bind(array('iso_code' => $language->iso_code, 'table' => $this->name, 'status' => $status, 'original' => $original)); $query = $this->getObject('lib:database.query.insert')->table('languages_translations')->columns(array('iso_code', 'table', 'row', 'status', 'original'))->values($select); $database->execute($query); } } return $result; }
public function save() { $return = parent::save(); if ($return && $this->row && $this->table) { $relation = $this->getObject('com:attachments.database.row.relation'); $relation->attachments_attachment_id = $this->id; $relation->table = $this->table; $relation->row = $this->row; if (!$relation->load()) { $relation->save(); } } // Save the thumbnail if the attachment is an image if ($this->file->isImage()) { $thumbnail = $this->getObject('com:files.database.row.thumbnail'); $thumbnail->source = $this->file; if (!file_exists($this->thumbnail_fullpath)) { $thumbnail->setThumbnailSize(4 / 3)->generateThumbnail()->save($this->thumbnail_fullpath); } if (isset($this->x1) && isset($this->x2)) { // Cropping existing thumbnail $thumbnail->setData(array('source' => $this->file, 'x1' => $this->x1, 'x2' => $this->x2, 'y1' => $this->y1, 'y2' => $this->y2))->cropThumbnail()->save($this->thumbnail_fullpath); } } return $return; }
public function save() { $result = parent::save(); if ($this->users) { // Add new users to group foreach ($this->users as $user) { $group_user = $this->getObject('com:users.database.row.groups_users'); $group_user->group_id = $this->id; $group_user->user_id = $user; if (!$group_user->load()) { $group_user->save(); } } // Remove users no longer attached to group foreach ($this->getObject('com:users.model.groups_users')->group_id($this->id)->getRowset() as $group_user) { // Remove all users that are no longer selected if (!in_array($group_user->user_id, $this->users)) { $row = $this->getObject('com:users.model.groups_users')->group_id($this->id)->user_id($group_user->user_id)->getRow(); $row->delete(); } } } else { // @TODO: Bug, this should work by using the entire rowset instead of getting a row object for each row foreach ($this->getObject('com:users.model.groups_users')->group_id($this->id)->getRowset() as $group_user) { $row = $this->getObject('com:users.model.groups_users')->group_id($this->id)->user_id($group_user->user_id)->getRow(); $row->delete(); } } return $result; }
public function save() { if ($source = $this->source) { if (!$source->isNew()) { $str = $this->generateThumbnail(); $this->setData(array('files_container_id' => $source->getContainer()->id, 'folder' => $source->folder, 'filename' => $source->name, 'thumbnail' => $str)); } else { return false; } } return parent::save(); }
public function save() { $return = parent::save(); if ($return && $this->row && $this->table) { $relation = $this->getObject('com:attachments.database.row.relation'); $relation->attachments_attachment_id = $this->id; $relation->table = $this->table; $relation->row = $this->row; if (!$relation->load()) { $relation->save(); } } return $return; }
public function save() { $result = false; //@TODO : Implement automatic schema validation if (!empty($this->id)) { if ($result = parent::save()) { // Hit the user last visit field $row = $this->getObject('com:users.database.row.user')->setData(array('email' => $this->email))->load(); if ($row) { $row->last_visited_on = gmdate('Y-m-d H:i:s'); $row->save(); $this->setStatus(self::LOGGED_IN); } } } return $result; }
public function save() { //Set the introtext and the full text $text = str_replace('<br>', '<br />', $this->text); $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i'; if (preg_match($pattern, $text)) { list($introtext, $fulltext) = preg_split($pattern, $text, 2); $this->introtext = trim($introtext); $this->fulltext = trim($fulltext); } else { $this->introtext = trim($text); $this->fulltext = ''; } //Validate the title if (empty($this->title)) { $this->_status = Library\Database::STATUS_FAILED; $this->_status_message = JText::_('Article must have a title'); return false; } return parent::save(); }
public function save() { $modified = $this->isModified('enabled'); $result = parent::save(); if ($this->getStatus() == Library\Database::STATUS_UPDATED && $modified && $this->enabled && $this->application == 'site') { $tables = $this->getObject('com:languages.model.tables')->getRowset(); $database = $this->getTable()->getAdapter(); foreach ($tables as $table) { $table_name = strtolower($this->iso_code) . '_' . $table->name; // Add language specific table and copy the content of the original table. $database->execute('CREATE TABLE ' . $database->quoteIdentifier($table_name) . ' LIKE ' . $database->quoteIdentifier($table->name)); $select = $this->getObject('lib:database.query.select')->table($table->name); $insert = $this->getObject('lib:database.query.insert')->table($table_name)->values($select); $database->insert($insert); // Add items to the translations table. $columns = array('iso_code' => ':iso_code', 'table' => ':table', 'row' => 'tbl.' . $table->unique_column, 'status' => ':status', 'original' => ':original'); $select = $this->getObject('lib:database.query.select')->columns($columns)->table(array('tbl' => $table_name))->bind(array('iso_code' => $this->iso_code, 'table' => $table->name, 'status' => DatabaseRowTranslation::STATUS_MISSING, 'original' => 0)); $insert = $this->getObject('lib:database.query.insert')->table('languages_translations')->columns(array_keys($columns))->values($select); $database->insert($insert); } } return $result; }
public function save() { $user = $this->getObject('com:users.model.users')->email($this->id)->getRow(); // Check if referenced user actually exists. if ($user->isNew()) { $this->setStatus(Library\Database::STATUS_FAILED); $this->setStatusMessage(\JText::sprintf('USER NOT FOUND', $this->id)); return false; } if ($password = $this->password) { // Check the password length. $params = $this->getObject('application.extensions')->users->params; $length = $params->get('password_length', 5); if (strlen($password) < $length) { $this->setStatus(Library\Database::STATUS_FAILED); $this->setStatusMessage(\JText::sprintf('PASSWORD TOO SHORT', $length)); return false; } if (!$this->isNew()) { // Check if new and current hashes are the same. if ($this->verify($password)) { $this->setStatus(Library\Database::STATUS_FAILED); $this->setStatusMessage(\JText::_('New and old passwords are the same')); return false; } } // Reset expiration date. $this->resetExpiration(false); // Create hash. $this->hash = $this->getHash($password); // Clear reset. $this->reset = ''; // Unset plain text password for allowing subsequent save calls. unset($this->password); } return parent::save(); }
/** * Saves the row to the database. * * This performs an intelligent insert/update and reloads the properties * with fresh data from the table on success. * * @return boolean If successfull return TRUE, otherwise FALSE */ public function save() { $modified = $this->getModified(); $result = parent::save(); if (in_array('pages', $modified)) { $table = $this->getObject('com:pages.database.table.modules'); //Clean up existing assignemnts $table->select(array('pages_module_id' => $this->id))->delete(); if (is_array($this->pages)) { foreach ($this->pages as $page) { $table->select(null, Library\Database::FETCH_ROW)->setData(array('pages_module_id' => $this->id, 'pages_page_id' => $page))->save(); } } elseif ($this->pages == 'all') { $table->select(null, Library\Database::FETCH_ROW)->setData(array('moduleid' => $this->id, 'menuid' => 0))->save(); } } return $result; }
public function save() { if ($source = $this->source) { if (!$source->isNew()) { $string = (string) $this->generateThumbnail(); $string = sprintf('data:image/png;base64,%s', base64_encode($string)); $this->setData(array('files_container_id' => $source->getContainer()->id, 'folder' => $source->folder, 'filename' => $source->name, 'thumbnail' => $string)); } else { return false; } } return parent::save(); }
public function save() { // Validate name if ($this->isModified('name') && trim($this->name) == '') { $this->setStatus(Library\Database::STATUS_FAILED); $this->setStatusMessage(\JText::_('Please enter a name')); return false; } if ($this->isModified('email')) { // Validate E-mail if (!$this->getObject('lib:filter.email')->validate($this->email)) { $this->setStatus(Library\Database::STATUS_FAILED); $this->setStatusMessage(\JText::_('Please enter a valid E-mail address')); return false; } // Check if E-mail address is not already being used $query = $this->getObject('lib:database.query.select')->where('email = :email')->bind(array('email' => $this->email)); if ($this->getObject('com:users.database.table.users')->count($query)) { $this->setStatus(Library\Database::STATUS_FAILED); $this->setStatusMessage(\JText::_('The provided E-mail address is already registered')); return false; } } // Check if the attached role exists if ($this->isModified('role_id') && $this->getRole()->isNew()) { $this->setStatus(Library\Database::STATUS_FAILED); $this->setStatusMessage('Invalid role'); return false; } // Set parameters. if ($this->isModified('params')) { $params = new \JParameter(''); $params->bind($this->_data['params']); $this->params = $params->toString(); /*if(!$this->isNew() && $this->_data['params'] == $current->params->toString()) { unset($this->_modified['params']); }*/ } if ($this->isModified('role_id')) { // Clear role cache $this->_role = null; } if (!$this->isNew()) { // Load the current user row for checks. $current = $this->getObject('com:users.database.table.users')->select($this->id, Library\Database::FETCH_ROW); // There must be at least one enabled super administrator if (($this->isModified('role_id') || $this->isModified('enabled') && !$this->enabled) && $current->role_id == 25) { $query = $this->getObject('lib:database.query.select')->where('enabled = :enabled')->where('users_role_id = :role_id')->bind(array('enabled' => 1, 'role_id' => 25)); if ($this->getObject('com:users.database.table.users')->count($query) <= 1) { $this->setStatus(Library\Database::STATUS_FAILED); $this->setStatusMessage('There must be at least one enabled super administrator'); return false; } } } return parent::save(); }