/** * 从数据库载入符合条件的一个对象 * * @param mixed $conditions */ function load($conditions) { $row = $this->_table->find($conditions); if (is_array($row)) { $this->attach($row); } }
/** * 删除一个用户组及其子用户组树 * * @param int $groupId * * @return boolean */ function removeByPkv($groupId) { $group = parent::find((int) $groupId); if (!$group) { FLEA::loadClass('FLEA_Acl_Exception_UserGroupNotFound'); __THROW(new FLEA_Acl_Exception_UserGroupNotFound($groupId)); return false; } $this->dbo->startTrans(); $group['left_value'] = (int) $group['left_value']; $group['right_value'] = (int) $group['right_value']; $span = $group['right_value'] - $group['left_value'] + 1; $conditions = "WHERE left_value >= {$group['left_value']} AND right_value <= {$group['right_value']}"; $rowset = $this->findAll($conditions, null, null, $this->primaryKey, false); foreach ($rowset as $row) { if (!parent::removeByPkv($row[$this->primaryKey])) { $this->dbo->completeTrans(false); return false; } } if (!parent::removeByPkv($groupId)) { $this->dbo->completeTrans(false); return false; } $sql = "UPDATE {$this->fullTableName} " . "SET left_value = left_value - {$span} " . "WHERE left_value > {$group['right_value']}"; if (!$this->dbo->execute($sql)) { $this->dbo->completeTrans(false); return false; } $sql = "UPDATE {$this->fullTableName} " . "SET right_value = right_value - {$span} " . "WHERE right_value > {$group['right_value']}"; if (!$this->dbo->execute($sql)) { $this->dbo->completeTrans(false); return false; } $this->dbo->completeTrans(); return true; }