/** * 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) { $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); }
public function getTable($baseurl) { $model = $this->getModel(); $bridge = $model->getBridgeFor('table', array('class' => 'timeTable table table-condensed table-bordered')); $repeater = $bridge->getRepeater(); $bridge->setBaseUrl(array($this->_actionKey => 'index', 'reset' => null) + $baseurl); // + $model->getFilter(); $columnClass = \MUtil_Lazy::iff($repeater->range, null, 'selectedColumn'); $this->setTableHeader($bridge, $repeater, $columnClass); $this->setTableBody($bridge, $repeater, $columnClass); $this->setTableFooter($bridge, $repeater, $columnClass); return $bridge->getTable(); }
/** * 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); } }
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; }
/** * 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) { $tUtil = $this->util->getTokenData(); $table = $bridge->getTable(); $table->appendAttrib('class', 'compliance'); $thead = $table->thead(); $th_row = $thead->tr(array('class' => 'rounds')); $th = $th_row->td(); $span = 1; $cRound = null; $cDesc = null; $thead->tr(); if ($showMenuItem = $this->getShowMenuItem()) { $bridge->addItemLink($showMenuItem->toActionLinkLower($this->request, $bridge)); } // Initialize alter $alternateClass = new \MUtil_Lazy_Alternate(array('odd', 'even')); foreach ($model->getItemsOrdered() as $name) { if ($label = $model->get($name, 'label')) { $round = $model->get($name, 'round'); if ($round == $cRound) { $span++; $class = null; } else { // If the round has an icon, show the icon else just 'R' since // complete round description messes up the display $th->append($cDesc); $th->title = $cRound; $th->colspan = $span; $span = 1; $cRound = $round; if ($cIcon = $model->get($name, 'roundIcon')) { $cDesc = \MUtil_Html_ImgElement::imgFile($cIcon, array('alt' => $cRound, 'title' => $cRound)); } else { if (substr($name, 0, 5) == 'stat_') { $cDesc = 'R'; } else { $cDesc = null; } } $class = 'newRound'; $thClass = $class . ' ' . $alternateClass; // Add alternate class only for th $th = $th_row->td(array('class' => $thClass)); } if ($model->get($name, 'noSort')) { $title = array(\MUtil_Lazy::method($tUtil, 'getStatusDescription', $bridge->{$name}), "\n" . $model->get($name, 'description')); $token = 'tok_' . substr($name, 5); $href = new \MUtil_Html_HrefArrayAttribute(array($this->request->getControllerKey() => 'track', $this->request->getActionKey() => 'show', \MUtil_Model::REQUEST_ID => $bridge->{$token})); $href->setRouteReset(); $onclick = new \MUtil_Html_OnClickArrayAttribute(); $onclick->addUrl($href)->addCancelBubble(); $tds = $bridge->addColumn(array(\MUtil_Html_AElement::iflink($bridge->{$token}, array($href, 'onclick' => 'event.cancelBubble = true;', 'title' => $title, $bridge->{$name}), $bridge->{$name}), 'class' => array('round', \MUtil_Lazy::method($tUtil, 'getStatusClass', $bridge->{$name})), 'title' => $title, 'onclick' => \MUtil_Lazy::iff($bridge->{$token}, $onclick)), array($label, 'title' => $model->get($name, 'description'), 'class' => 'round')); } else { $tds = $bridge->addSortable($name, $label); } if ($class) { $tds->appendAttrib('class', $class); } } } $th->append($cRound); $th->colspan = $span; }
/** * Returns a sequence of frist, previous, range, next and last conditional links. * * The condition is them being valid links, otherwise they are returned as span * elements. * * Note: This sequence is not added automatically to this object, you will have to * position it manually. * * @param string $first Label for goto first page link * @param string $previous Label for goto previous page link * @param string $next Label for goto next page link * @param string $last Label for goto last page link * @param string $glue In between links glue * @param mixed $args \MUtil_Ra::args extra arguments applied to all links * @return \MUtil_Html_Sequence */ public function pageLinks($first = '<<', $previous = '<', $next = '>', $last = '>>', $glue = ' ', $args = null) { $argDefaults = array('first' => '<<', 'previous' => '<', 'next' => '>', 'last' => '>>', 'glue' => ' '); $argNames = array_keys($argDefaults); $args = \MUtil_Ra::args(func_get_args(), $argNames, $argDefaults); foreach ($argNames as $name) { ${$name} = $args[$name]; unset($args[$name]); } $div = \MUtil_Html::create()->sequence(array('glue' => $glue)); if ($first) { // Can be null or array() $div[] = $this->firstPage((array) $first + $args); } if ($previous) { // Can be null or array() $div[] = $this->previousPage((array) $previous + $args); } $div[] = $this->rangePages($glue, $args); if ($next) { // Can be null or array() $div[] = $this->nextPage((array) $next + $args); } if ($last) { // Can be null or array() $div[] = $this->lastPage((array) $last + $args); } return \MUtil_Lazy::iff(\MUtil_Lazy::comp($this->pages->pageCount, '>', 1), $div); }
/** * Add an item based of a lazy if * * @param mixed $if * @param mixed $item * @param mixed $else * @return array */ public function itemIf($if, $item, $else = null) { if (is_string($if)) { $if = $this->{$if}; } return \MUtil_Lazy::iff($if, $item, $else); }
/** * Returns a sequence of frist, previous, range, next and last conditional links. * * The condition is them being valid links, otherwise they are returned as span * elements. * * Note: This sequence is not added automatically to this object, you will have to * position it manually. * * @param string $first Label for goto first page link * @param string $previous Label for goto previous page link * @param string $next Label for goto next page link * @param string $last Label for goto last page link * @param string $glue In between links glue * @param mixed $args \MUtil_Ra::args extra arguments applied to all links * @return \MUtil_Html_Sequence */ public function pageLinks($first = '<<', $previous = '<', $next = '>', $last = '>>', $glue = ' ', $args = null) { $argDefaults = array('first' => '<<', 'previous' => '<', 'next' => '>', 'last' => '>>', 'glue' => ' '); $argNames = array_keys($argDefaults); $args = \MUtil_Ra::args(func_get_args(), $argNames, $argDefaults); foreach ($argNames as $name) { ${$name} = $args[$name]; unset($args[$name]); } $container = \MUtil_Html::create()->ul(array('class' => 'pagination pagination-sm pull-left')); if ($first) { // Can be null or array() $container[] = $this->firstPage((array) $first + $args); } if ($previous) { // Can be null or array() $container[] = $this->previousPage((array) $previous + $args); } $this->range = true; $container[] = $this->rangePages('', $args); $this->range = false; if ($next) { // Can be null or array() $container[] = $this->nextPage((array) $next + $args); } if ($last) { // Can be null or array() $container[] = $this->lastPage((array) $last + $args); } return \MUtil_Lazy::iff(\MUtil_Lazy::comp($this->pages->pageCount, '>', 1), $container); }
/** * * @param mixed $parameterSources_args * @return \MUtil_Html_AElement */ public function toActionLink($parameterOrLabelSources_args = null) { if ($this->get('allowed')) { $parameterSources = func_get_args(); $label = $this->get('label'); $showDisabled = false; foreach ($parameterSources as $key => $source) { if (is_string($source) || $source instanceof \MUtil_Html_HtmlInterface) { $label = $source; unset($parameterSources[$key]); } if (is_bool($source)) { $showDisabled = $source; unset($parameterSources[$key]); } } if ($this->has('icon')) { $label = array($this->get('icon'), $label); } $condition = true; if ($href = $this->_toHRef(new \Gems_Menu_ParameterCollector($parameterSources), $condition)) { if ($condition instanceof \MUtil_Lazy_LazyInterface) { if ($showDisabled) { // There is a (lazy) condition and disabled buttons should show // so make the link an if $element = \MUtil_Html::create()->actionLink(\MUtil_Lazy::iff($condition, $href), $label); // and make the tagName an if $element->tagName = \MUtil_Lazy::iff($condition, 'a', 'span'); $element->appendAttrib('class', \MUtil_Lazy::iff($condition, '', 'disabled')); } else { // There is a (lazy) condition and nothing should show when not there // so make the label an if $label = \MUtil_Lazy::iff($condition, $label); $element = \MUtil_Html::create()->actionLink($href, $label); } } else { $element = \MUtil_Html::create()->actionLink($href, $label); } if ($title = $this->get('title')) { $element->title = $title; } // and make sure nothing shows when empty $element->setOnEmpty(null); $element->renderWithoutContent = false; foreach (array('onclick', 'rel', 'target', 'type') as $name) { if ($this->has($name)) { $value = $this->get($name); if (is_scalar($value) && isset($href[$value])) { $value = $href[$value]; } if ($condition instanceof \MUtil_Lazy_LazyInterface && $showDisabled) { $element->{$name} = \MUtil_Lazy::iff($condition, $value); } else { $element->{$name} = $value; } } } } elseif ($showDisabled) { // \MUtil_Echo::r($label, 'No href'); $element = \MUtil_Html::create()->actionDisabled($label); } else { return; } if ($class = $this->get('class')) { $element->appendAttrib('class', $class); } return $element; } }