/**
  * Adds a form multiple times in a table
  *
  * You can add your own 'form' either to the model or here in the parameters.
  * Otherwise a form of the same class as the parent form will be created.
  *
  * All elements not yet added to the form are added using a new FormBridge
  * instance using the default label / non-label distinction.
  *
  * @param string $name Name of element
  * @param mixed $arrayOrKey1 \MUtil_Ra::pairs() name => value array
  * @return \MUtil_Form_Element_Table
  */
 public function addFormTabs($parentBridge, $name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null)
 {
     $options = func_get_args();
     $options = \MUtil_Ra::pairs($options, 2);
     /*$options = $this->_mergeOptions($name, $options,
       self::SUBFORM_OPTIONS);*/
     //\MUtil_Echo::track($options);
     if (isset($options['form'])) {
         $form = $options['form'];
         unset($options['form']);
     } else {
         $formClass = get_class($parentBridge->getForm());
         $form = new $formClass();
     }
     $parentForm = $parentBridge->getForm();
     $submodel = $parentBridge->getModel()->get($name, 'model');
     if ($submodel instanceof \MUtil_Model_ModelAbstract) {
         $bridge = $submodel->getBridgeFor('form', $form);
         $subItemNumber = 0;
         foreach ($submodel->getItemsOrdered() as $itemName) {
             if (!$form->getElement($name)) {
                 if ($submodel->has($itemName, 'label')) {
                     $bridge->add($itemName);
                     $subelement = $form->getElement($itemName);
                 } else {
                     $bridge->addHidden($itemName);
                 }
             }
         }
     }
     $form->activateJQuery();
     $element = new \Gems_Form_Element_Tabs($form, $name, $options);
     $parentBridge->getForm()->addElement($element);
     return $element;
 }
 /**
  * Set one or more attributes for a field names in the model.
  *
  * @see \MUtil_Model_ModelAbstract->set()
  *
  * @param string $name The fieldname
  * @param mixed  $arrayOrKey1 A key => value array or the name of the first key, see \MUtil_Args::pairs()
  * @param mixed  $value1      The value for $arrayOrKey1 or null when $arrayOrKey1 is an array
  * @param string $key2        Optional second key when $arrayOrKey1 is a string
  * @param mixed  $value2      Optional second value when $arrayOrKey1 is a string,
  *                            an unlimited number of $key values pairs can be given.
  * @return \MUtil_Model_ModelTransformerAbstract
  */
 public function set($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null)
 {
     $args = func_get_args();
     $args = \MUtil_Ra::pairs($args, 1);
     if ($args) {
         foreach ($args as $key => $value) {
             // If $key end with ] it is array value
             if (substr($key, -1) == ']') {
                 if (substr($key, -2) == '[]') {
                     // If $key ends with [], append it to array
                     $key = substr($key, 0, -2);
                     $this->_fields[$name][$key][] = $value;
                 } else {
                     // Otherwise extract subkey
                     $pos = strpos($key, '[');
                     $subkey = substr($key, $pos + 1, -1);
                     $key = substr($key, 0, $pos);
                     $this->_fields[$name][$key][$subkey] = $value;
                 }
             } else {
                 $this->_fields[$name][$key] = $value;
             }
         }
     } elseif (!array_key_exists($name, $this->_fields)) {
         $this->_fields[$name] = array();
     }
     return $this;
 }
Пример #3
0
 /**
  * Searches and loads multiple .php snippet file.
  *
  * @param string $filenames Array of snippet names with optionally extra parameters included
  * @param \MUtil_Ra::pairs $parameter_value_pairs name/value pairs ot add to the source for this snippet
  * @return array Of filename => \MUtil_Snippets_SnippetInterface snippets
  */
 public function getSnippets($filenames, $parameter_value_pairs = null)
 {
     if (func_num_args() > 1) {
         $extraSourceParameters = \MUtil_Ra::pairs(func_get_args(), 1);
     } else {
         $extraSourceParameters = array();
     }
     if (is_array($filenames)) {
         list($filenames, $params) = \MUtil_Ra::keySplit($filenames);
         if ($params) {
             $extraSourceParameters = $params + $extraSourceParameters;
         }
     } else {
         $filenames = array($filenames);
     }
     $results = array();
     if ($filenames) {
         $loader = $this->getSnippetLoader();
         foreach ($filenames as $filename) {
             $results[$filename] = $loader->getSnippet($filename, $extraSourceParameters);
         }
     }
     return $results;
 }
Пример #4
0
 /**
  * Add a field to add a totals row on.
  *
  * The other parameters contains fixed field values for that row, e.g. a fixed value:
  *
  * <code>
  * $transformer->addTotal('groupField', 'rowClass', 'total');
  * </code>
  *
  * or a lookup array:
  *
  * <code>
  * $transformer->addTotal('groupField', 'labelField', array('x' => 'Total for X', 'y' => 'Total for Y'));
  * </code>
  *
  * or a callable:
  *
  * <code>
  * $transformer->addTotal('groupField', 'labelField', function ($value, $keyField) {sprintf('Total %d', $value);});
  * </code>
  *
  * for as many fields as required.
  *
  * @param type $field
  * @param type $fixedFieldsArrayOrName1
  * @param type $fixedFieldsValue1
  * @return \MUtil\Model\Transform\SumTotalTransformer
  */
 public function addTotal($field, $fixedFieldsArrayOrName1 = null, $fixedFieldsValue1 = null)
 {
     $args = \MUtil_Ra::pairs(func_get_args(), 1);
     $fixed = array();
     foreach ($args as $fixedName => $value) {
         if (is_callable($value)) {
             $fixed['calls'][$fixedName] = $value;
         } elseif (is_array($value)) {
             $fixed['arrays'][$fixedName] = $value;
         } elseif (true === $value) {
             $fixed['values'][$fixedName] = $fixedName;
         } else {
             $fixed['string'][$fixedName] = $value;
         }
         // Make sure the fields are known to the model
         $this->_fields[$fixedName] = array();
     }
     $this->_summarizeOn[$field] = $fixed;
     return $this;
 }
Пример #5
0
 public function addElementFunction($name_1, $function_1, $name_n = null, $function_n = null)
 {
     $args = \MUtil_Ra::pairs(func_get_args());
     $this->setElementFunctionList($args, true);
     return $this;
 }
Пример #6
0
 /**
  *
  * @param string $name Snippet name
  * @param \MUtil_Ra::pairs $parameter_value_pairs Optional extra snippets
  * @return \MUtil_Snippets_SnippetInterface
  */
 public static function snippet($name, $parameter_value_pairs = null)
 {
     if (func_num_args() > 1) {
         $extraSourceParameters = \MUtil_Ra::pairs(func_get_args(), 1);
     } else {
         $extraSourceParameters = array();
     }
     if (is_array($name)) {
         list($names, $params) = \MUtil_Ra::keySplit($name);
         if ($params) {
             $extraSourceParameters = $params + $extraSourceParameters;
         }
         if (isset($names[0])) {
             $name = $names[0];
         } else {
             throw new \MUtil_Html_HtmlException('Missing snippet name in call to create snippet.');
         }
     }
     $loader = self::getSnippetLoader();
     $snippet = $loader->getSnippet($name, $extraSourceParameters);
     if ($snippet->hasHtmlOutput()) {
         return $snippet;
     }
 }
Пример #7
0
 /**
  * Set attributes for a specified array of field names in the model.
  *
  * Example:
  * <code>
  * $this->setMulti(array('field_x', 'field_y'), 'save', true) ;
  * $this->setMulti(array('field_x', 'field_y'), array('save' => true)) ;
  * </code>
  * both set the attribute 'save' to true for 'field_x' and 'field_y'.
  *
  * @param array $names An array of fieldnames
  * @param string|array $arrayOrKey1 A key => value array or the name of the first key
  * @param mixed $value1 The value for $arrayOrKey1 or null when $arrayOrKey1 is an array
  * @param string $key2 Optional second key when $arrayOrKey1 is a string
  * @param mixed $value2 Optional second value when $arrayOrKey1 is a string, an unlimited number of $key values pairs can be given.
  * @return \MUtil_Model_ModelAbstract (continuation pattern)
  */
 public function setMulti(array $names, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null)
 {
     $args = func_get_args();
     $args = \MUtil_Ra::pairs($args, 1);
     foreach ($names as $name) {
         $this->set($name, $args);
     }
     return $this;
 }
 public function setParameterFilter($arrayOrKey1 = null, $value1 = null)
 {
     $filter = \MUtil_Ra::pairs(func_get_args());
     $this->_parameterFilter = $filter;
     return $this;
 }
Пример #9
0
 public function addToggleCheckboxes($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null)
 {
     $options = $this->_mergeOptions($name, \MUtil_Ra::pairs(func_get_args(), 1), self::DISPLAY_OPTIONS, array('selector', 'selectorName'));
     if (!isset($options['label'])) {
         if (isset($options['selectorName']) && $this->model->has($options['selectorName'], 'label')) {
             $options['label'] = sprintf('Toggle %s', $this->model->get($options['selectorName'], 'label'));
         } else {
             $options['label'] = 'Toggle';
         }
     }
     if (isset($options['selectorName'])) {
         $options['selector'] = sprintf('input[name^=%s]', $options['selectorName']);
         unset($options['selectorName']);
     }
     $this->form->activateJQuery();
     if (\MUtil_Bootstrap::enabled() || !class_exists('Gems_JQuery_Form_Element_ToggleCheckboxes')) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes($name, $options);
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes($name, $options);
     }
     $this->form->addElement($element);
     return $element;
 }
Пример #10
0
 /**
  * Setting DeleteValues means delete() updates the selected rows with these values, instead of physically deleting the rows.
  *
  * @param string|array $arrayOrField1 \MUtil_Ra::pairs() arguments
  * @param mxied $value1
  * @param string $field2
  * @param mixed $key2
  * @return \MUtil_Model_DatabaseModelAbstract (continuation pattern)
  */
 public function setDeleteValues($arrayOrField1 = null, $value1 = null, $field2 = null, $key2 = null)
 {
     $args = \MUtil_Ra::pairs(func_get_args());
     $this->_deleteValues = $args;
     return $this;
 }