File modules/cms/model/Bookmark.class.php
Last commit: Mon Dec 9 20:12:19 2024 +0100 Jan Dankert New: Order bookmarks by last change date.
1 <?php 2 3 namespace cms\model; 4 5 use cms\base\DB; 6 use database\Database; 7 use logger\Logger; 8 use util\exception\ObjectNotFoundException; 9 use util\FileUtils; 10 use util\Request; 11 use util\Session; 12 13 14 /** 15 * Bookmark. 16 * 17 * @author Jan Dankert 18 */ 19 class Bookmark extends ModelBase 20 { 21 public $bookmarkId; 22 public $userId; 23 public $objectId; 24 25 /** 26 * Get all bookmarks. 27 * @return array 28 */ 29 public static function getBookmarkedObjectIdsForUser( $userId ) 30 { 31 $sql = DB::sql( <<<SQL 32 SELECT {{bookmark}}.objectid 33 from {{bookmark}} 34 LEFT JOIN {{object}} 35 ON {{bookmark}}.objectid={{object}}.id 36 WHERE userid={userid} 37 ORDER BY {{object}}.lastchange_date DESC 38 SQL 39 ); 40 $sql->setInt('userid',$userId ); 41 return $sql->getCol(); 42 } 43 44 public function getName() 45 { 46 return ''; 47 } 48 49 public function load() 50 { 51 $sql = DB::sql( <<<SQL 52 SELECT * 53 from {{bookmark}} 54 WHERE userid={userid} AND objectid={objectid} 55 SQL 56 ); 57 $sql->setInt('userid' ,$this->userId ); 58 $sql->setInt('objectid',$this->objectId ); 59 60 $result = $sql->getRow(); 61 if ( $result) { 62 $this->bookmarkId = $result['id' ]; 63 $this->userId = $result['userid' ]; 64 $this->objectId = $result['objectid']; 65 } 66 67 } 68 69 protected function save() 70 { 71 } 72 73 protected function add() 74 { 75 // New PK 76 $sql = Db::sql(<<<'SQL' 77 SELECT MAX(id) FROM {{bookmark}} 78 SQL 79 ); 80 $this->bookmarkId = intval($sql->getOne())+1; 81 82 // Insert new bookmark 83 $sql = DB::sql( <<<SQL 84 INSERT INTO {{bookmark}} 85 (id,userid,objectid) values ({bookmarkId},{userid},{objectid}) 86 SQL 87 ); 88 $sql->setInt('bookmarkId' ,$this->bookmarkId ); 89 $sql->setInt('userid' ,$this->userId ); 90 $sql->setInt('objectid' ,$this->objectId ); 91 $sql->execute(); 92 } 93 94 public function delete() 95 { 96 // Remove existing bookmark 97 $sql = DB::sql( <<<SQL 98 DELETE 99 from {{bookmark}} 100 WHERE id={bookmarkId} 101 SQL 102 ); 103 $sql->setInt('bookmarkId' ,$this->bookmarkId ); 104 $sql->execute(); 105 } 106 107 public function getId() 108 { 109 return $this->bookmarkId; 110 } 111 } 112
Downloadmodules/cms/model/Bookmark.class.php
History Mon, 9 Dec 2024 20:12:19 +0100 Jan Dankert New: Order bookmarks by last change date. Sun, 8 Dec 2024 20:56:47 +0100 Jan Dankert New: Users are now able to store bookmarks.