$fvalues = array(); $fUrl = \com\indigloo\Url::tryFormUrl("fUrl"); try { $fhandler = new Form\Handler("edit-form", $_POST); $fhandler->addRule("name", "Name", array('required' => 1)); $fvalues = $fhandler->getValues(); $name = $fvalues["name"]; if (!Util::isAlphaNumeric($name)) { $fhandler->addError("Bad name : only letters and numbers are allowed!"); } if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } $loginId = Login::getLoginIdInSession(); $listDao = new \com\indigloo\sc\dao\Lists(); $listDao->createNew($loginId, $name, $fvalues["description"]); $message = sprintf("success! new list created"); $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"; //SQLState 23000 is duplicate key violation if ($ex->getCode() == 23000) {
update sc_list set dl_bit = 1 where name = 'Favorites' ; */ ob_end_clean(); $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) {