Inheritance: extends DB\Cursor
 /**
  * for testing only
  */
 public function createUser()
 {
     $user = new Mapper($this->db, 'users');
     $user->username = '******';
     $user->password = md5('piggy');
     $user->save();
 }
Exemplo n.º 2
0
 public function save()
 {
     if (parent::changed('pass')) {
         $this->pass = $this->passwordify($this->pass);
     }
     parent::save();
 }
Exemplo n.º 3
0
 public function __construct($id = null)
 {
     parent::__construct(\Base::instance()->get('DB'), 'connections');
     if ($id) {
         $this->load('id = ' . $id);
     }
 }
Exemplo n.º 4
0
 function __construct()
 {
     $f3 = \Base::instance();
     $db = $f3->get('DB');
     // This is where the mapper and DB structure synchronization occurs
     parent::__construct($db, 'tb_users');
 }
Exemplo n.º 5
0
 public function __construct()
 {
     $this->tableName || ($this->tableName = Shap::className(get_called_class()));
     $connID = 'CONNECTION.' . $this->connection;
     if (!Registry::exists($connID)) {
         $fw = Base::instance();
         $config = ($fw[$connID] ?: []) + ['type' => null, 'file' => null, 'name' => null, 'host' => null, 'user' => null, 'pass' => null, 'port' => 3306];
         $dsn = $config['type'] . ':';
         switch ($config['type']) {
             case 'sqlite':
                 $dsn .= $config['file'];
                 break;
             case 'mysql':
                 $dsn .= 'host=' . $config['host'] . ';port=' . $config['port'] . ';dbname=' . $config['name'];
                 break;
             default:
                 $dsn = null;
                 break;
         }
         if (empty($dsn)) {
             throw new InvalidArgumentException(sprintf(self::E_Connection, $connID));
         }
         Registry::set($connID, new \DB\SQL($dsn, $config['user'], $config['pass']));
     }
     parent::__construct(Registry::get($connID), $this->tableName);
     if (empty($this->pkeys)) {
         foreach ($this->fields as $field => $schema) {
             false === $schema['pkey'] || ($this->pkeys[] = $field);
         }
     }
     $this->init();
 }
Exemplo n.º 6
0
Arquivo: model.php Projeto: svlt/back
 /**
  * Load by ID directly if a number is passed
  * @param  string|array  $filter
  * @param  array         $options
  * @param  integer       $ttl
  * @return mixed
  */
 function load($filter = NULL, array $options = NULL, $ttl = 0)
 {
     if (is_numeric($filter)) {
         return parent::load(array("id = ?", $filter), $options, $ttl);
     } else {
         return parent::load($filter, $options, $ttl);
     }
 }
 /**
  * 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();
 }
Exemplo n.º 8
0
 function cast($obj = NULL)
 {
     $ox = parent::cast($obj);
     $user = new \Model\User($ox['uid']);
     return array_merge($ox, array("user" => $user->cast()));
 }
Exemplo n.º 9
0
 public function __construct()
 {
     parent::__construct(\Base::instance()->get('DB'), \Config::instance()->prefix . "log");
 }
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
 /**
  * Load by ID directly if a string is passed
  * @param  int|array  $filter
  * @param  array         $options
  * @param  integer       $ttl
  * @return mixed
  */
 function load($filter = NULL, array $options = NULL, $ttl = 0)
 {
     if (is_numeric($filter)) {
         return parent::load(array("id = ?", $filter), $options, $ttl);
     } elseif (is_array($filter)) {
         return parent::load($filter, $options, $ttl);
     }
     throw new Exception("\$filter must be either int or array.");
 }
Exemplo n.º 12
0
 /** Set up a new SQL mapped object */
 public function __construct($name, $db)
 {
     parent::__construct($db->connection, strtolower($name));
     $this->name = strtolower($name);
     $this->database = $db;
 }
Exemplo n.º 13
0
 public function __construct($table = null, $fields = null, $ttl = 60)
 {
     $db = Base::instance()->get($this->connection);
     parent::__construct($db, $table ?: $this->source, $fields, $ttl);
     $this->init();
 }
Exemplo n.º 14
0
 public function __construct(DB\SQL $db)
 {
     parent::__construct($db, 'loan_type');
 }
Exemplo n.º 15
0
 /**
  *
  * @param mixed $table 数据表的名字,如果是单个表,可以是 'user',多个表可以是 array('user', 'user_info' => 'ui')
  * @param int   $ttl   缓存多少秒
  *
  * */
 function __construct($table, $ttl = 600)
 {
     $dbEngine = static::getDbEngine();
     // 检查数据库连接
     if (null == $dbEngine) {
         throw new \InvalidArgumentException('can not find dbEngine');
     }
     if (null == $table) {
         return parent::__construct($dbEngine, null, null, $ttl);
     }
     // 多表联合查询
     if (is_array($table)) {
         $tableArray = array();
         foreach ($table as $key => $value) {
             if (is_string($key)) {
                 $tableArray[] = static::tableName($key);
                 continue;
             }
             $tableArray[] = static::tableName($value);
         }
         // By Syncxplus: 这里表名传入数组会出错, 修改为传入第一张表名;
         // 实际进行多表查询的时候, 没有用到parent(f3: \DB\SQL\Mapper)的实例或函数, 因此只要传入一个表名能够成功调用构造函数即可
         // return parent::__construct($dbEngine, $tableArray, null, $ttl);
         return parent::__construct($dbEngine, $tableArray[0], null, $ttl);
     }
     // 单表查询
     if (is_string($table)) {
         parent::__construct($dbEngine, static::tableName($table), null, $ttl);
     }
 }
Exemplo n.º 16
0
 public function __construct(\DB\SQL $db)
 {
     parent::__construct($db, 'cards');
 }
Exemplo n.º 17
0
 public function __construct(\DB\SQL $db)
 {
     parent::__construct($db, 'affiliates');
 }
 /**
  * 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();
 }
Exemplo n.º 19
0
 function __construct()
 {
     $f3 = \Base::instance();
     $db = $f3->get('DB');
     parent::__construct($db, 'tb_rating');
 }
Exemplo n.º 20
0
 public function __construct(\DB\SQL $db)
 {
     parent::__construct($db, 'upcoming');
 }
Exemplo n.º 21
0
 public function __construct()
 {
     $this->db = static::getDibi();
     parent::__construct($this->db, static::TABLE_NAME);
 }
Exemplo n.º 22
0
 /**
  *
  * @param mixed $table 数据表的名字,如果是单个表,可以是 'user',多个表可以是 array('user', 'user_info' => 'ui')
  * @param int   $ttl   缓存多少秒
  *
  * */
 function __construct($table, $ttl = 600)
 {
     $dbEngine = static::getDbEngine();
     // 检查数据库连接
     if (Utils::isEmpty($dbEngine)) {
         throw new \InvalidArgumentException('can not find dbEngine');
     }
     if (null == $table) {
         return parent::__construct($dbEngine, null, null, $ttl);
     }
     // 多表联合查询
     if (is_array($table)) {
         $tableArray = array();
         foreach ($table as $key => $value) {
             if (is_string($key)) {
                 $tableArray[] = static::tableName($key);
                 continue;
             }
             $tableArray[] = static::tableName($value);
         }
         return parent::__construct($dbEngine, $tableArray, null, $ttl);
     }
     // 单表查询
     if (is_string($table)) {
         parent::__construct($dbEngine, static::tableName($table), null, $ttl);
     }
 }
Exemplo n.º 23
0
 public function __construct()
 {
     parent::__construct(\Base::instance()->get('DB'), 'serietype');
 }
Exemplo n.º 24
0
 public function __construct(\DB\SQL $db)
 {
     parent::__construct($db, 'members');
 }