/** * Add or Delete Bookmark. */ public function addDel($postId) { $row = Bookmark::model()->find('postId=:postId and userId=:userId', array(':postId' => $postId, ':userId' => Yii::app()->user->id)); if (empty($row)) { $row = new Bookmark(); $row->postId = $postId; $row->userId = Yii::app()->user->id; $row->save(); return true; } else { $row->delete(); return false; } }
/** * This test case demonstrates an issue with the identity case in the * Doctrine_Table class. The brief summary is that if you create a * record, then delete it, then create another record with the same * primary keys, the record can get into a state where it is in the * database but may appear to be marked as TCLEAN under certain * circumstances (such as when it comes back as part of a collection). * This makes the $record->exists() method return false, which prevents * the record from being deleted among other things. */ public function testIdentityMapAndRecordStatus() { // load our user and our collection of pages $user = Doctrine_Query::create()->query('SELECT * FROM BookmarkUser u WHERE u.name=?', array('Anonymous'))->getFirst(); $pages = Doctrine_Query::create()->query('SELECT * FROM Page'); // bookmark the pages (manually) foreach ($pages as $page) { $bookmark = new Bookmark(); $bookmark['page_id'] = $page['id']; $bookmark['user_id'] = $user['id']; $bookmark->save(); } // select all bookmarks $bookmarks = Doctrine_Manager::connection()->query('SELECT * FROM Bookmark b'); $this->assertEqual(count($bookmarks), 1); // verify that they all exist foreach ($bookmarks as $bookmark) { $this->assertTrue($bookmark->exists()); } // now delete them all. $user['Bookmarks']->delete(); // verify count when accessed directly from database $bookmarks = Doctrine_Query::create()->query('SELECT * FROM Bookmark'); $this->assertEqual(count($bookmarks), 0); // now recreate bookmarks and verify they exist: foreach ($pages as $page) { $bookmark = new Bookmark(); $bookmark['page_id'] = $page['id']; $bookmark['user_id'] = $user['id']; $bookmark->save(); } // select all bookmarks for the user $bookmarks = Doctrine_Manager::connection()->query('SELECT * FROM Bookmark b'); $this->assertEqual(count($bookmarks), 1); // verify that they all exist foreach ($bookmarks as $bookmark) { $this->assertTrue($bookmark->exists()); } }
if ($title == "") { $validinfo = false; $error .= "<li>" . lang('nofieldgiven', array(lang('title'))) . "</li>"; } if ($myurl == "") { $validinfo = false; $error .= "<li>" . lang('nofieldgiven', array(lang('url'))) . "</li>"; } if ($validinfo) { cmsms()->GetBookmarkOperations(); $markobj = new Bookmark(); $markobj->bookmark_id = $bookmark_id; $markobj->title = $title; $markobj->url = $myurl; $markobj->user_id = $userid; $result = $markobj->save(); if ($result) { redirect("listbookmarks.php" . $urlext); return; } else { $error .= "<li>" . lang('errorupdatingbookmark') . "</li>"; } } } else { if ($bookmark_id != -1) { $query = "SELECT * from " . cms_db_prefix() . "admin_bookmarks WHERE bookmark_id = ?"; $result = $db->Execute($query, array($bookmark_id)); $row = $result->FetchRow(); $myurl = $row["url"]; $title = $row["title"]; }
public function executeConfirmEmail($request) { // we only accept GET method $this->forward404Unless($request->isMethod('get')); $email = EmailPeer::getFromField(EmailPeer::CONFIRM_CODE, $this->getRequestParameter('confirm_code')); if ($email) { if ($email->getIsPrimary() && !$email->getActualEmail()) { // if invited, send acceptance email and add to quick contact $user = $email->getUser(); if ($user->getInvitedBy()) { // add to bookmark $b = new Bookmark(); $b->setUser($user->getUserRelatedByInvitedBy()); $b->setTag($user->retrievePrimaryJotag()); $b->save(); // give credit to the inviter $credits = $user->getUserRelatedByInvitedBy()->giveCredit(OptionPeer::retrieveOption('BONUS_ACCEPT_CREDIT')); Mailer::sendEmail($user->getUserRelatedByInvitedBy()->getPrimaryEmail(), 'inviteAccepted', array('owner' => $user->getUserRelatedByInvitedBy(), 'user' => $user, 'email' => $email, 'credits' => $credits), $user->getUserRelatedByInvitedBy()->getPreferedLanguage()); } // activate primary jotag $jotag = $email->getUser()->retrievePrimaryJotag(); $jotag->setStatus(TagPeer::ST_ACTIVE); $jotag->save(); $this->setMessage('ACCOUNT_CONFIRM', 'SUCCESS'); } else { $this->setMessage('EMAIL_CONFIRM', 'SUCCESS'); } $email->setIsConfirmed(true); $email->setConfirmCode(null); $email->setActualEmail(null); $email->save(); } else { $this->setMessage('EMAIL_CONFIRM_ERROR', 'ERROR'); } $this->redirect('@homepage'); }
#(at your option) any later version. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #$Id: makebookmark.php 7647 2012-01-01 15:28:10Z calguy1000 $ global $CMS_ADMIN_PAGE; $CMS_ADMIN_PAGE = 1; require_once '../include.php'; $urlext = '?' . CMS_SECURE_PARAM_NAME . '=' . $_SESSION[CMS_USER_KEY]; include_once "header.php"; check_login(); $config = cmsms()->GetConfig(); $link = $_SERVER['HTTP_REFERER']; $newmark = new Bookmark(); $newmark->user_id = get_userid(); $newmark->url = $link; $newmark->title = $_GET['title']; $result = $newmark->save(); if ($result) { header('HTTP_REFERER: ' . $config['admin_url'] . '/index.php'); redirect($link); } else { include_once "header.php"; echo "<h3>" . lang('erroraddingbookmark') . "</h3>"; }
/** * Ставит закладку на перевод/фрагмент * Если закладка была, то редактируется $note (если указано) * Если не было, то создаётся с min(ord) - 1 **/ public static function set($book_id, $orig_id = null, $note = null) { if (Yii::app()->user->isGuest) { return false; } $pk = array("user_id" => Yii::app()->user->id, "book_id" => $book_id); if ($orig_id) { $pk["orig_id"] = $orig_id; } $bm = Bookmark::model()->findByAttributes($pk); if (!$bm) { $bm = new Bookmark(); $bm->user_id = Yii::app()->user->id; $bm->book_id = $book_id; if ($orig_id) { $bm->orig_id = $orig_id; } $bm->ord = Yii::app()->db->createCommand("SELECT MAX(ord) FROM bookmarks WHERE user_id = :user_id AND orig_id IS NULL")->queryScalar(array(":user_id" => Yii::app()->user->id)) + 1; } if ($note !== null) { $bm->note = $note; } return $bm->save(); }
/** * Добавление в закладки */ public function bookmark() { if (!Request::ajax()) { App::redirect('/'); } $token = Request::input('token', true); $topic_id = Request::input('id'); if (User::check() && $token == $_SESSION['token']) { /* Проверка темы на существование */ if ($topic = Topic::find_by_id($topic_id)) { /* Добавление темы в закладки */ if ($bookmark = Bookmark::find_by_topic_id_and_user_id($topic_id, User::get('id'))) { if ($bookmark->delete()) { exit(json_encode(['status' => 'deleted'])); } } else { $bookmark = new Bookmark(); $bookmark->topic_id = $topic->id; $bookmark->user_id = User::get('id'); $bookmark->posts = $topic->postCount(); if ($bookmark->save()) { exit(json_encode(['status' => 'added'])); } } } } exit(json_encode(['status' => 'error'])); }
public function actionBookmark_set() { if (!is_array($_POST["B"])) { throw new CHttpException(500, "Неверный запрос."); } // Есть ли уже такая закладка? $bookmark = Bookmark::model()->findByAttributes(array("user_id" => Yii::app()->user->id, "typ" => substr($_POST["B"]["typ"], 0, 1), "obj_id" => (int) $_POST["B"]["obj_id"])); if (!$bookmark) { $bookmark = new Bookmark(); $bookmark->user_id = Yii::app()->user->id; } $bookmark->setAttributes($_POST["B"]); if ($bookmark->typ == "o") { $orig = Orig::model()->with("chap.book")->findByPk($bookmark->obj_id); if (!$orig) { throw new CHttpException(404, "Фрагмент оригинала удалён."); } $bookmark->url = $orig->url; } elseif ($bookmark->typ == "c") { $chap = Chapter::model()->with("book")->findByPk($bookmark->obj_id); if (!$chap) { throw new CHttpException(404, "Глава удалена"); } $bookmark->url = $chap->url; } elseif ($bookmark->typ == "b") { $book = Book::model()->findByPk($bookmark->obj_id); if (!$book) { throw new CHttpException(404, "Глава удалена"); } $bookmark->url = $book->url; } else { throw new CHttpException(500, "Неверный запрос. Если вам интересны грязные подробности, то я не знаю, что такое тип закладки '{$bookmark->typ}'."); } if ($bookmark->isNewRecord) { $bookmark->ord = Yii::app()->db->createCommand("SELECT MAX(ord) FROM bookmarks WHERE typ = :typ AND user_id = :user_id")->queryScalar(array(":typ" => $bookmark->typ, ":user_id" => Yii::app()->user->id)) + 1; } if (!$bookmark->save()) { throw new CHttpException(500, $bookmark->getErrorsString()); } $json = array("id" => $bookmark->id, "title" => $bookmark->title); echo json_encode($json); }
public function actionSet() { $book_id = (int) $_POST["book_id"]; $orig_id = (int) $_POST["orig_id"]; $pk = array("user_id" => Yii::app()->user->id, "book_id" => $book_id); if ($orig_id) { $pk["orig_id"] = $orig_id; } $bm = Bookmark::model()->findByAttributes($pk); if (!$bm) { $bm = new Bookmark(); $bm->user_id = Yii::app()->user->id; $bm->book_id = $book_id; if ($orig_id) { $bm->orig_id = $orig_id; } } if (isset($_POST["note"])) { $post = $_POST; unset($post["book_id"]); unset($post["orig_id"]); $bm->setAttributes($post); $bm->watch = (int) $_POST["watch"]; $new_ord = Yii::app()->db->createCommand("SELECT MAX(ord) FROM bookmarks WHERE user_id = :user_id AND orig_id IS NULL")->queryScalar(array(":user_id" => Yii::app()->user->id)) + 1; if ($orig_id) { // А есть ли закладка на перевод? if (!Yii::app()->db->createCommand("SELECT 1 FROM bookmarks WHERE user_id = :user_id AND book_id = :book_id AND orig_id IS NULL")->queryScalar(array(":user_id" => Yii::app()->user->id, ":book_id" => $book_id))) { Yii::app()->db->createCommand("INSERT INTO bookmarks (user_id, book_id, ord) VALUES (:user_id, :book_id, :ord)")->execute(array(":user_id" => Yii::app()->user->id, ":book_id" => $book_id, ":ord" => $new_ord)); } } else { $bm->ord = $new_ord; } if (!$bm->save()) { throw new CHttpException(500, $bm->getErrorsString()); } echo json_encode(array("book_id" => (int) $bm->book_id, "orig_id" => (int) $bm->orig_id, "note" => $bm->note, "status" => "set")); } else { $this->renderPartial("set", array("bm" => $bm)); } }