/** * @param mixed $id * @return WeLearn_DTO_IDTO */ public function remover($id) { $UUID = CassandraUtil::import($id); $paginaRemovida = $this->recuperar($id); $aulaUUID = CassandraUtil::import($paginaRemovida->getAula()->getId()); $this->_cf->remove($UUID->bytes); $this->_paginaPorAulaCF->remove($aulaUUID->bytes, array($paginaRemovida->getNroOrdem())); $curso = $paginaRemovida->getAula()->getModulo()->getCurso(); $cursoUUID = CassandraUtil::import($curso->getId()); $this->_contadorCF->add($this->_keyContador, $cursoUUID->bytes, -1); $controlePaginaDao = WeLearn_DAO_DAOFactory::create('ControlePaginaDAO', null, false); $idsAlunos = WeLearn_DAO_DAOFactory::create('AlunoDAO')->recuperarTodasIdsPorCurso($curso); for ($i = 0; $i < count($idsAlunos); $i++) { $cfKey = $idsAlunos[$i] . '::' . $curso->getId(); $controlePaginaDao->decrementarPaginasVistas($cfKey); } $paginaRemovida->setPersistido(false); return $paginaRemovida; }
/** * Increments or decrements a counter. * * `value` should be an integer, either positive or negative, to be added * to a counter column. By default, `value` is 1. * * This method is not idempotent. Retrying a failed add may result * in a double count. You should consider using a separate * ConnectionPool with retries disabled for column families * with counters. * * Only available in Cassandra 0.8.0 and later. * * @param string $key the row to insert or update the columns in * @param mixed $column the column name of the counter * @param int $value the amount to adjust the counter by * @param mixed $superColumn the super column to use if this is a * super column family * @param cassandra_ConsistencyLevel $writeConsistencyLevel affects the guaranteed * number of nodes that must respond before the operation returns * @param ECassandraConnection $cassandraConnection a separate connection pool to execute this kind of query. * If this value is left null, the current pool will be used. */ public function add($key, $column, $value = 1, $superColumn = null, $writeConsistencyLevel = null, $cassandraConnection = null) { if (empty($this->_columnFamily)) { $this->init(); } // If no separate connection is specified, use the current connection. if ($cassandraConnection === null) { $cassandraConnection = $this; $columnFamily = $this->_columnFamily; } else { // Create a new ColumnFamily instance to execute this query. $columnFamily = new ColumnFamily($cassandraConnection->getConnectionPool(), $this->cfName()); $shouldDispose = true; } $returnValue = $columnFamily->add($key, $column, $value, $superColumn, $writeConsistencyLevel); // If the column family is newly created, dispose it. if (isset($shouldDispose) && $shouldDispose === true) { $columnFamily = null; } return $returnValue; }
} $keyspace_name = ''; if (isset($_POST['keyspace_name'])) { $keyspace_name = $_POST['keyspace_name']; } $columnfamily_name = ''; if (isset($_POST['columnfamily_name'])) { $columnfamily_name = $_POST['columnfamily_name']; } try { $pool = new ConnectionPool($keyspace_name, $cluster_helper->getArrayOfNodesForCurrentCluster(), null, 5, 5000, 5000, 10000, $cluster_helper->getCredentialsForCurrentCluster()); $column_family = new ColumnFamily($pool, $columnfamily_name); if ($action == 'dec') { $value *= -1; } $column_family->add($key, $column, $value, $super_column); $new_value = $column_family->get($key); if ($column_family->cfdef->column_type == 'Super') { $new_value = $new_value[$super_column][$column]; } else { $new_value = $new_value[$column]; } redirect('counters.php?keyspace_name=' . $keyspace_name . '&columnfamily_name=' . $columnfamily_name . '&new_value=' . $new_value); } catch (Exception $e) { $_SESSION['message'] = $e->getMessage(); redirect('counters.php?keyspace_name=' . $keyspace_name . '&columnfamily_name=' . $columnfamily_name . '&error=1'); } } if (!$included_header) { echo getHTML('header.php'); if (!$is_valid_action) {
/** * @param string $chaveParticipacaoCurso */ public function decrementarPaginasVistas($chaveParticipacaoCurso) { $this->_contadorCF->add($this->_keyContador, $chaveParticipacaoCurso, -1); }