function getRightholder()
 {
     $id = max(0, (int) $this->params['rightholder_id']);
     $query = 'SELECT * FROM `rightholders` WHERE `id`=' . $id;
     $data = Database::sql2row($query);
     $this->data['partner'] = $data;
 }
Beispiel #2
0
 function getPostsUpdatesLast()
 {
     $query = 'SELECT * FROM `posts_updates_last`';
     $data = Database::sql2row($query);
     $data['time'] = date('Y/m/d H:i:s', $data['time']);
     $this->data['snippet'] = $data;
 }
Beispiel #3
0
 function write()
 {
     global $current_user;
     /*@var $current_user CurrentUser*/
     $current_user->can_throw('books_edit');
     $id = isset(Request::$post['id']) ? Request::$post['id'] : 0;
     $id = max(0, (int) $id);
     $row = Database::sql2row('SELECT * FROM genre WHERE `id`=' . $id);
     if (!$row) {
         return;
     }
     if (!$id) {
         throw new Exception('Illegal id');
     }
     $description = prepare_review(isset(Request::$post['description']) ? Request::$post['description'] : '');
     if (!$description) {
         throw new Exception('Empty description');
     }
     $description = prepare_review($description);
     $query = 'UPDATE `genre` SET `description`=' . Database::escape($description) . ' WHERE `id`=' . $id;
     Database::query($query);
     ob_end_clean();
     header('Location:' . Config::need('www_path') . '/genres/' . $row['name']);
     $current_user->gainActionPoints('genres_edit', $id, BiberLog::TargetType_genre);
     exit;
 }
 function write()
 {
     global $current_user;
     /* @var $current_user CurrentUser */
     $mask = array('user_id' => 'int', 'hash' => array('type' => 'string', 'regexp' => '/^[A-Za-z0-9]+$/', 'min_length' => 32, 'max_length' => 32));
     $params = Request::checkParameters(Request::getAllParameters(), $mask);
     // проверяем, есть ли в базе неподтвержденный юзер с таким хешем
     $query = 'SELECT * FROM `users` WHERE `id`=' . (int) $params['user_id'];
     $res = Database::sql2row($query);
     if (!$res || $res['hash'] != $params['hash']) {
         if ($res['hash'] != '') {
             $this->setWriteParameter('emailconfirm_module', 'error', 'Неправильный код подтверждения.');
         } else {
             if ($res['id']) {
                 $this->setWriteParameter('emailconfirm_module', 'error', 'Почта пользователя уже подтверждена');
             } else {
                 $this->setWriteParameter('emailconfirm_module', 'error', 'Такого пользователя не существует');
             }
         }
     } else {
         // ура! авторизуем пользователя
         $current_user->load($res);
         $current_user->setRole(User::ROLE_READER_CONFIRMED);
         $current_user->authorized = true;
         $current_user->onLogin();
         $current_user->save();
         // затираем ему хеш и меняем роль на авторизованного пользователя
         $this->setWriteParameter('emailconfirm_module', 'success', 1);
     }
 }
Beispiel #5
0
 function getMessageNode()
 {
     $messageA = array();
     $node = false;
     if ($r = Request::get('redirect')) {
         list($type, $id) = explode('_', $r);
         switch ($type) {
             case 's':
                 $query = 'SELECT * FROM `series` WHERE `id`=' . (int) $id;
                 $res = Database::sql2row($query);
                 if ($res && isset($res['is_s_duplicate']) && $res['is_s_duplicate']) {
                     $messageA = array('html' => 'Cерия «' . $res['title'] . '» была склеена с данной серией');
                     $node = XMLClass::createNodeFromObject($messageA, false, 'message', true);
                 }
                 break;
             case 'b':
                 $query = 'SELECT * FROM `book` WHERE `id`=' . (int) $id;
                 $book = new Book((int) $id);
                 if ($book->getDuplicateId()) {
                     $messageA = array('html' => 'Книга «' . $book->getTitle(true) . '» была склеена с данной книгой');
                     $node = XMLClass::createNodeFromObject($messageA, false, 'message', true);
                 }
                 break;
             case 'a':
                 $person = new Person((int) $id);
                 if ($person->getDuplicateId()) {
                     $messageA = array('html' => 'Автор «' . $person->getName() . '» был склеен с данным автором');
                     $node = XMLClass::createNodeFromObject($messageA, false, 'message', true);
                 }
                 break;
         }
     }
     return $node;
 }
Beispiel #6
0
    function getOnePost()
    {
        $aid = (int) $this->params['user_id'];
        $pid = (int) $this->params['post_id'];
        $query = 'SELECT * FROM `posts_index` WHERE 
			`id_post`=' . $pid . ' AND
			`id_author`=' . $aid;
        $res = Database::sql2row($query);
        if ($res) {
            $res['m'] = str_pad($res['m'], 2, '0', STR_PAD_LEFT);
            $tblname = 'posts_data__' . $res['y'] . '_' . $res['m'];
            try {
                $query = 'SELECT * FROM `' . $tblname . '` WHERE
					`id`=' . $pid . ' AND
					`id_author`=' . $aid;
                $data = Database::sql2row($query);
                if ($data) {
                    $post = new Post($data);
                    $this->data['post'] = $post->getFull();
                    $aid = $post->data['id_author'];
                    $authors = Database::sql2array('SELECT * FROM `authors` WHERE `id` =' . $aid . '');
                    foreach ($authors as $data) {
                        $author = new Author($data);
                        $this->data['authors'][] = $author->getShort();
                    }
                    return true;
                }
            } catch (Exception $e) {
            }
        }
        throw new Exception('Не можем найти такой записи', '404');
    }
Beispiel #7
0
	function getOne() {
		$query = 'SELECT * FROM `genre` WHERE `name`=' . Database::escape($this->genre_name);
		$data = Database::sql2row($query);
		if (!isset($data['name']))
			return;
		$this->data['genres'][$data['id']] = array(
		    'name' => $data['name'],
		    'id' => $data['id'],
		    'id_parent' => $data['id_parent'],
		    'title' => $data['title'],
		    'books_count' => $data['books_count']
		);

		if (!$data['id_parent']) {
			$this->data['genres'][$data['id']]['subgenres'] = $this->getAll($data['id']);
			return;
		}

		$query = 'SELECT `id_book` FROM `book_genre` BG JOIN `book` B ON B.id = BG.id_book WHERE BG.id_genre = ' . $data['id'] . ' ORDER BY B.mark DESC LIMIT 20';
		$bids = Database::sql2array($query, 'id_book');
		$books = Books::getByIdsLoaded(array_keys($bids));
		Books::LoadBookPersons(array_keys($bids));

		foreach ($books as $book) {
			$book = Books::getById($book->id);
			list($aid, $aname) = $book->getAuthor(1, 1, 1); // именно наш автор, если их там много
			$this->data['genres'][$data['id']]['books'][] = array('id' => $book->id,
			    'cover' => $book->getCover(),
			    'title' => $book->getTitle(true),
			    'author' => $aname,
			    'author_id' => $aid,
			    'lastSave' => $book->data['modify_time']);
		}
	}
Beispiel #8
0
 public static function getByIdLoaded($user_id)
 {
     $data = Database::sql2row('SELECT * FROM `user` WHERE `id`=' . $user_id);
     if ($data) {
         return new User($user_id, $data);
     } else {
         return false;
     }
 }
Beispiel #9
0
	function getLikes() {
		if (!$this->genre_id)
			return;
		$query = 'SELECT * FROM `genre` WHERE `name`=' . Database::escape($this->genre_id);
		$data = Database::sql2row($query);
		if($data['id']){
			
		}
	}
Beispiel #10
0
	function write() {
		global $current_user;
		/* @var $current_user CurrentUser */
		if (!$current_user->authorized)
			throw new Exception('Access denied');

		$data = array(
		    'target_id' => max(0, (int) Request::$post['target_id']),
		    'target_type' => max(0, (int) Request::$post['target_type']),
		    'comment' => prepare_review(Request::$post['annotation']),
		    'rate' => min(6, max(0, (int) Request::$post['rate'])) + 1,
		);


		$event = new Event();


		if (!$data['comment']) {
			// inserting rate
			if ($data['rate'] && ($data['target_type'] == 0)) {
				$time = time();
				if ($data['rate'] > 1) {
					$query = 'INSERT INTO `book_rate` SET `id_book`=' . $data['target_id'] . ',`id_user`=' . $current_user->id . ',`rate`=' . ($data['rate'] - 1) . ',`time`=' . $time . ' ON DUPLICATE KEY UPDATE
				`rate`=' . ($data['rate'] - 1) . ',`time`=' . $time . '';
					Database::query($query);
				}
				//recalculating rate
				$query = 'SELECT COUNT(1) as cnt, SUM(`rate`) as rate FROM `book_rate` WHERE `id_book`=' . $data['target_id'];
				$res = Database::sql2row($query);
				$book_mark = round($res['rate'] / $res['cnt'] * 10);
				$query = 'UPDATE `book` SET `mark`=' . $book_mark . ' WHERE `id`=' . $data['target_id'];
				Database::query($query);
				$event->event_BookRateAdd($current_user->id, $data['target_id'], $data['rate'] - 1);
			}
		} else {
			if (!$data['target_id'])
				return;
			$query = 'INSERT INTO `reviews` SET
				`id_target`=' . $data['target_id'] . ',
				`target_type`=' . $data['target_type'] . ',
				`id_user`=' . $current_user->id . ',
				`time`=' . time() . ',
				`comment`=' . Database::escape($data['comment']) . ',
				`rate`=' . ($data['rate'] - 1) . '
					ON DUPLICATE KEY UPDATE
				`time`=' . time() . ',
				`comment`=' . Database::escape($data['comment']) . ',
				`rate`=' . ($data['rate'] - 1) . '';
			Database::query($query);
			//event
			$event->event_BookReviewAdd($current_user->id, $data['target_id'],$data['target_type'], $data['rate'] - 1 , $data['comment']);
		}


		$event->push();
	}
Beispiel #11
0
 function _edit()
 {
     $id = max(0, (int) (isset($this->params['group_id']) ? $this->params['group_id'] : false));
     if (!$id) {
         throw new Exception('no group id');
     }
     $query = 'SELECT * FROM `feature_groups` WHERE `id`=' . $id;
     $data = Database::sql2row($query);
     $this->data['group'] = $data;
 }
Beispiel #12
0
 function load($data = false)
 {
     if ($this->is_loaded()) {
         return $this->data;
     }
     $this->data = Database::sql2row('SELECT * FROM `user` WHERE `id`=' . $this->id);
     if ($this->data) {
         $this->registered = true;
     }
     $this->loaded = true;
 }
Beispiel #13
0
 function getTheme()
 {
     if (!$this->theme_id) {
         return;
     }
     $query = 'SELECT uid as user_id,title,body FROM `node_revisions` WHERE `nid`=' . $this->theme_id . ' LIMIT 1';
     $theme = Database::sql2row($query);
     if (!$theme) {
         throw new Exception('Мы проебали эту тему форума');
     }
     $theme['body'] = _bbcode_filter_process($theme['body']);
     $this->data['theme'] = $theme;
     Request::pass('theme-title', $theme['title']);
     $cond = new Conditions();
     $per_page = 0;
     if (isset($this->params['per_page'])) {
         $per_page = (int) $this->params['per_page'];
     }
     $per_page = $per_page > 0 ? $per_page : 5;
     $query = 'SELECT pid=0 as pid, COUNT(1) as cnt FROM `comments_v2` WHERE `nid` = ' . $this->theme_id . ' GROUP BY (pid=0)';
     $count_arr = Database::sql2array($query, 'pid');
     $count = isset($count_arr[0]['cnt']) ? $count_arr[0]['cnt'] : 0;
     $count_arr[0] = array('cnt' => $count);
     $count_with_answers = isset($count_arr[1]['cnt']) ? $count_arr[1]['cnt'] + $count_arr[0]['cnt'] : $count_arr[0]['cnt'];
     $cond->setPaging($count, $per_page);
     $limit = $cond->getLimit();
     $query = 'SELECT rid,cid,pid,subject,comment,timestamp,uid FROM `comments_v2` WHERE `nid` = ' . $this->theme_id . ' AND `pid`=0 ORDER BY `timestamp` LIMIT ' . $limit;
     $comments = Database::sql2array($query, 'cid');
     // childs?
     if (count($comments)) {
         $query = 'SELECT * FROM `comments_v2` WHERE `pid` IN(' . implode(',', array_keys($comments)) . ') ORDER BY `sort`';
         $answers = Database::sql2array($query, 'cid');
         foreach ($answers as &$answer) {
             $answer['comment'] = _bbcode_filter_process($answer['comment']);
             $answer['time'] = date('Y/m/d H:i', $answer['timestamp']);
             $comments[$answer['pid']]['answers'][] = $answer;
         }
     }
     $uids = array();
     foreach ($comments as &$comment) {
         $uids[$comment['uid']] = $comment['uid'];
         $comment['comment'] = _bbcode_filter_process($comment['comment']);
         $comment['time'] = date('Y/m/d H:i', $comment['timestamp']);
     }
     $uids[$theme['user_id']] = $theme['user_id'];
     $this->data['theme']['users'] = $this->getUsers($uids);
     $this->data['theme']['tid'] = $this->forum_id;
     $this->data['theme']['theme_id'] = $this->theme_id;
     $this->data['theme']['comments'] = $comments;
     $this->data['theme']['comments']['count'] = $count_with_answers;
     $this->data['theme']['comments']['count_nop'] = $count;
     $this->data['conditions'] = $cond->getConditions();
 }
Beispiel #14
0
 function load($data = false)
 {
     if ($this->loaded) {
         return false;
     }
     if (!$data) {
         $query = 'SELECT * FROM `news` WHERE `id`=' . $this->id;
         $this->data = Database::sql2row($query);
     } else {
         $this->data = $data;
     }
     $this->exists = true;
     $this->loaded = true;
 }
Beispiel #15
0
    public function load()
    {
        if ($this->loaded) {
            return;
        }
        $query = 'SELECT * FROM `magazines` M LEFT JOIN `book_magazines` BM 
			ON BM.id_magazine=M.id WHERE M.`id`=' . $this->id;
        $this->data = Database::sql2row($query);
        $query = 'SELECT * FROM `book_magazines` WHERE `id_magazine`=' . $this->id;
        $books = Database::sql2array($query, 'id_book');
        foreach ($books as $row) {
            $this->books[$row['year']][$row['n']] = $row['id_book'];
        }
        $this->loaded = true;
    }
Beispiel #16
0
    function write()
    {
        $id = Request::post('entry_id');
        $title = Request::post('title');
        $body = Request::post('body');
        $id_parent = Request::post('answer_to');
        global $current_user;
        $query = 'SELECT * FROM `blog_entries` WHERE `id`=' . $id;
        $data = Database::sql2row($query);
        $entry = new Entrie($data);
        if (!$current_user->authorized) {
            throw new Exception('must be autorized');
        }
        if (!$body) {
            throw new Exception('body missed');
        }
        if (!$title) {
            throw new Exception('title missed');
        }
        if ($id_parent) {
            // answer
            $query = 'SELECT * FROM `blog_entries_comments` WHERE `id`=' . $id_parent;
            $parent_comment = Database::sql2row($query);
            if ($parent_comment['id_parent'] > 0) {
                $answer_to = $id_parent;
                $id_parent = $parent_comment['id_parent'];
            } else {
                $answer_to = $id_parent;
                $id_parent = $parent_comment['id'];
            }
        } else {
            $answer_to = 0;
            $id_parent = 0;
        }
        $query = 'INSERT INTO `blog_entries_comments` SET
			`id_entry`=' . $id . ',
			`id_user`=' . $current_user->id . ',
			`id_parent`=' . $id_parent . ',
			`time`=' . time() . ',
			`title`=' . Database::escape($title) . ',
			`comment`=' . Database::escape($body) . ',
			`answer_to`=' . $answer_to;
        Database::query($query);
        $comment_id = Database::lastInsertId();
        $entry->updateCommentsCount();
        header('Location: ' . '/blog/' . $entry->user->getNickName() . '/' . $entry->id . '#comment-' . $comment_id);
        exit(0);
    }
Beispiel #17
0
 public static function getNotifies()
 {
     // about user relationships
     $notifications = array();
     $query = 'SELECT * FROM  `album_family` WHERE `user_id`=' . self::$id . ' AND `accepted_time`=0';
     $rels = Database::sql2array($query);
     foreach ($rels as $rel) {
         $album = Database::sql2row('SELECT * FROM `album` WHERE `id`=' . $rel['album_id']);
         $sizekey = 'pic_small';
         $sub = substr(md5($album[$sizekey]), 1, 4);
         //$link = Config::img_prefix . Config::MEDIA_TYPE_ALBUM_COVER . '/' . $sizekey . '/' . $sub . '/' . $album[$sizekey] . '.jpg';
         $kem = Config::$family_kem[$rel['family_role']];
         $notifications[] = array('img' => $link, 'url' => '/album/' . $rel['album_id'] . '/rel_accept', 'title' => 'Вас пригласили быть ' . $kem . ' ребёнку в альбоме "' . $album['child_name'] . '"');
     }
     return $notifications;
 }
Beispiel #18
0
 function getNew()
 {
     $id_book = max(0, (int) $this->params['id_book']);
     if (!$id_book) {
         throw new Exception('illegal book id');
     }
     $query = 'SELECT `id_book`,`status`, `state` , `time` FROM `ocr` WHERE `id_book`=' . $id_book . ' ORDER BY status DESC, state DESC LIMIT 1';
     $this->data['ocr'] = Database::sql2row($query);
     if (isset(Ocr::$statuses[$this->data['ocr']['status']]['name'])) {
         $this->data['ocr']['status_name'] = Ocr::$statuses[$this->data['ocr']['status']]['name'];
     }
     if (isset(Ocr::$statuses[$this->data['ocr']['state']]['name'])) {
         $this->data['ocr']['state_name'] = Ocr::$states[$this->data['ocr']['state']]['name'];
     }
     $this->data['ocr']['id_book'] = $id_book;
     $this->setStatusesNode();
 }
Beispiel #19
0
 function load($data = false)
 {
     if ($this->loaded || $this->exists === false || !$this->id) {
         return false;
     }
     if (!$data) {
         $query = 'SELECT * FROM `persons` WHERE `id`=' . $this->id;
         $this->data = Database::sql2row($query);
     } else {
         $this->data = $data;
     }
     if (isset($data['is_deleted']) && $data['is_deleted']) {
         $this->exists = false;
     } else {
         $this->exists = true;
     }
     $this->loaded = true;
 }
Beispiel #20
0
    function getPicture($id = false) {
        if (!$id)
            $id = isset($this->params['id']) ? (int) $this->params['id'] : false;
        if (!$id) {
            throw new Exception('illegal picture id #' . $id);
        }
        $query = 'SELECT * FROM `content_pictures` WHERE `id`=' . $id;
        $data = Database::sql2row($query);
        if (!$data)
            return;
        $data['time'] = date('Y/m/d H:i', $data['time']);
        $this->data['picture'] = $data;
        $this->data['picture']['source'] = $this->getPicUrl($data['id'], 'medium');
        $this->data['picture']['link_url'] = Config::need('www_path') . '/pictures/' . $data['id'];

        $tags = Database::sql2array('SELECT `id_tag`,`title` FROM `content_pictures_tags` CPT
            LEFT JOIN `tags` T ON T.id = CPT.id_tag WHERE CPT.`id_content_picture`=' . $id);
        $this->data['picture']['tags'] = $tags;
        $this->setPageTitle($data['title'] . ' — Жмячне картинки');
    }
Beispiel #21
0
    public function authorize_password($email, $password, $md5used = false)
    {
        $row = Database::sql2row('SELECT * FROM `users` WHERE 
			(`email`=\'' . $email . '\' OR 
			`nickname`=\'' . $email . '\')');
        if (!$row) {
            // нет такого пользователя
            return 'user_missed';
        }
        $password = $md5used ? $password : md5($password);
        if ($row) {
            if ($password != $row['password']) {
                return 'user_password';
            }
        }
        $this->load($row);
        $this->authorized = true;
        $this->onLogin();
        return true;
    }
Beispiel #22
0
	function getTheme() {
		if (!$this->theme_id)
			return;

		$query = 'SELECT uid as user_id,title,body FROM `node_revisions` WHERE `nid`=' . $this->theme_id . ' LIMIT 1';
		$theme = Database::sql2row($query);
		$theme['body'] = _bbcode_filter_process($theme['body']);
		$this->data['theme'] = $theme;

		$query = 'SELECT subject,comment,timestamp,uid FROM `comments` WHERE `nid` = ' . $this->theme_id . ' ORDER BY `timestamp`';
		$comments = Database::sql2array($query);
		$uids = array();
		foreach ($comments as &$comment) {
			$uids[$comment['uid']] = $comment['uid'];
			$comment['comment'] = _bbcode_filter_process($comment['comment']);
		}
		$uids[$theme['user_id']] = $theme['user_id'];
		$this->data['theme']['users'] = $this->getUsers($uids);
		$this->data['theme']['tid'] = $this->forum_id;
		$this->data['theme']['comments'] = $comments;
	}
Beispiel #23
0
    function write()
    {
        global $current_user;
        if (!$current_user->authorized) {
            throw new Exception('Access Denied');
        }
        $data = array('target_id' => max(0, (int) Request::$post['target_id']), 'target_type' => max(0, (int) Request::$post['target_type']), 'comment' => prepare_review(Request::$post['annotation']), 'rate' => min(6, max(0, (int) Request::$post['rate'])) + 1);
        $event = new Event();
        $time = time();
        //$old = MongoDatabase::findReviewEventData($current_user->id, $data['target_id']);
        //$with_review = (isset($old['body']) && $old['body']) ? 1 : 0;
        $with_review = 0;
        // upsert rate into database
        if ($data['rate']) {
            $query = 'INSERT INTO `book_rate` SET `with_review`=' . $with_review . ', `id_book`=' . $data['target_id'] . ',`id_user`=' . $current_user->id . ',`rate`=' . ($data['rate'] - 1) . ',`time`=' . $time . ' ON DUPLICATE KEY UPDATE
				`rate`=' . ($data['rate'] - 1) . ',`time`=' . $time . ',`with_review`=' . $with_review . '';
            Database::query($query);
            //recalculating rate
            $query = 'SELECT COUNT(1) as cnt, SUM(`rate`) as rate FROM `book_rate` WHERE `id_book`=' . $data['target_id'];
            $res = Database::sql2row($query);
            $book_mark = round($res['rate'] / $res['cnt'] * 10);
            $query = 'UPDATE `book` SET `mark`=' . $book_mark . ' WHERE `id`=' . $data['target_id'];
            Database::query($query);
        }
        // insert data into mongo
        if (!$data['comment']) {
            unset($data['comment']);
        }
        if (isset($data['comment']) && $data['comment']) {
            $event->event_BookReviewAdd($current_user->id, $data);
            Notify::notifyNewBookReview($data['target_id'], $current_user->id);
        } else {
            if ($data['rate'] > 1) {
                $event->event_BookRateAdd($current_user->id, $data);
            }
        }
        $event->push();
    }
Beispiel #24
0
 function loadRightsholder()
 {
     if (!$this->loaded) {
         $this->load();
     }
     if ($this->rightsholderLoaded) {
         return false;
     }
     if ($this->data['id_rightholder']) {
         $query = 'SELECT * FROM `rightholders` WHERE `id`=' . $this->data['id_rightholder'];
         $this->rightsholder = Database::sql2row($query);
         if (!is_array($this->rightsholder)) {
             $this->rightsholder = array();
         }
     } else {
         $this->rightsholder = array();
     }
     $this->rightsholderLoaded = true;
 }
Beispiel #25
0
 public function load($rowData = false)
 {
     if ($this->loaded) {
         return true;
     }
     if (!$rowData) {
         if (!$this->id) {
             $this->setXMLAttibute('auth', 0);
         } else {
             if ($cachedUser = Users::getFromCache($this->id)) {
                 $this->profile = $cachedUser->profile;
                 foreach ($this->profile as $field => $value) {
                     $this->setXMLAttibute($field, $value);
                 }
                 $this->profileAdditional = $cachedUser->profileAdditional;
                 $this->loaded = true;
                 return;
             } else {
                 $rowData = Database::sql2row('SELECT * FROM `users` WHERE `id`=' . $this->id);
             }
         }
     }
     if (!$rowData) {
         // нет юзера в базе
         throw new Exception('Такого пользователя #' . $this->id . ' не существует', Error::E_USER_NOT_FOUND);
     }
     $this->id = (int) $rowData['id'];
     foreach ($rowData as $field => $value) {
         if ($field == 'serialized') {
             $arr = json_decode($value, true);
             if (is_array($arr)) {
                 foreach ($arr as $field => $value) {
                     $this->setPropertySerialized($field, $value, $save = false);
                     $this->setXMLAttibute($field, $value);
                 }
             }
         }
         // все данные в profile
         $this->setProperty($field, $value, $save = false);
         // данные для xml - в xml
         $this->setXMLAttibute($field, $value);
     }
     Users::add($this);
     $this->loaded = true;
     Users::putInCache($this->id);
     return;
 }
Beispiel #26
0
 function add_genre()
 {
     global $current_user;
     $this->ca();
     if (is_numeric($_POST['id_genre'])) {
         $id_genre = (int) $_POST['id_genre'];
     } else {
         $id_genre = Database::sql2single('SELECT `id` FROM `genre` WHERE `name`=' . Database::escape($_POST['id_genre']));
     }
     $id_book = (int) $_POST['id'];
     if ($id_genre && $id_book) {
         $query = 'SELECT `id`,`name`,`title` FROM `genre` WHERE id=' . $id_genre . ' AND `id_parent`>0';
         $result = Database::sql2row($query);
         if (!isset($result['id'])) {
             $this->data['success'] = 0;
             $this->data['error'] = 'Нет такого жанра';
             return;
         }
         $query = 'INSERT INTO `book_genre` SET `id_book`=' . $id_book . ' , `id_genre`=' . $id_genre;
         $r = Database::query($query, false);
         if ($r) {
             $this->data['success'] = 1;
             $this->data['item_id'] = $id_genre;
             $this->data['name'] = $result['name'];
             $this->data['title'] = $result['title'];
             BookLog::addLog(array('id_genre' => $id_genre), array('id_genre' => 0), $id_book);
             BookLog::saveLog($id_book, BookLog::TargetType_book, $current_user->id, BiberLog::BiberLogType_bookEditGenre);
             $search = Search::getInstance();
             /* @var $search Search */
             $search->updateBook(new Book($id_book));
             Notify::notifyGenreNewBook($id_genre, $id_book);
         } else {
             $this->data['error'] = 'Жанр уже есть в списке жанров';
         }
         return;
     }
     $this->data['item_id'] = $id_genre;
     $this->data['success'] = 0;
 }
Beispiel #27
0
    function addLoved()
    {
        global $current_user;
        $event = new Event();
        /* @var $current_user CurrentUser */
        if (!$current_user->authorized) {
            $this->error('Auth');
            return;
        }
        $item_type = isset($_POST['item_type']) ? $_POST['item_type'] : false;
        $item_id = isset($_POST['item_id']) ? (int) $_POST['item_id'] : false;
        if (!$item_type || !$item_id) {
            $this->error('item_id or item_type missed');
            return;
        }
        if (!isset(Config::$loved_types[$item_type])) {
            $this->error('illegal item_type#' . $item_type);
            return;
        }
        $query = 'INSERT INTO `users_loved` SET `id_target`=' . $item_id . ',`target_type`=' . Config::$loved_types[$item_type] . ',`id_user`=' . $current_user->id;
        if (Database::query($query, false)) {
            $this->data['success'] = 1;
            $this->data['item_id'] = $item_id;
            $this->data['in_loved'] = 1;
            $event->event_LovedAdd($current_user->id, $item_id, $item_type);
            $event->push();
            if ($item_type == 'book') {
                $time = time();
                // inserting a new mark
                $query = 'INSERT INTO `book_rate` SET `id_book`=' . $item_id . ',`id_user`=' . $current_user->id . ',`rate`=5,`time`=' . $time . ' ON DUPLICATE KEY UPDATE
				`rate`=5 ,`time`=' . $time . ',`with_review`=0';
                Database::query($query);
                //recalculating rate
                $query = 'SELECT COUNT(1) as cnt, SUM(`rate`) as rate FROM `book_rate` WHERE `id_book`=' . $item_id;
                $res = Database::sql2row($query);
                $book_mark = round($res['rate'] / $res['cnt'] * 10);
                $book = Books::getInstance()->getById($item_id);
                /* @var $book Book */
                $book->updateLovedCount();
                $query = 'UPDATE `book` SET `mark`=' . $book_mark . ' WHERE `id`=' . $item_id;
                Database::query($query);
            }
            return;
        } else {
            $query = 'DELETE FROM `users_loved` WHERE `id_target`=' . $item_id . ' AND `target_type`=' . Config::$loved_types[$item_type] . ' AND `id_user`=' . $current_user->id;
            if (Database::query($query, false)) {
                $this->data['success'] = 1;
                $this->data['item_id'] = $item_id;
                $this->data['in_loved'] = 0;
                if ($item_type == 'book') {
                    $book = Books::getInstance()->getById($item_id);
                    /* @var $book Book */
                    $book->updateLovedCount();
                }
                return;
            } else {
                $this->data['success'] = 0;
            }
        }
    }
Beispiel #28
0
 function getSerieContributionComments()
 {
     global $current_user;
     /* @var $current_user CurrentUser */
     $id_serie = isset($this->params['serie_id']) ? (int) $this->params['serie_id'] : false;
     if (!$id_serie) {
         return;
     }
     $data = Database::sql2row('SELECT * FROM `series` WHERE `id`=' . $id_serie);
     if (!count($data)) {
         throw new Exception('serie #' . $id_serie . ' not exists');
     }
     $cond = new Conditions();
     $per_page = 0;
     if (isset($this->params['per_page'])) {
         $per_page = (int) $this->params['per_page'];
     }
     $per_page = $per_page > 0 ? $per_page : 20;
     $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p';
     $cond->setPaging(1000, $per_page, $pagingName);
     $limit = $cond->getMongoLimit();
     list($comments, $count) = MongoDatabase::getSerieComments($id_serie, $per_page, $limit);
     $uids = array();
     $comments['comments'] = isset($comments['comments']) ? $comments['comments'] : array();
     foreach ($comments['comments'] as &$comment) {
         $comment['commenter_id'] = $comment['user_id'];
         $comment['type'] = 'serie';
         $comment['time'] = date('Y/m/d H:i:s', $comment['time']);
         $uids[$comment['user_id']] = $comment['user_id'];
     }
     $cond = new Conditions();
     $cond->setPaging($count, $per_page, $pagingName);
     $this->data['conditions'] = $cond->getConditions();
     $this->data['comments'] = isset($comments['comments']) ? $comments['comments'] : array();
     $this->data['comments']['title'] = 'Обсуждение серии «' . $data['title'] . '»';
     $this->data['comments']['count'] = $count;
     $this->data['users'] = $this->getCommentsUsers($uids);
 }
Beispiel #29
0
	public function load($rowData = false) {
		if ($this->loaded)
			return true;
		$this->loaded = true;
		if (!$rowData) {
			if (!$this->id) {
				$this->setXMLAttibute('auth', 0);
			} else {
				$rowData = Database::sql2row('SELECT * FROM `users` WHERE `id`=' . $this->id);
			}
		}
		if (!$rowData) {
			// нет юзера в базе
			throw new Exception('No user #' . $this->id . ' in database', Error::E_USER_NOT_FOUND);
		}

		$this->id = (int) $rowData['id'];

		foreach ($rowData as $field => $value) {
			if ($field == 'serialized') {
				$arr = json_decode($value, true);
				if (is_array($arr))
					foreach ($arr as $field => $value) {
						$this->setPropertySerialized($field, $value, $save = false);
						$this->setXMLAttibute($field, $value);
					}
			}
			// все данные в profile
			$this->setProperty($field, $value, $save = false);
			// данные для xml - в xml
			$this->setXMLAttibute($field, $value);
		}
		return;
	}
Beispiel #30
0
 function load()
 {
     $this->data = Database::sql2row('SELECT * FROM `user` WHERE `id`=' . $this->id);
     $this->loaded = true;
 }