/**
  * 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.");
 }
 /**
  * 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';
     }
 }
 /**
  * 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;
 }
 /**
  * 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), '\';');
 }
 /**
  * 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. 7
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. 8
0
 /**
  * Return the lazy value without any processing.
  *
  * @param string $name The field name or key name
  * @return \MUtil_Lazy_Call
  */
 public function getLazy($name)
 {
     return \MUtil_Lazy::call(array($this, 'getLazyValue'), $name);
 }
Esempio n. 9
0
 /**
  * FilesystemIterator::current — The current file
  *
  * @return mixed null or artray
  */
 public function current()
 {
     $file = parent::current();
     if (!$file instanceof SplFileInfo) {
         return null;
     }
     $real = \MUtil_File::cleanupSlashes($file->getRealPath());
     // The relative file name uses the windows directory seperator convention as this
     // does not screw up the use of this value as a parameter
     $rel = \MUtil_File::cleanupSlashes(\MUtil_String::stripStringLeft($real, $this->startPath));
     // Function was first implemented in PHP 5.3.6
     if (method_exists($file, 'getExtension')) {
         $extension = $file->getExtension();
     } else {
         $extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
     }
     return array('fullpath' => $real, 'relpath' => $rel, 'urlpath' => str_replace(array('\\', '/'), '|', $rel), 'path' => \MUtil_File::cleanupSlashes($file->getPath()), 'filename' => $file->getFilename(), 'extension' => $extension, 'content' => \MUtil_Lazy::call('file_get_contents', $real), 'size' => $file->getSize(), 'changed' => new \MUtil_Date($file->getMTime()));
 }
 /**
  * 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)
 {
     if ($this->escort instanceof \Gems_Project_Layout_MultiLayoutInterface) {
         $styles = \MUtil_Lazy::call(array($this->escort, 'getStyles'));
     } else {
         $styles = array();
     }
     $model = $this->loader->getModels()->getOrganizationModel($styles);
     if ($detailed) {
         if ('create' == $action || 'edit' == $action) {
             $model->applyEditSettings();
         } else {
             $model->applyDetailSettings();
         }
     } else {
         $model->applyBrowseSettings();
     }
     return $model;
 }
 /**
  * Creates a fake form so that it is (slightly) easier to
  * copy and paste a token.
  *
  * @param string $value Gems token value
  * @return \Gems_Form
  */
 public static function makeFakeForm($value)
 {
     $form = new \Gems_Form();
     $form->removeDecorator('HtmlTag');
     $element = new \Zend_Form_Element_Text('gto_id_token');
     $element->class = 'token_copy';
     $element->setDecorators(array('ViewHelper', array('HtmlTag', 'Div')));
     $form->addElement($element);
     $form->isValid(array('gto_id_token' => \MUtil_Lazy::call('strtoupper', $value)));
     return $form;
 }
 /**
  * The automatically filtered result
  *
  * @param $resetMvc When true only the filtered resulsts
  */
 public function autofilterAction($resetMvc = true)
 {
     // \MUtil_Model::$verbose = true;
     // We do not need to return the layout, just the above table
     if ($resetMvc) {
         // Make sure all links are generated as if the current request was index.
         $this->aliasAction('index');
         \Zend_Layout::resetMvcInstance();
     }
     if ($this->autofilterSnippets) {
         $params = $this->_processParameters($this->autofilterParameters + $this->_defaultAutofilterParameters);
         $this->addSnippets($this->autofilterSnippets, $params);
     }
     if ($resetMvc) {
         // Lazy call here, because any echo calls in the snippets have not yet been
         // performed. so they will appear only in the next call when not lazy.
         $this->html->raw(\MUtil_Lazy::call(array('MUtil_Echo', 'out')));
     }
 }
 /**
  * Add a cancel bubble command
  *
  * @param boolean $cancelBubble
  * @return \MUtil_Html_JavascriptArrayAttribute (continuation pattern)
  */
 public function addConfirm($question)
 {
     $this->add(array("if (!confirm('", \MUtil_Lazy::call('addslashes', $question), "')) {event.cancelBubble = true; return false;}"));
     return $this;
 }