示例#1
0
 function __construct($id, $since)
 {
     $this->user = intval($id);
     global $con;
     // shared lists
     $sql = "\n      SELECT `share`.`id`, `share`.`list`, `share`.`permissions`, `list`.`creator`, `share`.`time`\n      FROM `share`, `list` \n      WHERE `list`.`id` = `share`.`list` AND `share`.`user` = " . $id . " AND `share`.`permissions` <> 0 AND `share`.`time` >= " . $since . "\n      ORDER BY `share`.`time` DESC;";
     $query = mysqli_query($con, $sql);
     while ($row = mysqli_fetch_assoc($query)) {
         array_push($this->events, new FeedItem(FeedItemType::ListShared, intval($row['time']), new SharingInformation($row['id'], SimpleUser::get_by_id($row['creator']), $row['list'], $row['permissions'])));
     }
     // another user has added a word to a list which is shared with you
     $sql = "\n      SELECT `list`.`creator`, `word`.`user`, COUNT(`word`.`id`) AS 'amount', MIN(`word`.`time`) AS 'time', `list`.`id`\n      FROM `list`, `share`, `word` \n      WHERE `share`.`user` = " . $id . " AND `word`.`user` <> " . $id . " AND \n        `word`.`list` = `list`.`id` AND `share`.`list` = `list`.`id` AND\n        `list`.`active` <> 0 AND `share`.`permissions` <> 0 AND `word`.`status` <> 0 AND\n        `word`.`time` > " . $since . "\n      GROUP BY `word`.`list`, `word`.`user`\n      ORDER BY `word`.`time` ASC;\n    ";
     $query = mysqli_query($con, $sql);
     while ($row = mysqli_fetch_assoc($query)) {
         if ($row['user'] == 0) {
             continue;
         }
         array_push($this->events, new FeedItem(FeedItemType::WordAdded, intval($row['time']), new WordsAddedFeedItem($row['amount'], BasicWordList::get_by_id($row['id']), SimpleUser::get_by_id($row['creator']), SimpleUser::get_by_id($row['user']))));
     }
     // another user has added a word to your word list
     $sql = "\n      SELECT `list`.`creator`, `word`.`user`, COUNT(`word`.`id`) AS 'amount', MIN(`word`.`time`) AS 'time', `list`.`id`\n      FROM `list`, `word` \n      WHERE `word`.`list` = `list`.`id` AND `word`.`user` <> " . $id . " AND `list`.`creator` = " . $id . " AND\n        `list`.`active` <> 0 AND `word`.`status` <> 0 AND\n        `word`.`time` > " . $since . "\n      GROUP BY `word`.`list`, `word`.`user`\n      ORDER BY `word`.`time` ASC;\n    ";
     $query = mysqli_query($con, $sql);
     while ($row = mysqli_fetch_assoc($query)) {
         if (intval($row['user']) === 0) {
             continue;
         }
         array_push($this->events, new FeedItem(FeedItemType::WordAdded, intval($row['time']), new WordsAddedFeedItem($row['amount'], BasicWordList::get_by_id($row['id']), SimpleUser::get_by_id($row['creator']), SimpleUser::get_by_id($row['user']))));
     }
     // users added
     $sql = "\n      SELECT `user1`, `time`\n      FROM `relationship` \n      WHERE `type` <> 0 AND `user2` = " . $id . " AND `time` >= " . $since . "\n      ORDER BY `time` DESC;";
     $query = mysqli_query($con, $sql);
     while ($row = mysqli_fetch_assoc($query)) {
         array_push($this->events, new FeedItem(FeedItemType::UserAdded, intval($row['time']), SimpleUser::get_by_id($row['user1'])));
     }
 }
示例#2
0
 function test_delete_by_pk_throws_exception()
 {
     try {
         SimpleUser::finder()->deleteByPk('admin');
         $this->fail();
     } catch (TDbException $e) {
         $this->pass();
     }
 }
 static function get_word_list($user_id, $word_list_id, $log)
 {
     global $con;
     $sql = "\n\t\tSELECT `list`.`id`, `list`.`name`, `list`.`creator`, `list`.`comment`, `list`.`language1`, `list`.`language2`, `list`.`creation_time`\n\t\tFROM `list`, `share`\n\t\tWHERE (`list`.`creator` = '" . $user_id . "' OR `share`.`user` = '" . $user_id . "' AND `share`.`list` = '" . $word_list_id . "') AND \n          `list`.`id` = '" . $word_list_id . "' AND \n          `list`.`active` = 1 AND `share`.`permissions` <> 0";
     $query = mysqli_query($con, $sql);
     while ($row = mysqli_fetch_assoc($query)) {
         $list = new WordList($row['id'], $row['name'], SimpleUser::get_by_id($row['creator']), $row['comment'], $row['language1'], $row['language2'], $row['creation_time'], null);
         $list->load_words(true, $user_id, "ASC");
         $list->load_sharing_information($user_id);
         $list->set_labels(WordList::get_labels_of_list($user_id, $word_list_id));
         // log the list access inside the loop to make sure it is only logged if the user has actually access to the list
         if ($log === true) {
             self::add_list_usage($user_id, $word_list_id);
         }
         return $list;
     }
     return NULL;
 }