Dotclear

source: inc/admin/lib.admincombos.php @ 1774:147afd09394c

Revision 1774:147afd09394c, 5.1 KB checked in by Dsls, 12 years ago (diff)

fixed categories combo "same name conflict". Hats off Franck for the clue! see #1564

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13/**
14@ingroup DC_CORE
15@nosubgrouping
16@brief Admin combo library
17
18Dotclear utility class that provides reuseable combos across all admin
19
20*/
21class dcAdminCombos {
22
23     /** @var dcCore dcCore instance */
24     public static $core;
25     
26     /**
27     Returns an hierarchical categories combo from a category record
28     
29     @param    categories          <b>record</b>       the category record
30     @return   <b>array</b> the combo box (form::combo -compatible format)
31     */
32     public static function getCategoriesCombo($categories) {
33          $categories_combo[__('(No cat)')] = '';
34          while ($categories->fetch()) {
35               $categories_combo[] = new formSelectOption (
36                    str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').
37                    html::escapeHTML($categories->cat_title).' ('.$categories->nb_post.')',
38                    $categories->cat_id
39               );
40          }
41          return $categories_combo;
42     }
43     
44     /**
45     Returns available post status combo
46     
47     @return   <b>array</b> the combo box (form::combo -compatible format)
48     */
49     public static function getPostStatusesCombo() {
50          $status_combo =  array();
51          foreach (self::$core->blog->getAllPostStatus() as $k => $v) {
52               $status_combo[$v] = (string) $k;
53          }
54          return $status_combo;
55     }
56     
57     /**
58     Returns an users combo from a users record
59     
60     @param    users          <b>record</b>       the users record
61     @return   <b>array</b> the combo box (form::combo -compatible format)
62     */
63     public static function getUsersCombo($users) {
64          $users_combo = array();
65          while ($users->fetch())
66          {
67               $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name,
68               $users->user_firstname,$users->user_displayname);
69               
70               if ($user_cn != $users->user_id) {
71                    $user_cn .= ' ('.$users->user_id.')';
72               }
73               
74               $users_combo[$user_cn] = $users->user_id; 
75          }
76          return $users_combo;
77     }
78     
79     /**
80     Returns an date combo from a date record
81     
82     @param    dates          <b>record</b>       the dates record
83     @return   <b>array</b> the combo box (form::combo -compatible format)
84     */   
85     public static function getDatesCombo($dates) {
86          $dt_m_combo= array();
87          while ($dates->fetch()) {
88               $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month();
89          }         
90          return $dt_m_combo;
91     }
92     
93     /**
94     Returns an lang combo from a lang record
95     
96     @param    langs          <b>record</b>       the langs record
97     @param    with_available <b>boolean</b> if false, only list items from record
98                                                       if true, also list available languages
99     @return   <b>array</b> the combo box (form::combo -compatible format)
100     */   
101     public static function getLangsCombo($langs,$with_available=false) {
102          $all_langs = l10n::getISOcodes(0,1);
103          if ($with_available) {
104               $langs_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
105               while ($langs->fetch()) {
106                    if (isset($all_langs[$langs->post_lang])) {
107                         $langs_combo[__('Most used')][$all_langs[$langs->post_lang]] = $langs->post_lang;
108                         unset($langs_combo[__('Available')][$all_langs[$langs->post_lang]]);
109                    } else {
110                         $langs_combo[__('Most used')][$langs->post_lang] = $langs->post_lang;
111                    }
112               }
113          } else {
114               $langs_combo = array();
115               while ($langs->fetch()) {
116                    $lang_name = isset($all_langs[$langs->post_lang]) ? $all_langs[$langs->post_lang] : $langs->post_lang;
117                    $langs_combo[$lang_name] = $langs->post_lang;
118               }
119          }
120          unset($all_langs);
121          return $langs_combo;
122     }
123     
124     /**
125     Returns a combo containing all available and installed languages for administration pages
126     
127     @return   <b>array</b> the combo box (form::combo -compatible format)
128     */   
129     public static function getAdminLangsCombo() {
130          $lang_combo = array();
131          $langs = l10n::getISOcodes(1,1);
132          foreach ($langs as $k => $v) {
133               $lang_avail = $v == 'en' || is_dir(DC_L10N_ROOT.'/'.$v);
134               $lang_combo[] = new formSelectOption($k,$v,$lang_avail ? 'avail10n' : '');
135          }
136          return $lang_combo;
137     }
138     
139     /**
140     Returns a combo containing all available formaters in admin
141     
142     @return   <b>array</b> the combo box (form::combo -compatible format)
143     */   
144     public static function getFormatersCombo() {
145          foreach (self::$core->getFormaters() as $v) {
146               $formaters_combo[$v] = $v;
147          }
148          return $formaters_combo;
149     }
150     
151     /**
152     Returns a combo containing available blog statuses
153     
154     @return   <b>array</b> the combo box (form::combo -compatible format)
155     */   
156     public static function getBlogStatusesCombo() {
157          $status_combo = array();
158          foreach (self::$core->getAllBlogStatus() as $k => $v) {
159               $status_combo[$v] = (string) $k;
160          }
161          return $status_combo;
162     }
163     
164     /**
165     Returns a combo containing available comment statuses
166     
167     @return   <b>array</b> the combo box (form::combo -compatible format)
168     */   
169     public static function getCommentStatusescombo() {
170          $status_combo = array();
171          foreach (self::$core->blog->getAllCommentStatus() as $k => $v) {
172               $status_combo[$v] = (string) $k;
173          }
174          return $status_combo;
175     }
176}
177dcAdminCombos::$core = $GLOBALS['core'];
Note: See TracBrowser for help on using the repository browser.

Sites map