Example #1
0
File: user.php Project: jaz303/zing
 public static function authenticate_by_email($email, $password)
 {
     $class = get_called_class();
     $db = \GDB::instance();
     $row = $db->q("SELECT * FROM zing_user WHERE email = {s}", $email)->first_row();
     if ($row) {
         return self::authenticate(new $class($row), $password);
     } else {
         return false;
     }
 }
Example #2
0
 public static function collection_select_options($table, $value, $options = array())
 {
     if (is_string($options)) {
         $options = array('order' => $options);
     }
     $options += array('key' => 'id', 'select' => '*');
     $sql = "SELECT {$options['select']} FROM {$table}";
     if (isset($options['where'])) {
         $sql .= " WHERE {$options['where']}";
     }
     if (isset($options['order'])) {
         $sql .= " ORDER BY {$options['order']}";
     }
     $res = \GDB::instance()->q($sql)->key($options['key']);
     if (is_string($value)) {
         $res->mode('value', $value);
         return $res->stack();
     } else {
         return kmap($res, $value);
     }
 }
Example #3
0
/**
 * Uninstall plugin
 *
 * Removes configuration options
 * Drops table from Wordpress database
 */
function gdocs_uninstall()
{
    delete_option('gdocs_user');
    delete_option('gdocs_pwd');
    delete_option('gdocs_proxy_host');
    delete_option('gdocs_proxy_port');
    delete_option('gdocs_proxy_user');
    delete_option('gdocs_proxy_pwd');
    delete_option('gdocs_cache_expiry');
    delete_option('gdocs_style_dir');
    // remove table from DB
    GDB::drop();
}
/**
 * Updates list of Google Documents and Spreadsheets
 * 
 * Connects to Google and retrieves list of documents and spreadsheets.
 * Updates table in Wordpress database.
 * Returns data to browser in a JSON variable via http headers.
 */
function gdocs_update_list()
{
    // get Google Documents client
    $gdClient = GClient::getInstance(GDOCS_DOCUMENT);
    // initialize collector stack
    $docs = array();
    // update document list
    gdocs_update_documents($gdClient, &$docs);
    $doc_count = sizeof($docs);
    // get Google Spreadsheets client
    $gsClient = GClient::getInstance(GDOCS_SPREADSHEET);
    // update spreadsheet list
    $data = gdocs_update_sts($gdClient, $gsClient, &$docs);
    $st_count = sizeof($docs) - $doc_count;
    header('HTTP/1.0 200 OK');
    header('Content-Type: application/x-json');
    $json = array('dc' => $doc_count, 'sc' => $st_count);
    // update DB
    try {
        GDB::write($data);
    } catch (GDB_Exception $e) {
        $json['error'] = $e->getMessage();
        gdocs_error($e);
    }
    header('X-JSON: (' . json_encode($json) . ')');
    echo json_encode($docs);
}
Example #5
0
 public function __get($k)
 {
     switch ($k) {
         case 'session':
             $this->init_session();
             return $this->session;
         case 'db':
             $this->db = \GDB::instance();
             return $this->db;
         case 'logger':
             $this->logger = \zing\Logger::instance();
             return $this->logger;
         default:
             return null;
     }
 }
Example #6
0
 public function _database()
 {
     $this->usage = \GDB::instance()->get_usage();
 }
Example #7
0
<?php

require 'configure.php';
$db = GDB::instance();
$builder = $db->new_schema_builder();
try {
    $builder->drop_table('user');
} catch (\Exception $e) {
}
var_dump($builder->table_exists('user'));
$def = new gdb\TableDefinition('user', array('no_id' => true, 'mysql.engine' => 'InnoDB'));
$def->string('username', array('limit' => 50, 'null' => false));
$def->integer('user_code', array('null' => false, 'mysql.size' => 'big'));
$def->datetime('created_at', array('null' => false));
$def->datetime('updated_at', array('null' => true));
$def->set_primary_key('username', 'user_code');
echo $builder->sql_for_table($def);
$builder->create_table($def);
$builder->remove_column('user', 'updated_at');
$builder->add_column('user', 'age', 'integer', array('null' => true, 'default' => 20));
$builder->add_index('user', array('age', 'created_at'), array('unique' => true));
$builder->remove_index('user', 'age_created_at_index');
var_dump($builder->table_exists('user'));
Example #8
0
 protected function find_all($page, $rpp)
 {
     $res = \GDB::instance()->q($this->sql_for_find_all());
     if ($rpp) {
         $res->paginate($rpp, $page);
     }
     return $this->collection_for_gdb_result($res);
 }
Example #9
0
 public static function db()
 {
     return GDB::instance();
 }
Example #10
0
 public function delete()
 {
     if ($this->before_delete() === false) {
         return false;
     }
     \GDB::instance()->x("DELETE FROM {$this->get_table_name()} WHERE id = {i}", $this->id);
     $this->set_id(null);
     $this->after_delete();
     return true;
 }
Example #11
0
 /**
  * Singleton instance handler
  * Used for the static methods of this class
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #12
0
 protected function get_database_instance()
 {
     return \GDB::instance('default');
 }