public function __construct($submitUrl, $targetId, $formId = null, $args = null)
 {
     // Filter out elements passed by type
     $args = \MUtil_Ra::args(func_get_args(), array('submitUrl' => array('MUtil_Html_UrlArrayAttribute', 'is_array', 'is_string'), 'targetId' => array('MUtil_Html_ElementInterface', 'is_string'), 'formId' => array('Zend_Form', 'is_string')), null, \MUtil_Ra::STRICT);
     // \MUtil_Echo::r($args);
     parent::__construct($args);
 }
예제 #2
0
 /**
  * \MUtil_Ra::args() parameter passing is allowed.
  *
  * @param string $seperatorChar
  * @param string $displaySeperator
  * @param boolean $valuePad
  */
 public function __construct($seperatorChar = ' ', $displaySeperator = ' ', $valuePad = true)
 {
     $args = \MUtil_Ra::args(func_get_args(), array('seperatorChar' => 'is_string', 'displaySeperator' => array('MUtil_Html_HtmlInterface', 'is_string'), 'valuePad' => 'is_boolean'), array('seperatorChar' => ' ', 'displaySeperator' => ' ', 'valuePad' => true));
     $this->seperatorChar = substr($args['seperatorChar'] . ' ', 0, 1);
     $this->displaySeperator = $args['displaySeperator'];
     $this->valuePad = $args['valuePad'];
 }
 /**
  * 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;
 }
예제 #4
0
 public function __construct($repeatable_args = null)
 {
     $args = \MUtil_Ra::args(func_get_args());
     foreach ($args as $id => $repeatable) {
         if (null != $repeatable) {
             $this->addRepeater($repeatable, $id);
         }
     }
 }
예제 #5
0
 /**
  * Function to allow overruling of transform for certain models
  *
  * @param \MUtil_Model_ModelAbstract $model Parent model
  * @param \MUtil_Model_ModelAbstract $sub Sub model
  * @param array $data The nested data rows
  * @param array $join The join array
  * @param string $name Name of sub model
  * @param boolean $new True when loading a new item
  * @param boolean $isPostData With post data, unselected multiOptions values are not set so should be added
  */
 protected function transformLoadSubModel(\MUtil_Model_ModelAbstract $model, \MUtil_Model_ModelAbstract $sub, array &$data, array $join, $name, $new, $isPostData)
 {
     if (1 === count($join)) {
         // Suimple implementation
         $mkey = key($join);
         $skey = reset($join);
         $mfor = \MUtil_Ra::column($mkey, $data);
         // \MUtil_Echo::track($mfor);
         if ($new) {
             $sdata = $sub->loadNew(1);
         } else {
             $sdata = $sub->load(array($skey => $mfor));
         }
         // \MUtil_Echo::track($sdata);
         if ($sdata) {
             $skeys = array_flip(\MUtil_Ra::column($skey, $sdata));
             $empty = array_fill_keys(array_keys(reset($sdata)), null);
             foreach ($data as &$mrow) {
                 $mfind = $mrow[$mkey];
                 if (isset($skeys[$mfind])) {
                     $mrow += $sdata[$skeys[$mfind]];
                 } else {
                     $mrow += $empty;
                 }
             }
         } else {
             $empty = array_fill_keys($sub->getItemNames(), null);
             foreach ($data as &$mrow) {
                 $mrow += $empty;
             }
         }
         // \MUtil_Echo::track($mrow);
     } else {
         // Multi column implementation
         $empty = array_fill_keys($sub->getItemNames(), null);
         foreach ($data as &$mrow) {
             $filter = $sub->getFilter();
             foreach ($join as $from => $to) {
                 if (isset($mrow[$from])) {
                     $filter[$to] = $mrow[$from];
                 }
             }
             if ($new) {
                 $sdata = $sub->loadNew();
             } else {
                 $sdata = $sub->loadFirst($filter);
             }
             if ($sdata) {
                 $mrow += $sdata;
             } else {
                 $mrow += $empty;
             }
             // \MUtil_Echo::track($sdata, $mrow);
         }
     }
 }
 public function __construct(array $options = null)
 {
     $args = \MUtil_Ra::args(func_get_args());
     foreach ($args as $name => $arg) {
         if (!is_int($name)) {
             if (method_exists($this, $fname = 'set' . ucfirst($name))) {
                 $this->{$fname}($arg);
             } else {
                 $this->setJQueryParam($name, $arg);
             }
         }
     }
 }
예제 #7
0
 /**
 *
 * <code>
   $select = $db->select();
   $select->from('gems__rounds', array('gro_id_track', 'gro_id_survey', 'gro_id_round', 'gro_id_order'))->where('gro_id_track = 220');
   $existing = $select->query()->fetchAll();
   \MUtil_Echo::r(\MUtil_Ra_Nested::toTree($existing), 'Auto tree');
   \MUtil_Echo::r(\MUtil_Ra_Nested::toTree($existing, 'gro_id_track', 'gro_id_survey'), 'Named tree with set at end (data loss in this case)');
   \MUtil_Echo::r(\MUtil_Ra_Nested::toTree($existing, 'gro_id_track', 'gro_id_survey', null), 'Named tree with append');
   \MUtil_Echo::r(\MUtil_Ra_Nested::toTree($existing, 'gro_id_track', null, 'gro_id_survey', null), 'Named tree with double append');
 </code>
 */
 public static function toTree(array $data, $key_args = null)
 {
     if (!$data) {
         return $data;
     }
     if (func_num_args() == 1) {
         // Get the keys of the first nested item
         $keys = array_keys(reset($data));
     } else {
         $keys = \MUtil_Ra::args(func_get_args(), 1);
     }
     $valueKeys = array_diff(array_keys(reset($data)), $keys);
     switch (count($valueKeys)) {
         case 0:
             // Drop the last item
             $valueKey = array_pop($keys);
             $valueKeys = false;
             break;
         case 1:
             $valueKey = reset($valueKeys);
             $valueKeys = false;
             break;
     }
     $results = array();
     foreach ($data as $item) {
         $current =& $results;
         foreach ($keys as $key) {
             if (null === $key) {
                 $count = count($current);
                 $current[$count] = array();
                 $current =& $current[$count];
             } elseif (array_key_exists($key, $item)) {
                 $value = $item[$key];
                 if (!array_key_exists($value, $current)) {
                     $current[$value] = array();
                 }
                 $current =& $current[$value];
             }
         }
         if ($valueKeys) {
             foreach ($valueKeys as $key) {
                 $current[$key] = $item[$key];
             }
         } else {
             $current = $item[$valueKey];
         }
     }
     return $results;
 }
 public function __construct()
 {
     $sources = \MUtil_Ra::args(func_get_args());
     $array = array();
     foreach ($sources as $key => $source) {
         // Fix for array sources.
         if (is_string($key)) {
             $array[$key] = $source;
         } else {
             $this->addSource($source);
         }
     }
     if ($array) {
         $this->addSource($array);
     }
 }
예제 #9
0
 public function addAnswers(array $inputRows)
 {
     $tokens = \MUtil_Ra::column('gto_id_token', $inputRows);
     $answerRows = $this->source->getRawTokenAnswerRows(array('token' => $tokens), $this->survey->getSurveyId());
     $emptyRow = array_fill_keys($this->getItemNames(), null);
     $resultRows = array();
     $answerTokens = \MUtil_Ra::column('token', $answerRows);
     foreach ($inputRows as $row) {
         $tokenId = $row['gto_id_token'];
         $idx = array_search($tokenId, $answerTokens);
         if ($idx !== false && isset($answerRows[$idx])) {
             $resultRows[$tokenId] = $row + $answerRows[$idx] + $emptyRow;
         } else {
             $resultRows[$tokenId] = $row + $emptyRow;
         }
     }
     return $resultRows;
 }
 /**
  * Returns a nested array containing the items requested, including answers.
  *
  * @param array $inputRows Nested rows with Gems token information
  * @return array Nested array or false
  */
 protected function addAnswers(array $inputRows)
 {
     $resultRows = $inputRows;
     $tokens = \MUtil_Ra::column('gto_id_token', $inputRows);
     // \MUtil_Echo::track($tokens);
     /*$answerRows = $this->source->getRawTokenAnswerRows(array('token' => $tokens), $this->survey->getSurveyId());
             $emptyRow   = array_fill_keys($this->getItemNames(), null);
             $resultRows = array();
     
             foreach ($inputRows as $row) {
                 $tokenId = $row['gto_id_token'];
     
                 if (isset($answerRows[$tokenId])) {
                     $resultRows[$tokenId] = $row + $answerRows[$tokenId] + $emptyRow;
                 } else {
                     $resultRows[$tokenId] = $row + $emptyRow;
                 }
             }*/
     return $resultRows;
 }
 /**
  * The transform function performs the actual transformation of the data and is called after
  * the loading of the data in the source model.
  *
  * @param \MUtil_Model_ModelAbstract $model The parent model
  * @param array $data Nested array
  * @param boolean $new True when loading a new item
  * @param boolean $isPostData With post data, unselected multiOptions values are not set so should be added
  * @return array Nested array containing (optionally) transformed data
  */
 public function transformLoad(\MUtil_Model_ModelAbstract $model, array $data, $new = false, $isPostData = false)
 {
     // get tokens
     $tokens = \MUtil_Ra::column('gto_id_token', $data);
     $answerRows = $this->source->getRawTokenAnswerRows(array('token' => $tokens), $this->survey->getSurveyId());
     $resultRows = array();
     $emptyRow = array_fill_keys($model->getItemNames(), null);
     foreach ($data as $row) {
         $tokenId = $row['gto_id_token'];
         if (isset($answerRows[$tokenId])) {
             $resultRows[$tokenId] = $row + $answerRows[$tokenId] + $emptyRow;
         } else {
             $resultRows[$tokenId] = $row + $emptyRow;
         }
     }
     //\MUtil_Echo::track($tokens);
     //\MUtil_Echo::track($resultRows);
     // No changes
     return $resultRows;
 }
예제 #12
0
 public function __construct(\MUtil_Html_PagePanel $panel, $glue = ' ', $args_array = null)
 {
     $args = \MUtil_Ra::args(func_get_args(), array('panel' => 'MUtil_Html_PagePanel', 'glue'), array('glue' => ' '));
     if (isset($args['panel'])) {
         $this->_panel = $args['panel'];
         unset($args['panel']);
     } else {
         throw new \MUtil_Html_HtmlException('Illegal argument: no panel passed to ' . __CLASS__ . ' constructor.');
     }
     if (isset($args['glue'])) {
         $this->setGlue($args['glue']);
         unset($args['glue']);
     } else {
         $this->setGlue($glue);
     }
     $page = $this->toLazy()->page;
     $args = array($page) + $args;
     // We create the element here as this creates as an element using the specifications at this moment.
     // If created at render time the settings might have changed, introducing hard to trace bugs.
     $this->_element = $panel->createPageLink($this->toLazy()->notCurrent(), $page, $args);
 }
예제 #13
0
 /**
  * Create a page panel
  *
  * @param mixed $paginator \MUtil_Ra::args() arguements
  * @param mixed $request
  * @param mixed $translator
  * @param mixed $args
  * @return \MUtil_Html_PagePanel
  */
 public static function pagePanel($paginator = null, $request = null, $translator = null, $args = null)
 {
     $types = array('paginator' => 'Zend_Paginator', 'request' => 'Zend_Controller_Request_Abstract', 'translator' => 'Zend_Translate', 'view' => 'Zend_View');
     $args = \MUtil_Ra::args(func_get_args(), $types, null, \MUtil_Ra::STRICT);
     $panel_args = array();
     foreach (array('baseUrl', 'paginator', 'request', 'scrollingStyle', 'view', 'itemCount') as $var) {
         if (isset($args[$var])) {
             $panel_args[$var] = $args[$var];
             unset($args[$var]);
         }
     }
     if (isset($args['translator'])) {
         $translator = $args['translator'];
         unset($args['translator']);
     } else {
         $translator = \Zend_Registry::get('Zend_Translate');
     }
     if (isset($args['class'])) {
         if ($args['class'] instanceof \MUtil_Html_AttributeInterface) {
             $args['class']->add('browselink');
         } else {
             $args['class'] = new \MUtil_Html_ClassArrayAttribute('browselink', $args['class']);
         }
     } else {
         $args['class'] = new \MUtil_Html_ClassArrayAttribute('browselink');
     }
     // \MUtil_Echo::track($args);
     // \MUtil_Echo::track($panel_args['baseUrl']);
     if (\MUtil_Bootstrap::enabled()) {
         $pager = new \MUtil_Bootstrap_Html_PagePanel($panel_args);
     } else {
         $pager = new \MUtil_Html_PagePanel($panel_args);
     }
     $pager[] = $pager->pageLinks(array($translator->_('<< First'), 'class' => new \MUtil_Html_ClassArrayAttribute('browselink', 'keyHome')), array($translator->_('< Previous'), 'class' => new \MUtil_Html_ClassArrayAttribute('browselink', 'keyPgUp')), array($translator->_('Next >'), 'class' => new \MUtil_Html_ClassArrayAttribute('browselink', 'keyPgDn')), array($translator->_('Last >>'), 'class' => new \MUtil_Html_ClassArrayAttribute('browselink', 'keyEnd')), $translator->_(' | '), $args);
     $pager->div($pager->uptoOffDynamic($translator->_('to'), $translator->_('of'), array('-', 'class' => new \MUtil_Html_ClassArrayAttribute('browselink btn btn-xs', 'keyCtrlUp')), array('+', 'class' => new \MUtil_Html_ClassArrayAttribute('browselink btn btn-xs', 'keyCtrlDown')), null, ' ', $args), array('class' => 'pagination-index rightFloat pull-right'));
     return $pager;
 }
예제 #14
0
 /**
  * Return all messages in an array without status info.
  */
 public function getMessagesOnly()
 {
     if ($this->hasMessages()) {
         $messages = $this->getMessages();
     } else {
         $messages = array();
     }
     if ($this->hasCurrentMessages()) {
         $messages = array_merge($messages, $this->getCurrentMessages());
     }
     if (!$messages) {
         return null;
     }
     $output = array();
     foreach ($messages as $message) {
         if (is_array($message)) {
             if (2 === count($message) && isset($message[0], $message[1]) && is_string($message[1])) {
                 $message = $message[0];
             }
         }
         $output[] = $message;
     }
     return \MUtil_Ra::flatten($output);
 }
예제 #15
0
 protected function _checkParams(array $params)
 {
     $checks = \MUtil_Ra::nonScalars($params);
     if ($this->_allowedClasses) {
         $checks = \MUtil_Ra::nonScalars($params);
         if (is_array($checks)) {
             foreach ($checks as $object) {
                 if (!$this->_allowedClasses->get($object)) {
                     $name = get_class($object);
                     $method = reset($params);
                     throw new \MUtil_Batch_BatchException("Not allowed batch class {$name} parameter for method: '{$method}'.");
                 }
             }
         }
     } elseif (!\MUtil_Ra::isScalar($params)) {
         $checks = \MUtil_Ra::nonScalars($params);
         if (is_array($checks)) {
             $object = reset($checks);
             $name = get_class($object);
             $method = reset($params);
             throw new \MUtil_Batch_BatchException("Not allowed batch class {$name} parameter for method: '{$method}'.");
         }
     }
 }
예제 #16
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;
 }
예제 #17
0
 /**
  * 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;
 }
예제 #18
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;
 }
예제 #19
0
 /**
  *
  * @param mixed $arg_array \MUtil_Ra::args parameter passing
  */
 public static function sprintf($arg_array = null)
 {
     $args = \MUtil_Ra::args(func_get_args());
     return new self($args);
 }
예제 #20
0
파일: Acl.php 프로젝트: GemsTracker/MUtil
 /**
  * Removes a previously set "allow" rule from the ACL
  *
  * @param  \Zend_Acl_Role_Interface|string|array     $roles
  * @param  string|array                             $privileges
  * @uses   \Zend_Acl::allow()
  * @return \Zend_Acl Provides a fluent interface
  */
 public function removePrivilege($roles, $privileges_args)
 {
     $privileges = \MUtil_Ra::args(func_get_args(), 1);
     return $this->removeAllow($roles, null, $privileges);
 }
 protected function findAllowedMenuItem($action)
 {
     $actions = \MUtil_Ra::args(func_get_args());
     $controller = $this->_getParam('controller');
     foreach ($actions as $action) {
         $menuItem = $this->menu->find(array('controller' => $controller, 'action' => $action, 'allowed' => true));
         if ($menuItem) {
             return $menuItem;
         }
     }
 }
예제 #22
0
 /**
  * Save a single model item.
  *
  * @param array $newValues The values to store for a single model item.
  * @param array $filter If the filter contains old key values these are used
  * to decide on update versus insert.
  * @return array The values as they are after saving (they may change).
  */
 protected function _save(array $newValues, array $filter = null)
 {
     if ($this->_saveable) {
         $data = $this->_loadAllTraversable();
         if ($data instanceof \Traversable) {
             $data = iterator_to_array($this->_loadAllTraversable());
         }
         if ($keys = $this->getKeys()) {
             $search = array();
             if (is_array($filter)) {
                 $newValues = $newValues + $filter;
             }
             foreach ($keys as $key) {
                 if (isset($newValues[$key])) {
                     $search[$key] = $newValues[$key];
                 } else {
                     // Crude but hey
                     throw new \MUtil_Model_ModelException(sprintf('Key value "%s" missing when saving data.', $key));
                 }
             }
             $rowId = \MUtil_Ra::findKeys($data, $search);
             if ($rowId) {
                 // Overwrite to new values
                 $data[$rowId] = $newValues + $data[$rowId];
             } else {
                 $data[] = $newValues;
             }
         } else {
             $data[] = $newValues;
         }
         $this->_saveAllTraversable($data);
         return $newValues;
     } else {
         throw new \MUtil_Model_ModelException(sprintf('Save not implemented for model "%s".', $this->getName()));
     }
 }
 /**
  * The place to check if the data set in the snippet is valid
  * to generate the snippet.
  *
  * When invalid data should result in an error, you can throw it
  * here but you can also perform the check in the
  * checkRegistryRequestsAnswers() function from the
  * {@see \MUtil_Registry_TargetInterface}.
  *
  * @return boolean
  */
 public function hasHtmlOutput()
 {
     // Apply translations
     if (!$this->showAnswersTranslated) {
         // Here, not in e.g. __construct as these vars may be set during initiation
         $this->showAnswersNone = $this->_($this->showAnswersNone);
         $this->showAnswersRemoved = $this->_($this->showAnswersRemoved);
         $this->showAnswersSeparator = $this->_($this->showAnswersSeparator);
         $this->showAnswersTranslated = true;
     }
     // Overrule any setting of these values from source
     $this->data = null;
     $this->repeater = null;
     if (!$this->surveyId) {
         if ($this->token instanceof \Gems_Tracker_Token && $this->token->exists) {
             $this->surveyId = $this->token->getSurveyId();
         } elseif ($this->trackData && !$this->trackId) {
             // Look up key values from trackData
             if (isset($this->trackData['gsu_id_survey'])) {
                 $this->surveyId = $this->trackData['gsu_id_survey'];
             } elseif (isset($this->trackData['gro_id_survey'])) {
                 $this->surveyId = $this->trackData['gro_id_survey'];
             } elseif (!$this->trackId) {
                 if (isset($this->trackData['gtr_id_track'])) {
                     $this->trackId = $this->trackData['gtr_id_track'];
                 } elseif (isset($this->trackData['gro_id_track'])) {
                     $this->trackId = $this->trackData['gro_id_track'];
                 }
             }
         }
         if (!$this->trackId && $this->trackEngine) {
             $this->trackId = $this->trackEngine->getTrackId();
         }
         if ($this->trackId && !$this->surveyId) {
             // Use the track ID to get the id of the first active survey
             $this->surveyId = $this->db->fetchOne('SELECT gro_id_survey FROM gems__rounds WHERE gro_active = 1 AND gro_id_track = ? ORDER BY gro_id_order', $this->trackId);
         }
     }
     // \MUtil_Echo::track($this->surveyId, $this->trackId);
     // Get the survey
     if ($this->surveyId && !$this->survey instanceof \Gems_Tracker_Survey) {
         $this->survey = $this->loader->getTracker()->getSurvey($this->surveyId);
     }
     // Load the data
     if ($this->survey instanceof \Gems_Tracker_Survey && $this->survey->exists) {
         $this->data = \MUtil_Ra::addKey($this->survey->getQuestionInformation($this->locale->getLanguage()), 'key');
         //\MUtil_Echo::track($this->data);
     }
     return parent::hasHtmlOutput();
 }
예제 #24
0
 /**
  * Returns a reset form for handling both the incoming request and the outgoing reset request
  *
  * @param mixed $args_array \MUtil_Ra::args array for LoginForm initiation.
  * @return \Gems_User_Form_ResetRequestForm
  */
 public function getResetRequestForm($args_array = null)
 {
     $args = \MUtil_Ra::args(func_get_args());
     return $this->_loadClass('Form_ResetRequestForm', true, array($args));
 }
예제 #25
0
 /**
  * Return a mailto: link object
  *
  * @param mixed $email
  * @param mixed $arg_array
  * @return \self
  */
 public static function email($email, $arg_array = null)
 {
     $args = \MUtil_Ra::args(func_get_args(), 1);
     if (isset($args['href'])) {
         $href = $args['href'];
         unset($args['href']);
     } else {
         if (!isset($args['title'])) {
             $args['title'] = $email;
         }
         $href = array('mailto:', $email);
     }
     if (!isset($args['onclick'])) {
         // Make sure the mail link only opens a mail window.
         $args['onclick'] = 'event.cancelBubble=true;';
     }
     return new self($href, $email, $args);
 }
 /**
  *
  * @param string $key_arg1 First of optionally many arguments
  * @return \Gems_Util_RequestCache
  */
 public function removeParams($key_arg1)
 {
     $args = \MUtil_Ra::flatten(func_get_args());
     $this->_baseUrl = null;
     $params = $this->getProgramParams();
     foreach ($args as $key) {
         if (isset($params[$key])) {
             unset($params[$key]);
         }
     }
     // \MUtil_Echo::track($params);
     $this->setProgramParams($params);
     return $this;
 }
 /**
  * Add items in hidden form to the bridge, and remove them from the items array
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param string $element1
  *
  * @return void
  */
 protected function addItemsHidden(\MUtil_Model_Bridge_FormBridgeInterface $bridge, $element1)
 {
     $args = func_get_args();
     if (count($args) < 2) {
         throw new \Gems_Exception_Coding('Use at least 2 arguments, first the bridge and then one or more individual items');
     }
     $bridge = array_shift($args);
     $elements = \MUtil_Ra::flatten($args);
     $form = $bridge->getForm();
     //Remove the elements from the _items variable
     $this->_items = array_diff($this->_items, $elements);
     // And add them to the bridge
     foreach ($elements as $name) {
         // Use $bridge->addHidden as that adds validators and filters.
         $bridge->addHidden($name);
     }
 }
예제 #28
0
 /**
  * Static helper function to create an iframe element.
  *
  * Any extra parameters are added as either content, attributes or handled
  * as special types, if defined as such for this element.
  *
  * @param mixed $src We assume the first element is src, unless a later element is explicitly specified as such
  * @param mixed $arg_array \MUtil_Ra::args arguments
  */
 public static function iFrame($src, $arg_array = null)
 {
     $args = \MUtil_Ra::args(func_get_args(), array('src' => 'MUtil_Html_SrcArrayAttribute'));
     return new self($args);
 }
예제 #29
0
 /**
  * Set the parameters where the survey should return to
  *
  * @param mixed $return \Zend_Controller_Request_Abstract, array of something that can be turned into one.
  * @return \Gems_User_User
  */
 public function setSurveyReturn($return = null)
 {
     if (null === $return) {
         $this->_unsetVar('surveyReturn');
         return $this;
     }
     if ($return instanceof \Zend_Controller_Request_Abstract) {
         $return = $return->getParams();
     } elseif (!is_array($return)) {
         $return = \MUtil_Ra::to($return);
     }
     if ('autofilter' == $return['action']) {
         $return['action'] = 'index';
     }
     $return = array_filter($return);
     // \MUtil_Echo::track($return);
     $this->_setVar('surveyReturn', $return);
     return $this;
 }
 /**
  * Default login page
  */
 public function loginAction()
 {
     $request = $this->getRequest();
     $form = $this->createLoginForm();
     // Retrieve these before the session is reset
     $staticSession = \GemsEscort::getInstance()->getStaticSession();
     $previousRequestParameters = $staticSession->previousRequestParameters;
     $previousRequestMode = $staticSession->previousRequestMode;
     if ($form->wasSubmitted()) {
         if ($form->isValid($request->getPost(), false)) {
             $user = $form->getUser();
             $user->setAsCurrentUser();
             if ($messages = $user->reportPasswordWeakness($request->getParam($form->passwordFieldName))) {
                 $user->setPasswordResetRequired(true);
                 $this->addMessage($this->_('Your password must be changed.'));
                 foreach ($messages as &$message) {
                     $message = ucfirst($message) . '.';
                 }
                 $this->addMessage($messages);
             }
             /**
              * Fix current locale in cookies
              */
             \Gems_Cookies::setLocale($user->getLocale(), $this->basepath->getBasePath());
             /**
              * Ready
              */
             $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $user->getFullName()), 'success');
             /**
              * Log the login
              */
             $this->accesslog->logChange($request);
             if ($previousRequestParameters) {
                 $this->_reroute(array('controller' => $previousRequestParameters['controller'], 'action' => $previousRequestParameters['action']), false);
             } else {
                 // This reroutes to the first available menu page after login.
                 //
                 // Do not user $user->gotoStartPage() as the menu is still set
                 // for no login.
                 $this->_reroute(array('controller' => null, 'action' => null), true);
             }
             return;
         } else {
             $errors = \MUtil_Ra::flatten($form->getMessages());
             // \MUtil_Echo::track($errors);
             //Also log the error to the log table
             //when the project has logging enabled
             $logErrors = join(' - ', $errors);
             $msg = sprintf('Failed login for : %s (%s) - %s', $request->getParam($form->usernameFieldName), $request->getParam($form->organizationFieldName), $logErrors);
             $this->accesslog->logChange($request, $msg);
         }
         // */
     } else {
         if ($request->isPost()) {
             $form->populate($request->getPost());
         }
     }
     $this->displayLoginForm($form);
 }