Dotclear

source: inc/admin/lib.admincombos.php @ 1719:b8c48f380463

Revision 1719:b8c48f380463, 4.9 KB checked in by Dsls, 12 years ago (diff)

Added dcAdminCombos utility class, lots of combos available from everywhere now. Closes #1599

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[str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').
36                    html::escapeHTML($categories->cat_title).
37                    ' ('.$categories->nb_post.')'] = $categories->cat_id;
38          }
39          return $categories_combo;
40     }
41     
42     /**
43     Returns available post status combo
44     
45     @return   <b>array</b> the combo box (form::combo -compatible format)
46     */
47     public static function getPostStatusesCombo() {
48          $status_combo =  array();
49          foreach (self::$core->blog->getAllPostStatus() as $k => $v) {
50               $status_combo[$v] = (string) $k;
51          }
52          return $status_combo;
53     }
54     
55     /**
56     Returns an users combo from a users record
57     
58     @param    users          <b>record</b>       the users record
59     @return   <b>array</b> the combo box (form::combo -compatible format)
60     */
61     public static function getUsersCombo($users) {
62          $users_combo = array();
63          while ($users->fetch())
64          {
65               $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name,
66               $users->user_firstname,$users->user_displayname);
67               
68               if ($user_cn != $users->user_id) {
69                    $user_cn .= ' ('.$users->user_id.')';
70               }
71               
72               $users_combo[$user_cn] = $users->user_id; 
73          }
74          return $users_combo;
75     }
76     
77     /**
78     Returns an date combo from a date record
79     
80     @param    dates          <b>record</b>       the dates record
81     @return   <b>array</b> the combo box (form::combo -compatible format)
82     */   
83     public static function getDatesCombo($dates) {
84          $dt_m_combo= array();
85          while ($dates->fetch()) {
86               $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month();
87          }         
88          return $dt_m_combo;
89     }
90     
91     /**
92     Returns an lang combo from a lang record
93     
94     @param    langs          <b>record</b>       the langs record
95     @param    with_available <b>boolean</b> if false, only list items from record
96                                                       if true, also list available languages
97     @return   <b>array</b> the combo box (form::combo -compatible format)
98     */   
99     public static function getLangsCombo($langs,$with_available=false) {
100          if ($with_available) {
101               $all_langs = l10n::getISOcodes(0,1);
102               $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
103               while ($langs->fetch()) {
104                    if (isset($all_langs[$langs->post_lang])) {
105                         $lang_combo[__('Most used')][$all_langs[$langs->post_lang]] = $langs->post_lang;
106                         unset($lang_combo[__('Available')][$all_langs[$langs->post_lang]]);
107                    } else {
108                         $lang_combo[__('Most used')][$langs->post_lang] = $langs->post_lang;
109                    }
110               }
111               unset($all_langs);
112          } else {
113               $lang_combo = array();
114               while ($langs->fetch()) {
115                    $lang_combo[$langs->post_lang] = $langs->post_lang;
116               }
117          }
118          return $lang_combo;
119     }
120     
121     /**
122     Returns a combo containing all available and installed languages for administration pages
123     
124     @return   <b>array</b> the combo box (form::combo -compatible format)
125     */   
126     public static function getAdminLangsCombo() {
127          $lang_combo = array();
128          $langs = l10n::getISOcodes(1,1);
129          foreach ($langs as $k => $v) {
130               $lang_avail = $v == 'en' || is_dir(DC_L10N_ROOT.'/'.$v);
131               $lang_combo[] = new formSelectOption($k,$v,$lang_avail ? 'avail10n' : '');
132          }
133          return $lang_combo;
134     }
135     
136     /**
137     Returns a combo containing all available formaters in admin
138     
139     @return   <b>array</b> the combo box (form::combo -compatible format)
140     */   
141     public static function getFormatersCombo() {
142          foreach (self::$core->getFormaters() as $v) {
143               $formaters_combo[$v] = $v;
144          }
145          return $formaters_combo;
146     }
147     
148     /**
149     Returns a combo containing available blog statuses
150     
151     @return   <b>array</b> the combo box (form::combo -compatible format)
152     */   
153     public static function getBlogStatusesCombo() {
154          $status_combo = array();
155          foreach (self::$core->getAllBlogStatus() as $k => $v) {
156               $status_combo[$v] = (string) $k;
157          }
158          return $status_combo;
159     }
160     
161     /**
162     Returns a combo containing available comment statuses
163     
164     @return   <b>array</b> the combo box (form::combo -compatible format)
165     */   
166     public static function getCommentStatusescombo() {
167          $status_combo = array();
168          foreach (self::$core->blog->getAllCommentStatus() as $k => $v) {
169               $status_combo[$v] = (string) $k;
170          }
171          return $status_combo;
172     }
173}
174dcAdminCombos::$core = $GLOBALS['core'];
Note: See TracBrowser for help on using the repository browser.

Sites map