function add_user_key($user_name, $user_id) { // some random string $random = sha1(microtime() . rand()); // insert random string into user_key colomn Record::update('User', array('user_key' => $random), 'id = :user_id', array(':user_id' => (int) $user_id)); }
public static function update($model, $id, $update_lit = '') { Session::permit_admin(); $success = parent::update(Record::allow($model, ['title', 'name', 'type']), $id, $update_lit); if (isset($model['content'])) { $success = DocContent::create(['doc_id' => $id, 'content' => $model['content']]); } if (isset($model['routes'])) { DocRoute::destroy_all($id); if ($model['routes']) { $routes = []; foreach (explode(',', $model['routes']) as $route_def) { $parts = explode('=>', $route_def); $route = trim($parts[0]); if (strlen($route) == 0 || $route[0] != '/') { $route = '/' . $route; } $handler = count($parts) > 1 ? trim($parts[1]) : null; $routes[] = ['doc_id' => $id, 'route' => $route, 'handler' => $handler ? $handler : null]; } DocRoute::create_all($routes); } } return $success; }
function save() { $data = $_POST['redirect']; if (empty($data['url'])) { Flash::set('error', __('You have to specify a url!')); redirect(get_url('plugin/redirector/')); } if (empty($data['destination'])) { Flash::set('error', __('You have to specify a destination url!')); redirect(get_url('plugin/redirector/')); } if ($existing_redirect = Record::findOneFrom('RedirectorRedirects', 'url = \'' . ($data['url'] . '\''))) { Record::update('RedirectorRedirects', array('url' => $data['url'], 'destination' => $data['destination']), 'url = \'' . ($data['url'] . '\'')); } else { $entry = new RedirectorRedirects($data); if (!$entry->save()) { Flash::set('error', __('There was a problem adding your redirect.')); } else { if ($error = Record::findOneFrom('Redirector404s', 'url = \'' . ($data['url'] . '\''))) { $error->delete(); } Flash::set('success', __('Redirect has been added!')); } } redirect(get_url('plugin/redirector/')); }
public static function update_one($model, $id) { $model = Record::allow($model, ['email', 'password', 'auth']); if (isset($model['password'])) { $model['password'] = crypt($model['password'], SALT); } return parent::update($model, $id); }
public static function update($model, $id, $update_lit = '') { $success = parent::update(self::allow($model, ['title', 'summary']), $id, $update_lit); if (isset($model['content'])) { $success = SolutionContent::create(['solution_id' => $id, 'content' => $model['content']]); } return $success; }
public function testShouldUpdateDateFromArray() { $update = array('name' => 'Jéssica Santana'); $record = new Record(); $record->name = 'Henrique Moody'; $record->update($update); $this->assertEquals($update['name'], $record->name); }
function comment_on_page_saved($page) { $status = Comment::NONE; $input = $_POST['page']; if (isset($input['comment_status']) && is_int((int) $input['comment_status'])) { $status = $input['comment_status']; } Record::update('Page', array('comment_status' => $status), 'id = ?', array($page->id)); }
function redirector_log_404() { $redirect = Record::findAllFrom('Redirector404s', 'url = \'' . $_SERVER['REQUEST_URI'] . '\''); if (sizeof($redirect) > 0) { Record::update('Redirector404s', array('hits' => $redirect[0]->hits + 1), 'id = ' . $redirect[0]->id); } else { Record::insert('Redirector404s', array('url' => $_SERVER['REQUEST_URI'])); } }
public static function update_location($doc) { $nav = self::read_by_doc($doc['id']); $changes = []; if (array_key_exists('parent_id', $doc)) { $changes['parent_doc_id'] = $doc['parent_id']; } if (array_key_exists('order', $doc)) { $changes['sort_order'] = $doc['order']; } parent::update($changes, $nav['id']); }
<?php require_once dirname(__FILE__) . './vendor/autoload.php'; //autoload packages use McKay\Flash; chk_lgn(); $db = new Database(); $user = new User($db->conn); $record = new Record($db->conn); if ($_POST) { $id = $_POST['id']; $update = $_POST['record']; if ($record->update($id, $update)) { Flash::success('Record Successfully Updated!!'); unset($_POST); } else { Flash::error('Record Could Not Be Updated!!'); } } if (isset($_GET['id'])) { $user_id = $_GET['id']; } else { $user_id = $_SESSION['user_id']; } $data = $record->read($user_id); require 'templates/header.php'; ?> <div id="page-wrapper"> <div class="container-fluid">
public function setTags($tags) { if (is_string($tags)) { $tags = explode(',', $tags); } $tags = array_map('trim', $tags); $current_tags = $this->getTags(); // no tag before! no tag now! ... nothing to do! if (count($tags) == 0 && count($current_tags) == 0) { return; } // delete all tags if (count($tags) == 0) { $tablename = self::tableNameFromClassName('Tag'); // update count (-1) of those tags foreach ($current_tags as $tag) { Record::update('Tag', array('count' => 'count - 1'), 'name = :tag_name', array(':tag_name' => $tag)); } return Record::deleteWhere('PageTag', 'page_id = :page_id', array(':page_id' => $this->id)); } else { $old_tags = array_diff($current_tags, $tags); $new_tags = array_diff($tags, $current_tags); // insert all tags in the tag table and then populate the page_tag table foreach ($new_tags as $index => $tag_name) { if (!empty($tag_name)) { // try to get it from tag list, if not we add it to the list if (!($tag = Tag::findByName($tag_name))) { $tag = new Tag(array('name' => trim($tag_name))); } $tag->count++; $tag->save(); // create the relation between the page and the tag $tag = new PageTag(array('page_id' => $this->id, 'tag_id' => $tag->id)); $tag->save(); } } // remove all old tag foreach ($old_tags as $index => $tag_name) { // get the id of the tag $tag = Tag::findByName($tag_name); // delete the pivot record Record::deleteWhere('PageTag', 'page_id = :page_id AND tag_id = :tag_id', array(':page_id' => $this->id, ':tag_id' => $tag->id)); $tag->count--; $tag->save(); } } }
public static function saveFromData($data) { foreach ($data as $name => $value) { Record::update('Setting', array('value' => $value), 'name = :name', array(':name' => $name)); } }