Exemplo n.º 1
0
 /**
  * Removes columns from a row.
  * My suggestion is not to allow users to delete any pieces of your data.
  * Instead, use "soft delete" technique, which set a flag to indicate that a column or a row is deleted.
  *
  * @param string $key the row to remove columns from
  * @param mixed[] $columns the columns to remove. If null, the entire row will be removed.
  * @param mixed $superColumn only remove this super column
  * @param cassandra_ConsistencyLevel $writeConsistencyLevel affects the guaranteed
  *        number of nodes that must respond before the operation returns
  *
  * @return int the timestamp for the operation
  */
 public function delete($key, $columns = null, $superColumn = null, $writeConsistencyLevel = null)
 {
     if (empty($this->_columnFamily)) {
         $this->init();
     }
     return $this->_columnFamily->remove($key, $columns, $superColumn, $writeConsistencyLevel);
 }
Exemplo n.º 2
0
 public function removerTodosPorAvaliacao(WeLearn_Cursos_Avaliacoes_Avaliacao $avaliacao)
 {
     try {
         $questoesRemovidas = $this->recuperarTodosPorAvaliacao($avaliacao);
     } catch (cassandra_NotFoundException $e) {
         return array();
     }
     foreach ($questoesRemovidas as $questao) {
         $questaoUUID = UUID::import($questao->getId());
         $alternativasRemovidas = $this->_alternativaDAO->removerTodosPorQuestao($questao);
         $this->_cf->remove($questaoUUID->bytes);
         $alternativaCorreta = null;
         for ($i = 0; $i < count($alternativasRemovidas); $i++) {
             if ($alternativasRemovidas[$i]->isCorreta()) {
                 $questao->setAlternativaCorreta($alternativasRemovidas[$i]);
                 unset($alternativasRemovidas[$i]);
                 break;
             }
         }
         $questao->setAlternativasIncorretas($alternativasRemovidas);
         $questao->setPersistido(false);
     }
     $avaliacaoUUID = CassandraUtil::import($avaliacao->getId());
     $this->_questaoPorAvaliacaoCF->remove($avaliacaoUUID->bytes);
     return $questoesRemovidas;
 }
Exemplo n.º 3
0
 /**
  * @param WeLearn_DTO_IDTO $dto
  * @return boolean
  */
 protected function _atualizar(WeLearn_DTO_IDTO $dto)
 {
     $UUID = CassandraUtil::import($dto->getId());
     $cursoUUID = CassandraUtil::import($dto->getCurso()->getId());
     $dadosAntigos = $this->_cf->get($UUID->bytes, array('status', 'situacao'));
     $statusAntigo = (int) $dadosAntigos['status'];
     $situacaoAntiga = (int) $dadosAntigos['situacao'];
     $this->_cf->insert($UUID->bytes, $dto->toCassandra());
     if ($statusAntigo != $dto->getStatus()) {
         if ($dto->getStatus() == WeLearn_Cursos_Enquetes_StatusEnquete::ATIVA) {
             $this->_enquetePorStatusInativoCF->remove($cursoUUID->bytes, array($UUID->bytes));
             $this->_enquetePorStatusAtivoCF->insert($cursoUUID->bytes, array($UUID->bytes => ''));
         } else {
             $this->_enquetePorStatusAtivoCF->remove($cursoUUID->bytes, array($UUID->bytes));
             $this->_enquetePorStatusInativoCF->insert($cursoUUID->bytes, array($UUID->bytes => ''));
         }
     }
     if ($situacaoAntiga != $dto->getSituacao()) {
         if ($dto->getSituacao() == WeLearn_Cursos_Enquetes_SituacaoEnquete::ABERTA) {
             $this->_enquetePorSituacaoFechadoCF->remove($cursoUUID->bytes, array($UUID->bytes));
             $this->_enquetePorSituacaoAbertoCF->insert($cursoUUID->bytes, array($UUID->bytes => ''));
         } else {
             $this->_enquetePorSituacaoAbertoCF->remove($cursoUUID->bytes, array($UUID->bytes));
             $this->_enquetePorSituacaoFechadoCF->insert($cursoUUID->bytes, array($UUID->bytes => ''));
         }
     }
 }
Exemplo n.º 4
0
 public function removerTodosPorPagina(WeLearn_Cursos_Conteudo_Pagina $pagina)
 {
     $paginaUUID = CassandraUtil::import($pagina->getId());
     $idsRemover = array_keys($this->_comentarioPorPaginaCF->get($paginaUUID->bytes, null, '', '', false, 1000000));
     $this->_comentarioPorPaginaCF->remove($paginaUUID->bytes);
     foreach ($idsRemover as $id) {
         $this->_cf->remove($id);
     }
 }
Exemplo n.º 5
0
 /**
  * @param mixed $id
  * @return WeLearn_DTO_IDTO
  */
 public function remover($id)
 {
     $UUID = CassandraUtil::import($id);
     $moduloRemovido = $this->recuperar($id);
     $cursoUUID = CassandraUtil::import($moduloRemovido->getCurso()->getId());
     $this->_cf->remove($UUID->bytes);
     $this->_moduloPorCursoCF->remove($cursoUUID->bytes, array($moduloRemovido->getNroOrdem()));
     $moduloRemovido->setPersistido(false);
     return $moduloRemovido;
 }
Exemplo n.º 6
0
 /**
  * @param WeLearn_Cursos_Curso $curso
  */
 public function removerTodosPorCurso(WeLearn_Cursos_Curso $curso)
 {
     $cursoUUID = UUID::import($curso->getId());
     $idsGerenciadores = array_keys($this->_gerenciadoresPorCursoCF->get($cursoUUID->bytes, null, $de, $ate, false, $count));
     $idsConvites = array_keys($this->_convitesGerenciadorPorCursoCF->get($cursoUUID->bytes, null, $de, $ate, false, $count));
     $this->_gerenciadoresPorCursoCF->remove($cursoUUID->bytes);
     $this->_convitesGerenciadorPorCursoCF->remove($cursoUUID->bytes);
     $this->_cursoDao->removerTodosGerenciadores($idsGerenciadores, $curso);
     $this->_cursoDao->removerTodosConvitesGerenciador($idsConvites, $curso);
 }
 /**
  * @param string $usuarioId
  * @return void
  */
 private function _removerListaDeRS($usuarioId)
 {
     try {
         $idsRS = array_keys($this->_RSPorUsuarioCF->get($usuarioId));
         foreach ($idsRS as $id) {
             $this->_RSCF->remove($id);
         }
         $this->_RSPorUsuarioCF->remove($usuarioId);
     } catch (cassandra_NotFoundException $e) {
         return;
     }
 }
Exemplo n.º 8
0
 /**
  * @param WeLearn_Cursos_Enquetes_Enquete $enquete
  */
 public function removeTodosrPorEnquete(WeLearn_Cursos_Enquetes_Enquete $enquete)
 {
     $enqueteUUID = CassandraUtil::import($enquete->getId());
     $alternativasUUIDs = array();
     foreach ($enquete->getAlternativas() as $alternativa) {
         $alternativasUUIDs[] = CassandraUtil::import($alternativa->getId());
     }
     $this->_cf->remove($enqueteUUID->bytes);
     foreach ($alternativasUUIDs as $alternativaUUID) {
         $this->_votosPorAlternativaCF->remove($alternativaUUID->bytes);
     }
 }
Exemplo n.º 9
0
 private function _recuperarRestantesPorAluno(array $ids, WeLearn_Usuarios_Aluno $aluno)
 {
     $columns = array();
     for ($i = 0; $i < count($ids); $i++) {
         try {
             $column = $this->_cf->get($ids[$i]);
             $columns[] = $column;
         } catch (cassandra_NotFoundException $e) {
             $this->_certificadosPorAlunoCF->remove($aluno->getId(), array($ids[$i]));
         }
     }
     return $columns;
 }
Exemplo n.º 10
0
 private function _recuperarRestantes(array $ids, WeLearn_Cursos_ParticipacaoCurso $participacaoCurso)
 {
     $columns = array();
     foreach ($ids as $nroOrdem => $id) {
         try {
             $column = $this->_cf->get($id);
             $columns[] = $column;
         } catch (cassandra_NotFoundException $e) {
             $this->_controleAvaliacaoPorParticipacaoCF->remove($participacaoCurso->getId(), array($nroOrdem));
         }
     }
     return $columns;
 }
Exemplo n.º 11
0
 /**
  * @param WeLearn_Usuarios_Usuario $usuario
  * @return void
  */
 public function limparNovas(WeLearn_Usuarios_Usuario $usuario)
 {
     try {
         $cfKeys = array_keys($this->_notificacoesNovasPorUsuarioCF->get($usuario->getId(), null, '', '', false, 1000000));
     } catch (cassandra_NotFoundException $e) {
         return;
     }
     $batchAtualizacao = array();
     for ($i = 0; $i < count($cfKeys); $i++) {
         $batchAtualizacao[$cfKeys[$i]] = array('status' => WeLearn_Notificacoes_StatusNotificacao::LIDO);
     }
     $this->_cf->batch_insert($batchAtualizacao);
     $this->_notificacoesNovasPorUsuarioCF->remove($usuario->getId());
 }
Exemplo n.º 12
0
 /**
  * @param WeLearn_Cursos_Conteudo_Modulo $modulo
  * @param array $novasPosicoes
  */
 public function atualizarPosicao(WeLearn_Cursos_Conteudo_Modulo $modulo, array $novasPosicoes)
 {
     $posicoes = array();
     $rows = array();
     foreach ($novasPosicoes as $posicao => $id) {
         $UUID = UUID::import($id)->bytes;
         $posicoes[$posicao] = $UUID;
         $rows[$UUID] = array('nroOrdem' => $posicao);
     }
     $moduloUUID = UUID::import($modulo->getId())->bytes;
     $this->_cf->batch_insert($rows);
     $this->_aulaPorModuloCF->remove($moduloUUID);
     $this->_aulaPorModuloCF->insert($moduloUUID, $posicoes);
 }
Exemplo n.º 13
0
 /**
  * @param mixed $id
  * @return WeLearn_DTO_IDTO
  */
 public function remover($id)
 {
     $UUID = CassandraUtil::import($id);
     $recursoRemovido = $this->recuperar($id);
     $this->_cf->remove($UUID->bytes);
     if ($recursoRemovido instanceof WeLearn_Cursos_Recursos_RecursoRestrito) {
         $aulaUUID = CassandraUtil::import($recursoRemovido->getAula()->getId());
         $this->_recursosRestritosCF->remove($aulaUUID->bytes, array($UUID->bytes));
     } elseif ($recursoRemovido instanceof WeLearn_Cursos_Recursos_RecursoGeral) {
         $cursoUUID = CassandraUtil::import($recursoRemovido->getCurso()->getId());
         $this->_recursosGeraisCF->remove($cursoUUID->bytes, array($UUID->bytes));
     } else {
         throw new WeLearn_Base_Exception('A classe removida tem que derivar
                                          de WeLearn_Cursos_Recursos_Recurso.');
     }
     $recursoRemovido->setPersistido(false);
     return $recursoRemovido;
 }
Exemplo n.º 14
0
 /**
  * @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;
 }
Exemplo n.º 15
0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * PHP Template.
 * Author: Sheetal Patil. Sun Microsystems, Inc.
 *
 */
session_start();
require_once "../etc/config.php";
require_once '../etc/phpcassa_config.php';
$friends = Users_Controller::getInstance();
$person = $_REQUEST['person'];
$friend = $_REQUEST['friend'];
$revokeSql = new ColumnFamily($conn, 'PERSON_PERSON');
$index_exp_person = CassandraUtil::create_index_expression('Person_username', $friend);
$index_exp_friend = CassandraUtil::create_index_expression('friends_username', $person);
$index_clause = CassandraUtil::create_index_clause(array($index_exp_person, $index_exp_friend));
$result = $revokeSql->get_indexed_slices($index_clause);
foreach ($result as $key => $col) {
    $revokeSql->remove($col['id']);
}
$outgoingRequests = $friends->outgoingRequests($person, $conn);
echo "<font color=green>You have revoked your friendship request to " . $friend . "</font>\n";
echo $outgoingRequests;
?>

Exemplo n.º 16
0
 public function test_get_indexed_slices()
 {
     $indexed_cf = new ColumnFamily($this->pool, 'Indexed1');
     $indexed_cf->truncate();
     $columns = array('birthdate' => 1);
     foreach (range(1, 3) as $i) {
         $indexed_cf->insert('key' . $i, $columns);
     }
     $expr = CassandraUtil::create_index_expression($column_name = 'birthdate', $value = 1);
     $clause = CassandraUtil::create_index_clause(array($expr), 10000);
     $result = $indexed_cf->get_indexed_slices($clause);
     $count = 0;
     foreach ($result as $key => $cols) {
         $count++;
         self::assertEqual($columns, $cols);
         self::assertEqual($key, "key{$count}");
     }
     self::assertEqual($count, 3);
     # Insert and remove a matching row at the beginning
     $indexed_cf->insert('key0', $columns);
     $indexed_cf->remove('key0');
     # Insert and remove a matching row at the end
     $indexed_cf->insert('key4', $columns);
     $indexed_cf->remove('key4');
     # Remove a matching row from the middle
     $indexed_cf->remove('key2');
     $result = $indexed_cf->get_indexed_slices($clause);
     $count = 0;
     foreach ($result as $key => $cols) {
         $count++;
         self::assertTrue($key == "key1" || $key == "key3");
     }
     self::assertEqual($count, 2);
     $indexed_cf->truncate();
     $keys = array();
     foreach (range(1, 1000) as $i) {
         $indexed_cf->insert("key{$i}", $columns);
         if ($i % 50 != 0) {
             $indexed_cf->remove("key{$i}");
         } else {
             $keys[] = "key{$i}";
         }
     }
     $count = 0;
     foreach ($result as $key => $cols) {
         $count++;
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
     }
     self::assertEqual($count, 20);
     $indexed_cf->truncate();
 }
    $columnfamily_name = '';
    if (isset($_GET['columnfamily_name'])) {
        $columnfamily_name = $_GET['columnfamily_name'];
    }
    $key = '';
    if (isset($_GET['key'])) {
        $key = $_GET['key'];
    }
    $super_column_key = null;
    if (isset($_GET['super_column_key'])) {
        $super_column_key = $_GET['super_column_key'];
    }
    try {
        $pool = new ConnectionPool($keyspace_name, $cluster_helper->getArrayOfNodesForCurrentCluster(), null, 5, 5000, 5000, 10000, $cluster_helper->getCredentialsForCurrentCluster());
        $column_family = new ColumnFamily($pool, $columnfamily_name);
        $column_family->remove($key, null, $super_column_key);
        redirect('columnfamily_action.php?action=browse_data&keyspace_name=' . $keyspace_name . '&columnfamily_name=' . $columnfamily_name);
    } catch (cassandra_NotFoundException $e) {
        $included_header = true;
        echo getHTML('header.php');
        echo displayErrorMessage('columnfamily_doesnt_exists', array('column_name' => $columnfamily_name));
    } catch (Exception $e) {
        $included_header = true;
        echo getHTML('header.php');
        echo displayErrorMessage('something_wrong_happened', array('message' => $e->getMessage()));
    }
}
/*
	Modify counter
*/
if (isset($_POST['btn_modify_counter'])) {
Exemplo n.º 18
0
 * limitations under the License.
 */
/**
 * PHP Template.
 * Author: Sheetal Patil. Sun Microsystems, Inc.
 *
 */
session_start();
require_once "../etc/config.php";
require_once '../etc/phpcassa_config.php';
$events = Events_Controller::getInstance();
$dateFormat = "l,  F j,  Y,  h:i A";
$commentid = $_REQUEST['commentid'];
$se = $_REQUEST['socialEventID'];
$cf = new ColumnFamily($conn, 'COMMENTS_RATING');
$cf->remove($commentid);
$commentsrating = new ColumnFamily($conn, 'COMMENTS_RATING');
$index_exp = CassandraUtil::create_index_expression('socialeventid', $se);
$index_clause = CassandraUtil::create_index_clause(array($index_exp));
$commentsratingResult = $commentsrating->get_indexed_slices($index_clause);
ob_start();
foreach ($commentsratingResult as $key => $row1) {
    $tmp_commentid = $row1['commentid'];
    $tmp_uname = $row1['username'];
    $tmp_uname_comments = $row1['comments'];
    $tmp_uname_rating = $row1['ratings'];
    $tmp_uname_created_at = trim($events->formatdatetime($dateFormat, $row1['created_at']));
    $tmp_uname_updated_at = trim($events->formatdatetime($dateFormat, $row1['updated_at']));
    require "../views/commentsRating.php";
}
unset($commentsratingResult);
Exemplo n.º 19
0
 protected function expireValue($key)
 {
     unset($this->cache[$key]);
     $cf = new ColumnFamily($this->cassandra, $this->config['column_family']);
     try {
         // __data key set as C* requires a field
         $cf->remove($key, array('__data'));
     } catch (\Exception $e) {
         return false;
     }
     return true;
 }
Exemplo n.º 20
0
$frnd = $_REQUEST['frnd'];
$user = $_REQUEST['query'];
$flag = $_REQUEST['flag'];
$cf = new ColumnFamily($conn, 'PERSON_PERSON');
$index_exp1 = CassandraUtil::create_index_expression('Person_username', $friend);
$index_exp2 = CassandraUtil::create_index_expression('friends_username', $person);
if ($flag == "add") {
    $personid = exec("python /usr/pysnowflakeclient/pysnowflakeclient/__init__.py");
    $cf->insert($personid, array('id' => $personid, 'Person_username' => $friend, 'friends_username' => $person, 'is_accepted' => 0));
} else {
    if ($flag == "delete") {
        $index_exp3 = CassandraUtil::create_index_expression('is_accepted', 0);
        $index_clause = CassandraUtil::create_index_clause(array($index_exp1, $index_exp2, $index_exp3));
        $result = $cf->get_indexed_slices($index_clause);
        foreach ($result as $key => $col) {
            $cf->remove($col["id"]);
        }
    } else {
        if ($flag == "frnd") {
            $index_exp3 = CassandraUtil::create_index_expression('is_accepted', 1);
            $index_clause = CassandraUtil::create_index_clause(array($index_exp1, $index_exp2, $index_exp3));
            $result = $cf->get_indexed_slices($index_clause);
            foreach ($result as $key => $col) {
                $cf->remove($col["id"]);
            }
        }
    }
}
if ($flag == "frnd") {
    header("Location:friends.php?username={$person}&flag={$flag}&reqUser={$friend}");
} else {
Exemplo n.º 21
0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * PHP Template.
 * Author: Sheetal Patil. Sun Microsystems, Inc.
 *
 */
session_start();
require_once "../etc/config.php";
require "../etc/phpcassa_config.php";
$friends = Users_Controller::getInstance();
$person = $_REQUEST['person'];
$friend = $_REQUEST['friend'];
$rejectSql = new ColumnFamily($conn, 'PERSON_PERSON');
$index_exp_person = CassandraUtil::create_index_expression('Person_username', $person);
$index_exp_friend = CassandraUtil::create_index_expression('friends_username', $friend);
$index_clause = CassandraUtil::create_index_clause(array($index_exp_person, $index_exp_friend));
$result = $rejectSql->get_indexed_slices($index_clause);
foreach ($result as $key => $col) {
    $rejectSql->remove($col['id']);
}
$_SESSION["friendshipreqs"] = $friends->numFriendshipRequests($person, $conn);
$incomingRequests = $friends->incomingRequests($person, $conn);
echo "<font color=green>You rejected " . $friend . "'s friendship request.</font>\n";
echo "friendship requests (" . $_SESSION["friendshipreqs"] . ")\n";
echo $incomingRequests;
Exemplo n.º 22
0
 *
 */
session_start();
require_once "../etc/config.php";
require_once '../etc/phpcassa_config.php';
$se = $_REQUEST['id'];
$username = $_SESSION["uname"];
if (!is_null($username)) {
    $cf = new ColumnFamily($conn, 'PERSON_SOCIALEVENT');
    $index_exp = CassandraUtil::create_index_expression('socialeventid', $se);
    $index_exp1 = CassandraUtil::create_index_expression('username', $username);
    $index_clause = CassandraUtil::create_index_clause(array($index_exp, $index_exp1));
    $result = $cf->get_indexed_slices($index_clause);
    foreach ($result as $key => $column) {
        $id = $column['id'];
    }
    $cf->remove($id);
}
$username = $_SESSION["uname"];
$listquery = new ColumnFamily($conn, 'PERSON_SOCIALEVENT');
$index_exp = CassandraUtil::create_index_expression('socialeventid', $se);
$index_clause = CassandraUtil::create_index_clause(array($index_exp));
$listqueryresult = $listquery->get_indexed_slices($index_clause);
foreach ($listqueryresult as $key => $column) {
    $tmp_uname = $column['username'];
    $attendeeList = $attendeeList . " " . '<a href="users.php?username='******'">' . $tmp_uname . '</a><br />';
}
unset($listqueryresult);
$numofattendees = $_SESSION["numofattendees"] - 1;
$_SESSION["numofattendees"] = $numofattendees;
echo '<h2 class="smaller_heading">' . $numofattendees . ' Attendees:</h2><br/><input name="attend" type="button" value="Attend" onclick="addAttendee();"/><br/><div id="attendees">' . $attendeeList . '</div>';
Exemplo n.º 23
0
<?php

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * PHP Template.
 * Author: Sheetal Patil. Sun Microsystems, Inc.
 *
 */
session_start();
require_once "../etc/config.php";
$connection = DBConnection::getWriteInstance();
$se = $_REQUEST['socialEventID'];
$cf = new ColumnFamily($conn, 'SOCIALEVENT');
$cf->remove($se);
header("Location:index.php");