public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     parent::getHtmlOutput($view);
     $respondentModel = $this->model;
     $respondentData = $this->data;
     $respondentId = $this->respondentId;
     $html = $this->getHtmlSequence();
     if (empty($this->data)) {
         $html->p()->b(sprintf($this->_('Unknown respondent %s'), $respondentId));
         return $html;
     }
     $bridge = $respondentModel->getBridgeFor('itemTable', array('class' => 'browser table'));
     $bridge->setRepeater(\MUtil_Lazy::repeat(array($respondentData)));
     $bridge->th($this->_('Respondent information'), array('colspan' => 4));
     $bridge->setColumnCount(2);
     foreach ($respondentModel->getItemsOrdered() as $name) {
         if ($label = $respondentModel->get($name, 'label')) {
             $bridge->addItem($name, $label);
         }
     }
     $tableContainer = \MUtil_Html::create()->div(array('class' => 'table-container'));
     $tableContainer[] = $bridge->getTable();
     $html->h2($this->_('Respondent information') . ': ' . $respondentId);
     $html[] = $tableContainer;
     $html->hr();
     return $html;
 }
 /**
  * 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)
 {
     // \MUtil_Model::$verbose = true;
     //
     // Initiate data retrieval for stuff needed by links
     $bridge->gr2o_patient_nr;
     $bridge->gr2o_id_organization;
     $bridge->gr2t_id_respondent_track;
     $HTML = \MUtil_Html::create();
     $roundIcon[] = \MUtil_Lazy::iif($bridge->gto_icon_file, \MUtil_Html::create('img', array('src' => $bridge->gto_icon_file, 'class' => 'icon')), \MUtil_Lazy::iif($bridge->gro_icon_file, \MUtil_Html::create('img', array('src' => $bridge->gro_icon_file, 'class' => 'icon'))));
     $bridge->addMultiSort('gsu_survey_name', $roundIcon);
     $bridge->addSortable('ggp_name');
     $bridge->addSortable('calc_used_date', null, $HTML->if($bridge->is_completed, 'disabled date', 'enabled date'));
     $bridge->addSortable('gto_changed');
     $bridge->addSortable('assigned_by', $this->_('Assigned by'));
     // If we are allowed to see the result of the survey, show them
     $user = $this->loader->getCurrentUser();
     if ($user->hasPrivilege('pr.respondent.result')) {
         $bridge->addSortable('gto_result', $this->_('Score'), 'date');
     }
     $bridge->useRowHref = false;
     $actionLinks[] = $this->createMenuLink($bridge, 'track', 'answer');
     $actionLinks[] = array($bridge->ggp_staff_members->if($this->createMenuLink($bridge, 'ask', 'take'), $bridge->calc_id_token->strtoupper()), 'class' => $bridge->ggp_staff_members->if(null, $bridge->calc_id_token->if('token')));
     // calc_id_token is empty when the survey has been completed
     // Remove nulls
     $actionLinks = array_filter($actionLinks);
     if ($actionLinks) {
         $bridge->addItemLink($actionLinks);
     }
     $this->addTokenLinks($bridge);
 }
 /**
  * A list of all participating organizations.
  *
  * @return \MUtil_Html_HtmlElement
  */
 private function _getOrganizationsList()
 {
     $html = new \MUtil_Html_Sequence();
     $sql = '
         SELECT *
         FROM gems__organizations
         WHERE gor_active=1 AND gor_url IS NOT NULL AND gor_task IS NOT NULL
         ORDER BY gor_name';
     // $organizations = array();
     // $organizations = array(key($organizations) => reset($organizations));
     $organizations = $this->db->fetchAll($sql);
     $orgCount = count($organizations);
     switch ($orgCount) {
         case 0:
             return $html->pInfo(sprintf($this->_('%s is still under development.'), $this->project->getName()));
         case 1:
             $organization = reset($organizations);
             $p = $html->pInfo(sprintf($this->_('%s is run by: '), $this->project->getName()));
             $p->a($organization['gor_url'], $organization['gor_name']);
             $p->append('.');
             $html->pInfo()->sprintf($this->_('Please contact the %s if you have any questions regarding %s.'), $organization['gor_name'], $this->project->getName());
             return $html;
         default:
             $p = $html->pInfo(sprintf($this->_('%s is a collaboration of these organizations:'), $this->project->getName()));
             $data = \MUtil_Lazy::repeat($organizations);
             $ul = $p->ul($data, array('class' => 'indent'));
             $li = $ul->li();
             $li->a($data->gor_url->call($this, '_'), $data->gor_name, array('rel' => 'external'));
             $li->append(' (');
             $li->append($data->gor_task->call(array($this, '_')));
             $li->append(')');
             $html->pInfo()->sprintf($this->_('You can contact any of these organizations if you have questions regarding %s.'), $this->project->getName());
             return $html;
     }
 }
 /**
  * Returns a callable if a method is called as a variable
  *
  * @param string $name
  * @return \MUtil_Lazy_Call
  */
 public function __get($name)
 {
     if (method_exists($this, $name)) {
         // Return a callable
         return \MUtil_Lazy::call(array($this, $name));
     }
     throw new \Gems_Exception_Coding("Unknown method '{$name}' requested as callable.");
 }
Esempio n. 5
0
 /**
  * When true the output should be displayed in the result HEAD,
  * otherwise in the BODY.
  *
  * @return boolean
  */
 public function getInHeader()
 {
     if ($this->_inHeader instanceof \MUtil_Lazy_LazyInterface) {
         return (bool) \MUtil_Lazy::raise($this->_inHeader);
     } else {
         return (bool) $this->_inHeader;
     }
 }
Esempio n. 6
0
 /**
  * Returns a value for $name
  *
  * @param string $name A name indentifying a value in this stack.
  * @return A value for $name
  */
 public function lazyGet($name)
 {
     // \MUtil_Echo::track($name, isset($this->_object->$name), \MUtil_Lazy::rise($this->_object->$name), $this->_object->getLazyValue($name));
     $value = $this->_object->__get($name);
     if ($value instanceof \MUtil_Lazy_LazyInterface) {
         return \MUtil_Lazy::rise($value);
     }
     return $value;
 }
 /**
  * Place to set the data to display
  *
  * @param \MUtil_Model_Bridge_VerticalTableBridge $bridge
  * @return void
  */
 protected function addTableCells(\MUtil_Model_Bridge_VerticalTableBridge $bridge)
 {
     $bridge->setColumnCount(1);
     $HTML = \MUtil_Html::create();
     $bridge->tdh($this->getCaption(), array('colspan' => 2));
     // Caption for tracks
     $trackLabel = $this->_('Assigned tracks');
     if ($menuItem = $this->findMenuItem('track', 'index')) {
         $href = $menuItem->toHRefAttribute($this->request, $bridge);
         $bridge->tdh(array('class' => 'linked'))->a($href, $trackLabel);
     } else {
         $bridge->tdh($trackLabel, array('class' => 'linked'));
     }
     $bridge->tr();
     // ROW 1
     $bridge->addItem($bridge->gr2o_patient_nr, $this->_('Respondent nr: '));
     $rowspan = 10;
     // Column for tracks
     $tracksModel = $this->model->getRespondentTracksModel();
     $tracksData = \MUtil_Lazy::repeat($tracksModel->load(array('gr2o_patient_nr' => $this->repeater->gr2o_patient_nr, 'gr2o_id_organization' => $this->repeater->gr2o_id_organization), array('gr2t_created' => SORT_DESC)));
     $tracksList = $HTML->div($tracksData, array('class' => 'tracksList'));
     $tracksList->setOnEmpty($this->_('No tracks'));
     if ($menuItem = $this->findMenuItem('track', 'show-track')) {
         $href = $menuItem->toHRefAttribute($tracksData, array('gr2o_patient_nr' => $this->repeater->gr2o_patient_nr));
         $tracksTarget = $tracksList->p()->a($href);
     } else {
         $tracksTarget = $tracksList->p();
     }
     $tracksTarget->strong($tracksData->gtr_track_name);
     $tracksTarget[] = ' ';
     $tracksTarget->em($tracksData->gr2t_track_info, array('renderWithoutContent' => false));
     $tracksTarget[] = ' ';
     $tracksTarget[] = \MUtil_Lazy::call($this->util->getTranslated()->formatDate, $tracksData->gr2t_created);
     $bridge->td($tracksList, array('rowspan' => $rowspan, 'class' => 'linked tracksList'));
     // OTHER ROWS
     $bridge->addItem($HTML->spaced($bridge->itemIf('grs_last_name', array($bridge->grs_last_name, ',')), $bridge->grs_first_name, $bridge->grs_surname_prefix), $this->_('Respondent'));
     $bridge->addItem('grs_gender');
     $bridge->addItem('grs_birthday');
     $bridge->addItem('grs_email');
     $bridge->addItem('gr2o_created');
     $bridge->addItem('gr2o_created_by');
     if ($this->onclick) {
         // TODO: can we not use $repeater?
         $href = array('location.href=\'', $this->onclick, '\';');
         foreach ($bridge->tbody() as $tr) {
             foreach ($tr as $td) {
                 if (strpos($td->class, 'linked') === false) {
                     $td->onclick = $href;
                 } else {
                     $td->onclick = 'event.cancelBubble=true;';
                 }
             }
         }
         $bridge->tbody()->onclick = '// Dummy for CSS';
     }
 }
 /**
  * Create the snippets content
  *
  * This is a stub function either override getHtmlOutput() or override render()
  *
  * @param \Zend_View_Abstract $view Just in case it is needed here
  * @return \MUtil_Html_HtmlInterface Something that can be rendered
  */
 public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     $tUtil = $this->util->getTokenData();
     $repeater = new \MUtil_Lazy_RepeatableByKeyValue($tUtil->getEveryStatus());
     $table = new \MUtil_Html_TableElement();
     $table->class = 'compliance timeTable rightFloat table table-condensed';
     $table->setRepeater($repeater);
     $table->throw($this->_('Legend'));
     $table->td($repeater->key)->class = array('round', \MUtil_Lazy::method($tUtil, 'getStatusClass', $repeater->key));
     $table->td($repeater->value);
     return $table;
 }
 public function __construct($data)
 {
     $result = array();
     $cvars = get_class_vars(get_class($data));
     $vars = get_object_vars($data);
     if (count($vars)) {
         foreach ($vars as $name => $value) {
             $result[] = array('name' => $name, 'value' => \MUtil_Lazy::property($data, $name), 'from_code' => array_key_exists($name, $cvars));
         }
         $this->_hasProperties = true;
     } else {
         $this->_hasProperties = false;
     }
     parent::__construct($result);
 }
 /**
  * Create the snippets content
  *
  * This is a stub function either override getHtmlOutput() or override render()
  *
  * @param \Zend_View_Abstract $view Just in case it is needed here
  * @return \MUtil_Html_HtmlInterface Something that can be rendered
  */
 public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     $html = $this->getHtmlSequence();
     if ($this->trackName) {
         $html->h3(sprintf($this->_('Surveys in %s track'), $this->trackName));
     }
     $trackRepeater = $this->getRepeater($this->trackId);
     $table = $html->div(array('class' => 'table-container'))->table($trackRepeater, array('class' => 'browser table'));
     if ($link = $this->findMenuItem('project-tracks', 'questions')) {
         $table->tr()->onclick = array('location.href=\'', $link->toHRefAttribute($trackRepeater), '\';');
         $table->addColumn($link->toActionLinkLower($trackRepeater));
     }
     $surveyName[] = $trackRepeater->gsu_survey_name;
     $surveyName[] = \MUtil_Lazy::iif($trackRepeater->gro_icon_file, \MUtil_Html::create('img', array('src' => $trackRepeater->gro_icon_file, 'class' => 'icon')));
     $table->addColumn($surveyName, $this->_('Survey'));
     $table->addColumn($trackRepeater->gro_round_description, $this->_('Details'));
     $table->addColumn($trackRepeater->ggp_name, $this->_('By'));
     $table->addColumn($trackRepeater->gsu_survey_description->call(array(__CLASS__, 'oneLine')), $this->_('Description'));
     return $html;
 }
 /**
  * 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)
 {
     $bridge->tr()->class = $bridge->row_class;
     if ($showMenuItem = $this->getShowMenuItem()) {
         $bridge->addItemLink($showMenuItem->toActionLinkLower($this->request, $bridge));
     }
     // make sure search results are highlighted
     $this->applyTextMarker();
     $br = \MUtil_Html::create()->br();
     $orgName[] = \MUtil_Lazy::iff($bridge->gor_url, \MUtil_Html_AElement::a($bridge->gor_name, array('href' => $bridge->gor_url, 'target' => '_blank', 'class' => 'globe')), $bridge->gor_name);
     $orgName[] = $bridge->createSortLink('gor_name');
     $mailName[] = \MUtil_Lazy::iff($bridge->gor_contact_email, \MUtil_Html_AElement::email(\MUtil_Lazy::first($bridge->gor_contact_name, $bridge->gor_contact_email), array('href' => array('mailto:', $bridge->gor_contact_email))), $bridge->gor_contact_name);
     $mailName[] = $bridge->createSortLink('gor_contact_name');
     $bridge->addMultiSort($orgName, $br, 'gor_task', $br, 'gor_location');
     $bridge->addMultiSort($mailName, $br, 'gor_active', $br, 'gor_has_login');
     $bridge->addMultiSort('gor_add_respondents', $br, 'gor_has_respondents', $br, 'gor_respondent_group');
     $bridge->add('gor_accessible_by');
     if ($editMenuItem = $this->getEditMenuItem()) {
         $bridge->addItemLink($editMenuItem->toActionLinkLower($this->request, $bridge));
     }
 }
 /**
  * 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)
 {
     // Signal the bridge that we need these values
     $bridge->gr2t_id_respondent_track;
     $bridge->gr2t_id_respondent_track;
     $bridge->gr2o_patient_nr;
     $bridge->can_edit;
     $controller = $this->request->getControllerName();
     $menuList = $this->menu->getMenuList();
     $menuList->addByController($controller, 'show-track')->addByController($controller, 'edit-track')->addParameterSources($bridge)->setLowerCase()->showDisabled();
     $bridge->setOnEmpty($this->_('No other assignments of this track.'));
     // If we have a track Id and is not excluded: mark it!
     if ($this->respondentTrackId && !$this->excludeCurrent) {
         $bridge->tr()->appendAttrib('class', \MUtil_Lazy::iff(\MUtil_Lazy::comp($bridge->gr2t_id_respondent_track, '==', $this->respondentTrackId), 'currentRow', null));
     }
     // Add show-track button if allowed, otherwise show, again if allowed
     $bridge->addItemLink($menuList->getActionLink($controller, 'show-track'));
     parent::addBrowseTableColumns($bridge, $model);
     // Add edit-track button if allowed (and not current
     $bridge->addItemLink($menuList->getActionLink($controller, 'edit-track'));
 }
 /**
  * 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)
 {
     // Signal the bridge that we need these values
     $bridge->gr2t_id_respondent_track;
     $bridge->gr2o_patient_nr;
     $bridge->tr()->appendAttrib('class', \MUtil_Lazy::iif($bridge->gro_id_round, $bridge->row_class, array($bridge->row_class, ' inserted')));
     $title = \MUtil_Html::create()->strong($this->_('+'));
     $showLinks[] = $this->createMenuLink($bridge, 'track', 'show', $title);
     // Remove nulls
     $showLinks = array_filter($showLinks);
     // Columns
     $bridge->addSortable('gsu_survey_name')->append(\MUtil_Lazy::iif($bridge->gro_icon_file, \MUtil_Lazy::iif($bridge->gto_icon_file, \MUtil_Html::create('img', array('src' => $bridge->gto_icon_file, 'class' => 'icon')), \MUtil_Lazy::iif($bridge->gro_icon_file, \MUtil_Html::create('img', array('src' => $bridge->gro_icon_file, 'class' => 'icon'))))));
     $bridge->addSortable('gto_round_description');
     $bridge->addSortable('ggp_name');
     $bridge->addSortable('gto_valid_from', null, 'date');
     $bridge->addSortable('gto_completion_time', null, 'date');
     $bridge->addSortable('gto_valid_until', null, 'date');
     if ($this->loader->getCurrentUser()->hasPrivilege('pr.respondent.result')) {
         $bridge->addSortable('gto_result', $this->_('Score'), 'date');
     }
     $actionLinks[] = $this->createMenuLink($bridge, 'track', 'answer');
     $actionLinks[] = array($bridge->ggp_staff_members->if($this->createMenuLink($bridge, 'ask', 'take'), $bridge->can_be_taken->if($bridge->calc_id_token->strtoupper())), 'class' => $bridge->ggp_staff_members->if(null, $bridge->calc_id_token->if('token')));
     // Remove nulls
     $actionLinks = array_filter($actionLinks);
     if ($actionLinks) {
         $bridge->addItemLink($actionLinks);
     }
     if ($showLinks) {
         foreach ($showLinks as $showLink) {
             if ($showLink) {
                 $showLink->title = array($this->_('Token'), $bridge->gto_id_token->strtoupper());
             }
         }
         $bridge->addItemLink($showLinks);
     }
 }
 /**
  * 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')));
 }
 /**
  * Get the file icons
  *
  * @param \MUtil_Model_Bridge_TableBridge $bridge
  * @return array $icon => $menuItem or array($menuItem, $other)
  */
 protected function getFileIcons(\MUtil_Model_Bridge_TableBridge $bridge)
 {
     $onDelete = new \MUtil_Html_OnClickArrayAttribute();
     $onDelete->addConfirm(\MUtil_Lazy::call('sprintf', $this->_("Are you sure you want to delete '%s'?"), $bridge->relpath));
     return array('process.png' => $this->findMenuItem($this->request->getControllerName(), 'import'), 'download.png' => $this->findMenuItem($this->request->getControllerName(), 'download'), 'eye.png' => $this->findMenuItem($this->request->getControllerName(), 'show'), 'edit.png' => $this->findMenuItem($this->request->getControllerName(), 'edit'), 'delete.png' => array($this->findMenuItem($this->request->getControllerName(), 'delete'), $onDelete));
 }
Esempio n. 16
0
 /**
  * The current content
  *
  * @return string
  */
 public function getValue()
 {
     return \MUtil_Lazy::raise($this->_value);
 }
Esempio n. 17
0
 /**
  * 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()
 {
     if (!$this->repeater) {
         $this->repeater = \MUtil_Lazy::repeat($this->data);
     } else {
         // We do not know whether there is any link between
         // the data and the repeater, so do not use the data
         $this->data = null;
     }
     // If onEmpty is set, we alwars have output
     if ($this->onEmpty) {
         return true;
     }
     // Is there any data in the repeater?
     return $this->repeater->__start();
 }
Esempio n. 18
0
 /**
  * Mark the searches in $value
  *
  * @param mixed $value Lazy, Html, Raw or string
  * @return \MUtil_Html_Raw
  */
 public function mark($value)
 {
     if (!$this->_replaces) {
         // Late setting of search & replaces
         $searches = $this->_searches;
         $this->_searches = array();
         // Do not use the $tag itself here: str_replace will then replace
         // the text of tag itself on later finds
         $topen = '<' . self::TAG_MARKER . '>';
         $tclose = '</' . self::TAG_MARKER . '>';
         foreach ((array) $searches as $search) {
             $searchHtml = $this->escape($search);
             $this->_searches[] = $searchHtml;
             $this->_replaces[] = $topen . $searchHtml . $tclose;
         }
     }
     if ($value instanceof \MUtil_Lazy_LazyInterface) {
         $value = \MUtil_Lazy::rise($value);
     }
     if ($value instanceof \MUtil_Html_Raw) {
         $values = array();
         // Split into HTML Elements
         foreach ($value->getElements() as $element) {
             if (strlen($element)) {
                 switch ($element[0]) {
                     case '<':
                     case '&':
                         // No replace in element
                         $values[] = $element;
                         break;
                     default:
                         $values[] = $this->_findTags($element);
                 }
             }
         }
         // \MUtil_Echo::r($values);
         return $value->setValue($this->_fillTags(implode('', $values)));
     } elseif ($value instanceof \MUtil_Html_HtmlElement) {
         foreach ($value as $key => $item) {
             // \MUtil_Echo::r($key);
             $value[$key] = $this->mark($item);
         }
         return $value;
     } elseif ($value || $value === 0) {
         // \MUtil_Echo::r($value);
         $valueHtml = $this->escape($value);
         $valueTemp = $this->_findTags($valueHtml);
         return new \MUtil_Html_Raw($this->_fillTags($valueTemp));
     }
 }
 /**
  * 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);
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $model = new \Gems_Model_JoinModel('resptrack', 'gems__respondent2track');
     $model->addTable('gems__respondent2org', array('gr2t_id_user' => 'gr2o_id_user', 'gr2t_id_organization' => 'gr2o_id_organization'));
     $model->addTable('gems__tracks', array('gr2t_id_track' => 'gtr_id_track'));
     $model->addTable('gems__reception_codes', array('gr2t_reception_code' => 'grc_id_reception_code'));
     $model->addFilter(array('grc_success' => 1));
     $model->resetOrder();
     $model->set('gr2o_patient_nr', 'label', $this->_('Respondent nr'));
     $model->set('gr2t_start_date', 'label', $this->_('Start date'), 'dateFormat', 'dd-MM-yyyy');
     $model->set('gr2t_end_date', 'label', $this->_('End date'), 'dateFormat', 'dd-MM-yyyy');
     $filter = $this->getSearchFilter($action !== 'export');
     if (!(isset($filter['gr2t_id_organization']) && $filter['gr2t_id_organization'])) {
         $model->addFilter(array('gr2t_id_organization' => $this->currentUser->getRespondentOrgFilter()));
     }
     if (!(isset($filter['gr2t_id_track']) && $filter['gr2t_id_track'])) {
         $model->setFilter(array('1=0'));
         $this->autofilterParameters['onEmpty'] = $this->_('No track selected...');
         return $model;
     }
     // Add the period filter - if any
     if ($where = \Gems_Snippets_AutosearchFormSnippet::getPeriodFilter($filter, $this->db)) {
         $model->addFilter(array($where));
     }
     $select = $this->db->select();
     $select->from('gems__rounds', array('gro_id_round', 'gro_id_order', 'gro_round_description', 'gro_icon_file'))->joinInner('gems__surveys', 'gro_id_survey = gsu_id_survey', array('gsu_survey_name'))->where('gro_id_track = ?', $filter['gr2t_id_track'])->order('gro_id_order');
     if (isset($filter['gsu_id_primary_group']) && $filter['gsu_id_primary_group']) {
         $select->where('gsu_id_primary_group = ?', $filter['gsu_id_primary_group']);
     }
     $data = $this->db->fetchAll($select);
     if (!$data) {
         return $model;
     }
     $status = $this->util->getTokenData()->getStatusExpression();
     $select = $this->db->select();
     $select->from('gems__tokens', array('gto_id_respondent_track', 'gto_id_round', 'gto_id_token', 'status' => $status))->joinInner('gems__reception_codes', 'gto_reception_code = grc_id_reception_code', array())->where('gto_id_track = ?', $filter['gr2t_id_track'])->order('grc_success')->order('gto_id_respondent_track')->order('gto_round_order');
     // \MUtil_Echo::track($this->db->fetchAll($select));
     $newModel = new \MUtil_Model_SelectModel($select, 'tok');
     $newModel->setKeys(array('gto_id_respondent_track'));
     $transformer = new \MUtil_Model_Transform_CrossTabTransformer();
     $transformer->addCrosstabField('gto_id_round', 'status', 'stat_')->addCrosstabField('gto_id_round', 'gto_id_token', 'tok_');
     foreach ($data as $row) {
         $name = 'stat_' . $row['gro_id_round'];
         $transformer->set($name, 'label', \MUtil_Lazy::call('substr', $row['gsu_survey_name'], 0, 2), 'description', sprintf("%s\n[%s]", $row['gsu_survey_name'], $row['gro_round_description']), 'noSort', true, 'round', $row['gro_round_description'], 'roundIcon', $row['gro_icon_file']);
         $transformer->set('tok_' . $row['gro_id_round']);
     }
     $newModel->addTransformer($transformer);
     // \MUtil_Echo::track($data);
     $joinTrans = new \MUtil_Model_Transform_JoinTransformer();
     $joinTrans->addModel($newModel, array('gr2t_id_respondent_track' => 'gto_id_respondent_track'));
     $model->resetOrder();
     $model->set('gr2o_patient_nr');
     $model->set('gr2t_start_date');
     $model->addTransformer($joinTrans);
     return $model;
 }
Esempio n. 21
0
 /**
  * The functions that fixes and returns a value.
  *
  * Be warned: this function may return a lazy value.
  *
  * @param \MUtil_Lazy_StackInterface $stack A \MUtil_Lazy_StackInterface object providing variable data
  * @return mixed
  */
 public function __toValue(\MUtil_Lazy_StackInterface $stack)
 {
     foreach ($this->_values as $value) {
         if ($value && $value instanceof \MUtil_Lazy_LazyInterface) {
             $value = \MUtil_Lazy::riseObject($value, $stack);
         }
         if (!$value) {
             return false;
         }
     }
     return true;
 }
 /**
  * Add first columns (group) from the model to the bridge that creates the browse table.
  *
  * You can actually add more than one column in this function, but just call all four functions
  * with the default columns in each
  *
  * 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 addBrowseColumn3(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
 {
     $br = \MUtil_Html::create('br');
     if ($model->hasAlias('gems__respondent2track')) {
         $model->set('gtr_track_name', 'label', $this->_('Track'));
         $model->set('gr2t_track_info', 'label', $this->_('Track description'));
         $items = $this->findMenuItems('track', 'show-track');
         $track = 'gtr_track_name';
         if ($items) {
             $menuItem = reset($items);
             if ($menuItem instanceof \Gems_Menu_MenuAbstract) {
                 $href = $menuItem->toHRefAttribute($this->request, $bridge, array('gr2t_id_respondent_track' => $bridge->gr2t_id_respondent_track));
                 $track = array();
                 $track[0] = \MUtil_Lazy::iif($bridge->gr2t_id_respondent_track, \MUtil_Html::create()->a($href, $bridge->gtr_track_name, array('onclick' => "event.cancelBubble = true;")));
                 $track[1] = $bridge->createSortLink('gtr_track_name');
             }
         }
         $bridge->addMultiSort($track, $br, 'gr2t_track_info');
     } else {
         $citysep = \MUtil_Html::raw('&nbsp;&nbsp;');
         // $bridge->itemIf($bridge->grs_zipcode, \MUtil_Html::raw('&nbsp;&nbsp;'));
         $bridge->addMultiSort('grs_address_1', $br, 'grs_zipcode', $citysep, 'grs_city');
     }
 }
Esempio n. 23
0
 /**
  * Get a Lazy call to the current element's decorator output or property
  * output if the decorator does not exist
  *
  * @param string $name
  * @return \MUtil_Lazy_Call
  */
 public function __get($name)
 {
     // Form elements have few public properties, so usually we use this as a
     // shortcut for a decorator function, however, if the property exists
     // (and no Decorator with the same name exists) the property value will
     // be returned.
     return \MUtil_Lazy::call(array($this, 'getDecorator'), ucfirst($name));
 }
 protected function setTableHeader(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Lazy_RepeatableInterface $repeater, $columnClass)
 {
     $baseurl = $bridge->getBaseUrl();
     // Left cell with period types
     $th = $bridge->th($this->_('Period'), ' ');
     $th->class = 'middleAlign';
     $thdiv = $th->span()->spaced();
     // array('class' => 'rightFloat'));
     $contents = $this->getDateLabels();
     foreach ($this->getDateDescriptions() as $letter => $title) {
         if (isset($contents[$letter])) {
             $content = $contents[$letter];
         } else {
             $content = strtolower($this->_($letter));
         }
         if ($letter == $this->dateType) {
             $thdiv->span($content, array('class' => 'browselink btn btn-primary btn-xs disabled'));
         } else {
             $thdiv->a(array(self::DATE_TYPE => $letter, self::DATE_FACTOR => $this->dateFactorChanges[$letter]) + $baseurl, $content, array('class' => 'browselink btn btn-default btn-xs', 'title' => $title));
         }
     }
     // Repeating column
     switch ($this->dateType) {
         case 'D':
             // $header = $repeater->period_1;
             $header = $repeater->period_1->call($this->util->getTranslated()->formatDate);
             break;
         case 'W':
             $header = array($repeater->period_1, \MUtil_Html::create()->br(), \MUtil_Lazy::call('sprintf', $this->_('week %s'), $repeater->period_2));
             break;
         case 'M':
             $header = array($repeater->period_1, \MUtil_Html::create()->br(), $repeater->period_2->call($this->util->getLocalized()->getMonthName));
             break;
         case 'Y':
             $header = $repeater->period_1;
             break;
         default:
             throw new \Gems_Exception_Coding('Incorrect date_type value: ' . $this->dateType);
             //  $this->_getParam('date_type', 'W'));
     }
     $th = $bridge->th();
     $th->class = array($this->dataCellClass, $columnClass);
     $th->a(array(self::DATE_FACTOR => $repeater->date_factor, \MUtil_Model::AUTOSEARCH_RESET => null) + $baseurl, $header);
     $th->setRepeater($repeater);
     $th->setRepeatTags(true);
     $baseurl[\Gems_Selector_DateSelectorAbstract::DATE_FACTOR] = $repeater->date_factor;
     $baseurl[\Gems_Selector_DateSelectorAbstract::DATE_GROUP] = null;
     $th->onclick = array('location.href=\'', new \MUtil_Html_HrefArrayAttribute($baseurl), '\';');
 }
 /**
  * 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()
 {
     if ($this->model) {
         $this->model->setIfExists('grs_email', 'itemDisplay', array('MUtil_Html_AElement', 'ifmail'));
         $this->model->setIfExists('gr2o_comments', 'rowspan', 2);
         if ($this->showConsentWarning && $this->model->has('gr2o_consent')) {
             $this->model->set('gr2o_consent', 'formatFunction', array($this, 'checkConsent'));
         }
         if (!$this->repeater) {
             if (!$this->respondent) {
                 $this->repeater = $this->model->loadRepeatable();
             } else {
                 $data = array($this->respondent->getArrayCopy());
                 $this->repeater = \MUtil_Lazy::repeat($data);
             }
         }
         return true;
     }
     return false;
 }
 /**
  * This is the actual format function, copied from the Exhibitor for field
  *
  * @param type $name
  * @param type $result
  *@param \MUtil_Model_ModelAbstract $model
  * @return type
  */
 private function _format($name, $result, $model)
 {
     static $view = null;
     if (!isset($this->_options[$name])) {
         $this->_options[$name] = $model->get($name, array('default', 'multiOptions', 'formatFunction', 'dateFormat', 'storageFormat', 'itemDisplay'));
     }
     $options = $this->_options[$name];
     foreach ($options as $key => $value) {
         switch ($key) {
             case 'default':
                 if (is_null($result)) {
                     $result = $value;
                 }
                 break;
             case 'multiOptions':
                 $multiOptions = $value;
                 if (is_array($multiOptions)) {
                     /*
                      *  Sometimes a field is an array and will be formatted later on using the
                      *  formatFunction -> handle each element in the array.
                      */
                     if (is_array($result)) {
                         foreach ($result as $key => $value) {
                             if (array_key_exists($value, $multiOptions)) {
                                 $result[$key] = $multiOptions[$value];
                             }
                         }
                     } else {
                         if (array_key_exists($result, $multiOptions)) {
                             $result = $multiOptions[$result];
                         }
                     }
                 }
                 break;
             case 'formatFunction':
                 $callback = $value;
                 $result = call_user_func($callback, $result);
                 break;
             case 'dateFormat':
                 if (array_key_exists('formatFunction', $options)) {
                     // if there is a formatFunction skip the date formatting
                     continue;
                 }
                 $dateFormat = $value;
                 $storageFormat = $model->get($name, 'storageFormat');
                 $result = \MUtil_Date::format($result, $dateFormat, $storageFormat);
                 break;
             case 'itemDisplay':
                 $function = $value;
                 if (is_callable($function)) {
                     $result = call_user_func($function, $result);
                 } elseif (is_object($function)) {
                     if ($function instanceof \MUtil_Html_ElementInterface || method_exists($function, 'append')) {
                         $object = clone $function;
                         $result = $object->append($result);
                     }
                 } elseif (is_string($function)) {
                     // Assume it is a html tag when a string
                     $result = \MUtil_Html::create($function, $result);
                 }
             default:
                 break;
         }
     }
     if (is_object($result)) {
         // If it is Lazy, execute it
         if ($result instanceof \MUtil_Lazy_LazyInterface) {
             $result = \MUtil_Lazy::rise($result);
         }
         // If it is Html, render it
         if ($result instanceof \MUtil_Html_HtmlInterface) {
             if (is_null($view)) {
                 $viewRenderer = \Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
                 if (null === $viewRenderer->view) {
                     $viewRenderer->initView();
                 }
                 $view = $viewRenderer->view;
             }
             $result = $result->render($view);
         }
     }
     return $result;
 }
Esempio n. 27
0
 /**
  * Converts an associative array to a string of tag attributes.
  *
  * @access public
  *
  * @param array $attribs From this array, each key-value pair is
  * converted to an attribute name and value.
  *
  * @return string The XHTML for the attributes.
  */
 protected function _htmlAttribs($attribs)
 {
     if (isset($attribs['src'])) {
         $filename = \MUtil_Lazy::rise($attribs['src']);
         if ($dir = self::getImageDir($filename)) {
             if (!isset($attribs['width'], $attribs['height'])) {
                 try {
                     $info = getimagesize(self::getWebRoot() . $dir . $filename);
                     if (!isset($attribs['width'])) {
                         $attribs['width'] = $info[0];
                     }
                     if (!isset($attribs['height'])) {
                         $attribs['height'] = $info[1];
                     }
                 } catch (\Exception $e) {
                     if (\MUtil_Html::$verbose) {
                         \MUtil_Echo::r($e, __CLASS__ . '->' . __FUNCTION__);
                     }
                 }
             }
             $attribs['src'] = $this->view->baseUrl() . $dir . $filename;
         }
         // \MUtil_Echo::r($attribs['src']);
     }
     return parent::_htmlAttribs($attribs);
 }
Esempio n. 28
0
 /**
  * Return a mailto link if $email exists and other wise return nothing.
  *
  * @param mixed $email
  * @param mixed $arg_array
  * @return mixed
  */
 public static function ifmail($email, $arg_array = null)
 {
     $args = func_get_args();
     if ($email instanceof \MUtil_Lazy_LazyInterface) {
         return \MUtil_Lazy::iff($email, call_user_func_array(array(__CLASS__, 'email'), $args));
     }
     if ($email) {
         return self::email($args);
     }
 }
Esempio n. 29
0
 /**
  * Apply this element to the form as the output decorator with automatically calculated widths.
  *
  * @param \Zend_Form $form
  * @param float $factor To multiply the widest nummers of letters in the labels with to calculate the width in em at drawing time
  * @param array $order The display order of the elements
  * @return \MUtil_Html_PFormElement
  */
 public function setAutoWidthFormLayout(\Zend_Form $form, $factor = 1, array $order = array('label', 'element', 'description'))
 {
     // Lazy call becase the form might not be completed at this stage.
     return $this->setAsFormLayout($form, \MUtil_Lazy::call(array('MUtil_Html_DlElement', 'calculateAutoWidthFormLayout'), $form, $factor), $order);
 }
Esempio n. 30
0
 public static function smallData($value, $args_array = null)
 {
     $args = func_get_args();
     $element = \MUtil_Lazy::iff($value, \MUtil_Html::createArray('small', array(' [', $args, ']')));
     return $element;
 }