Exemplo n.º 1
0
 /**
  * Saves a token
  * 
  * @return mixed (boolean/integer) false if failed
  */
 public function save()
 {
     $this->token = $this->generateToken();
     $this->date = $this->now();
     $dataToSave = array();
     $q = "select `id` from `" . $this->table . "` where `app`='" . $this->app . "'  LIMIT 1";
     $rows = Service::getDB()->query($q);
     foreach ($this->attributes as $attr) {
         $k = $attr[0];
         $dataToSave[$k] = $this->{$k};
     }
     if (sizeof($rows) > 0) {
         Service::getDB()->where('id', $rows[0]['id']);
         $insertId = Service::getDB()->update($this->table, $dataToSave);
     } else {
         $insertId = Service::getDB()->insert($this->table, $dataToSave);
     }
     if ($this->id == "") {
         $this->id = $insertId;
     }
     return $this->token;
 }
Exemplo n.º 2
0
 /**
  * Adds stock items to the company
  * @param integer $quantity amount of stock to be added
  * @param integer $type can be RESOURCE or PRODUCT
  * 
  * @return boolean if added
  */
 public function addStock($quantity, $type)
 {
     $db = Service::getDB();
     $where = array('company' => $this->id, 'product' => $this->product, 'productType' => $type);
     if ($type == Company::PRODUCT_TYPE_PRODUCT) {
         $condition = "AND quality='" . $this->quality . "' ";
         $where['quality'] = $this->quality;
     } else {
         $condition = "";
         $where['quality'] = 0;
     }
     $r = $db->query("SELECT quantity FROM company_stock WHERE company='" . $this->id . "' AND product='" . $this->product . "' AND productType='" . $type . "' " . $condition);
     if (sizeof($r) == 0) {
         $stock = $quantity;
         $where['quantity'] = $stock;
         return $db > insert('company_stock', $where);
     } else {
         $stock = $r[0]['quantity'] + $quantity;
         $data = array('quantity' => $stock);
         $db->where($where);
         return $db->update('company_stock', $data);
     }
 }
Exemplo n.º 3
0
 /**
  * creates a new user
  * 
  * @return mixed (uid or false)
  */
 public function saveNew()
 {
     $this->status = self::STATUS_PENDING;
     $this->gold = 0;
     $this->xp = 0;
     $this->language = 'en';
     $q = "select `id` from `" . $this->table . "` where `email`='" . $this->email . "' OR `nick`='" . $this->nick . "' LIMIT 1";
     $rows = Service::getDB()->query($q);
     if (sizeof($rows) > 0) {
         return false;
     }
     return parent::saveNew();
 }
Exemplo n.º 4
0
 /**
  * Deletes the object from the database
  * @return boolean
  */
 function delete()
 {
     Service::getDB()->where('id', $this->id);
     return Service::getDB()->delete($this->table, 1);
 }