Example #1
0
 public static function getByIdsLoaded($ids)
 {
     $out = array();
     $tofetch = array();
     if (is_array($ids)) {
         foreach ($ids as $uid) {
             $uid = (int) $uid;
             if (!isset(self::$users[$uid])) {
                 if (!self::getFromCache($uid)) {
                     $tofetch[] = $uid;
                 }
             }
         }
         if (count($tofetch)) {
             $query = 'SELECT * FROM `users` WHERE `id` IN (' . implode(',', $tofetch) . ')';
             $data = Database::sql2array($query, 'id');
         }
         foreach ($ids as $uid) {
             if (!isset(self::$users[(int) $uid])) {
                 if (isset($data[$uid])) {
                     $tmp = new User($uid, $data[$uid]);
                     self::$users[$tmp->id] = $tmp;
                     self::putInCache($tmp->id);
                     unset($tmp);
                 }
             }
         }
         foreach ($ids as $uid) {
             if (isset(self::$users[$uid])) {
                 $out[$uid] = self::$users[$uid];
             }
         }
     }
     return $out;
 }
Example #2
0
 function getRightholders()
 {
     $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 : 1;
     $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p';
     $where = '';
     $order = 'ORDER BY `id` DESC ';
     $group_by = '';
     $query = 'SELECT COUNT(1) FROM `rightholders` ' . $where . ' ' . $group_by . '';
     $count = Database::sql2single($query);
     $cond->setPaging($count, $per_page, $pagingName);
     $limit = $cond->getLimit();
     $limit = ' LIMIT ' . $limit;
     $query = 'SELECT * FROM `rightholders`' . $where . ' ' . $group_by . ' ' . $order . ' ' . $limit;
     $data = Database::sql2array($query);
     foreach ($data as &$row) {
         $row['path'] = Config::need('www_path') . '/admin/rightholders/' . $row['id'];
     }
     $this->data['rightholders'] = $data;
     $this->data['rightholders']['title'] = 'Правообладатели';
     $this->data['rightholders']['count'] = $count;
     $this->data['conditions'] = $cond->getConditions();
 }
Example #3
0
 function get_likes($params, &$data)
 {
     $ids = $_POST['ids'];
     $to_check = array();
     foreach ($ids as $event_id) {
         if (is_numeric($event_id) && $event_id > 0) {
             $to_check[$event_id] = $event_id;
         }
     }
     if (count($to_check)) {
         $res = Database::sql2array('SELECT `user_id`,`event_id` FROM `event_likes` WHERE `event_id` IN (' . implode(',', $to_check) . ')');
         $uids = array();
         foreach ($res as $row) {
             $uids[$row['user_id']] = $row['user_id'];
         }
         if (count($uids)) {
             $users = Users::getByIdsLoaded(array_keys($uids));
             foreach ($res as $row) {
                 if (isset($users[$row['user_id']])) {
                     $data['likes'][$row['event_id']][$row['user_id']] = array('nickname' => $users[$row['user_id']]->data['nickname'], 'id' => $users[$row['user_id']]->data['id']);
                     if (CurrentUser::$id == $row['user_id']) {
                         $data['self'][$row['event_id']] = $row['user_id'];
                     }
                 }
             }
         }
     }
     foreach ($to_check as $event_id) {
         if (!isset($data['likes'][$event_id])) {
             $data['likes'][$event_id] = array();
         }
     }
     $data['owner'] = CurrentUser::$id;
     return $data;
 }
Example #4
0
	function getThreadList() {
		global $current_user;
		$out = array();
		$query = 'SELECT * FROM `users_messages_index` UMI
			RIGHT JOIN `users_messages` UM ON UM.id = UMI.message_id
			WHERE `id_recipient`=' . $current_user->id . ' AND `is_deleted`=0';
		$messages = Database::sql2array($query);
		// загрузили все сообщения вообще
		// для каждого треда выбираем последнее сообщение
		$messages_prepared = array();
		$uids = array();
		foreach ($messages as &$message) {
			if (!isset($messages_prepared[$message['thread_id']])) {
				$messages_prepared[$message['thread_id']]['newest']['time'] = 0;
				$messages_prepared[$message['thread_id']]['oldest']['time'] = time() + 10000;
			}
			if ($messages_prepared[$message['thread_id']]['newest']['time'] < $message['time']) {
				$messages_prepared[$message['thread_id']]['newest'] = $message;
				$messages_prepared[$message['thread_id']]['html'] = $message['html'];
			}

			if ($message['is_new'])
				$messages_prepared[$message['thread_id']]['is_new'] = 1;



			if ($messages_prepared[$message['thread_id']]['oldest']['time'] > $message['time']) {
				$messages_prepared[$message['thread_id']]['oldest'] = $message['time'];
				$messages_prepared[$message['thread_id']]['subject'] = $message['subject'];
			}

			$messages_prepared[$message['thread_id']]['members'][$message['id_recipient']] = $message['id_recipient'];
			$messages_prepared[$message['thread_id']]['members'][$message['id_author']] = $message['id_author'];
			$messages_prepared[$message['thread_id']]['thread_id'] = $message['thread_id'];
		}

		foreach ($messages_prepared as $thread_id => &$mess) {
			$mess['oldest'] = date('Y/m/d H:i:s', $mess['oldest']);
			$tmpmess = $mess['newest'];
			$tmpmess['oldest'] = $mess['oldest'];
			$tmpmess['newest'] = date('Y/m/d H:i:s', $mess['newest']['time']);
			$tmpmess['time'] = date('Y/m/d H:i:s', $tmpmess['time']);
			$tmpmess['subject'] = $mess['subject'];
			$tmpmess['is_new'] = isset($mess['is_new']) ? 1 : 0;
			foreach ($mess['members'] as $uid) {
				if ($current_user->id != $uid)
					$tmpmess['members'][] = array(
					    'id' => $uid
					);
				$uids[$uid] = $uid;
			}
			$out[] = $tmpmess;
		}
		$users = Users::getByIdsLoaded($uids);
		foreach ($users as $user) {
			$this->data['users'][$user->id] = $user->getListData();
		}

		$this->data['messages'] = $out;
	}
Example #5
0
 public static function getByIdsLoaded($ids)
 {
     $out = array();
     $tofetch = array();
     if (is_array($ids)) {
         foreach ($ids as $uid) {
             if (!isset(self::$persons[(int) $uid])) {
                 $tofetch[] = $uid;
             }
         }
         if (count($tofetch)) {
             $query = 'SELECT * FROM `persons` WHERE `id` IN (' . implode(',', $tofetch) . ')';
             $data = Database::sql2array($query, 'id');
         }
         foreach ($ids as $id) {
             if (!isset(self::$persons[(int) $id])) {
                 if (isset($data[$id])) {
                     $tmp = new Person($id, $data[$id]);
                     self::$persons[$tmp->id] = $tmp;
                     unset($tmp);
                 } else {
                     //self::$persons[$id] = new Person($id); // todo
                 }
             }
         }
         foreach ($ids as $id) {
             if (isset(self::$persons[$id])) {
                 $out[$id] = self::$persons[$id];
             }
         }
     }
     return $out;
 }
Example #6
0
 function getCityList()
 {
     $country = isset($_POST['country_id']) ? (int) $_POST['country_id'] : 1;
     $this->data['city_list'] = Database::sql2array('SELECT `id`,`name` FROM `lib_city` WHERE `country_id`=' . $country . ' LIMIT 1000', 'id');
     $this->data['country_id'] = $country;
     $this->data['city_id'] = Database::sql2single('SELECT `id` FROM `lib_city` WHERE `country_id`=' . $country . ' LIMIT 1');
 }
Example #7
0
 public static function getByIdsLoaded($uids)
 {
     $data = Database::sql2array('SELECT * FROM `user` WHERE `id` IN(' . implode(',', $uids) . ')');
     $users = array();
     foreach ($data as $row) {
         $users[$row['id']] = new User($row['id'], $row);
     }
     return $users;
 }
Example #8
0
 public static function sqlLoad(array $ids, array $users)
 {
     if (count($ids)) {
         $query = 'SELECT * FROM `user` WHERE `id` IN (' . implode(',', $ids) . ')';
         $data = Database::sql2array($query, 'id');
         foreach ($data as $row) {
             $users[$row['id']] = self::add($row['id'], $row);
         }
     }
     return $users;
 }
Example #9
0
function getTemplateFields($template_id)
{
    $query = 'SELECT * FROM `lib_event_templates` LET
        LEFT JOIN `lib_event_templates_fields` LETF ON LET.id=LETF.template_id
        LEFT JOIN `lib_event_templates_fields_types` LETFT ON LETFT.id=LETF.`type`
        WHERE LET.id=' . $template_id . ' ORDER BY pos';
    $data = Database::sql2array($query);
    foreach ($data as $field) {
        $out[$field['type_name']] = array('type' => $field['type_name'], 'important' => $field['important'], 'title' => $field['title'], 'field_id' => $field['field_id'], 'pos' => $field['pos']);
    }
    return $out;
}
Example #10
0
    function _list($opts)
    {
        $data = array();
        $has_paging = !isset($opts['no_paging']);
        $show_sortings = isset($opts['show_sortings']);
        $per_page = isset($opts['per_page']) ? $opts['per_page'] : 10;
        $per_page = min(100, max(1, (int) $per_page));
        $cond = new Conditions();
        $cond->setSorting(array('time' => array('order' => 'desc', 'title' => 'по дате')), array('time' => array('order' => 'desc', 'title' => 'по дате')));
        $cond->setPaging(100000, $per_page);
        $where = array('parent_id=0');
        if (isset($opts['where'])) {
            foreach ($opts['where'] as $w) {
                $where[] = $w;
            }
        }
        $order = $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL();
        $limit = $cond->getLimit();
        $query = 'SELECT * FROM `comments`
WHERE (' . implode(' AND ', $where) . ')
ORDER BY ' . $order . ' LIMIT ' . $limit . '';
        $comments = Database::sql2array($query, 'id');
        $pids = array();
        $uids = array();
        foreach ($comments as $comment) {
            $pids[$comment['id']] = $comment['id'];
            $uids[$comment['user_id']] = $comment['user_id'];
        }
        if (count($pids)) {
            $query = 'SELECT * FROM `comments` WHERE `thread` IN (' . implode(',', $pids) . ') ORDER BY `thread`,`id`';
            $nextlevel = Database::sql2array($query, 'id');
            $comments += $nextlevel;
            foreach ($comments as $comment) {
                $uids[$comment['user_id']] = $comment['user_id'];
            }
            if (count($uids)) {
                $users = Users::getByIdsLoaded($uids);
            } else {
                $users = array();
            }
            foreach ($comments as &$comment) {
                if (!isset($users[$comment['user_id']])) {
                    continue;
                }
                $comment['user'] = $users[$comment['user_id']];
                $parents[$comment['parent_id']][$comment['id']] = $comment;
                uasort($parents[$comment['parent_id']], 'x_sort_comment');
            }
            $comments = $this->build_tree($parents, 0);
        }
        return $comments;
    }
Example #11
0
	function write() {
		global $current_user;
		if (!$current_user->authorized)
			throw new Exception('Access Denied');

		$id_author = $current_user->id;
		$to_users = isset(Request::$post['to']) ? Request::$post['to'] : array($current_user->id);
		if (strstr($to_users, ','))
			$to_users = explode(',', $to_users);
		if (!is_array($to_users))
			$to_users = array($to_users);
		foreach ($to_users as $id) {
			if (strstr($id, ',')) {
				$t_to_users = explode(',', $id);
				foreach ($t_to_users as $n) {
					$to_users_p[(int) $n] = (int) $n;
				}
			}
			else $to_users_p[$id] = (int)$id;
		}

		$to_users = $to_users_p;
		$subject = isset(Request::$post['subject']) ? Request::$post['subject'] : 'Без темы';
		$body = isset(Request::$post['body']) ? Request::$post['body'] : false;
		$subject = prepare_review($subject, '');
		$body = prepare_review($body, '');
		if (!$body)
			throw new Exception('body!');
		$time = time();
		$thread_id = isset(Request::$post['thread_id']) ? Request::$post['thread_id'] : false;

		if ($thread_id) {
			// а можно ли писать в этот тред этому человеку?
			$query = 'SELECT DISTINCT id_recipient FROM `users_messages_index` WHERE `thread_id`=' . $thread_id;
			$usrs = Database::sql2array($query);
			$found = false;
			$to_users = array();
			if ($usrs) {
				foreach ($usrs as $usr) {
					if ($usr['id_recipient'] == $current_user->id)
						$found = true;
					$to_users[$usr['id_recipient']] = $usr['id_recipient'];
				}
			}
			if (!$found)
				throw new Exception('You cant post to thread #' . $thread_id);
		}

		$to_users[$current_user->id] = $current_user->id;

		$this->sendMessage($id_author, $to_users, $subject, $body, $time, $thread_id);
	}
Example #12
0
	function getBookShelf() {
		if ($this->shelfLoaded)
			return $this->shelf;
		$query = 'SELECT * FROM `users_bookshelf` WHERE `id_user`=' . $this->id;
		$array = Database::sql2array($query);
		$out = array();
		foreach ($array as $row) {
			$out[$row['bookshelf_type']][$row['id_book']] = $row;
		}
		$this->shelfLoaded = true;
		$this->shelf = $out;
		return $this->shelf;
	}
Example #13
0
 function saveSettings()
 {
     require_once $filename = dirname(Config::need('xslt_files_path')) . '/localconfig.php';
     global $local_config;
     $query = 'SELECT * FROM `settings`';
     $arr = Database::sql2array($query);
     $local_config['-----------------'] = '-----------------';
     foreach ($arr as $setting) {
         $local_config[$setting['name']] = $setting['value'];
     }
     $s = var_export($local_config, true);
     file_put_contents($filename, '<?php $local_config = ' . $s . ";\n" . '//some settings generated by setting module');
 }
Example #14
0
 function getDataFromUids($ids)
 {
     if (!count($ids)) {
         return array();
     }
     $out = array();
     $query = 'SELECT * FROM `users` WHERE `id` IN (' . implode(',', $ids) . ')';
     $result = Database::sql2array($query);
     foreach ($result as $userRow) {
         $user = Users::getById($userRow['id'], $userRow);
         /* @var $user User */
         $out[$user->id] = array('id' => $user->id, 'nickname' => $user->getProperty('nickname'), 'picture' => $user->getProperty('picture') ? $user->id . '.jpg' : 'default.jpg', 'lastSave' => $user->getProperty('lastSave'));
     }
     return $out;
 }
Example #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;
    }
Example #16
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;
 }
Example #17
0
 function check()
 {
     global $current_user;
     $this->data['success'] = 1;
     if (!$current_user->authorized) {
         $this->error('Auth');
         return;
     }
     $id_user = $current_user->id;
     $id_book = max(0, (int) $_POST['id_book']);
     $query = 'SELECT * FROM `ocr` WHERE `id_book`=' . $id_book . ' AND `id_user`=' . $id_user . '';
     $r = Database::sql2array($query);
     foreach ($r as $row) {
         $this->data['ocr'] = array('id_book' => $row['id_book'], 'status' => $row['status'], 'state' => $row['state']);
     }
 }
Example #18
0
	function getThemesList() {
		$query = 'SELECT NCS.last_comment_timestamp,NCS.last_comment_uid,N.title,N.nid,N.created,N.changed,N.comment,N.promote,N.sticky,N.status FROM `term_node` TN 
		LEFT JOIN `node` N ON TN.nid = N.nid 
		INNER JOIN `node_comment_statistics` NCS ON N.nid = NCS.nid 
		WHERE `tid`=' . $this->forum_id . '
		ORDER BY `last_comment_timestamp` DESC ';

		$themesList = Database::sql2array($query);
		foreach ($themesList as &$theme) {
			$uids[$theme['last_comment_uid']] = $theme['last_comment_uid'];
			$theme['last_comment_timestamp'] = date('Y-m-d H:i', $theme['last_comment_timestamp']);
			$theme['created'] = date('Y-m-d H:i', $theme['created']);
		}
		$this->data['users'] = $this->getUsers($uids);
		$this->data['themes'] = $themesList;
		$this->data['themes']['tid'] = $this->forum_id;
	}
Example #19
0
	function getInGroup($data) {
		$groups = array();
		foreach ($data['features'] as $item) {
			$groups[$item['group_id']] = $item['group_id'];
		}
		$query = 'SELECT * FROM `feature_groups` WHERE `id` IN(' . implode(',', $groups) . ')';
		$groups = Database::sql2array($query, 'id');


		foreach ($data['features'] as $feature) {
			$groups[$feature['group_id']]['features'][] = $feature;
		}
		if (isset($groups[0]))
			$groups[0] = array('title' => 'без группы');

		return $groups;
	}
Example #20
0
 public function LoadBookPersons($ids)
 {
     $this->getByIdsLoaded($ids);
     $out = array();
     $tofetch = array();
     $aids = array();
     if (is_array($ids)) {
         foreach ($ids as $id) {
             if (!isset($this->items[$id])) {
                 continue;
             }
             if (!$this->items[$id]->personsLoaded) {
                 $tofetch[] = (int) $id;
             }
         }
         $bookPersons = array();
         if (count($tofetch)) {
             $query = 'SELECT * FROM `book_persons` WHERE `id_book` IN (' . implode(',', $tofetch) . ')';
             $bookPersons = Database::sql2array($query);
         }
         $bookPersonsPrepared = array();
         foreach ($bookPersons as $book) {
             $bookPersonsPrepared[$book['id_book']][] = $book;
             $aids[$book['id_person']] = $book['id_person'];
         }
         Persons::getInstance()->getByIdsLoaded($aids);
         foreach ($ids as $id) {
             if (isset($this->items[$id])) {
                 if (isset($bookPersonsPrepared[$id])) {
                     $this->items[$id]->loadPersons(isset($bookPersonsPrepared[$id]) ? $bookPersonsPrepared[$id] : array());
                 } else {
                     // no any persons
                     $this->items[$id]->personsLoaded = true;
                     //$this->items[$id]->persons = array();
                 }
             }
         }
         foreach ($ids as $id) {
             if (isset($this->items[$id])) {
                 $out[$id] = $this->items[$id];
             }
         }
     }
     return $out;
 }
    function _list($opts = array())
    {
        $has_paging = !isset($opts['no_paging']);
        $show_sortings = isset($opts['show_sortings']);
        $per_page = isset($opts['per_page']) ? $opts['per_page'] : 10;
        $per_page = min(100, max(1, (int) $per_page));
        $cond = new Conditions();
        $cond->setSorting(array('created' => array('order' => 'desc', 'title' => 'по дате')));
        $cond->setPaging(100000, $per_page);
        $where = array('1');
        if (isset($opts['where'])) {
            foreach ($opts['where'] as $w) {
                $where[] = $w;
            }
        }
        $order = $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL();
        $limit = $cond->getLimit();
        $query = 'SELECT SQL_CALC_FOUND_ROWS P. * , GROUP_CONCAT( T.title ) AS tags, GROUP_CONCAT( PT.tag_id ) AS tags_indexes
FROM `publications` P
LEFT JOIN `publications_tags` PT ON PT.publication_id = P.id
LEFT JOIN `tags` T ON T.id = PT.tag_id
WHERE (' . implode(' AND ', $where) . ')
GROUP BY P.id
ORDER BY ' . $order . ' LIMIT ' . $limit . '';
        $publications = Database::sql2array($query, 'id');
        foreach ($publications as $publication) {
            $uids[$publication['user_id']] = $publication['user_id'];
        }
        $users = Users::getByIdsLoaded($uids);
        foreach ($publications as &$publication) {
            $publication['user'] = isset($users[$publication['user_id']]) ? $users[$publication['user_id']]->data : array();
        }
        $cond->setPaging(Database::sql2single('SELECT FOUND_ROWS()'), $per_page);
        $data['publications'] = $publications;
        $data['conditions'] = $cond->getConditions();
        if (!$show_sortings) {
            foreach ($data['conditions'] as $key => $group) {
                if ($group['mode'] == 'sorting') {
                    unset($data['conditions'][$key]);
                }
            }
        }
        return $data;
    }
Example #22
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'] . ' — Жмячне картинки');
    }
Example #23
0
 function work()
 {
     // забираем от яндекса кусок
     $i = 0;
     while (is_array($data = $this->getYandexPage($i++))) {
         $posts = array();
         foreach ($data as $postData) {
             if (isLjUrl($postData['link'])) {
                 list($author, $id) = getAuthorAndIdByUrl($postData['link']);
                 if ($id && $author) {
                     $posts[$author][$id] = $postData;
                 }
             }
         }
         $usernames = array_keys($posts);
         // тянем по именам пользователей
         $query = 'SELECT `id`,`name` FROM `journals` WHERE `name` IN (\'' . implode('\',\'', $usernames) . '\')';
         $journals = Database::sql2array($query, 'name');
         $toFetchJournal = array();
         $toInsert = array();
         // если нет такого пользователя - придется создать и распарсить его данные потом
         foreach ($posts as $username => $posts) {
             if (!isset($journals[$username])) {
                 $toFetchJournal[$username] = $username;
             } else {
                 foreach ($posts as $id => $postOne) {
                     $postOne['id'] = $id;
                     $postOne['author'] = $username;
                     $postOne['journalId'] = $journals[$username]['id'];
                     $toInsert[] = $postOne;
                 }
             }
         }
         if (count($toFetchJournal)) {
             $this->addJournals($toFetchJournal);
         }
         if (count($toInsert)) {
             $this->updatePosts($toInsert);
         }
     }
 }
Example #24
0
 function _list()
 {
     $doc_id = max(0, (int) $this->params['doc_id']);
     $table = $this->params['table'];
     $query = 'SELECT * FROM `comments` WHERE `table`=' . Database::escape($table) . ' AND `doc_id`=' . $doc_id;
     $comments = Database::sql2array($query);
     $user_ids = array();
     $parents = array();
     $commentsNode = array();
     foreach ($comments as &$comment) {
         $user_ids[$comment['id_author']] = $comment['id_author'];
         $comment['date'] = date('Y/m/d H:i:s', $comment['time']);
         $parents[$comment['parent']][$comment['id']] = $comment;
     }
     $commentsNode = array();
     $this->addCommentsLevel($comments, 0, &$commentsNode, $parents);
     $this->data['comments'] = $commentsNode;
     $this->data['users'] = $this->getCommentUsers($user_ids);
     $this->data['comments']['doc_id'] = $doc_id;
     $this->data['comments']['table'] = $table;
 }
Example #25
0
 function getInGroup($data)
 {
     $groups = array();
     foreach ($data['features'] as $item) {
         $groups[$item['group_id']] = $item['group_id'];
     }
     $query = 'SELECT * FROM `feature_groups` WHERE `id` IN(' . implode(',', $groups) . ') AND `deleted`=0';
     $groups = Database::sql2array($query, 'id');
     $i = 0;
     foreach ($data['features'] as $feature) {
         $groups[$feature['group_id']]['features'][] = $feature;
         if ($feature['group_id']) {
             $groups[$feature['group_id']]['path_edit'] = 'groups/' . $feature['group_id'] . '/edit';
             $groups[$feature['group_id']]['path_delete'] = 'groups/' . $feature['group_id'] . '/delete';
         }
     }
     if (isset($groups[0])) {
         $groups[0]['title'] = 'без группы';
     }
     return $groups;
 }
Example #26
0
 function write()
 {
     global $current_user;
     /* @var $current_user CurrentUser */
     $current_user->can_throw('logs_view');
     $log_array = Request::$post['log'];
     $to_parse_log = array();
     foreach ($log_array as $logid => $on) {
         $logid = max(0, (int) $logid);
         $to_parse_log[$logid] = $logid;
     }
     if (!count($to_parse_log)) {
         throw new Exception('no log to process');
     }
     $query = 'SELECT * FROM `biber_log` WHERE `id` IN(' . implode(',', $to_parse_log) . ')';
     $logdata = Database::sql2array($query);
     if (!$logdata || !count($logdata)) {
         throw new Exception('no log in db to process');
     }
     foreach ($logdata as $data) {
         BiberLog::undo($data['id'], $data, isset(Request::$post['apply']) ? true : false);
     }
 }
Example #27
0
	function getAll($parent_id = 0) {
		if (!$parent_id)
			$query = 'SELECT id,id_parent,name,title,books_count FROM `genre` ORDER BY `id_parent`,`books_count` DESC';
		else
			$query = 'SELECT id,id_parent,name,title,books_count FROM `genre` WHERE id_parent=' . $parent_id . ' ORDER BY `id_parent`,`books_count` DESC';
		$genres = Database::sql2array($query);

		$parents = array();
		foreach ($genres as &$g) {
			$parents[$g['id_parent']][] = $g;
		}
		if (isset($parents[$parent_id]))
			foreach ($parents[$parent_id] as $item) {
				$genres_prepared[$item['id']] = $item;
				if (isset($parents[$item['id']])) {
					foreach ($parents[$item['id']] as $item_2) {
						$genres_prepared[$item['id']]['subgenres'][$item_2['id']] = $item_2;
					}
				}
			}

		return $genres_prepared;
	}
Example #28
0
 function getSettings()
 {
     $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 : 1;
     $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p';
     $where = '';
     $order = 'ORDER BY `id` DESC ';
     $group_by = '';
     $query = 'SELECT COUNT(1) FROM `settings` ' . $where . ' ' . $group_by . '';
     $count = Database::sql2single($query);
     $cond->setPaging($count, $per_page, $pagingName);
     $limit = $cond->getLimit();
     $limit = ' LIMIT ' . $limit;
     $query = 'SELECT * FROM `settings`' . $where . ' ' . $group_by . ' ' . $order . ' ' . $limit;
     $data = Database::sql2array($query);
     $this->data['settings'] = $data;
     $this->data['settings']['title'] = 'Настройки';
     $this->data['settings']['count'] = $count;
     $this->data['conditions'] = $cond->getConditions();
 }
Example #29
0
	function getAll() {
		// вся периодика
		$query = 'SELECT `id`,`title`,`first_year`,`last_year` FROM `magazines` ORDER BY `last_year` DESC';
		$magazines = Database::sql2array($query);
		$this->data['magazines'] = $magazines;
	}
Example #30
0
 function getContributionGenres($sids)
 {
     $query = 'SELECT * FROM `genre` WHERE `id` IN(' . implode(',', $sids) . ')';
     $series = Database::sql2array($query);
     foreach ($series as &$serie) {
         $serie['path'] = Config::need('www_path') . '/genres/' . $serie['id'];
     }
     return $series;
 }