/**
  * Returns a list with category ids of accessible linklist categories.
  * 
  * @param	array		$permissions
  * @return	array<integer>
  */
 public static function getAccessibleCategoryIDs(array $permissions = array('canViewCategory'))
 {
     $categoryIDs = array();
     foreach (CategoryHandler::getInstance()->getCategories('de.incendium.linklist.category') as $category) {
         $result = true;
         $category = new LinklistCategory($category);
         foreach ($permissions as $permission) {
             $result = $result && $category->getPermission($permission);
         }
         if ($result) {
             $categoryIDs[] = $category->categoryID;
         }
     }
     return $categoryIDs;
 }
 /**
  * @see    \wcf\system\search\ISearchableObjectType::getConditions()
  */
 public function getConditions(IForm $form = null)
 {
     $conditionBuilder = new PreparedStatementConditionBuilder();
     // accessible category ids
     if (isset($_POST['linklistCategoryIDs'])) {
         $this->linklistCategoryIDs = ArrayUtil::toIntegerArray($_POST['linklistCategoryIDs']);
     }
     $categoryIDs = LinklistCategory::getAccessibleCategoryIDs();
     if (!empty($this->linklistCategoryIDs)) {
         $this->linklistCategoryIDs = array_intersect($categoryIDs, $this->linklistCategoryIDs);
     } else {
         $this->linklistCategoryIDs = $categoryIDs;
     }
     if (empty($this->linklistCategoryIDs)) {
         throw new PermissionDeniedException();
     }
     $conditionBuilder->add($this->getTableName() . '.entryID IN (SELECT entryID FROM linklist' . WCF_N . '_entry_to_category WHERE categoryID IN (?))', array($this->linklistCategoryIDs));
     // default conditions
     $conditionBuilder->add($this->getTableName() . '.isDisabled = 0');
     $conditionBuilder->add($this->getTableName() . '.isDeleted = 0');
     // language
     if (LINKLIST_ENABLE_MULTILINGUALISM && LanguageFactory::getInstance()->multilingualismEnabled() && count(WCF::getUser()->getLanguageIDs())) {
         $conditionBuilder->add('(' . $this->getTableName() . '.languageID IN (?) OR ' . $this->getTableName() . '.languageID IS NULL)', array(WCF::getUser()->getLanguageIDs()));
     }
     return $conditionBuilder;
 }
 /**
  * Creates a new DeletedFileList object.
  */
 public function __construct()
 {
     parent::__construct();
     // categories
     $accessibleCategoryIDs = LinklistCategory::getAccessibleCategoryIDs();
     if (!empty($accessibleCategoryIDs)) {
         $this->getConditionBuilder()->add('entry.entryID IN (SELECT entryID FROM linklist' . WCF_N . '_entry_to_category WHERE categoryID IN (?))', array($accessibleCategoryIDs));
     } else {
         $this->getConditionBuilder()->add('1=0');
     }
     $this->getConditionBuilder()->add('entry.isDeleted = ?', array(1));
 }
 /**
  * Creates a new AccessibleFileList object.
  */
 public function __construct()
 {
     parent::__construct();
     if ($this->applyCategoryFilter) {
         $accessibleCategoryIDs = LinklistCategory::getAccessibleCategoryIDs();
         if (!empty($accessibleCategoryIDs)) {
             $this->getConditionBuilder()->add('entry.entryID IN (SELECT entryID FROM linklist' . WCF_N . '_entry_to_category WHERE categoryID IN (?))', array($accessibleCategoryIDs));
         } else {
             $this->getConditionBuilder()->add('1=0');
         }
     }
     if (!WCF::getSession()->getPermission('mod.linklist.canModerateEntry')) {
         $this->getConditionBuilder()->add('entry.isDisabled = 0');
     }
     if (!WCF::getSession()->getPermission('mod.linklist.canViewDeletedEntry')) {
         $this->getConditionBuilder()->add('entry.isDeleted = 0');
     }
     // apply language filter
     if (LanguageFactory::getInstance()->multilingualismEnabled() && count(WCF::getUser()->getLanguageIDs())) {
         $this->getConditionBuilder()->add('(entry.languageID IN (?) OR entry.languageID IS NULL)', array(WCF::getUser()->getLanguageIDs()));
     }
 }
 /**
  * @see	\wcf\page\IPage::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (empty($this->objectIDs)) {
         // get all category ids
         $this->objectIDs = LinklistCategory::getAccessibleCategoryIDs();
         if (empty($this->objectIDs)) {
             throw new IllegalLinkException();
         }
     } else {
         // validate ids
         foreach ($this->objectIDs as $objectID) {
             $category = LinklistCategory::getCategory($objectID);
             // wrong ID
             if ($category === null) {
                 throw new IllegalLinkException();
             }
             // one may not enter
             if (!$category->isAccessible()) {
                 throw new PermissionDeniedException();
             }
         }
     }
 }
 /**
  * Returns the number of unread entries.
  * 
  * @return    integer
  */
 public static function getUnreadEntries()
 {
     if (self::$unreadEntries === null) {
         self::$unreadEntries = 0;
         if (WCF::getUser()->userID) {
             $data = UserStorageHandler::getInstance()->getField('linklistUnreadEntries');
             // cache does not exist or is outdated
             if ($data === null) {
                 $categoryIDs = LinklistCategory::getAccessibleCategoryIDs();
                 // removed ignored boards
                 if (!empty($categoryIDs)) {
                     $conditionBuilder = new PreparedStatementConditionBuilder();
                     $conditionBuilder->add("entry.entryID IN (SELECT entryID FROM linklist" . WCF_N . "_entry_to_category WHERE categoryID IN (?))", array($categoryIDs));
                     $conditionBuilder->add("entry.lastChangeTime > ?", array(VisitTracker::getInstance()->getVisitTime('de.incendium.linklist.entry')));
                     $conditionBuilder->add("entry.isDisabled = 0 AND entry.isDeleted = 0");
                     $conditionBuilder->add("(entry.lastChangeTime > tracked_visit.visitTime OR tracked_visit.visitTime IS NULL)");
                     // apply language filter
                     if (LanguageFactory::getInstance()->multilingualismEnabled() && count(WCF::getUser()->getLanguageIDs())) {
                         $conditionBuilder->add('(entry.languageID IN (?) OR entry.languageID IS NULL)', array(WCF::getUser()->getLanguageIDs()));
                     }
                     $sql = "SELECT        COUNT(*) AS count\n                            FROM        linklist" . WCF_N . "_entry entry\n                            LEFT JOIN    wcf" . WCF_N . "_tracked_visit tracked_visit\n                            ON        (tracked_visit.objectTypeID = " . VisitTracker::getInstance()->getObjectTypeID('de.incendium.linklist.entry') . " AND tracked_visit.objectID = entry.entryID AND tracked_visit.userID = " . WCF::getUser()->userID . ")\n                            " . $conditionBuilder;
                     $statement = WCF::getDB()->prepareStatement($sql);
                     $statement->execute($conditionBuilder->getParameters());
                     $row = $statement->fetchArray();
                     self::$unreadEntries = $row['count'];
                 }
                 // update storage data
                 UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'linklistUnreadEntries', self::$unreadEntries);
             } else {
                 self::$unreadEntries = $data;
             }
         }
     }
     return self::$unreadEntries;
 }
 /**
  * @see    \wcf\page\IPage::readData()
  */
 public function readData()
 {
     parent::readData();
     // get categories
     $excludedCategoryIDs = array_diff(LinklistCategory::getAccessibleCategoryIDs(), LinklistCategory::getAccessibleCategoryIDs(array('canUseCategory')));
     $categoryTree = new LinklistCategoryNodeTree('de.incendium.linklist.category', 0, false, $excludedCategoryIDs);
     $this->categoryList = $categoryTree->getIterator();
     $this->categoryList->setMaxDepth(0);
     if (empty($_POST)) {
         // multilingualism
         if (!empty($this->availableContentLanguages)) {
             if (!$this->languageID) {
                 $language = LanguageFactory::getInstance()->getUserLanguage();
                 $this->languageID = $language->languageID;
             }
             if (!isset($this->availableContentLanguages[$this->languageID])) {
                 $languageIDs = array_keys($this->availableContentLanguages);
                 $this->languageID = array_shift($languageIDs);
             }
         }
     }
 }