コード例 #1
0
ファイル: display.php プロジェクト: Sajaki/customisation-db
 /**
  * Generate the category select (much is from the make_jumpbox function)
  *
  * @param array|bool $selected		Array of selected categories. Defaults to false.
  * @param bool $is_manage			Whether in category management, in which case all are listed
  * @param bool $disable_parents		Whether to disable categories that do not have a contribution type
  * @param bool|int $category_type	Category type to limit list to
  * @return void
  */
 public function generate_category_select($selected = false, $is_manage = false, $disable_parents = true, $category_type = false)
 {
     if (!is_array($selected)) {
         $selected = array($selected);
     }
     $right = $padding = 0;
     $padding_store = array('0' => 0);
     $categories = $this->cache->get_categories();
     $hidden_categories = array();
     $category = new \titania_category();
     foreach ($categories as $row) {
         $type = $this->types->get($row['category_type']);
         if ($type && (!$type->acl_get('submit') || $category_type && $type->id != $category_type)) {
             continue;
         }
         $category->__set_array($row);
         if ($row['left_id'] < $right) {
             $padding++;
             $padding_store[$row['parent_id']] = $padding;
         } else {
             if ($row['left_id'] > $right + 1) {
                 $padding = isset($padding_store[$row['parent_id']]) ? $padding_store[$row['parent_id']] : $padding;
             }
         }
         $right = $row['right_id'];
         if (!$is_manage) {
             // Non-postable category with no children, don't display
             $not_postable = $row['category_type'] == 0 && $row['left_id'] + 1 == $row['right_id'];
             $hidden = !$row['category_visible'] || in_array($row['parent_id'], $hidden_categories);
             $team_only_restriction = $category->is_option_set('team_only') && !$type->acl_get('moderate');
             if ($not_postable || $hidden || $team_only_restriction) {
                 if ($hidden) {
                     $hidden_categories[] = $row['category_id'];
                 }
                 continue;
             }
         }
         $this->template->assign_block_vars('category_select', array('S_SELECTED' => in_array($row['category_id'], $selected), 'S_DISABLED' => $row['category_type'] == 0 && $disable_parents, 'VALUE' => $row['category_id'], 'TYPE' => $row['category_type'], 'NAME' => $category->get_name()));
         for ($i = 0; $i < $padding; $i++) {
             $this->template->assign_block_vars('category_select.level', array());
         }
     }
 }
コード例 #2
0
    /**
     * Set the relations between contribs and categories
     *
     * @param array $contrib_categories		Categories to put the contribution in
     * @param bool $protect_team_only		Whether to protect "Team only" categories.
     *	If true, existing categories that are "Team only" and are not part of $contrib_categories
     *	will be preserved.
     *
     * @return null
     */
    public function put_contrib_in_categories($contrib_categories = array(), $protect_team_only = true)
    {
        if (!$this->contrib_id) {
            return;
        }
        $protected_categories = array();
        $exclude_sql = '';
        if ($protect_team_only && !empty($this->category_data)) {
            $category = new \titania_category();
            foreach ($this->category_data as $row) {
                $category->__set_array($row);
                if ($category->is_option_set('team_only')) {
                    $protected_categories[] = (int) $category->category_id;
                }
            }
        }
        if (!empty($protected_categories)) {
            $exclude_sql = 'AND ' . phpbb::$db->sql_in_set('category_id', $protected_categories, true);
        }
        // Resync the count
        $this->update_category_count('-');
        // Remove them from the old categories
        $sql = 'DELETE
			FROM ' . TITANIA_CONTRIB_IN_CATEGORIES_TABLE . '
			WHERE contrib_id = ' . $this->contrib_id . "\n\t\t\t\t{$exclude_sql}";
        phpbb::$db->sql_query($sql);
        if (!sizeof($contrib_categories)) {
            return;
        }
        $sql_ary = array();
        foreach ($contrib_categories as $category_id) {
            $sql_ary[] = array('contrib_id' => $this->contrib_id, 'category_id' => $category_id);
        }
        phpbb::$db->sql_multi_insert(TITANIA_CONTRIB_IN_CATEGORIES_TABLE, $sql_ary);
        $this->contrib_categories = implode(',', array_merge($contrib_categories, $protected_categories));
        $this->fill_categories();
        // Resync the count
        $this->update_category_count();
    }