コード例 #1
0
 /**
  * Adds rows from the model to the bridge that creates the browse table.
  *
  * Overrule this function to add different columns to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_VerticalTableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addShowTableRows(\MUtil_Model_Bridge_VerticalTableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     $items = $model->getItemsOrdered();
     foreach ($items as $name) {
         if ($model->get($name, 'type') === \MUtil_Model::TYPE_CHILD_MODEL) {
             $this->submodel = $model->get($name, 'model');
             $subitems = $this->submodel->getItemsOrdered();
         }
     }
     if (isset($subitems) && is_array($subitems)) {
         $items = array_diff($items, $subitems);
     }
     foreach ($items as $name) {
         if ($label = $model->get($name, 'label')) {
             $bridge->addItem($name, $label);
         }
     }
     /*if ($subitems) {
           $bridge->addItem('gctt', 'moo');
       }*/
     if ($model->has('row_class')) {
         // Make sure deactivated rounds are show as deleted
         foreach ($bridge->getTable()->tbody() as $tr) {
             foreach ($tr as $td) {
                 if ('td' === $td->tagName) {
                     $td->appendAttrib('class', $bridge->row_class);
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * Adds columns from the model to the bridge that creates the browse table.
  *
  * Overrule this function to add different columns to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     if ($model->has('row_class')) {
         $bridge->getTable()->tbody()->getFirst(true)->appendAttrib('class', $bridge->row_class);
     }
     if ($editMenuItem = $this->getEditMenuItem()) {
         $bridge->addItemLink($editMenuItem->toActionLinkLower($this->request, $bridge));
     }
     // make sure search results are highlighted
     $this->applyTextMarker();
     if ($this->columns) {
         foreach ($this->columns as $column) {
             call_user_func_array(array($bridge, 'addMultiSort'), $column);
         }
     } elseif ($this->sortableLinks) {
         foreach ($model->getItemsOrdered() as $name) {
             if ($label = $model->get($name, 'label')) {
                 $bridge->addSortable($name, $label);
             }
         }
     } else {
         foreach ($model->getItemsOrdered() as $name) {
             if ($label = $model->get($name, 'label')) {
                 $bridge->add($name, $label);
             }
         }
     }
     if ($deleteMenuItem = $this->findMenuItem($this->request->getControllerName(), 'delete')) {
         $bridge->addItemLink($deleteMenuItem->toActionLinkLower($this->request, $bridge));
     }
 }
コード例 #3
0
 private function _addIf(array $names, \MUtil_Model_Bridge_VerticalTableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     foreach ($names as $name) {
         if ($model->has($name, 'label')) {
             $bridge->addItem($name);
         }
     }
 }
コード例 #4
0
ファイル: ChangeTracker.php プロジェクト: GemsTracker/MUtil
 /**
  * A ModelAbstract->setOnSave() function that tracks the change
  *
  * @see \MUtil_Model_ModelAbstract
  *
  * @param mixed $value The value being saved
  * @param boolean $isNew True when a new item is being saved
  * @param string $name The name of the current field
  * @param array $context Optional, the other values being saved
  * @return string Of the values concatenated
  */
 public function saveValue($value, $isNew = false, $name = null, array $context = array())
 {
     // \MUtil_Echo::track($value, $this->_changedValue);
     // Once the value is set (and e.g. stored in the database) do not overwrite it
     if ($this->_changedValue == $value) {
         return $value;
     }
     $compare = $this->_model->get($name, __CLASS__);
     if (!(is_array($compare) && 2 === count($compare))) {
         // Actually a valid setting, do nothring
         return $value;
     }
     list($trackedField, $oldValueField) = $compare;
     if (!isset($context[$trackedField], $context[$oldValueField])) {
         return $value;
     }
     if (!($context[$trackedField] && $context[$oldValueField])) {
         return $context[$trackedField] || $context[$oldValueField] ? $this->_changedValue : $this->_unchangedValue;
     }
     $storageFormat = $this->_model->get($trackedField, 'storageFormat');
     if (!$storageFormat) {
         return $context[$trackedField] == $context[$oldValueField] ? $this->_unchangedValue : $this->_changedValue;
     }
     if ($context[$oldValueField] instanceof \Zend_Date) {
         $oldValue = $context[$oldValueField];
     } else {
         $oldValue = new \MUtil_Date($context[$oldValueField], $storageFormat);
     }
     if ($context[$trackedField] instanceof \Zend_Date) {
         $currentValue = $context[$trackedField];
     } elseif (\Zend_Date::isDate($context[$trackedField], $storageFormat)) {
         $currentValue = new \MUtil_Date($context[$trackedField], $storageFormat);
     } else {
         if ($this->_model->has($trackedField, 'dateFormat')) {
             $secondFormat = $this->_model->get($trackedField, 'dateFormat');
         } else {
             $secondFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat');
         }
         if (!\Zend_Date::isDate($context[$trackedField], $secondFormat)) {
             // Cannot compare, do nothing
             return $value;
         }
         $currentValue = new \MUtil_Date($context[$trackedField], $secondFormat);
     }
     // \MUtil_Echo::track($trackedField, $oldValueField, $oldValue->toString(), $currentValue->toString(), $oldValue->getTimestamp() === $currentValue->getTimestamp());
     return $oldValue->getTimestamp() === $currentValue->getTimestamp() ? $this->_unchangedValue : $this->_changedValue;
 }
コード例 #5
0
 /**
  * If the transformer add's fields, these should be returned here.
  * Called in $model->AddTransformer(), so the transformer MUST
  * know which fields to add by then (optionally using the model
  * for that).
  *
  * @param \MUtil_Model_ModelAbstract $model The parent model
  * @return array Of filedname => set() values
  */
 public function getFieldInfo(\MUtil_Model_ModelAbstract $model)
 {
     $data = array();
     foreach ($this->_subModels as $sub) {
         foreach ($sub->getItemNames() as $name) {
             if (!$model->has($name)) {
                 $data[$name] = $sub->get($name);
                 $data[$name]['no_text_search'] = true;
                 // Remove unsuited data
                 unset($data[$name]['table'], $data[$name]['column_expression']);
                 unset($data[$name]['label']);
                 $data[$name]['elementClass'] = 'None';
                 // Remove the submodel's own transformers to prevent changed/created to show up in the data array instead of only in the nested info
                 unset($data[$name][\MUtil_Model_ModelAbstract::LOAD_TRANSFORMER]);
                 unset($data[$name][\MUtil_Model_ModelAbstract::SAVE_TRANSFORMER]);
             }
         }
     }
     return $data;
 }
コード例 #6
0
 /**
  * Adds columns from the model to the bridge that creates the browse table.
  *
  * Overrule this function to add different columns to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     if ($model->has('row_class')) {
         $bridge->getTable()->tbody()->getFirst(true)->appendAttrib('class', $bridge->row_class);
     }
     if ($this->showMenu) {
         $showMenuItems = $this->getShowMenuItems();
         foreach ($showMenuItems as $menuItem) {
             $bridge->addItemLink($menuItem->toActionLinkLower($this->request, $bridge));
         }
     }
     // Newline placeholder
     $br = \MUtil_Html::create('br');
     $by = \MUtil_Html::raw($this->_(' / '));
     $sp = \MUtil_Html::raw(' ');
     // make sure search results are highlighted
     $this->applyTextMarker();
     $bridge->addMultiSort('grco_created', $br, 'gr2o_patient_nr', $sp, 'respondent_name', $br, 'grco_address', $br, 'gtr_track_name');
     $bridge->addMultiSort('grco_id_token', $br, 'assigned_by', $br, 'grco_sender', $br, 'gsu_survey_name');
     $bridge->addMultiSort('status', $by, 'filler', $br, 'grco_topic');
     if ($this->showMenu) {
         $items = $this->findMenuItems('track', 'show');
         $links = array();
         $params = array('gto_id_token' => $bridge->gto_id_token, \Gems_Model::ID_TYPE => 'token');
         $title = \MUtil_Html::create('strong', $this->_('+'));
         foreach ($items as $item) {
             if ($item instanceof \Gems_Menu_SubMenuItem) {
                 $bridge->addItemLink($item->toActionLinkLower($this->request, $params, $title));
             }
         }
     }
     $bridge->getTable()->appendAttrib('class', 'compliance');
     $tbody = $bridge->tbody();
     $td = $tbody[0][0];
     $td->appendAttrib('class', \MUtil_Lazy::method($this->util->getTokenData(), 'getStatusClass', $bridge->getLazy('status')));
 }
コード例 #7
0
 /**
  * Checks and updates the on and off strings when one of the effecteds is a date, time or datetime field
  * 
  * @param string $valueOn
  * @param string $valueOff
  */
 protected function checkPicker(&$valueOn, &$valueOff)
 {
     $effecteds = array_keys($this->getEffecteds());
     foreach ($effecteds as $field) {
         if ($this->model instanceof \MUtil_Model_ModelAbstract && $this->model->has($field)) {
             $modelItemType = $this->model->get($field, 'type');
             $dateFormat = $this->model->get($field, 'dateFormat');
             $timeFormat = $this->model->get($field, 'timeFormat');
             switch ($modelItemType) {
                 case \MUtil_Model::TYPE_DATE:
                 case \MUtil_Model::TYPE_TIME:
                 case \MUtil_Model::TYPE_DATETIME:
                     $picker = 'datepicker';
                     break;
                 default:
                     $picker = '';
                     break;
             }
             if (!empty($picker)) {
                 // If none set, get the locale default dateformat
                 if (!$dateFormat && !$timeFormat && \Zend_Registry::isRegistered('Zend_Locale')) {
                     $dateFormat = \ZendX_JQuery_View_Helper_DatePicker::resolveZendLocaleToDatePickerFormat();
                 }
                 if ($dateFormat) {
                     if ($timeFormat) {
                         $picker = 'datetimepicker';
                     }
                 } elseif ($timeFormat) {
                     $picker = 'timepicker';
                 }
                 $valueOn .= "\$('#{$field}').{$picker}('enable');";
                 $valueOff .= "\$('#{$field}').{$picker}('disable');";
             }
         }
     }
 }
コード例 #8
0
 /**
  * Adds columns from the model to the bridge that creates the browse table.
  *
  * Overrule this function to add different columns to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     if ($model->has('row_class')) {
         $bridge->getTable()->tbody()->getFirst(true)->appendAttrib('class', $bridge->row_class);
     }
     if ($this->showMenu) {
         $showMenuItems = $this->getShowMenuItems();
         foreach ($showMenuItems as $menuItem) {
             $bridge->addItemLink($menuItem->toActionLinkLower($this->request, $bridge));
         }
     }
     // make sure search results are highlighted
     $this->applyTextMarker();
     parent::addBrowseTableColumns($bridge, $model);
     if ($this->showMenu) {
         $editMenuItems = $this->getEditMenuItems();
         foreach ($editMenuItems as $menuItem) {
             $bridge->addItemLink($menuItem->toActionLinkLower($this->request, $bridge));
         }
     }
 }
コード例 #9
0
 /**
  * Use this function for a default application of this dependency to the model
  *
  * @param \MUtil_Model_ModelAbstract $model Try not to store the model as variabe in the dependency (keep it simple)
  */
 public function applyToModel(\MUtil_Model_ModelAbstract $model)
 {
     if ($this->applyOnChange) {
         foreach ($this->getDependsOn() as $name) {
             if ($model->is($name, 'elementClass', 'Checkbox')) {
                 if (!$model->has($name, 'onclick')) {
                     $model->set($name, 'onclick', $this->onChangeJs);
                 }
             } else {
                 if (!$model->has($name, 'onchange')) {
                     $model->set($name, 'onchange', $this->onChangeJs);
                 }
             }
         }
     }
 }
コード例 #10
0
 /**
  * Adds rows from the model to the bridge that creates the browse table.
  *
  * Overrule this function to add different columns to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_VerticalTableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addShowTableRows(\MUtil_Model_Bridge_VerticalTableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     foreach ($model->getItemsOrdered() as $name) {
         if ($label = $model->get($name, 'label')) {
             $bridge->addItem($name, $label);
         }
     }
     if ($model->has('row_class')) {
         // Make sure deactivated rounds are show as deleted
         foreach ($bridge->getTable()->tbody() as $tr) {
             foreach ($tr as $td) {
                 if ('td' === $td->tagName) {
                     $td->appendAttrib('class', $bridge->row_class);
                 }
             }
         }
     }
 }
コード例 #11
0
 /**
  * Adds columns from the model to the bridge that creates the browse table.
  *
  * Overrule this function to add different columns to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     $br = \MUtil_Html::create('br');
     if ($this->showSelected) {
         $selectedClass = \MUtil_Lazy::iff(\MUtil_Lazy::comp($bridge->gto_id_token, '==', $this->tokenId), 'selectedColumn', null);
     } else {
         $selectedClass = null;
     }
     $bridge->th($this->_('Status'));
     $td = $bridge->tdh(\MUtil_Lazy::first($bridge->grc_description, $this->_('OK')));
     $td->appendAttrib('class', $selectedClass);
     $bridge->th($this->_('Question'));
     if ($model->has('grr_name') && $model->has('gtf_field_name')) {
         $td = $bridge->tdh(\MUtil_Lazy::iif($bridge->grr_name, array($bridge->grr_name, $br)), \MUtil_Lazy::iif($bridge->gtf_field_name, array($bridge->gtf_field_name, $br)), $bridge->gto_round_description, \MUtil_Lazy::iif($bridge->gto_round_description, $br), \MUtil_Lazy::iif($bridge->gto_completion_time, $bridge->gto_completion_time, $bridge->gto_valid_from));
     } else {
         $td = $bridge->tdh($bridge->gto_round_description, \MUtil_Lazy::iif($bridge->gto_round_description, $br), \MUtil_Lazy::iif($bridge->gto_completion_time, $bridge->gto_completion_time, $bridge->gto_valid_from));
     }
     $td->appendAttrib('class', $selectedClass);
     $td->appendAttrib('class', $bridge->row_class);
     // Apply filter on the answers displayed
     $answerNames = $model->getItemsOrdered();
     if ($this->answerFilter instanceof \Gems_Tracker_Snippets_AnswerNameFilterInterface) {
         $answerNames = $this->answerFilter->filterAnswers($bridge, $model, $answerNames);
     }
     foreach ($answerNames as $name) {
         $label = $model->get($name, 'label');
         if (null !== $label) {
             // Was strlen($label), but this ruled out empty sub-questions
             $bridge->thd($label, array('class' => $model->get($name, 'thClass')));
             $td = $bridge->td($bridge->{$name});
             $td->appendAttrib('class', 'answer');
             $td->appendAttrib('class', $selectedClass);
             $td->appendAttrib('class', $bridge->row_class);
         }
     }
     $bridge->th($this->_('Token'));
     $tokenUpper = $bridge->gto_id_token->strtoupper();
     if ($this->showTakeButton && ($menuItem = $this->menu->find(array('controller' => 'ask', 'action' => 'take', 'allowed' => true)))) {
         $source = new \Gems_Menu_ParameterSource();
         $source->setTokenId($bridge->gto_id_token);
         $source->offsetSet('can_be_taken', $bridge->can_be_taken);
         $link = $menuItem->toActionLink($source);
         if ($link) {
             $link->title = array($this->_('Token'), $tokenUpper);
         }
         $td = $bridge->tdh($bridge->can_be_taken->if($link, $tokenUpper));
     } else {
         $td = $bridge->tdh($tokenUpper);
     }
     $td->appendAttrib('class', $selectedClass);
     $td->appendAttrib('class', $bridge->row_class);
 }
コード例 #12
0
 /**
  * If the transformer add's fields, these should be returned here.
  * Called in $model->AddTransformer(), so the transformer MUST
  * know which fields to add by then (optionally using the model
  * for that).
  *
  * @param \MUtil_Model_ModelAbstract $model The parent model
  * @return array Of filedname => set() values
  */
 public function getFieldInfo(\MUtil_Model_ModelAbstract $model)
 {
     $data = array();
     foreach ($this->_subModels as $sub) {
         foreach ($sub->getItemNames() as $name) {
             if (!$model->has($name)) {
                 $data[$name] = $sub->get($name);
                 $data[$name]['no_text_search'] = true;
                 // Remove unsuited data
                 unset($data[$name]['table'], $data[$name]['column_expression']);
             }
         }
     }
     return $data;
 }
コード例 #13
0
 /**
  * Applies the fieldmap data to the model
  *
  * @param \MUtil_Model_ModelAbstract $model
  */
 public function applyToModel(\MUtil_Model_ModelAbstract $model)
 {
     $map = $this->_getMap();
     $oldfld = null;
     $parent = null;
     foreach ($map as $name => $field) {
         $tmpres = array();
         $tmpres['thClass'] = \Gems_Tracker_SurveyModel::CLASS_MAIN_QUESTION;
         $tmpres['group'] = $field['gid'];
         $tmpres['type'] = $this->_getType($field);
         $tmpres['survey_question'] = true;
         if ($tmpres['type'] === \MUtil_Model::TYPE_DATE) {
             $tmpres['storageFormat'] = 'yyyy-MM-dd';
             $tmpres['dateFormat'] = 'dd MMMM yyyy';
             // $tmpres['formatFunction']
         }
         if ($tmpres['type'] === \MUtil_Model::TYPE_DATETIME) {
             $tmpres['storageFormat'] = 'yyyy-MM-dd HH:mm:ss';
             $tmpres['dateFormat'] = 'dd MMMM yyyy HH:mm';
             // $tmpres['formatFunction']
         }
         if ($tmpres['type'] === \MUtil_Model::TYPE_TIME) {
             $tmpres['storageFormat'] = 'yyyy-MM-dd HH:mm:ss';
             $tmpres['dateFormat'] = 'HH:mm:ss';
             // $tmpres['formatFunction']
         }
         // \MUtil_Echo::track($field);
         $oldQuestion = isset($oldfld['question']) ? $oldfld['question'] : null;
         if (isset($field['question']) && (!isset($oldfld) || $oldQuestion !== $field['question'])) {
             $tmpres['label'] = \MUtil_Html::raw($this->removeMarkup($field['question']));
         }
         if (isset($field['help']) && $field['help']) {
             $tmpres['description'] = \MUtil_Html::raw($this->removeMarkup($field['help']));
         }
         // Juggle the labels for sub-questions etc..
         if (isset($field['sq_question'])) {
             if (isset($tmpres['label'])) {
                 // Add non answered question for grouping and make it the current parent
                 //$parent = '_' . $name . '_';
                 $parent = $field['title'];
                 $model->set($parent, $tmpres);
                 $model->set($parent, 'type', \MUtil_Model::TYPE_NOVALUE);
             }
             if (isset($field['sq_question1'])) {
                 $tmpres['label'] = \MUtil_Html::raw(sprintf($this->translate->_('%s: %s'), $this->removeMarkup($field['sq_question']), $this->removeMarkup($field['sq_question1'])));
             } else {
                 $tmpres['label'] = \MUtil_Html::raw($this->removeMarkup($field['sq_question']));
             }
             $tmpres['thClass'] = \Gems_Tracker_SurveyModel::CLASS_SUB_QUESTION;
         }
         if ($options = $this->_getMultiOptions($field)) {
             $tmpres['multiOptions'] = $options;
         }
         // Code does not have to be unique. So if a title is used
         // twice we only use it for the first result.
         if (isset($field['code']) && !$model->has($field['code'])) {
             $name = $field['code'];
         }
         // Parent storage
         if (\Gems_Tracker_SurveyModel::CLASS_MAIN_QUESTION === $tmpres['thClass']) {
             $parent = $name;
         } elseif ($parent) {
             // Add the name of the parent item
             $tmpres['parent_question'] = $parent;
         }
         $model->set($name, $tmpres);
         $oldfld = $field;
     }
 }
コード例 #14
0
 /**
  * Adds elements from the model to the bridge that creates the form.
  *
  * Overrule this function to add different elements to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @param array $data The data that will later be loaded into the form
  * @param optional boolean $new Form should be for a new element
  * @return void|array When an array of new values is return, these are used to update the $data array in the calling function
  */
 protected function addFormElements(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model, array $data, $new = false)
 {
     foreach ($model->getItemsOrdered() as $name) {
         if ($model->has($name, 'label') || $model->has($name, 'elementClass')) {
             $bridge->add($name);
         } else {
             $bridge->addHidden($name);
         }
     }
 }
コード例 #15
0
 /**
  * Get the descriptions of the translators
  *
  * @param mixed $for A single translator, an array of translators or all translators if null;
  * @return array key -> description
  */
 protected function getTranslatorTable($for = null)
 {
     if (!$this->targetModel) {
         return array();
     }
     if (null === $for) {
         $for = $this->getTranslatorDescriptions();
     } elseif (!is_array($for)) {
         $descriptors = $this->getTranslatorDescriptions();
         if (!isset($descriptors[$for])) {
             throw new \Zend_Exception("Unknown translator {$for} passed to " . __CLASS__ . '->' . __FUNCTION__ . '()');
         }
         $for = array($for => $descriptors[$for]);
     }
     $requiredKey = $this->_('Required');
     $minimal = array($requiredKey => ' ');
     // Array for making sure all fields are there
     $results = array_fill_keys($this->targetModel->getItemsOrdered(), array());
     $transCount = count($for);
     foreach ($for as $transKey => $transName) {
         if (!isset($this->importTranslators[$transKey])) {
             throw new \Zend_Exception("Unknown translator {$for} passed to " . __CLASS__ . '->' . __FUNCTION__ . '()');
         }
         $translator = $this->importTranslators[$transKey];
         if ($translator instanceof \MUtil_Model_ModelTranslatorInterface) {
             $translator->setTargetModel($this->targetModel);
             $translations = $translator->getFieldsTranslations();
             $requireds = $translator->getRequiredFields();
             $minimal[$transName] = ' ';
             foreach ($translations as $source => $target) {
                 // Skip numeric fields
                 if (!is_int($source)) {
                     $required = isset($requireds[$source]);
                     // Add required row
                     $results[$target][$requiredKey][$transName] = $required;
                     if (trim($required)) {
                         $results[$target][$transName] = new \MUtil_Html_HtmlElement('strong', $source);
                     } else {
                         $results[$target][$transName] = $source;
                     }
                 }
             }
         }
     }
     $output = array();
     foreach ($results as $name => $resultRow) {
         if (count($resultRow) > 1) {
             // Always first
             $requireds = count(array_filter($resultRow[$requiredKey]));
             $resultRow[$requiredKey] = $requireds ? $requireds == $transCount ? $this->_('Yes') : $this->_('For bold') : ' ';
             if ($this->targetModel->has($name, 'label')) {
                 $label = $this->targetModel->get($name, 'label');
             } else {
                 $label = $name;
             }
             // $field = $this->_targetModel->get($name, 'type', 'maxlength', 'label', 'required');
             switch ($this->targetModel->get($name, 'type')) {
                 case \MUtil_Model::TYPE_NOVALUE:
                     unset($results[$name]);
                     continue 2;
                 case \MUtil_Model::TYPE_NUMERIC:
                     $maxlength = $this->targetModel->get($name, 'maxlength');
                     if ($maxlength) {
                         $decimals = $this->targetModel->get($name, 'decimals');
                         if ($decimals) {
                             $type = sprintf($this->_('A number of length %d, with a precision of %d digits after the period.'), $maxlength, $decimals);
                         } else {
                             $type = sprintf($this->_('A whole number of length %d.'), $maxlength);
                         }
                     } else {
                         $type = $this->_('A numeric value');
                     }
                     break;
                 case \MUtil_Model::TYPE_DATE:
                     $type = $this->_('Date value using ISO 8601: yyyy-mm-dd');
                     break;
                 case \MUtil_Model::TYPE_DATETIME:
                     $type = $this->_('Datetime value using ISO 8601: yyyy-mm-ddThh:mm::ss[+-hh:mm]');
                     break;
                 case \MUtil_Model::TYPE_TIME:
                     $type = $this->_('Time value using ISO 8601: hh:mm::ss[+-hh:mm]');
                     break;
                 default:
                     $maxlength = $this->targetModel->get($name, 'maxlength');
                     $minlength = $this->targetModel->get($name, 'minlength');
                     if ($maxlength && $minlength) {
                         $type = sprintf($this->plural('Text, between %d and %d character', 'Text, between %d and %d characters', $maxlength), $minlength, $maxlength);
                     } elseif ($maxlength) {
                         $type = sprintf($this->plural('Text, %d character', 'Text, %d characters', $maxlength), $maxlength);
                     } elseif ($minlength) {
                         $type = sprintf($this->plural('Text, at least %d character', 'Text, at least %d characters', $minlength), $minlength);
                     } else {
                         $type = $this->_('Text');
                     }
                     break;
             }
             $options = $this->targetModel->get($name, 'multiOptions');
             if ($options) {
                 $cutoff = 6;
                 $i = 0;
                 $optionDescr = '';
                 $separator = $this->_(', ');
                 if (is_callable($options)) {
                     $options = call_user_func($options);
                 }
                 foreach ($options as $key => $value) {
                     $optionDescr .= $separator . $key;
                     $i++;
                     if ($key != $value) {
                         $optionDescr .= sprintf($this->_(', %s'), $value);
                         $i++;
                     }
                     if ($i > $cutoff) {
                         break;
                     }
                 }
                 $optionDescr = substr($optionDescr, strlen($separator));
                 if ($i < $cutoff) {
                     // $type .= $this->_('; one of: ') . implode($this->_(', '), array_keys($options));
                     $type .= sprintf($this->_('; one of: %s'), $optionDescr);
                 } else {
                     $type .= sprintf($this->_('; e.g. one of: %s, ...'), $optionDescr);
                 }
             }
             $typeDescr = $this->targetModel->get($name, 'import_descr');
             if ($typeDescr) {
                 $type .= $this->_('; ') . $typeDescr;
             }
             $resultRow[$this->_('Field description')] = (string) $label ? $label : $this->_('<<no description>>');
             $resultRow[$this->_('Content')] = $type;
             // Make sure all fields are there
             $resultRow = array_merge($minimal, $resultRow);
             $output[$name] = $resultRow;
         }
     }
     uksort($output, array($this, '_sortTranslatorTable'));
     return $output;
 }
コード例 #16
0
 /**
  * Adds elements from the model to the bridge that creates the form.
  *
  * Overrule this function to add different elements to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @param array $data The data that will later be loaded into the form
  * @param optional boolean $new Form should be for a new element
  * @return void|array When an array of new values is return, these are used to update the $data array in the calling function
  */
 protected function addFormElements(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model, array $data, $new = false)
 {
     $returnValues = array();
     if (APPLICATION_ENV !== 'production') {
         $bsn = new \MUtil_Validate_Dutch_Burgerservicenummer();
         $num = mt_rand(100000000, 999999999);
         while (!$bsn->isValid($num)) {
             $num++;
         }
         $model->set('grs_ssn', 'description', sprintf($this->_('Random Example BSN: %s'), $num));
     } else {
         $model->set('grs_ssn', 'description', $this->_('Enter a 9-digit SSN number.'));
     }
     if ($model->hashSsn === \Gems_Model_RespondentModel::SSN_HASH) {
         if (strlen($data['grs_ssn']) > 9) {
             // When longer the grs_ssn contains a hash, not a bsn number
             $returnValues['grs_ssn'] = '';
         }
     }
     $ucfirst = new \Zend_Filter_Callback('ucfirst');
     // \MUtil_Echo::track($data);
     $bridge->addTab('caption1')->h4($this->_('Identification'));
     //Add the hidden fields after the tab, so validation will work. They need to be in the
     //same tab where they are needed
     $bridge->addHidden('grs_id_user');
     $bridge->addHidden('gr2o_id_organization');
     $bridge->addHidden($model->getKeyCopyName('gr2o_patient_nr'));
     $bridge->addHidden($model->getKeyCopyName('gr2o_id_organization'));
     if (isset($data['gul_id_user'])) {
         $bridge->addHidden('gul_id_user');
     }
     $bridge->addText('grs_ssn', 'label', $this->_('SSN'), 'size', 10, 'maxlength', 12)->addValidator(new \MUtil_Validate_Dutch_Burgerservicenummer())->addValidator($model->createUniqueValidator('grs_ssn'))->addFilter('Digits');
     $bridge->addText('gr2o_patient_nr', 'label', $this->_('Patient number'), 'size', 15, 'minlength', 4)->addValidator($model->createUniqueValidator(array('gr2o_patient_nr', 'gr2o_id_organization'), array('gr2o_id_user' => 'grs_id_user', 'gr2o_id_organization')));
     $bridge->addText('grs_first_name')->addFilter($ucfirst);
     $bridge->addText('grs_surname_prefix', 'description', 'de, van der, \'t, etc...');
     $bridge->addText('grs_last_name', 'required', true)->addFilter($ucfirst);
     $bridge->addTab('caption2')->h4($this->_('Medical data'));
     $bridge->addRadio('grs_gender', 'separator', '', 'multiOptions', $this->util->getTranslated()->getGenders());
     $year = intval(date('Y'));
     // Als jQuery 1.4 gebruikt wordt: yearRange = c-130:c0
     $bridge->addDate('grs_birthday', 'jQueryParams', array('defaultDate' => '-30y', 'maxDate' => 0, 'yearRange' => $year - 130 . ':' . $year))->addValidator(new \MUtil_Validate_Date_DateBefore());
     //$bridge->addSelect(  'gr2o_id_physician');
     $bridge->addText('gr2o_treatment', 'size', 30, 'description', $this->_('DBC\'s, etc...'));
     $bridge->addTextarea('gr2o_comments', 'rows', 4, 'cols', 60);
     $bridge->addTab('caption3')->h4($this->_('Contact information'));
     // Setting e-mail to required is niet mogelijk, grijpt te diep in
     // misschien later proberen met ->addGroup('required', 'true'); ???
     $bridge->addText('grs_email', 'size', 30)->addValidator('SimpleEmail');
     $bridge->addCheckBox('calc_email', 'label', $this->_('Respondent has no e-mail'));
     $bridge->addRadio('gr2o_mailable');
     $bridge->addText('grs_address_1', 'size', 40, 'description', $this->_('With housenumber'))->addFilter($ucfirst);
     if ($model->has('grs_address_2')) {
         $bridge->addText('grs_address_2', 'size', 40);
     }
     $bridge->addText('grs_zipcode', 'size', 7, 'description', '0000 AA');
     $bridge->addFilter('grs_zipcode', new \Gems_Filter_DutchZipcode());
     $bridge->addText('grs_city')->addFilter($ucfirst);
     $bridge->addSelect('grs_iso_country', 'label', $this->_('Country'), 'multiOptions', $this->util->getLocalized()->getCountries());
     $bridge->addText('grs_phone_1', 'size', 15)->addValidator('Phone');
     $bridge->addTab('caption4')->h4($this->_('Settings'));
     $bridge->addSelect('grs_iso_lang', 'label', $this->_('Language'), 'multiOptions', $this->util->getLocalized()->getLanguages());
     $bridge->addRadio('gr2o_consent', 'separator', '', 'description', $this->_('Has the respondent signed the informed consent letter?'), 'required', true);
     return $returnValues;
 }
コード例 #17
0
 /**
  * Adds columns from the model to the bridge that creates the browse table.
  *
  * Adds a button column to the model, if such a button exists in the model.
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @param \MUtil_Model_ModelAbstract $model
  * @return void
  */
 protected function addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     if ($model->has('row_class')) {
         $bridge->getTable()->tbody()->getFirst(true)->appendAttrib('class', $bridge->row_class);
     }
     // Add edit button if allowed, otherwise show, again if allowed
     if ($menuItem = $this->findAllowedMenuItem('show')) {
         $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge));
     }
     parent::addBrowseTableColumns($bridge, $model);
     // Add edit button if allowed, otherwise show, again if allowed
     if ($menuItem = $this->findAllowedMenuItem('edit')) {
         $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge));
     }
 }
コード例 #18
0
 /**
  * Apply respondent relation settings to the round model
  * 
  * For respondent surveys, we allow to set a relation, with possible choices:
  * 
  *  null => the respondent
  *  0    => undefined (specifiy when assigning)
  *  >0   => the id of the track field of type relation to use
  * 
  * @param \MUtil_Model_ModelAbstract $model The round model
  * @param array $itemData    The current items data
  * 
  * @return boolean True if the update changed values (usually by changed selection lists).
  */
 protected function applyRespondentRelation(\MUtil_Model_ModelAbstract $model, array &$itemData)
 {
     $model->set('gro_id_survey', 'onchange', 'this.form.submit();');
     if (!empty($itemData['gro_id_survey']) && $model->has('gro_id_relationfield')) {
         $forStaff = $this->tracker->getSurvey($itemData['gro_id_survey'])->isTakenByStaff();
         if (!$forStaff) {
             $empty = array('-1' => $this->_('Patient'));
             $relations = $this->getRespondentRelationFields();
             if (!empty($relations)) {
                 $relations = $empty + $relations;
                 $model->set('gro_id_relationfield', 'label', $this->_('Assigned to'), 'multiOptions', $relations, 'order', 25);
             }
             $model->del('ggp_name');
         } else {
             $model->set('ggp_name', 'label', $this->translateAdapter->_('Assigned to'), 'elementClass', 'Exhibitor', 'order', 25);
             $model->set('gro_id_relationfield', 'elementClass', 'hidden');
             $itemData['ggp_name'] = $this->db->fetchOne('select ggp_name from gems__groups join gems__surveys on ggp_id_group = gsu_id_primary_group and gsu_id_survey = ?', $itemData['gro_id_survey']);
             if (!is_null($itemData['gro_id_relationfield'])) {
                 $itemData['gro_id_relationfield'] = null;
             }
         }
     } else {
         $model->del('gro_id_relationfield', 'label');
         $model->del('ggp_name');
         if ($model->has('gro_id_relationfield')) {
             $itemData['gro_id_relationfield'] = null;
         }
     }
 }
コード例 #19
0
 /**
  * Adds elements from the model to the bridge that creates the form.
  *
  * Overrule this function to add different elements to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  */
 protected function addFormElements(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model)
 {
     if (!$this->createData) {
         $bridge->addHidden('gtr_id_track');
     }
     $bridge->addText('gtr_track_name');
     // gtr_track_class
     if ($this->trackEngine) {
         $options = $model->get('gtr_track_class', 'multiOptions');
         $alternatives = $this->trackEngine->getConversionTargets($options);
         if (count($alternatives) > 1) {
             $options = $alternatives;
             $bridge->addHidden($this->_oldClassName);
             if (!isset($this->formData[$this->_oldClassName])) {
                 $this->formData[$this->_oldClassName] = $this->formData['gtr_track_class'];
             }
             $classEdit = true;
         } else {
             $classEdit = false;
         }
     } else {
         $tracker = $this->loader->getTracker();
         $options = $tracker->getTrackEngineList(true, true);
         $classEdit = true;
     }
     $model->set('gtr_track_class', 'multiOptions', $options, 'escape', false);
     if ($classEdit) {
         $bridge->addRadio('gtr_track_class');
     } else {
         $bridge->addExhibitor('gtr_track_class');
     }
     $bridge->addDate('gtr_date_start');
     $bridge->addDate('gtr_date_until');
     if (!$this->createData) {
         $bridge->addCheckbox('gtr_active');
     }
     if ($model->has('gtr_code')) {
         $bridge->addText('gtr_code');
     }
     if ($model->has('gtr_calculation_event', 'label')) {
         $bridge->add('gtr_calculation_event');
     }
     if ($model->has('gtr_completed_event', 'label')) {
         $bridge->add('gtr_completed_event');
     }
     if ($model->has('gtr_beforefieldupdate_event', 'label')) {
         $bridge->add('gtr_beforefieldupdate_event');
     }
     if ($model->has('gtr_fieldupdate_event', 'label')) {
         $bridge->add('gtr_fieldupdate_event');
     }
     $bridge->add('gtr_organizations');
     if (\MUtil_Bootstrap::enabled()) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gtr_organizations]'));
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gtr_organizations]'));
     }
     $element->setLabel($this->_('Toggle'));
     $bridge->addElement($element);
 }
コード例 #20
0
ファイル: BridgeAbstract.php プロジェクト: GemsTracker/MUtil
 /**
  * Returns true if name is in the model
  *
  * @param string $name
  * @return boolean
  */
 public function has($name)
 {
     if ($this->model->has($name)) {
         return true;
     }
     $modelKeys = $this->model->getKeys();
     return (bool) isset($modelKeys[$name]);
 }