Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • 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

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