Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cGuiBackendHelpbox
  • cGuiFileOverview
  • cGuiFoldingRow
  • cGuiList
  • cGuiMenu
  • cGuiNavigation
  • cGuiNotification
  • cGuiObjectPager
  • cGuiPage
  • cGuiScrollList
  • cGuiSourceEditor
  • cGuiTableForm
  • cGuiTree
  • cPager
  • cTemplate
  • cTree
  • cTreeItem
  • NoteLink
  • NoteList
  • NoteListItem
  • NoteView
  • TODOLink
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the scrollable lists GUI class.
  5:  *
  6:  * @package Core
  7:  * @subpackage GUI
  8:  * @version SVN Revision $Rev:$
  9:  *
 10:  * @author Mischa Holz
 11:  * @copyright four for business AG <www.4fb.de>
 12:  * @license http://www.contenido.org/license/LIZENZ.txt
 13:  * @link http://www.4fb.de
 14:  * @link http://www.contenido.org
 15:  */
 16: 
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: /**
 20:  * Scrollable lists GUI class
 21:  *
 22:  * @package Core
 23:  * @subpackage GUI
 24:  */
 25: class cGuiScrollList {
 26: 
 27:     /**
 28:      * Data container
 29:      *
 30:      * @var array
 31:      */
 32:     public $data = Array();
 33: 
 34:     /**
 35:      * Header container
 36:      *
 37:      * @var array
 38:      */
 39:     public $header = Array();
 40: 
 41:     /**
 42:      * Number of records displayed per page
 43:      *
 44:      * @var string
 45:      */
 46:     public $resultsPerPage;
 47: 
 48:     /**
 49:      * Start page
 50:      *
 51:      * @var string
 52:      */
 53:     public $listStart;
 54: 
 55:     /**
 56:      * sortable flag
 57:      *
 58:      * @var string
 59:      */
 60:     public $sortable;
 61: 
 62:     /**
 63:      * sortlink
 64:      *
 65:      * @var cHTMLLink
 66:      */
 67:     public $sortlink;
 68: 
 69:     /**
 70:      * Table item
 71:      *
 72:      * @var unknown_type
 73:      */
 74:     public $objTable;
 75: 
 76:     /**
 77:      * Header row
 78:      *
 79:      * @var unknown_type
 80:      */
 81:     public $objHeaderRow;
 82: 
 83:     /**
 84:      * Header item
 85:      *
 86:      * @var unknown_type
 87:      */
 88:     public $objHeaderItem;
 89: 
 90:     /**
 91:      * Header item
 92:      *
 93:      * @var unknown_type
 94:      */
 95:     public $objRow;
 96: 
 97:     /**
 98:      * Header item
 99:      *
100:      * @var unknown_type
101:      */
102:     public $objItem;
103: 
104:     /*
105:      * TODO: Shouldn't $area and $frame be parameters instead of global
106:      * variables?
107:      */
108: 
109:     /**
110:      * Creates a new FrontendList object.
111:      *
112:      * @param bool $defaultstyle [optional]
113:      *         use the default style for object initializing?
114:      * @param string $action [optional]
115:      */
116:     public function __construct($defaultstyle = true, $action = "") {
117:         global $cfg, $area, $frame;
118: 
119:         $this->resultsPerPage = 0;
120:         $this->listStart = 1;
121:         $this->sortable = false;
122: 
123:         $this->objTable = new cHTMLTable();
124:         if ($defaultstyle == true) {
125:             $this->objTable->setClass("generic");
126:             $this->objTable->updateAttributes(array(
127:                 "cellpadding" => "2"
128:             ));
129:         }
130: 
131:         $this->objHeaderRow = new cHTMLTableRow();
132: 
133:         $this->objHeaderItem = new cHTMLTableHead();
134: 
135:         $this->objRow = new cHTMLTableRow();
136: 
137:         $this->objItem = new cHTMLTableData();
138: 
139:         $this->sortlink = new cHTMLLink();
140:         $this->sortlink->setStyle("color: #666666;");
141:         $this->sortlink->setCLink($area, $frame, $action);
142:     }
143: 
144:     /**
145:      * Sets the sortable flag for a specific row.
146:      *
147:      * $obj->setSortable(true);
148:      *
149:      * @param unknown_type $key
150:      * @param bool $sortable
151:      *         true or false
152:      */
153:     public function setSortable($key, $sortable) {
154:         $this->sortable[$key] = $sortable;
155:     }
156: 
157:     /**
158:      * Sets the custom parameters for sortable links
159:      *
160:      * $obj->setCustom($key, $custom);
161:      *
162:      * @param unknown_type $key
163:      *         Custom entry key
164:      * @param unknown_type $custom
165:      *         Custom entry value
166:      */
167:     public function setCustom($key, $custom) {
168:         $this->sortlink->setCustom($key, $custom);
169:     }
170: 
171:     /**
172:      * Is called when a new row is rendered
173:      *
174:      * @param unknown_type $row
175:      *         The current row which is being rendered
176:      */
177:     public function onRenderRow($row) {
178:         $this->objRow->setStyle("white-space:nowrap;");
179:     }
180: 
181:     /**
182:      * Is called when a new column is rendered.
183:      *
184:      * @param unknown_type $column
185:      *         The current column which is being rendered
186:      */
187:     public function onRenderColumn($column) {
188:     }
189: 
190:     /**
191:      * Sets header data.
192:      *
193:      * Note: This public function eats as many parameters as you specify.
194:      *
195:      * Example:
196:      * $obj->setHeader("foo", "bar");
197:      *
198:      * Make sure that the amount of parameters stays the same for all
199:      * setData calls in a single object.
200:      *
201:      * @SuppressWarnings docBlocks
202:      * @param Additional parameters (data)
203:      */
204:     public function setHeader() {
205:         $numargs = func_num_args();
206: 
207:         for ($i = 0; $i < $numargs; $i++) {
208:             $this->header[$i] = func_get_arg($i);
209:         }
210:     }
211: 
212:     /**
213:      * Sets data.
214:      *
215:      * Note: This public function eats as many parameters as you specify.
216:      *
217:      * Example:
218:      * $obj->setData(0, "foo", "bar");
219:      *
220:      * Make sure that the amount of parameters stays the same for all
221:      * setData calls in a single object. Also make sure that your index
222:      * starts from 0 and ends with the actual number - 1.
223:      *
224:      * @param int $index
225:      *         Numeric index
226:      * @SuppressWarnings docBlocks
227:      * @param Additional parameters (data)
228:      */
229:     public function setData($index) {
230:         $numargs = func_num_args();
231: 
232:         for ($i = 1; $i < $numargs; $i++) {
233:             $this->data[$index][$i] = func_get_arg($i);
234:         }
235:     }
236: 
237:     /**
238:      * Sets hidden data.
239:      *
240:      * Note: This public function eats as many parameters as you specify.
241:      *
242:      * Example:
243:      * $obj->setHiddenData(0, "foo", "bar");
244:      *
245:      * Make sure that the amount of parameters stays the same for all
246:      * setData calls in a single object. Also make sure that your index
247:      * starts from 0 and ends with the actual number - 1.
248:      *
249:      * @param int $index
250:      *         Numeric index
251:      * @SuppressWarnings docBlocks
252:      * @param Additional parameters (data)
253:      */
254:     public function setHiddenData($index) {
255:         $numargs = func_num_args();
256: 
257:         for ($i = 1; $i < $numargs; $i++) {
258:             $this->data[$index]["hiddendata"][$i] = func_get_arg($i);
259:         }
260:     }
261: 
262:     /**
263:      * Sets the number of records per page.
264:      *
265:      * @param int $numresults
266:      *         Amount of records per page
267:      */
268:     public function setResultsPerPage($numresults) {
269:         $this->resultsPerPage = $numresults;
270:     }
271: 
272:     /**
273:      * Sets the starting page number.
274:      *
275:      * @param int $startpage
276:      *         Page number on which the list display starts
277:      */
278:     public function setListStart($startpage) {
279:         $this->listStart = $startpage;
280:     }
281: 
282:     /**
283:      * Returns the current page.
284:      *
285:      * @return int
286:      *         Current page number
287:      */
288:     public function getCurrentPage() {
289:         if ($this->resultsPerPage == 0) {
290:             return 1;
291:         }
292: 
293:         return $this->listStart;
294:     }
295: 
296:     /**
297:      * Returns the amount of pages.
298:      *
299:      * @return float
300:      *         Amount of pages
301:      */
302:     public function getNumPages() {
303:         return ceil(count($this->data) / $this->resultsPerPage);
304:     }
305: 
306:     /**
307:      * Sorts the list by a given field and a given order.
308:      *
309:      * @param int $field
310:      *         Field index
311:      * @param string|int $order
312:      *         Sort order (see php's sort documentation)
313:      */
314:     public function sort($field, $order) {
315:         if ($order == "") {
316:             $order = SORT_ASC;
317:         }
318: 
319:         if ($order == "ASC") {
320:             $order = SORT_ASC;
321:         }
322: 
323:         if ($order == "DESC") {
324:             $order = SORT_DESC;
325:         }
326: 
327:         $this->sortkey = $field;
328:         $this->sortmode = $order;
329: 
330:         $field = $field + 1;
331:         $this->data = cArray::csort($this->data, "$field", $order);
332:     }
333: 
334:     /**
335:      * Field converting facility.
336:      * Needs to be overridden in the child class to work properbly.
337:      *
338:      * @param unknown_type $field
339:      *         Field index
340:      * @param unknown_type $value
341:      *         Field value
342:      * @param unknown_type $hiddendata
343:      * @return unknown
344:      */
345:     public function convert($field, $value, $hiddendata) {
346:         return $value;
347:     }
348: 
349:     /**
350:      * Outputs or optionally returns
351:      *
352:      * @param bool $return [optional]
353:      *         If true, returns the list
354:      * @return string|void
355:      */
356:     public function render($return = true) {
357:         global $cfg;
358: 
359:         $currentpage = $this->getCurrentPage();
360: 
361:         $itemstart = (($currentpage - 1) * $this->resultsPerPage) + 1;
362: 
363:         $headeroutput = "";
364:         $output = "";
365: 
366:         /* Render header */
367:         foreach ($this->header as $key => $value) {
368:             if (is_array($this->sortable)) {
369:                 if (array_key_exists($key, $this->sortable) && $this->sortable[$key] == true) {
370:                     $this->sortlink->setContent($value);
371:                     $this->sortlink->setCustom("sortby", $key);
372: 
373:                     if ($this->sortkey == $key && $this->sortmode == SORT_ASC) {
374:                         $this->sortlink->setCustom("sortmode", "DESC");
375:                     } else {
376:                         $this->sortlink->setCustom("sortmode", "ASC");
377:                     }
378: 
379:                     $this->objHeaderItem->setContent($this->sortlink->render());
380:                     $headeroutput .= $this->objHeaderItem->render();
381:                 } else {
382:                     $this->objHeaderItem->setContent($value);
383:                     $headeroutput .= $this->objHeaderItem->render();
384:                 }
385:             } else {
386:                 $this->objHeaderItem->setContent($value);
387:                 $headeroutput .= $this->objHeaderItem->render();
388:             }
389:             $this->objHeaderItem->advanceID();
390:         }
391: 
392:         $this->objHeaderRow->setContent($headeroutput);
393: 
394:         $headeroutput = $this->objHeaderRow->render();
395: 
396:         if ($this->resultsPerPage == 0) {
397:             $itemend = count($this->data) - ($itemstart - 1);
398:         } else {
399:             $itemend = $currentpage * $this->resultsPerPage;
400:         }
401: 
402:         if ($itemend > count($this->data)) {
403:             $itemend = count($this->data);
404:         }
405: 
406:         for ($i = $itemstart; $i < $itemend + 1; $i++) {
407: 
408:             // At the last entry we get NULL as result
409:             // This produce an error, therefore use continue
410:             if ($this->data[$i - 1] == NULL) {
411:                 continue;
412:             }
413: 
414:             $items = "";
415: 
416:             $this->onRenderRow($i);
417: 
418:             foreach ($this->data[$i - 1] as $key => $value) {
419:                 $this->onRenderColumn($key);
420: 
421:                 if ($key != "hiddendata") {
422:                     $hiddendata = $this->data[$i - 1]["hiddendata"];
423: 
424:                     $this->objItem->setContent($this->convert($key, $value, $hiddendata));
425:                     $items .= $this->objItem->render();
426:                 }
427:                 $this->objItem->advanceID();
428:             }
429: 
430:             $this->objRow->setContent($items);
431:             $items = "";
432: 
433:             $output .= $this->objRow->render();
434:             $this->objRow->advanceID();
435:         }
436: 
437:         $this->objTable->setContent($headeroutput . $output);
438: 
439:         $output = stripslashes($this->objTable->render());
440: 
441:         if ($return == true) {
442:             return $output;
443:         } else {
444:             echo $output;
445:         }
446:     }
447: 
448: }
449: 
CMS CONTENIDO 4.9.8 API documentation generated by ApiGen 2.8.0