Beispiel #1
0
 /**
  * delete a record by its id
  * @param  int     $id
  * @return boolean
  */
 public static function delete($id)
 {
     static::validateParamTypes(array('id' => $id));
     DB\dbQuery('DELETE from `' . static::getTableName() . '` ' . 'WHERE id = $1 AND `type` = $2', array($id, static::$type)) or die(DB\dbQueryError());
     $rez = DB\dbAffectedRows() > 0;
     return $rez;
 }
Beispiel #2
0
 /**
  * delete a record by its id
  * @param  int     $id
  * @return boolean
  */
 public static function delete($id)
 {
     static::validateParamTypes(array('id' => $id));
     DB\dbQuery('DELETE from `' . static::$tableName . '` ' . 'WHERE id = $1', $id) or die(DB\dbQueryError());
     $rez = DB\dbAffectedRows() > 0;
     return $rez;
 }
Beispiel #3
0
 public static function deleteByNodeId($nodeId, $userId = false)
 {
     if ($userId == false) {
         $userId = \CB\User::getId();
     }
     DB\dbQuery('DELETE FROM ' . static::getTableName() . ' WHERE user_id = $1 AND node_id = $2', array($userId, $nodeId)) or die(DB\dbQueryError());
     $rez = DB\dbAffectedRows() > 0;
     return $rez;
 }
Beispiel #4
0
 /**
  * copy a record
  * @param  int     $id
  * @return boolean
  */
 public static function copy($sourceId, $targetId)
 {
     DB\dbQuery('INSERT INTO `objects`
             (`id`
             ,`data`
             ,`sys_data`)
         SELECT
             $2
             ,`data`
             ,`sys_data`
         FROM `objects`
         WHERE id = $1', array($sourceId, $targetId)) or die(DB\dbQueryError());
     return DB\dbAffectedRows() > 0;
 }
Beispiel #5
0
 /**
  * delete a record by its id
  * @param  []int   $ids
  * @return boolean
  */
 public static function delete($ids)
 {
     $sql = 'DELETE from ' . static::getTableName() . ' WHERE `type` = $1 and id';
     if (is_scalar($ids)) {
         static::validateParamTypes(array('id' => $ids));
         DB\dbQuery($sql . ' = $2', array(static::$type, $ids));
     } else {
         $ids = Util\toNumericArray($ids);
         if (!empty($ids)) {
             DB\dbQuery($sql . ' IN (' . implode(',', $ids) . ')', static::$type);
         }
     }
     $rez = DB\dbAffectedRows() > 0;
     return $rez;
 }
Beispiel #6
0
 /**
  * copy a record
  * @param  int     $id
  * @return boolean
  */
 public static function copy($sourceId, $targetId)
 {
     $r = Tree::read($targetId);
     $pid = empty($r) ? null : $r['pid'];
     DB\dbQuery('INSERT INTO ' . static::getTableName() . '
             (id,
             pid,
             `is_folder`,
             `type`,
             `name`,
             `l1`,
             `l2`,
             `l3`,
             `l4`,
             `order`,
             `visible`,
             `iconCls`,
             `default_field`,
             `cfg`,
             `title_template`,
             `info_template`)
         SELECT
             $2,
             $3,
             `is_folder`,
             `type`,
             `name`,
             `l1`,
             `l2`,
             `l3`,
             `l4`,
             `order`,
             `visible`,
             `iconCls`,
             `default_field`,
             `cfg`,
             `title_template`,
             `info_template`
         FROM ' . static::getTableName() . '
         WHERE id = $1', array($sourceId, $targetId, $pid));
     return DB\dbAffectedRows() > 0;
 }
Beispiel #7
0
 public static function deleteByUserId($userId)
 {
     DB\dbQuery('DELETE FROM sessions WHERE user_id = $1', $userId) or die(DB\dbQueryError());
     return DB\dbAffectedRows() > 0;
 }
Beispiel #8
0
 /**
  * move active (non deleted) children to other parent
  * @param  array $sourceId
  * @param  array $targetId
  * @return bool
  */
 public static function moveActiveChildren($sourceId, $targetId)
 {
     DB\dbQuery('UPDATE tree
         SET updated = 1
             ,pid = $2
         WHERE pid = $1 AND
             dstatus = 0', array($sourceId, $targetId));
     return DB\dbAffectedRows() > 0;
 }
Beispiel #9
0
 /**
  * write session data
  * @param  varchar $session_id
  * @param  varchar $session_data
  * @return bool
  */
 public function write($session_id, $session_data)
 {
     $lifetime = ini_get('session.cookie_lifetime');
     $lifetime = empty($this->lifetime) ? null : $this->lifetime;
     /* when updating/creating a new session
        then parent session and all other child sessions shoould be marked as
        expiring in corresponding timeout */
     if (!empty($this->previous_session_id)) {
         DB\dbQuery('UPDATE sessions
             SET expires = TIMESTAMPADD(SECOND, $3, CURRENT_TIMESTAMP)
             WHERE (
                 (id = $2) OR
                 (pid = $2)
                 ) and id <> $1', array($session_id, $this->previous_session_id, $this->lifetime_pid_sessions)) or die(DB\dbQueryError());
     }
     $res = DB\dbQuery('INSERT INTO sessions
         (id, pid, expires, user_id, data)
         VALUES($1, $2, TIMESTAMPADD(SECOND, $3, CURRENT_TIMESTAMP), $4, $5)
         ON DUPLICATE KEY UPDATE
         expires = TIMESTAMPADD(SECOND, $3, CURRENT_TIMESTAMP)
         ,last_action = CURRENT_TIMESTAMP
         ,user_id = $4
         ,data = $5', array($session_id, $this->previous_session_id, $lifetime, '0' . @$_SESSION['user']['id'], $session_data)) or die(DB\dbQueryError());
     return DB\dbAffectedRows() > 0;
 }