/** * for testing only */ public function createUser() { $user = new Mapper($this->db, 'users'); $user->username = '******'; $user->password = md5('piggy'); $user->save(); }
public function save() { if (parent::changed('pass')) { $this->pass = $this->passwordify($this->pass); } parent::save(); }
/** * Save model, triggering plugin hooks and setting created_date * @return mixed */ function save() { // Ensure created_date is set if possible if (!$this->query && array_key_exists("created_date", $this->fields) && !$this->get("created_date")) { $this->set("created_date", date("Y-m-d H:i:s")); } // Save object $result = parent::save(); return $result; }
function save() { if ($this->uid != $this->user->uid) { //this is SPARTAA!! if (empty($this->uid)) { $this->uid = $this->user->uid; } else { $this->user = new \Model\User($this->casted['uid']); } } parent::save(); }
/** * Save model, triggering plugin hooks and setting created_date * @return mixed */ function save() { // Ensure created_date is set if possible if (!$this->query && array_key_exists("created_date", $this->fields) && !$this->get("created_date")) { $this->set("created_date", date("Y-m-d H:i:s")); } // Call before_save hooks $hookName = str_replace("\\", "/", strtolower(get_class($this))); \Helper\Plugin::instance()->callHook("model.before_save", $this); \Helper\Plugin::instance()->callHook($hookName . ".before_save", $this); // Save object $result = parent::save(); // Call after save hooks \Helper\Plugin::instance()->callHook("model.after_save", $this); \Helper\Plugin::instance()->callHook($hookName . ".after_save", $this); return $result; }
/** * You cannot override the save method. If you need to disable the save * method on a model class, use the beforeinsert() trigger and throw an * exception and return the EX_NO_SAVE constant. * * @param array $struct * @return \DB\SQL\Mapper object */ public final function save(array $struct = null) { if ($struct !== null) { $this->candidate = $struct; $this->reset(); $fw = $this->fw(); $pkey = $this->pkey(); if (isset($this->candidate[$pkey])) { $id = $this->candidate[$pkey]; unset($this->candidate[$pkey]); $this->load(array('`' . $pkey . '`=?', $id)); } $candidate = self::CANDIDATE_PREFIX . $this->source; $fw->set($candidate, $this->candidate); $this->copyfrom($candidate); $fw->clear($candidate); } return parent::save(); }
/** * Logs the search details * search term, date, IP address * @param $username */ public function createlogEntry($username) { $log = new Mapper($this->db, 'search_logs'); $log->term = $username; $log->ip = $_SERVER['REMOTE_ADDR']; $date = new \DateTime('now', new \DateTimeZone(date_default_timezone_get())); $log->created = $date->format("Y-m-d H:i:s"); $log->save(); }
public function saveStoryChanges(\DB\SQL\Mapper $current, array $post) { // Step one: save the plain data $current->title = $post['story_title']; $current->summary = str_replace("\n", "<br />", $post['story_summary']); $current->storynotes = str_replace("\n", "<br />", $post['story_notes']); $current->ratingid = $post['ratingid']; $current->completed = $post['completed']; $current->validated = $post['validated']; $current->save(); // Step two: check for changes in relation tables // Check tags: $post['tags'] = explode(",", $post['tags']); $tags = new \DB\SQL\Mapper($this->db, $this->prefix . 'stories_tags'); foreach ($tags->find(array('`sid` = ? AND `character` = ?', $current->sid, 0)) as $X) { $temp = array_search($X['tid'], $post['tags']); if ($temp === FALSE) { // Excess relation, drop from table $tags->erase(['lid=?', $X['lid']]); } else { unset($post['tags'][$temp]); } } // Insert any tag IDs not already present if (sizeof($post['tags']) > 0) { foreach ($post['tags'] as $temp) { // Add relation to table $tags->reset(); $tags->sid = $current->sid; $tags->tid = $temp; $tags->character = 0; $tags->save(); } } unset($tags); // Check Characters: $post['characters'] = explode(",", $post['characters']); $characters = new \DB\SQL\Mapper($this->db, $this->prefix . 'stories_tags'); foreach ($characters->find(array('`sid` = ? AND `character` = ?', $current->sid, 1)) as $X) { $temp = array_search($X['tid'], $post['characters']); if ($temp === FALSE) { // Excess relation, drop from table $characters->erase(['lid=?', $X['lid']]); } else { unset($post['characters'][$temp]); } } // Insert any character IDs not already present if (sizeof($post['characters']) > 0) { foreach ($post['characters'] as $temp) { // Add relation to table $characters->reset(); $characters->sid = $current->sid; $characters->tid = $temp; $characters->character = 1; $characters->save(); } } unset($characters); // Check Categories: $post['category'] = explode(",", $post['category']); $categories = new \DB\SQL\Mapper($this->db, $this->prefix . 'stories_categories'); foreach ($categories->find(array('`sid` = ?', $current->sid)) as $X) { $temp = array_search($X['cid'], $post['category']); if ($temp === FALSE) { // Excess relation, drop from table $categories->erase(['lid=?', $X['lid']]); } else { unset($post['category'][$temp]); } } // Insert any character IDs not already present if (sizeof($post['category']) > 0) { foreach ($post['category'] as $temp) { // Add relation to table $categories->reset(); $categories->sid = $current->sid; $categories->cid = $temp; $categories->save(); } } unset($categories); // Author and co-Author preparation: $post['author'] = explode(",", $post['author']); $post['coauthor'] = explode(",", $post['coauthor']); // remove co-authors, that are already in the author field $post['coauthor'] = array_diff($post['coauthor'], $post['author']); // Check Authors: $author = new \DB\SQL\Mapper($this->db, $this->prefix . 'stories_authors'); foreach ($author->find(array('`sid` = ? AND `ca` = ?', $current->sid, 0)) as $X) { $temp = array_search($X['aid'], $post['author']); if ($temp === FALSE) { // Excess relation, drop from table $author->erase(['lid=?', $X['lid']]); } else { unset($post['author'][$temp]); } } // Insert any character IDs not already present if (sizeof($post['author']) > 0) { foreach ($post['author'] as $temp) { // Add relation to table $author->reset(); $author->sid = $current->sid; $author->aid = $temp; $author->ca = 0; $author->save(); } } unset($author); // Check co-Authors: $coauthor = new \DB\SQL\Mapper($this->db, $this->prefix . 'stories_authors'); foreach ($coauthor->find(array('`sid` = ? AND `ca` = ?', $current->sid, 1)) as $X) { $temp = array_search($X['aid'], $post['coauthor']); if ($temp === FALSE) { // Excess relation, drop from table $coauthor->erase(['lid=?', $X['lid']]); } else { unset($post['coauthor'][$temp]); } } // Insert any character IDs not already present if (sizeof($post['coauthor']) > 0) { foreach ($post['coauthor'] as $temp) { // Add relation to table $coauthor->reset(); $coauthor->sid = $current->sid; $coauthor->aid = $temp; $coauthor->ca = 1; $coauthor->save(); } } unset($coauthor); $this->rebuildStoryCache($current->sid); return TRUE; }