Ejemplo n.º 1
0
Archivo: update.php Proyecto: rjha/sc
    $flag = intval($fvalues["is_new"]);
    $listDao = new \com\indigloo\sc\dao\Lists();
    $name = $fvalues["new-list-name"];
    if ($flag == 1 && empty($listId)) {
        // create new list
        if (!Util::isAlphaNumeric($name)) {
            $error = "Bad name : only letters and numbers are allowed!";
            throw new UIException(array($error));
        }
        $listId = $listDao->create($loginId, $name, $itemId);
        $pListId = PseudoId::encode($listId);
    } else {
        // Add to existing list
        // this can also be defaults lists
        // so we should get listId from addItem call
        $listId = $listDao->addItem($loginId, $listId, $itemId);
        $pListId = PseudoId::encode($listId);
    }
    $listUrl = ListHtml::getPubLink($pListId);
    $message = sprintf("success! items added to list %s", $listUrl);
    $gWeb->store(Constants::FORM_MESSAGES, array($message));
    header("Location: " . $qUrl);
} catch (UIException $ex) {
    $gWeb->store(Constants::STICKY_MAP, $fvalues);
    $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages());
    header("Location: " . $qUrl);
    exit(1);
} catch (DBException $ex) {
    Logger::getInstance()->error($ex->getMessage());
    Logger::getInstance()->backtrace($ex->getTrace());
    $gWeb->store(Constants::STICKY_MAP, $fvalues);
Ejemplo n.º 2
0
     if ($fhandler->hasErrors()) {
         throw new UIException($fhandler->getErrors());
     }
     $loginId = Login::getLoginIdInSession();
     $listDao = new \com\indigloo\sc\dao\Lists();
     $itemId = AppUtil::getItemIdInUrl($link);
     if (is_null($itemId)) {
         $message = "invalid item URL : please add a valid item URL ";
         throw new UIException(array($message));
     }
     $postDao = new \com\indigloo\sc\dao\Post();
     if (!$postDao->exists($itemId)) {
         $message = sprintf("item {%s} does not exists", $itemId);
         throw new UIException(array($message));
     }
     $listDao->addItem($loginId, $fvalues["list_id"], $itemId);
     $message = sprintf("success! item added to list ");
     $gWeb->store(Constants::FORM_MESSAGES, array($message));
     header("Location: " . $fUrl);
 } catch (UIException $ex) {
     $gWeb->store(Constants::STICKY_MAP, $fvalues);
     $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages());
     header("Location: " . $fUrl);
     exit(1);
 } catch (DBException $ex) {
     Logger::getInstance()->error($ex->getMessage());
     Logger::getInstance()->backtrace($ex->getTrace());
     $gWeb->store(Constants::STICKY_MAP, $fvalues);
     $message = "Error: something went wrong with database operation";
     $gWeb->store(Constants::FORM_ERRORS, array($message));
     header("Location: " . $fUrl);
Ejemplo n.º 3
0
$mysqli = MySQL\Connection::getInstance()->getHandle();
// get all login_id from sc_bookmark
// people who have saved / liked items
$sql = " select count(id), subject_id from sc_bookmark group by subject_id ";
$rows = MySQL\Helper::fetchRows($mysqli, $sql);
$listDao = new \com\indigloo\sc\dao\Lists();
$listName = "Favorites";
$listDescription = "Items that I treat with special favor!";
$loginIds = array();
foreach ($rows as $row) {
    $loginId = $row["subject_id"];
    // create a Favorites list for all loginId in sc_bookmark
    $listDao->createNew($loginId, $listName, $listDescription, 1);
    array_push($loginIds, $loginId);
}
// list added
// now add sc_bookmark items to this list
$t1_sql = " select id from sc_list where login_id = %d and name = '%s' ";
$t2_sql = " select object_id from sc_bookmark where subject_id = %d and verb = 2 ";
foreach ($loginIds as $loginId) {
    // get list ID
    $sql = sprintf($t1_sql, $loginId, "Favorites");
    $row = MySQL\Helper::fetchRow($mysqli, $sql);
    $listId = $row["id"];
    // get bookmarked items
    $sql = sprintf($t2_sql, $loginId);
    $items = MySQL\Helper::fetchRows($mysqli, $sql);
    foreach ($items as $item) {
        $listDao->addItem($loginId, $listId, $item["object_id"]);
    }
}