示例#1
0
文件: ORM.php 项目: techart/tao
 /**
  * @param DB_ORM_SQLMapper|string $mapper
  */
 public function associate_table_for($mapper)
 {
     $tables = array($this->options['table'][0], self::table_from($mapper));
     sort($tables);
     return implode(DB_ORM::option('associate_tables_delimiter'), $tables);
 }
示例#2
0
 /**
  * This function saves the current session to the database.
  *
  * @access protected
  * @override
  * @return boolean                          whether the current session was
  *                                          successfully saved
  */
 protected function _write()
 {
     if ($this->_update_id === NULL) {
         // Insert a new row
         $query = DB_ORM::insert($this->_table)->column($this->_columns['last_active'], $this->_data['last_active'])->column($this->_columns['contents'], $this->__toString())->column($this->_columns['session_id'], $this->_session_id);
     } else {
         // Update the row
         $query = DB_ORM::update($this->_table)->set($this->_columns['last_active'], $this->_data['last_active'])->set($this->_columns['contents'], $this->__toString())->where($this->_columns['session_id'], DB_SQL_Operator::_EQUAL_TO_, $this->_update_id);
         if ($this->_update_id !== $this->_session_id) {
             // Also update the session id
             $query->set($this->_columns['session_id'], $this->_session_id);
         }
     }
     // Execute the query
     $query->execute();
     // The update and the session id are now the same
     $this->_update_id = $this->_session_id;
     // Update the cookie with the new session id
     Cookie::set($this->_name, $this->_session_id, $this->_lifetime);
     return TRUE;
 }
示例#3
0
 /**
  * This function returns a result set containing all nodes in the specified tree's scope.
  *
  * @access public
  * @static
  * @param integer $scope                            the scope of the desired tree
  * @param string $ordering                          the ordering token that signals whether the
  *                                                  left column will sorted either in ascending or
  *                                                  descending order
  * @param integer $limit                            the "limit" constraint
  * @return DB_ResultSet                             a result set containing all nodes in the
  *                                                  specified tree's scope
  */
 public static function full_tree($scope, $ordering = 'ASC', $limit = 0)
 {
     $model = get_called_class();
     $results = DB_ORM::select($model)->where('scope', DB_SQL_Operator::_EQUAL_TO_, $scope)->order_by('lft', $ordering)->limit($limit)->query();
     return $results;
 }
示例#4
0
 /**
  * This function logs the current user out.
  *
  * @access public
  * @param boolean $destroy                  whether the session is to be to completely
  *                                          destroyed
  * @param boolean $logout_all               whether all tokens for user are to be removed
  * @param boolean                           whether the logout was successful
  */
 public function logout($destroy = FALSE, $logout_all = FALSE)
 {
     // Set by force_login()
     $this->_session->delete('auth_forced');
     if ($token = Cookie::get('authautologin')) {
         // Delete the autologin cookie to prevent re-login
         Cookie::delete('authautologin');
         // Clear the autologin token from the database
         $token = DB_ORM::select($this->models['token'])->where($this->columns['token'], DB_SQL_Operator::_EQUAL_TO_, $token)->limit(1)->query()->fetch(0);
         $token_model = DB_ORM_Model::model_name($this->models['token']);
         if ($logout_all) {
             DB_ORM::delete($this->models['token'])->where($this->columns['user_id'], DB_SQL_Operator::_EQUAL_TO_, $token->user)->execute();
         } else {
             if ($token instanceof $token_model and $token->is_loaded()) {
                 $token->delete();
             }
         }
     }
     return parent::logout($destroy);
 }