示例#1
0
 /**
  * Retrieves markup/code of databrowser to be embedded in view.
  *
  * @return string markup/code of databrowser
  */
 public function getCode()
 {
     // get items to render in databrowser
     try {
         $this->processInput();
         $items = $this->getItems();
     } catch (\RuntimeException $e) {
         return markup::paragraph(markup::emphasize(_L('Failed to query datasource for listing items.')));
     }
     // render table including related pager widget
     if (count($items)) {
         // fetch form to use optionally
         $form = $this->getForm();
         $volatiles = _A(config::get('databrowser.volatiles', array()))->elements;
         $available = input::listNames();
         foreach ($volatiles as $volatile) {
             if (in_array($volatile, $available)) {
                 $form->setHidden($volatile, input::vget($volatile));
             }
         }
         // split items into raw data and additionally delivered data per row
         $rows = $extras = array();
         foreach ($items as $key => $row) {
             $rows[$key] = $row;
             unset($rows[$key]['|extra']);
             $extras[$key] = $row['|extra'];
         }
         // use local callback to wrap custom cell formatter for enriching
         // with additional data per row
         $browser = $this;
         $cellFormatter = function ($value, $name, $item, $id) use($browser, $extras) {
             return $browser->formatCell($value, $name, $item, $id, $extras[$id]);
         };
         // render table view
         $id = $form ? null : $this->datasource->name();
         $table = html::arrayToTable($rows, $id, $cellFormatter, array(&$this, 'formatHeader'), '', '', $this->className);
         $code = $this->pager . $table;
         // wrap rendered table view in form
         if ($form && !$this->callerForm) {
             $code = (string) $form->addContent($code);
         }
         // return code of rendered databrowser
         return $code;
     }
     $text = $this->emptyText ? $this->emptyText : _L('There is no data to be listed here ...');
     return markup::paragraph(markup::emphasize($text), trim($this->className . ' empty-text'));
 }
示例#2
0
 public function __call($method, $arguments)
 {
     /**
      * implement convenience methods for describing forms
      *
      * @example
      *  $form->setTexteditRow( 'username', 'Your Login' );
      *  $form->setTextAreaRow( 'message', 'Your Message', 'Type your message here ...' );
      *  $form->setPASSWoRDRow( 'token', 'Your Password' );
      *
      *  $form->setButtonRow( 'Submit', 'Cancel' );
      *
      *  $form->setSelectorRow( 'gender', 'Your Gender', array( 'm' => 'male', 'f' => 'female' ), 'm' );
      *
      */
     if (substr($method, 0, 3) === 'set' && substr($method, -3) === 'Row') {
         // normalize segment in method name to match markup-template
         $type = strtolower(substr($method, 3, -3));
         // get arguments depending on selected template
         switch ($type) {
             case 'selector':
             case 'multiselector':
                 list($name, $label, $options, $value) = array_splice($arguments, 0, 4);
                 break;
             case 'textarea':
                 list($name, $label, $value, $rows, $columns) = array_splice($arguments, 0, 5);
                 break;
             default:
                 list($name, $label, $value) = array_splice($arguments, 0, 3);
         }
         // auto-integrate available input
         if ($type !== 'button') {
             $value = input::vget($name, $value);
         }
         // recompile arguments to use in call for markup-template
         switch ($type) {
             case 'selector':
                 $args = array($name, $options, $value);
                 break;
             case 'multiselector':
                 $type = 'selector';
                 $args = array($name, $options, $value, null, true);
                 break;
             case 'button':
                 $args = array($name, $value, $label);
                 $label = null;
                 break;
             case 'file':
                 $type = 'upload';
             case 'upload':
                 $args = array($name);
                 break;
             case 'password':
                 $args = array($name);
                 break;
             case 'textarea':
                 $args = array($name, $value, '', $rows, $columns);
                 break;
             case 'static':
                 $type = 'inline';
                 $args = array($value);
                 break;
             default:
                 $args = array($name, $value);
         }
         // add row to form using markup-template for rendering content
         $template = array('de\\toxa\\txf\\markup', $type);
         $code = call_user_func_array($template, $args);
         // compile arguments to use on adding row (including extra information optionally given in call to this magic caller)
         array_unshift($arguments, $code);
         array_unshift($arguments, $label);
         array_unshift($arguments, $name);
         call_user_func_array(array(&$this, 'setRow'), $arguments);
     } else {
         throw new \BadMethodCallException(sprintf('invalid call for method html_form::%s(), choose set*Row() instead', $method));
     }
     return $this;
 }
示例#3
0
文件: pager.php 项目: cepharum/txf
 /**
  * Retrieves current number of records to skip.
  *
  * @return integer number of items to skip
  */
 public function offset()
 {
     $offset = $this->isVolatile !== false ? input::vget($this->offsetName, 0, input::FORMAT_INTEGER) : input::get($this->offsetName, 0, input::FORMAT_INTEGER);
     return max(0, min($this->itemCount - ($this->showFullFinalPage() ? $this->size() : 1), $offset));
 }
示例#4
0
文件: captcha.php 项目: cepharum/txf
 /**
  * Detects if any response by user is matching captcha's expected response.
  *
  * @return bool
  */
 public function check()
 {
     if ($this->valid === null) {
         $info =& $this->generate();
         $name = $info['name'];
         if ($name) {
             $this->valid = !!$this->isValid($info['a'], $info['b'], input::vget($name));
         } else {
             $this->valid = false;
         }
         // always generate new captcha
         $this->generate(true);
     }
     return $this->valid;
 }