/**
  * @expectedException \RuntimeException
  */
 public function testCanSetListData()
 {
     $l1 = ['1', '2', '3'];
     $l2 = '1,2,3';
     $list = new ListField();
     $list->setData($l1);
     $this->assertTrue(is_array($list->getData()));
     $this->assertCount(3, $list->getData());
     $list->setData($l2);
     $this->assertTrue(is_array($list->getData()));
     $this->assertCount(3, $list->getData());
     $list->setDelimiter($delimiter = '|');
     $this->assertEquals($list->getDelimiter(), '|');
     $list->setData(new \stdClass());
 }
 /**
  * dbListField::dbListField()
  *
  * Create a new dbListField object
  *
  * @param object &$oForm: the form where the datefield is located on
  * @param string $sName: the name of the datefield
  * @param object $oDb: object of the database handler
  * @param string $sTable: the table to get the fields from
  * @param mixed $mFields: array of string with the names of the fields which data we should get
  * @param string $sExtraSQL: extra SQL statements
  * @return dbListField
  * @access public
  * @author Teye Heimans
  */
 function dbListField(&$oForm, $sName, &$oDb, $sTable, $mFields, $sExtraSQL = null)
 {
     // make sure that the fields are set in an array
     $aFields = !is_array($mFields) ? array($mFields) : $mFields;
     // generate the query to retrieve the records
     $sQuery = 'SELECT ' . implode(', ', $aFields) . ' FROM ' . $oDb->quote($sTable) . ' ' . $sExtraSQL;
     // get the records and load the options
     $aOptions = array();
     // execute the query
     $sql = $oDb->query($sQuery);
     // query succeeded?
     if ($sql) {
         // fetch the results
         while ($row = $oDb->getRecord($sql)) {
             if (sizeof($row) == 1) {
                 $aOptions[] = array_shift($row);
             } else {
                 $aOptions[array_shift($row)] = array_shift($row);
             }
         }
     } else {
         trigger_error("Error, could not retrieve records.<br '. FH_XHTML_CLOSE .'>\n" . "Error message: " . $oDb->getError() . "<br '. FH_XHTML_CLOSE .'>\n" . "Query: " . $sQuery, E_USER_WARNING);
     }
     // call the constructor of the listfield with the new options
     parent::ListField($oForm, $sName, $aOptions);
     // if two fields are given, use the first field as value
     $this->useArrayKeyAsValue(sizeof($aFields) == 2);
 }
 /**
  * @inheritdoc
  */
 protected function view()
 {
     $parent = parent::view();
     $parentModel = $this->model->parents(1)->one();
     if ($parentModel) {
         $parent['value'] = $parentModel->{$this->viewAttr};
     }
     return $parent;
 }
 public function __construct($id, $name, $label, $regexp, $dir, $recursdirs = false, $length = 10, $requested = false, $help = NULL)
 {
     $this->regexp = $regexp;
     $this->dir = $dir;
     $this->recursdirs = $recursdirs;
     $this->options = array();
     $this->getFiles($dir);
     //		$options = glob($mask);
     parent::__construct($id, $name, $label, $this->options, $length, $requested, $regexp, $help);
     $this->type = "filelist";
 }
 /**
  * FormHandler::listField()
  *
  * Create a listField on the form
  *
  * @param string $title: The title of the field
  * @param string $name: The name of the field
  * @param array $options: The options used for the field
  * @param string $validator: The validator which should be used to validate the value of the field
  * @param string $onTitle: The title used above the ON section of the field
  * @param string $offTitle: The title used above the OFF section of the field
  * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
  * @param int $size: The size of the field (how many options are displayed)
  * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  * @param string $verticalMode: Verticalmode
  * @return void
  * @access public
  * @author Teye Heimans
  */
 function listField($title, $name, $options, $validator = null, $useArrayKeyAsValue = null, $onTitle = null, $offTitle = null, $size = null, $extra = null, $verticalMode = null)
 {
     require_once FH_INCLUDE_DIR . 'fields/class.SelectField.php';
     require_once FH_INCLUDE_DIR . 'fields/class.ListField.php';
     // options has to be an array
     if (!is_array($options)) {
         trigger_error("You have to give an array as value with the listfield '{$name}'", E_USER_WARNING);
         return;
     }
     // create a listfield
     $fld = new ListField($this, $name, $options);
     if (!empty($validator)) {
         $fld->setValidator($validator);
     }
     if (!is_null($useArrayKeyAsValue)) {
         $fld->useArrayKeyAsValue($useArrayKeyAsValue);
     }
     if (!empty($size)) {
         $fld->setSize($size);
     }
     if (!empty($extra)) {
         $fld->setExtra($extra);
     }
     if (!empty($onTitle)) {
         $fld->setOnTitle($onTitle);
     }
     if (!empty($offTitle)) {
         $fld->setOffTitle($offTitle);
     }
     if (!empty($verticalMode)) {
         $fld->setVerticalMode($verticalMode);
     }
     // register the field
     $this->_registerField($name, $fld, $title);
 }
 private static function parseReportBlueprint($xml)
 {
     $blueprint = new ReportBlueprint((string) $xml['key']);
     $blueprint->setName((string) $xml['name']);
     $blueprint->setRowIdKey((string) $xml['rowIdKey']);
     $blueprint->setQuery((string) $xml->query);
     // list fields (double as report fields)
     foreach ($xml->field as $f) {
         $field = new ListField((string) $f['key']);
         $field->setDisplayName((string) $f->displayName);
         $field->setFormat((string) $f->format);
         $field->setHref((string) $f->href);
         $blueprint->add($field);
     }
     return $blueprint;
 }
echo "<h1>Testing ReportTableDrafter</h1>";
$reportBP = ReportBlueprint::reportBlueprintWithQuery("SELECT * FROM Member", "id", "MemberList");
$drafter = new ReportTableDrafter($reportBP);
echo $drafter->render();
/*
// #3
*/
echo "<h1>Testing ReportTableDrafter with Specific Fields</h1>";
$reportBP = ReportBlueprint::reportBlueprintWithQuery("SELECT * FROM Member", "id", "MemberList");
$login = new ListField("login");
$login->setDisplayName("Login");
$reportBP->add($login);
$passwd = new ListField("passwd");
$passwd->setDisplayName("Secret Key");
$passwd->setFormat("password");
$reportBP->add($passwd);
$email = new ListField("email");
$email->setDisplayName("Email Address");
$email->setHref("/admin/members/send-email.php?id={id}");
$reportBP->add($email);
$params = array();
$params["order"] = "modified DESC";
$params["where"] = "login IS NOT NULL";
$actions = array();
$deleteAction = ReportAction::initWith("delete", ReportAction::REPORT_ACTION_TARGET_TYPE_COLLECTION, "Delete", "alert('Dummy!')");
$actions[] = $deleteAction;
$viewAction = ReportAction::initWith("view", ReportAction::REPORT_ACTION_TARGET_TYPE_ROW, "Details", "alert('Sure')");
$actions[] = $viewAction;
$params["actions"] = $actions;
$drafter = new ReportTableDrafter($reportBP, $params);
echo $drafter->render();