Example #1
0
 public static function get($ka = null)
 {
     if (is_string($ka)) {
         $keys = array($ka);
     } elseif (is_array($ka)) {
         $keys = $ka;
     } elseif (empty($ka)) {
         // return all key-values
         $ret = array();
         $arr = Pdb::fetchAll('*', self::$table);
         foreach ($arr as $entry) {
             $ret[$entry['key']] = $entry['value'];
         }
         return $ret;
     }
     $ret = array();
     foreach ($keys as $key) {
         $value = Pdb::fetchRow('`value`', self::$table, array('`key`=?' => $key));
         if ($value === false) {
             throw new Exception("there is no key: {$key}");
         }
         $ret[$key] = $value;
     }
     return count($ret) === 1 ? reset($ret) : $ret;
 }
Example #2
0
 public static function history($conds = array())
 {
     extract(self::defaultConds($conds));
     $cond = self::typeCond($type);
     $tail = "LIMIT {$limit} OFFSET {$offset}";
     return Pdb::fetchAll('*', self::$table, $cond, 'id desc', $tail);
 }
Example #3
0
 public static function history()
 {
     return safe_array_map(function ($info) {
         $info['user'] = new User($info['user']);
         return $info;
     }, Pdb::fetchAll('*', self::$table));
 }
Example #4
0
 public function listFactory($conds = array())
 {
     extract(self::defaultConds($conds));
     $tail = "LIMIT {$limit} OFFSET {$offset}";
     return safe_array_map(function ($id) {
         return new Factory($id);
     }, Pdb::fetchAll('id', Factory::$table, null, null, $tail));
 }
Example #5
0
 public function listAdmin($conds = array())
 {
     extract(self::defaultConds($conds));
     $conds = array('type=?' => 'Admin');
     $tail = "LIMIT {$limit} OFFSET {$offset}";
     return safe_array_map(function ($info) {
         return new Admin($info);
     }, Pdb::fetchAll('*', User::$table, $conds, array(), $tail));
 }
Example #6
0
File: Cart.php Project: name3/cheng
 public function orders()
 {
     if ($this->orders != null) {
         return $this->orders;
     }
     $ids = Pdb::fetchAll('small_order', self::$table);
     return $this->orders = safe_array_map(function ($id) {
         return new Order($id);
     }, $ids);
     // no paging here
 }
Example #7
0
 public function history($conds = array())
 {
     extract($conds);
     $tail = "LIMIT {$limit} OFFSET {$offset}";
     extract($this->buildHistoryArg($conds));
     if (!isset($sort) || empty($sort)) {
         $sort = 'DESC';
     }
     $order = array("time {$sort}");
     $ids = Pdb::fetchAll('id', AccountHistory::$table, $conds, $order);
     return safe_array_map(function ($id) {
         return new AccountHistory($id);
     }, $ids);
 }
Example #8
0
 public static function types()
 {
     $arr = Pdb::fetchAll('id,name', 'product_type');
     if (empty($arr)) {
         throw new Exception("no type");
     }
     // we should write a function for this
     $ret = array();
     foreach ($arr as $e) {
         $key = $e['id'];
         $value = $e['name'];
         $ret[$key] = $value;
     }
     return $ret;
 }
Example #9
0
 public function addresses()
 {
     $ids = Pdb::fetchAll('address', customer_address, array('customer=?' => $this->id));
     // if not found, create one
     if ($ids === false) {
         // insert to address db
         Pdb::insert(array('name' => ''), Address::$table);
         $id = Pdb::lastInsertId();
         $ids = array($id);
         // insert to relationship db
         Pdb::insert(array('customer' => $this->id, 'address' => $id), customer_address);
     }
     return array_map(function ($id) {
         return new Address($id);
     }, $ids);
 }
Example #10
0
function clear_relation_db($main_table, $ref_table, $relation_table = null, $key_main = null, $key_ref = null)
{
    if ($relation_table === null) {
        $relation_table = $main_table . '_' . $ref_table;
    }
    if ($key_main === null) {
        $key_main = $main_table;
    }
    if ($key_ref === null) {
        $key_ref = $ref_table;
    }
    $all = Pdb::fetchAll('*', $relation_table);
    if ($all === false) {
        Pdb::del($ref_table);
        return;
    }
    // del in relation table
    foreach ($all as $info) {
        if (!Pdb::exists($main_table, array('id=?' => $info[$key_main]))) {
            Pdb::del($relation_table, array($key_main . '=?' => $info[$key_main]));
        }
    }
    // del in ref table
    $all = Pdb::fetchAll('*', $ref_table);
    if (empty($all)) {
        return;
    }
    foreach ($all as $info) {
        $id = $info['id'];
        if (!Pdb::exists($relation_table, array($key_ref . '=?' => $id))) {
            Pdb::del($ref_table, array('id=?' => $id));
        }
    }
}
Example #11
0
 private static function saleInfo($date_str, $format)
 {
     $arr = Pdb::fetchAll('paid', Order::$table, array($format => $date_str));
     return array('date' => $date_str, 'count' => count($arr), 'sum' => $arr ? array_sum($arr) : 0);
 }
Example #12
0
 public static function read($conds = array())
 {
     $self = get_called_class();
     return Pdb::fetchAll('*', $self::$table);
 }
Example #13
0
 public function accountRecords($conds)
 {
     $order_id = $conds['order'];
     return Pdb::fetchAll('*', AccountHistory::$table, array('account = ?' => $this->account()->id, '`order` = ?' => $order_id));
 }
Example #14
0
File: User.php Project: name3/cheng
 public function loginHistory($conds = array())
 {
     extract(self::defaultConds($conds));
     $conds = $this->loginConds();
     $order = 'id desc';
     $tail = "LIMIT {$limit} OFFSET {$offset}";
     $ret = safe_array_map(function ($info) {
         $info['ip'] = $info['info'];
         return $info;
     }, Pdb::fetchAll('*', UserLog::$table, $conds, $order, $tail));
     return $ret;
 }
Example #15
0
 public function log()
 {
     $ret = Pdb::fetchAll(array('info as remark', 'time'), UserLog::$table, array('action LIKE ?' => '%Order', 'target=?' => $this->id));
     return empty($ret) ? array() : $ret;
 }
Example #16
0
File: test.php Project: name3/cheng
    foreach ($big_order_ids as $id) {
        if (!Pdb::exists('big_to_small_order', array('big=?' => $id))) {
            Pdb::del(BigOrder::$table, array('id=?' => $id));
        }
    }
}
// clear address
clear_relation_db(Customer::$table, Address::$table);
// clear user log
clear_db(UserLog::$table, Customer::$table, 'subject');
// clear account
clear_11_db(Customer::$table, Account::$table);
// clear account log
clear_1m_db(Account::$table, AccountHistory::$table);
// clear price_data
$pds = Pdb::fetchAll('id', PriceData::$table);
if ($pds) {
    $tbl = Order::$table;
    foreach ($pds as $id) {
        $cond1 = array('factory_price = ?' => $id);
        $cond2 = array('customer_price = ?' => $id);
        if (!Pdb::exists($tbl, $cond1) && !Pdb::exists($tbl, $cond2)) {
            Pdb::del(PriceData::$table, array('id = ?' => $id));
        }
    }
}
// clear stone
clear_11_db(Order::$table, Stone::$table);
if (_get('exit')) {
    echo '<script src="static/hide.js"></script>';
    echo '<div class="conclusion pass">All Clear!</div>';