sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
protected function getAutoSearchElements(array $data) { $elements = parent::getAutoSearchElements($data); $elements[] = new \Zend_Form_Element_Hidden(\MUtil_Model::REQUEST_ID); return $elements; }
Returns a text element for autosearch. Can be overruled. The form / html elements to search on. Elements can be grouped by inserting null's between them. That creates a distinct group of elements @param array $data The $form field values (can be usefull, but no need to set them) @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks.
entailment
public function writeTo($filename) { parent::writeTo($filename); if ($this->optimiserService instanceof ImageOptimiserInterface) { $this->optimiserService->optimiseImage($filename); } }
Calls the original writeTo function and then after that completes optimises the image @param string $filename
entailment
public function canResetPassword(\Gems_User_User $user = null) { if ($user) { // Depends on the user. if ($user->hasEmailAddress() && $user->canSetPassword()) { $email = $user->getEmailAddress(); if (empty($email)) { return false; } else { return true; } } } else { return true; } }
Return true if a password reset key can be created. Returns the setting for the definition whan no user is passed, otherwise returns the answer for this specific user. @param \Gems_User_User $user Optional, the user whose password might change @return boolean
entailment
public function checkRehash(\Gems_User_User $user, $password) { if (! $this->canSaveNewHash()) { return false; } $model = new \MUtil_Model_TableModel('gems__user_passwords'); $row = $model->loadFirst(['gup_id_user' => $user->getUserLoginId()]); if ($row && password_needs_rehash($row['gup_password'], $this->getHashAlgorithm(), $this->getHashOptions())) { $data['gup_id_user'] = $user->getUserLoginId(); $data['gup_password'] = $this->hashPassword($password); $model = new \MUtil_Model_TableModel('gems__user_passwords'); \Gems_Model::setChangeFieldsByPrefix($model, 'gup', $user->getUserId()); $model->save($data); return true; } return false; }
Checks if the current users hashed password uses the current hash algorithm. If not it rehashes and saves the current password @param \Gems_User_User $user Current logged in user @param integer $password Raw password @return boolean password has been rehashed
entailment
public function getAuthAdapter(\Gems_User_User $user, $password) { $db2 = $this->getDb2(); $credentialValidationCallback = $this->getCredentialValidationCallback(); $adapter = new CallbackCheckAdapter($db2, 'gems__user_passwords', 'gul_login', 'gup_password', $credentialValidationCallback); $select = $adapter->getDbSelect(); $select->join('gems__user_logins', 'gup_id_user = gul_id_user', array()) ->where('gul_can_login = 1') ->where(array('gul_id_organization ' => $user->getBaseOrganizationId())); $adapter->setIdentity($user->getLoginName()) ->setCredential($password); return $adapter; }
Returns an initialized Zend\Authentication\Adapter\AdapterInterface @param \Gems_User_User $user @param string $password @return Zend\Authentication\Adapter\AdapterInterface
entailment
public function getCredentialValidationCallback() { if ($this->checkOldHashes) { $credentialValidationCallback = function($dbCredential, $requestCredential) { if (password_verify($requestCredential, $dbCredential)) { return true; } elseif ($dbCredential == $this->hashOldPassword($requestCredential)) { return true; } return false; }; } else { $credentialValidationCallback = function($dbCredential, $requestCredential) { if (password_verify($requestCredential, $dbCredential)) { return true; } return false; }; } return $credentialValidationCallback; }
get the credential validation callback function for the callback check adapter @return callback Function
entailment
protected function getDb2() { if (!$this->db2 instanceof Adapter) { $config = Zend_Controller_Front::getInstance()->getParam('bootstrap'); $resources = $config->getOption('resources'); $dbConfig = array( 'driver' => $resources['db']['adapter'], 'hostname' => $resources['db']['params']['host'], 'database' => $resources['db']['params']['dbname'], 'username' => $resources['db']['params']['username'], 'password' => $resources['db']['params']['password'], 'charset' => $resources['db']['params']['charset'], ); $this->db2 = new Adapter($dbConfig); } return $this->db2; }
Create a Zend DB 2 Adapter needed for the Zend\Authentication library @return Zend\Db\Adapter\Adapter Zend Db Adapter
entailment
public function getPasswordResetKey(\Gems_User_User $user) { $model = new \MUtil_Model_TableModel('gems__user_passwords'); \Gems_Model::setChangeFieldsByPrefix($model, 'gup', $user->getUserId()); $data['gup_id_user'] = $user->getUserLoginId(); $filter = $data; if ((0 == ($this->hoursResetKeyIsValid % 24)) || \Zend_Session::$_unitTestEnabled) { $filter[] = 'ADDDATE(gup_reset_requested, ' . intval($this->hoursResetKeyIsValid / 24) . ') >= CURRENT_TIMESTAMP'; } else { $filter[] = 'DATE_ADD(gup_reset_requested, INTERVAL ' . $this->hoursResetKeyIsValid . ' HOUR) >= CURRENT_TIMESTAMP'; } $row = $model->loadFirst($filter); if ($row && $row['gup_reset_key']) { // Keep using the key. $data['gup_reset_key'] = $row['gup_reset_key']; } else { $data['gup_reset_key'] = hash('sha256', time() . $user->getEmailAddress()); } $data['gup_reset_requested'] = new \MUtil_Db_Expr_CurrentTimestamp(); // Loop for case when hash is not unique while (true) { try { $model->save($data); return $data['gup_reset_key']; } catch (\Zend_Db_Exception $zde) { $data['gup_reset_key'] = hash('sha256', time() . $user->getEmailAddress()); } } }
Return a password reset key @param \Gems_User_User $user The user to create a key for. @return string
entailment
public function getUserData($login_name, $organization) { $select = $this->getUserSelect($login_name, $organization); try { $result = $this->db->fetchRow($select, array($login_name, $organization), \Zend_Db::FETCH_ASSOC); } catch (\Zend_Db_Statement_Exception $e) { // \MUtil_Echo::track($e->getMessage()); // Yeah ugly. Can be removed when all projects have been patched to 1.8.4 $sql = $select->__toString(); $sql = str_replace(['`gems__user_logins`.`gul_two_factor_key`', '`gems__user_logins`.`gul_enable_2factor`'], 'NULL', $sql); // \MUtil_Echo::track($sql); try { // Next try $result = $this->db->fetchRow($sql, array($login_name, $organization), \Zend_Db::FETCH_ASSOC); } catch (\Zend_Db_Statement_Exception $e) { // Can be removed when all projects have been patched to 1.6.2 $sql = str_replace('gup_last_pwd_change', 'gup_changed', $sql); // Last try $result = $this->db->fetchRow($sql, array($login_name, $organization), \Zend_Db::FETCH_ASSOC); } } /* * Handle the case that we have a login record, but no matching userdata (ie. user is inactive) * if you want some kind of auto-register you should change this */ if ($result == false) { $result = \Gems_User_NoLoginDefinition::getNoLoginDataFor($login_name, $organization); } return $result; }
Returns a user object, that may be empty if the user is unknown. @param string $login_name @param int $organization @return array Of data to fill the user with.
entailment
public function hasPassword(\Gems_User_User $user) { $sql = "SELECT CASE WHEN gup_password IS NULL THEN 0 ELSE 1 END FROM gems__user_passwords WHERE gup_id_user = ?"; return (boolean) $this->db->fetchOne($sql, $user->getUserLoginId()); }
Return true if the user has a password. @param \Gems_User_User $user The user to check @return boolean
entailment
public function setPassword(\Gems_User_User $user, $password) { $data['gup_id_user'] = $user->getUserLoginId(); $data['gup_reset_key'] = null; $data['gup_reset_requested'] = null; $data['gup_reset_required'] = 0; if (null === $password) { // Passwords may be emptied. $data['gup_password'] = null; } elseif ($this->canSaveNewHash()) { $data['gup_password'] = $this->hashPassword($password); } else { $data['gup_password'] = $this->hashOldPassword($password); } $data['gup_last_pwd_change'] = new \Zend_Db_Expr('CURRENT_TIMESTAMP'); $model = new \MUtil_Model_TableModel('gems__user_passwords'); \Gems_Model::setChangeFieldsByPrefix($model, 'gup', $user->getUserId()); $model->save($data); return $this; }
Set the password, if allowed for this user type. @param \Gems_User_User $user The user whose password to change @param string $password @return \Gems_User_UserDefinitionInterface (continuation pattern)
entailment
public function getHtmlOutput(\Zend_View_Abstract $view) { $messages = false; if ($this->wasAnswered) { $this->currentToken = $this->token->getNextUnansweredToken(); } else { $validator = $this->loader->getTracker()->getTokenValidator(); if ($validator->isValid($this->token->getTokenId())) { $this->currentToken = $this->token; } else { $messages = $validator->getMessages(); $this->currentToken = $this->token->getNextUnansweredToken(); } } if ($this->currentToken instanceof \Gems_Tracker_Token) { $href = $this->getTokenHref($this->currentToken); $url = $href->render($this->view); // Redirect at once header('Location: ' . $url); exit(); } // After the header() so that the patient does not see the messages after answering surveys if ($messages) { $this->addMessage($messages); } $org = $this->token->getOrganization(); $html = $this->getHtmlSequence(); $html->h3($this->_('Token')); $html->pInfo(sprintf($this->_('Thank you %s,'), $this->token->getRespondentName())); if ($welcome = $org->getWelcome()) { $html->pInfo()->raw(\MUtil_Markup::render($this->_($welcome), 'Bbcode', 'Html')); } $p = $html->pInfo()->spaced(); if ($this->wasAnswered) { $p->append($this->_('Thanks for answering our questions.')); } elseif (! $this->token->isCurrentlyValid()) { if ($this->token->isExpired()) { $this->addMessage($this->_('This survey has expired. You can no longer answer it.')); } else { $this->addMessage($this->_('This survey is no longer valid.')); } } $p->append($this->_('We have no further questions for you at the moment.')); $p->append($this->_('We appreciate your cooperation very much.')); if ($sig = $org->getSignature()) { $html->pInfo()->raw(\MUtil_Markup::render($this->_($sig), 'Bbcode', 'Html')); } /* $html->br(); $href = array($this->request->getActionKey() => 'index', \MUtil_Model::REQUEST_ID => null); $buttonDiv = $html->buttonDiv(array('class' => 'centerAlign')); $buttonDiv->actionLink($href, $this->_('OK')); // */ return $html; }
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
entailment
public function Upgrade143to150() { $this->_batch->addTask('Db_AddPatches', 42); $this->_batch->addTask('Db_AddPatches', 43); $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Echo', $this->_('Syncing surveys for all sources')); //Now sync the db sources to allow limesurvey source to add a field to the tokentable $model = new \MUtil_Model_TableModel('gems__sources'); $data = $model->load(false); foreach ($data as $row) { $this->_batch->addTask('Tracker_SourceSyncSurveys', $row['gso_id_source']); } return true; }
To upgrade from 143 to 15 we need to do some work: 1. execute db patches 42 and 43 2. create new tables
entailment
public function Upgrade154to155() { $this->_batch->addTask('Db_AddPatches', 48); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); return true; }
To upgrade to 1.5.5 just execute patchlevel 48
entailment
public function Upgrade155to156() { $this->_batch->addTask('Db_AddPatches', 49); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); return true; }
To upgrade to 1.5.6 just execute patchlevel 49
entailment
public function Upgrade157to16() { $this->_batch->addTask('Db_AddPatches', 51); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); return true; }
To upgrade to 1.6 just execute patchlevel 51
entailment
public function Upgrade16to161() { $this->_batch->addTask('Db_AddPatches', 52); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); return true; }
To upgrade to 1.6.1 just execute patchlevel 52
entailment
public function Upgrade161to162() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 53); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); return true; }
To upgrade to 1.6.2 just execute patchlevel 53
entailment
public function Upgrade162to163() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 54); $this->_batch->addTask('Updates_UpdateRoleIds'); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); return true; }
To upgrade to 1.6.3 just execute patchlevel 54
entailment
public function Upgrade163to164() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 55); $this->_batch->addTask('Updates_CompileTemplates'); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); return true; }
To upgrade to 1.6.4 just execute patchlevel 55
entailment
public function Upgrade164to170() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 56); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); return true; }
To upgrade to 1.7.0
entailment
public function Upgrade170to171() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 57); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); $this->_batch->addTask('Echo', $this->_('Check the Code compatibility report for any issues with project specific code!')); return true; }
To upgrade to 1.7.1
entailment
public function Upgrade171to172() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 58); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); $this->_batch->addTask('Echo', $this->_('Check the Code compatibility report for any issues with project specific code!')); return true; }
To upgrade to 1.7.2
entailment
public function Upgrade172to181() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 59); $this->_batch->addTask('Echo', $this->_('Make sure to read the changelog as it contains important instructions')); $this->_batch->addTask('Echo', $this->_('Check the Code compatibility report for any issues with project specific code!')); return true; }
To upgrade to 1.8.1
entailment
public function Upgrade181to182() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 60); // Use AddTask task to execute after patches $this->_batch->addTask('AddTask', 'Updates\\FillTokenReplacementsTask'); $this->_batch->addTask('AddTask', 'Echo', $this->_('Make sure to read the changelog as it contains important instructions')); $this->_batch->addTask('AddTask', 'Echo', $this->_('Check the Code compatibility report for any issues with project specific code!')); return true; }
To upgrade to 1.8.2
entailment
public function Upgrade182to183() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 61); // Use AddTask task to execute after patches $this->_batch->addTask('AddTask', 'Echo', $this->_('Make sure to read the changelog as it contains important instructions')); $this->_batch->addTask('AddTask', 'Echo', $this->_('Check the Code compatibility report for any issues with project specific code!')); return true; }
To upgrade to 1.8.3
entailment
public function Upgrade183to184() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 62); $this->_batch->addTask('Updates_CompileTemplates'); // Use AddTask task to execute after patches $this->_batch->addTask('AddTask', 'Echo', $this->_('Make sure to read the changelog as it contains important instructions')); $this->_batch->addTask('AddTask', 'Echo', $this->_('Check the Code compatibility report for any issues with project specific code!')); return true; }
To upgrade to 1.8.4
entailment
public function Upgrade184to185() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 63); // Use AddTask task to execute after patches $this->_batch->addTask('AddTask', 'Echo', $this->_('Make sure to read the changelog as it contains important instructions')); $this->_batch->addTask('AddTask', 'Echo', $this->_('Check the Code compatibility report for any issues with project specific code!')); return true; }
To upgrade to 1.8.5
entailment
public function Upgrade185to186() { $this->_batch->addTask('Db_CreateNewTables'); $this->_batch->addTask('Db_AddPatches', 64); // Use AddTask task to execute after patches $this->_batch->addTask('AddTask', 'Updates_EncryptPasswords', 'gems__sources', 'gso_id_source', 'gso_ls_password'); $this->_batch->addTask('AddTask', 'Updates_EncryptPasswords', 'gems__mail_servers', 'gms_from', 'gms_password'); $this->_batch->addTask('AddTask', 'Updates_EncryptPasswords', 'gems__radius_config', 'grcfg_id', 'grcfg_secret'); // Use AddTask task to execute after patches $this->_batch->addTask('AddTask', 'Echo', $this->_('Make sure to read the changelog as it contains important instructions')); $this->_batch->addTask('AddTask', 'Echo', $this->_('Check the Code compatibility report for any issues with project specific code!')); return true; }
To upgrade to 1.8.6
entailment
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) { $submodel = $model->get($name, 'model'); $subitems = $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 ($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); } } } } if ($submodel) { $subrow = $bridge->tr(); $subrow->th(); $subContainer = $subrow->td(); $this->addSubModelTable($bridge, $submodel, $subContainer); } }
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
entailment
public function getHtmlOutput(\Zend_View_Abstract $view) { $model = $this->getModel(); if ($this->trackUsage) { $model->trackUsage(); } $table = $this->getShowTable($model); $table->setRepeater($this->getRepeater($model)); return $table; }
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
entailment
public function addElement($element, $name = null, $options = null) { if ($this->currentTab) { return $this->currentTab->addElement($element, $name, $options); } else { parent::addElement($element, $name, $options); if (is_string($element)) { $element = $this->getElement($name); } //$this->addToOtherGroup($element); // Causes duplicate links on old browse edit if ($element instanceof \Zend_Form_Element_Hidden) { //Remove decorators $element->removeDecorator('HtmlTag'); $element->removeDecorator('Label'); $element->removeDecorator('DtDdWrapper'); } elseif ($element instanceof \Zend_Form_Element) { $element->removeDecorator('DtDdWrapper'); if ($element instanceof \MUtil_Form_Element_Html) { $element->removeDecorator('HtmlTag'); $element->removeDecorator('Label'); } $error = $element->getDecorator('Errors'); if ($error instanceof \Zend_Form_Decorator_Errors) { $element->removeDecorator('Errors'); $element->addDecorator($error); } } return $this; } }
Add an element to the form, when a tab (subform) had been added, it will return the subform instead of the form, keep this in mind when chaining methods @param string|\Zend_Form_Element $element @param string $name @param array|\Zend_Config $options @throws \Zend_Form_Exception on invalid element @return \Gems_TabForm|\Gems_Form_TabSubForm
entailment
public function addTab($name, $title) { if ($title instanceof \MUtil_Html_HtmlInterface) { $title = $title->render($this->getView()); } $tab = new \Gems_Form_TabSubForm(array('name' => $name, 'title' => strip_tags($title))); $this->currentTab = $tab; $this->addSubForm($tab, $name); return $tab; }
Add a tab to the form @param string $name @param string $title @return \Gems_Form_TabSubForm
entailment
public function addToOtherGroup($element) { if ($element instanceof \Zend_Form_Element) { if ($group = $this->getDisplayGroup(self::GROUP_OTHER)) { $group->addElement($element); } else { $this->addDisplayGroup(array($element), self::GROUP_OTHER); } } return $this; }
Add to the group all non-tab elements are in @param mixed $element @return \Gems_TabForm
entailment
public function addDisplayGroup(array $elements, $name, $options = null) { if ($this->currentTab) { return $this->currentTab->addDisplayGroup($elements, $name, $options); } else { //Add the group as usual parent::addDisplayGroup($elements, $name, $options); //Retrieve it and set decorators $group = $this->getDisplayGroup($name); $group->setDecorators( array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => $group->getName(). ' ' . $group->getAttrib('class'))) )); return $this; } }
Add an element to the form, when a tab (subform) had been added, it will return the subform instead of the form, keep this in mind when chaining methods @param array $elements @param string $name @param array|\Zend_Config $options @return \Gems_TabForm|\Gems_Form_TabSubForm @throws \Zend_Form_Exception if no valid elements provided
entailment
public function getDisplayGroup($name) { if ($group = parent::getDisplayGroup($name)) { return $group; } else { $subforms = $this->getSubForms(); foreach($subforms as $subform) { if ($group = $subform->getDisplayGroup($name)) { return $group; } } return; } }
Return a display group, use recursive search in subforms to provide a transparent experience with tabs @param string $name @return \Zend_Form_DisplayGroup|null
entailment
public function getElement($name) { if ($element = parent::getElement($name)) { return $element; } else { $subforms = $this->getSubForms(); foreach($subforms as $subform) { if ($element = $subform->getElement($name)) { return $element; } } return; } }
Retrieve a single element, use recursive search in subforms to provide a transparent experience with tabs @param string $name @return \Zend_Form_Element|null
entailment
public function getTab($name) { $tab = $this->getSubForm($name); $this->currentTab = $tab; return $tab; }
Retrieve a named tab (subform) and set the active tab to this one @param string $name @return \Gems_Form_TabSubForm
entailment
public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->setDecorators(array( 'TabErrors', array(array('SubformElements' => 'FormElements')), array('HtmlTag', array('tag' => 'div', 'id' => 'tabContainer', 'class' => 'mainForm')), array('TabContainer', array('id' => 'tabContainer', 'style' => 'width: 99%;')), 'FormElements', 'Form' )); } }
Load the default decorators @return void
entailment
public function setVerbose($bool) { $decorator = $this->getDecorator('TabErrors'); if ($decorator) { $decorator->setOption('verbose', (bool) $bool); } }
Set the form to be verbose, showing above the form what tabs have errors and possibly add custom (sub)formlevel error messages @param boolean $bool
entailment
public function setView(\Zend_View_Interface $view = null) { /** * If the form is populated... and we have a tab set... select it */ $tab = $this->getValue('tab'); if ($tab > 0) { $this->selectTab($tab); } parent::setView($view); if ($this->_view !== $view) { $this->activateJQuery(); } return $this; }
Set the view object @param \Zend_View_Interface $view @return \Gems_TabForm
entailment
public function getValues($suppressArrayNotation = false) { $values = parent::getValues($suppressArrayNotation); foreach ($this->getSubForms() as $key => $subForm) { $values = $this->_array_replace_recursive($values, $values[$key]); } return $values; }
Retrieve all form element values Fix for ZF error where subform values will be pushed into an array with key: formname for compatibility both are now in the result array @param bool $suppressArrayNotation @return array
entailment
public function applyFormatting($detailed = false, $edit = false) { $translated = $this->util->getTranslated(); $translator = $this->getTranslateAdapter(); if ($edit) { $dateFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat'); } else { $dateFormat = $translated->dateFormatString; } $this->resetOrder(); $this->set('gtr_track_name', 'label', $translator->_('Name')); $this->set('gtr_track_class', 'label', $translator->_('Track Engine'), 'multiOptions', $this->tracker->getTrackEngineList($detailed)); $this->set('gtr_survey_rounds', 'label', $translator->_('Surveys')); $this->set('gtr_active', 'label', $translator->_('Active'), 'multiOptions', $translated->getYesNo()); $this->set('gtr_date_start', 'label', $translator->_('From'), 'dateFormat', $dateFormat, 'formatFunction', $translated->formatDate); $this->set('gtr_date_until', 'label', $translator->_('Use until'), 'dateFormat', $dateFormat, 'formatFunction', $translated->formatDateForever); $this->setIfExists('gtr_code', 'label', $translator->_('Track code'), 'size', 10, 'description', $translator->_('Optional code name to link the track to program code.')); if ($detailed) { $events = $this->loader->getEvents(); $caList = $events->listTrackCalculationEvents(); if (count($caList) > 1) { $this->setIfExists('gtr_calculation_event', 'label', $translator->_('Before (re)calculation'), 'multiOptions', $caList ); } $coList = $events->listTrackCompletionEvents(); if (count($coList) > 1) { $this->setIfExists('gtr_completed_event', 'label', $translator->_('After completion'), 'multiOptions', $coList ); } $bfuList = $events->listTrackBeforeFieldUpdateEvents(); if (count($bfuList) > 1) { $this->setIfExists('gtr_beforefieldupdate_event', 'label', $translator->_('Before field update'), 'multiOptions', $bfuList ); } $fuList = $events->listTrackFieldUpdateEvents(); if (count($fuList) > 1) { $this->setIfExists('gtr_fieldupdate_event', 'label', $translator->_('After field update'), 'multiOptions', $fuList ); } $this->setIfExists('gtr_organizations', 'label', $translator->_('Organizations'), 'elementClass', 'MultiCheckbox', 'multiOptions', $this->util->getDbLookup()->getOrganizationsWithRespondents(), 'required', true ); $ct = new \MUtil_Model_Type_ConcatenatedRow('|', $translator->_(', ')); $ct->apply($this, 'gtr_organizations'); } if ($edit) { $this->set('toggleOrg', 'elementClass', 'ToggleCheckboxes', 'selectorName', 'gtr_organizations' ); $this->set('gtr_track_name', 'minlength', 4, 'size', 30, 'validators[unique]', $this->createUniqueValidator('gtr_track_name') ); } return $this; }
Sets the labels, format functions, etc... @param boolean $detailed True when shopwing detailed information @param boolean $edit When true use edit settings @return \Gems_Tracker_Model_TrackModel
entailment
public function delete($filter = true) { $this->setChanged(0); $tracks = $this->load($filter); if ($tracks) { foreach ($tracks as $row) { if (isset($row['gtr_id_track'])) { $trackId = $row['gtr_id_track']; if ($this->isDeleteable($trackId)) { $this->db->delete('gems__tracks', $this->db->quoteInto('gtr_id_track = ?', $trackId)); // Now cascade to children, they should take care of further cascading // Delete rounds $trackEngine = $this->tracker->getTrackEngine($trackId); $roundModel = $trackEngine->getRoundModel(false, index); $roundModel->delete(['gro_id_track' => $trackId]); // Delete trackfields $trackFieldModel = $trackEngine->getFieldsMaintenanceModel(false, 'index'); $trackFieldModel->delete(['gtf_id_track' => $trackId]); // Delete assigned but unused tracks $this->db->delete('gems__respondent2track', $this->db->quoteInto('gr2t_id_track = ?', $trackId)); } else { $values['gtr_id_track'] = $trackId; $values['gtr_active'] = 0; $this->save($values); } $this->addChanged(); } } } return $this->getChanged(); }
Delete items from the model This method also takes care of cascading to track fields and rounds @param mixed $filter True to use the stored filter, array to specify a different filter @return int The number of items deleted
entailment
public function isDeleteable($trackId) { if (! $trackId) { return true; } $sql = "SELECT gto_id_token FROM gems__tokens WHERE gto_id_track = ? AND gto_start_time IS NOT NULL"; return (boolean) ! $this->db->fetchOne($sql, $trackId); }
Can this track be deleted as is? @param int $trackId @return boolean
entailment
protected function _getFinalSql($tablePrefix, $repeat = false) { $db = \Zend_Registry::getInstance()->get('db'); $sqlSuffix = $db->quoteIdentifier($tablePrefix . '_changed') . " timestamp NOT NULL,\n" . $db->quoteIdentifier($tablePrefix . '_changed_by') . " bigint(20) NOT NULL,\n" . $db->quoteIdentifier($tablePrefix . '_created') . " timestamp NOT NULL,\n" . $db->quoteIdentifier($tablePrefix . '_created_by') . " bigint(20) NOT NULL,\n"; if ($repeat) { $sqlSuffix .= 'PRIMARY KEY (`' . $tablePrefix . '_id`, `' . $tablePrefix . '_response_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'; } else { $sqlSuffix .= 'PRIMARY KEY (`' . $tablePrefix . '_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'; } return $sqlSuffix; }
Add the changed/created by fields and add primary key @param string $tablePrefix @return string
entailment
protected function _processAnswer($key, $input, $type) { $output = array(); $modelName = str_replace('/', '_', $key); if (array_key_exists($key, $input)) { $value = $input[$key]; } else { return $output; } switch ($type) { case 'dateTime': // A null value will sometimes be empty, causing errors in \Zend_Date if (empty($value)) {$value = null;} $output[$modelName] = new \Zend_Date($value, \Zend_Date::ISO_8601); break; case 'select': $items = explode(' ', $value); foreach ($items as $idx => $answer) { $multiName = $modelName . '_' . $answer; $output[$multiName] = 1; } break; case 'geopoint': // Location split in 4 fields latitude, longitude, altitude and accuracy. $items = explode(' ', $value); if (count($items) == 4) { $output[$modelName . '_lat'] = $items[0]; $output[$modelName . '_long'] = $items[1]; $output[$modelName . '_alt'] = $items[2]; $output[$modelName . '_acc'] = $items[3]; } break; default: $output[$modelName] = $value; break; } return $output; }
If needed process the answer @param string $key @param mixed $value @param string $type @return array
entailment
private function flattenBody($xml, $context = '') { foreach ($xml as $elementName => $element) { //Check ref first $elementContext = $context; foreach ($element->attributes() as $name => $value) { if ($name == 'ref' || $name == 'nodeset' ) { if (!empty($elementContext)) { $elementContext .= '/'; } else { $elementContext = $this->bindRoot; } if (substr($value, 0, 1) == '/') { $elementContext = ''; } $elementContext .= $value; break; } } $result['context'] = $elementContext; $result['name'] = $element->getName(); //elementName can be label, hint, or a sub element (group, input, select, select1 switch ($elementName) { case 'label': $result['label'] = (string) $element; break; case 'hint': $result['hint'] = (string) $element; break; case 'value': $result['value'] = (string) $element; break; case 'trigger': case 'upload': case 'input': case 'select': case 'select1': //has only value and label but repeated, add value/label pairs in array $rawItem = $this->flattenBody($element, $elementContext); $rawItem['context'] = $elementContext; $rawItem['name'] = $element->getName(); $rawItem['attribs'] = $element->attributes(); $result[$rawItem['context']] = $rawItem; break; case 'item': //has only value and label but repeated, add value/label pairs in array $rawItem = $this->flattenBody($element->children(), $elementContext); unset($rawItem['context']); unset($rawItem['name']); $result['item'][$rawItem['value']] = $rawItem['label']; break; case 'repeat': case 'group': default: if (isset($result['context'], $result['label'])) { $this->groupLabels[$result['context']] = $result['label']; } unset($result['context']); unset($result['name']); $subarray = $this->flattenBody($element->children(), $elementContext); unset($subarray['context']); unset($subarray['label']); unset($subarray['hint']); unset($subarray['name']); // If it is a repeat element, we need to do something special when data is coming in if ($elementName == 'repeat') { foreach($subarray as $key => &$info) { $info['repeat'] = substr($elementContext, strlen($this->bindRoot)); } } $result = $result + $subarray; break; } } return $result; }
Return flattend element @param SimpleXMLElement $xml @param type $context
entailment
public function getDeviceIdField() { if (empty($this->deviceIdField)) { foreach ($this->_xml->children('h', true)->head->children()->model->bind as $bind) { if ($presets = $bind->attributes('jr', true)) { foreach ($presets as $value) { if ($value == 'deviceid') { $this->deviceIdField = $bind->attributes()->nodeset; break; } } } } } return $this->deviceIdField; }
Returns what field (path) contains the attributes jr:preload="property" jr:preloadParams="deviceid" from the moden -> bind elements @return string
entailment
public function getFormID() { if (empty($this->formID)) { foreach ($this->_xml->children('h', true)->head->children()->model->instance->children() as $element) { if (!empty($element->attributes()->id)) { $this->formID = $element->attributes()->id->__toString(); break; } } } return $this->formID; }
Returns the formID from the instance element id attribute @return string
entailment
public function getFormVersion() { if (empty($this->formVersion)) { foreach ($this->_xml->children('h', true)->head->children()->model->instance->children() as $element) { if (!empty($element->attributes()->version)) { $this->formVersion = $element->attributes()->version; break; } } } return $this->formVersion; }
Returns the formVersion from the instance element version attribute @return string
entailment
public function getTitle() { if (empty($this->title)) { $this->title = $this->_xml->children('h', true)->head->children('h', true)->title; } return $this->title; }
Returns the form title from the h:title element @return string
entailment
public function getChanges(array $context, $new) { $multi = explode(FieldAbstract::FIELD_SEP, $context['gtf_field_values']); return array( 'gtf_field_values' => array( 'label' => $this->_('Values'), 'description' => $this->_('Separate multiple values with a vertical bar (|)'), 'elementClass' => 'Textarea', 'formatFunction' => array($this, 'formatValues'), 'minlength' => 3,// At least two single chars and a separator 'rows' => 4, 'required' => true, ), 'gtf_field_default' => array( 'label' => $this->_('Default'), 'description' => $this->_('Choose the default value'), 'elementClass' => 'Select', 'multiOptions' => $this->util->getTranslated()->getEmptyDropdownArray() + array_combine($multi, $multi), ), ); }
Returns the changes that must be made in an array consisting of <code> array( field1 => array(setting1 => $value1, setting2 => $value2, ...), field2 => array(setting3 => $value3, setting4 => $value4, ...), </code> By using [] array notation in the setting name you can append to existing values. Use the setting 'value' to change a value in the original data. When a 'model' setting is set, the workings cascade. @param array $context The current data this object is dependent on @param boolean $new True when the item is a new record not yet saved @return array name => array(setting => value)
entailment
public function isValid($value) { foreach ((array) $value as $val) { if (\MUtil_String::contains($val, $this->_options[0])) { return true; } } return false; }
IS the comparison valid? Settings should already be in place by the construtor. @param mixed $value The id of the condition @return bool
entailment
public function afterRegistry() { parent::afterRegistry(); $this->browse = true; $this->caption = $this->_('Rounds with this condition'); $this->onEmpty = $this->_('No rounds using this condition found'); }
Called after the check that all required registry values have been set correctly has run. @return void
entailment
protected function createModel() { if (! $this->_model instanceof RoundModel) { $this->_model = new RoundModel(); $this->_model->addTable('gems__tracks', ['gro_id_track' => 'gtr_id_track']); $this->_model->addTable('gems__surveys', ['gro_id_survey' => 'gsu_id_survey']); $this->_model->addLeftTable('gems__groups', ['gsu_id_primary_group' => 'ggp_id_group']); $this->_model->addColumn("CASE WHEN gro_active = 1 THEN '' ELSE 'deleted' END", 'row_class'); $this->_model->set('gro_id_round'); $this->_model->set('gtr_track_name', 'label', $this->_('Track name')); $this->_model->set('gro_id_order', 'label', $this->_('Round order')); $this->_model->set('gro_round_description', 'label', $this->_('Description')); $this->_model->set('gsu_survey_name', 'label', $this->_('Survey')); $this->_model->set('ggp_name', 'label', $this->_('Assigned to')); $this->_model->set('gro_active', 'label', $this->_('Active'), 'multiOptions', $this->util->getTranslated()->getYesNo()); } // Now add the joins so we can sort on the real name // // $this->model->set('gsu_survey_name', $this->model->get('gro_id_survey')); return $this->_model; }
Creates the model @return \MUtil_Model_ModelAbstract
entailment
protected function processFilterAndSort(\MUtil_Model_ModelAbstract $model) { $conditionId = $this->request->getParam(\MUtil_Model::REQUEST_ID); //\MUtil_Model::$verbose = true; if ($conditionId) { $model->addFilter(['gro_condition' => $conditionId]); } $this->processSortOnly($model); }
Overrule to implement snippet specific filtering and sorting. @param \MUtil_Model_ModelAbstract $model
entailment
public function execute($tableData = array()) { $batch = $this->getBatch(); $batch->addToCounter('createTableStep'); $result = $this->dbaModel->runScript($tableData); $result[] = sprintf( $this->_('Finished %s %s creation script for object %d of %d'), $tableData['name'], $this->_(strtolower($tableData['type'])), $batch->getCounter('createTableStep'), $batch->getCounter('NewTableCount') ); if (count($result)>0) { foreach ($result as $result) { $batch->addMessage($result); } //Perform a clean cache only when needed $batch->setTask('CleanCache', 'cleancache'); //If already scheduled, don't reschedule } }
Should be called after answering the request to allow the Target to check if all required registry values have been set correctly. @return boolean False if required values are missing.
entailment
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)); } } }
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
entailment
public function afterRegistry() { parent::afterRegistry(); if (! $this->menuActionController) { $this->menuActionController = $this->request->getControllerName(); } }
Called after the check that all required registry values have been set correctly has run. @return void
entailment
protected function applyTextMarker() { $model = $this->getModel(); $textKey = $model->getTextFilter(); $filter = $model->getFilter(); if (isset($filter[$textKey])) { $searchText = $filter[$textKey]; // \MUtil_Echo::r('[' . $searchText . ']'); $marker = new \MUtil_Html_Marker($model->getTextSearches($searchText), 'strong', 'UTF-8'); foreach ($model->getItemNames() as $name) { if ($model->get($name, 'label')) { $model->set($name, 'markCallback', array($marker, 'mark')); } } } }
Make sure generic search text results are marked @return void
entailment
protected function findMenuItem($defaultController, $actions = 'index') { foreach ((array) $actions as $key => $action) { $controller = is_int($key) ? $defaultController : $key; $item = $this->menu->find(array('controller' => $controller, 'action' => $action, 'allowed' => true)); if ($item) { return $item; } } }
Finds a specific active menu item @param string $defaultController @param string|array $actions @return \Gems_Menu_SubMenuItem The first that @deprecated since 1.7.1, use findMenuItems()
entailment
public function getHtmlOutput(\Zend_View_Abstract $view) { $table = parent::getHtmlOutput($view); $table->getOnEmpty()->class = 'centerAlign'; if (($this->containingId || $this->keyboard) && (! self::$keyboardUsed)) { // Assign keyboard tracking only once self::$keyboardUsed = true; $this->applyHtmlAttributes($table); // If we are already in a containing div it is simple if ($this->containingId) { return array($table, new \Gems_JQuery_TableRowKeySelector($this->containingId)); } // Create a new containing div $div = \MUtil_Html::create()->div(array('id' => 'keys_target', 'class' => 'table-container'), $table); return array($div, new \Gems_JQuery_TableRowKeySelector($div)); } else { return $table; } }
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
entailment
public function getHtmlOutput(\Zend_View_Abstract $view) { $html = $this->getHtmlSequence(); if (! $this->trackData) { $html->h2($this->_('Unknown track')); $this->addMessage(sprintf($this->_('Unknown track id %s'), $this->trackId)); return $html; } if ($this->showHeader) { $html->h2(sprintf($this->_('%s track'), $this->trackData['gtr_track_name'])); } if (isset($this->trackData['gtr_date_until']) && $this->trackData['gtr_date_until']) { $html->pInfo( sprintf( $this->_('This track can be assigned from %s until %s.'), \MUtil_Date::format($this->trackData['gtr_date_start'], \Zend_Date::DATE_LONG), \MUtil_Date::format($this->trackData['gtr_date_until'], \Zend_Date::DATE_LONG)) ); } else { $html->pInfo( sprintf( $this->_('This track can be assigned since %s.'), \MUtil_Date::format($this->trackData['gtr_date_start'], \Zend_Date::DATE_LONG)) ); } return $html; }
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
entailment
public function hasHtmlOutput() { if (! $this->multiTracks) { return false; } if (! $this->trackData) { if (! $this->trackId) { if ($this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) { $this->trackId = $this->trackEngine->getTrackId(); } else { return false; } } $trackModel = new \MUtil_Model_TableModel('gems__tracks'); $this->trackData = $trackModel->loadFirst(array('gtr_id_track' => $this->trackId)); } elseif (! $this->trackId) { $this->trackId = $this->trackData['gtr_id_track']; } return parent::hasHtmlOutput(); }
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
entailment
public function getHtmlOutput(\Zend_View_Abstract $view) { if ($this->request->isPost()) { $this->export->render( $this->getRespondentIds(), $this->request->getParam('group'), $this->request->getParam('format') ); } else { $seq = new \MUtil_Html_Sequence(); if ($this->formTitle) { $seq->h2($this->formTitle); } $form = $this->export->getForm($this->hideGroup); $div = $seq->div(array('id' => 'mainform'), $form); $table = new \MUtil_Html_TableElement(array('class' => 'formTable')); $table->setAsFormLayout($form); $form->populate($this->request->getParams()); return $seq; } }
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
entailment
protected function _ensureRounds() { if (! is_array($this->_rounds)) { $roundSelect = $this->db->select(); $roundSelect->from('gems__rounds') ->where('gro_id_track = ?', $this->_trackId) ->order('gro_id_order'); // \MUtil_Echo::r((string) $roundSelect); $this->_rounds = array(); foreach ($roundSelect->query()->fetchAll() as $round) { $this->_rounds[$round['gro_id_round']] = $round; } } }
Loads the rounds data for this type of track engine. Can be overruled by sub classes.
entailment
protected function _getAvailableIcons() { $dir = GEMS_WEB_DIR . '/gems-responsive/images/icons'; if (!file_exists($dir)) { $dir = GEMS_WEB_DIR . '/gems/icons'; } $icons = array(); if (file_exists($dir)) { $iterator = new DirectoryIterator($dir); foreach ($iterator as $fileinfo) { if ($fileinfo->isFile()) { // $icons[$fileinfo->getFilename()] = $fileinfo->getFilename(); $filename = $fileinfo->getFilename(); $url = $this->view->baseUrl() . \MUtil_Html_ImgElement::getImageDir($filename); $icons[$fileinfo->getFilename()] = \MUtil_Html::create('span', $filename, array('style' => 'background: transparent url(' . $url . $filename . ') center right no-repeat; padding-right: 20px;')); } } } ksort($icons); // Sort by key return $icons; }
Returns a list of available icons under 'htdocs/pulse/icons' @return string[]
entailment
private function _update(array $values, $userId) { if ($this->tracker->filterChangesOnly($this->_trackData, $values)) { if (\Gems_Tracker::$verbose) { $echo = ''; foreach ($values as $key => $val) { $echo .= $key . ': ' . $this->_trackData[$key] . ' => ' . $val . "\n"; } \MUtil_Echo::r($echo, 'Updated values for ' . $this->_trackId); } if (! isset($values['gto_changed'])) { $values['gtr_changed'] = new \MUtil_Db_Expr_CurrentTimestamp(); } if (! isset($values['gtr_changed_by'])) { $values['gtr_changed_by'] = $userId; } // Update values in this object $this->_trackData = $values + $this->_trackData; // return 1; return $this->db->update('gems__tracks', $values, array('gtr_id_track = ?' => $this->_trackId)); } else { return 0; } }
Update the track, both in the database and in memory. @param array $values The values that this token should be set to @param int $userId The current user @return int 1 if data changed, 0 otherwise
entailment
public function addFieldsToModel(\MUtil_Model_ModelAbstract $model, $addDependency = true, $respTrackId = false) { if ($this->_fieldsDefinition->exists) { // Add the data to the load / save $transformer = new AddTrackFieldsTransformer($this->loader, $this->_fieldsDefinition, $respTrackId); $model->addTransformer($transformer); if ($addDependency) { $dependency = $this->_fieldsDefinition->getDataModelDependency(); if ($dependency instanceof DependencyInterface) { $model->addDependency($dependency); } } } return $this; }
Integrate field loading en showing and editing @param \MUtil_Model_ModelAbstract $model @param boolean $addDependency True when editing, can be false in all other cases @param string $respTrackId Optional Database column name where Respondent Track Id is set @return \Gems_Tracker_Engine_TrackEngineAbstract
entailment
protected function addNewTokens(\Gems_Tracker_RespondentTrack $respTrack, $userId) { $orgId = $respTrack->getOrganizationId(); $respId = $respTrack->getRespondentId(); $respTrackId = $respTrack->getRespondentTrackId(); // $this->t $sql = "SELECT gro_id_round, gro_id_survey, gro_id_order, gro_icon_file, gro_round_description FROM gems__rounds WHERE gro_id_track = ? AND gro_active = 1 AND gro_id_round NOT IN (SELECT gto_id_round FROM gems__tokens WHERE gto_id_respondent_track = ?) AND (gro_organizations IS NULL OR gro_organizations LIKE CONCAT('%|',?,'|%')) ORDER BY gro_id_order"; $newRounds = $this->db->fetchAll($sql, array($this->_trackId, $respTrackId, $orgId)); $this->db->beginTransaction(); foreach ($newRounds as $round) { $values = array(); // From the respondent track $values['gto_id_respondent_track'] = $respTrackId; $values['gto_id_respondent'] = $respId; $values['gto_id_organization'] = $orgId; $values['gto_id_track'] = $this->_trackId; // From the rounds $values['gto_id_round'] = $round['gro_id_round']; $values['gto_id_survey'] = $round['gro_id_survey']; $values['gto_round_order'] = $round['gro_id_order']; $values['gto_icon_file'] = $round['gro_icon_file']; $values['gto_round_description'] = $round['gro_round_description']; // All other values are not changed by this query and get the default DB value on insertion $this->tracker->createToken($values, $userId); } $this->db->commit(); return count($newRounds); }
Creates all tokens that should exist, but do not exist NOTE: When overruling this function you should not create tokens because they were deleted by the user @param \Gems_Tracker_RespondentTrack $respTrack The respondent track to check @param int $userId Id of the user who takes the action (for logging) @return int The number of tokens created by this code
entailment
public function afterRegistry() { parent::afterRegistry(); $this->_fieldsDefinition = $this->tracker->createTrackClass('Engine\\FieldsDefinition', $this->_trackId); }
Called after the check that all required registry values have been set correctly has run. @return void
entailment
public function applyToMenuSource(\Gems_Menu_ParameterSource $source) { $source->setTrackId($this->_trackId); $source->offsetSet('gtr_active', isset($this->_trackData['gtr_active']) ? $this->_trackData['gtr_active'] : 0); return $this; }
Set menu parameters from this track engine @param \Gems_Menu_ParameterSource $source @return \Gems_Tracker_Engine_TrackEngineInterface (continuation pattern)
entailment
protected function checkExistingRoundsFor(\Gems_Tracker_RespondentTrack $respTrack, $userId) { // FOR TESTING: sqlite can not de update and joins, so when testing just return zero for now if (\Zend_Session::$_unitTestEnabled === true) return 0; // @@ TODO Make this testable and not db dependent anymore // Quote here, I like to keep bound parameters limited to the WHERE // Besides, these statements are not order dependent while parameters are and do not repeat $qOrgId = $this->db->quote($respTrack->getOrganizationId()); $qRespId = $this->db->quote($respTrack->getRespondentId()); $qTrackId = $this->db->quote($this->_trackId); $qUserId = $this->db->quote($userId); $respTrackId = $respTrack->getRespondentTrackId(); $sql = "UPDATE gems__tokens, gems__rounds, gems__reception_codes SET gto_id_respondent = $qRespId, gto_id_organization = $qOrgId, gto_id_track = $qTrackId, gto_id_survey = CASE WHEN gto_start_time IS NULL AND grc_success = 1 THEN gro_id_survey ELSE gto_id_survey END, gto_round_order = gro_id_order, gto_icon_file = gro_icon_file, gto_round_description = gro_round_description, gto_changed = CURRENT_TIMESTAMP, gto_changed_by = $qUserId WHERE gto_id_round = gro_id_round AND gto_reception_code = grc_id_reception_code AND gto_id_round != 0 AND gro_active = 1 AND ( gto_id_respondent != $qRespId OR gto_id_organization != $qOrgId OR gto_id_track != $qTrackId OR gto_id_survey != CASE WHEN gto_start_time IS NULL AND grc_success = 1 THEN gro_id_survey ELSE gto_id_survey END OR gto_round_order != gro_id_order OR (gto_round_order IS NULL AND gro_id_order IS NOT NULL) OR (gto_round_order IS NOT NULL AND gro_id_order IS NULL) OR gto_icon_file != gro_icon_file OR (gto_icon_file IS NULL AND gro_icon_file IS NOT NULL) OR (gto_icon_file IS NOT NULL AND gro_icon_file IS NULL) OR gto_round_description != gro_round_description OR (gto_round_description IS NULL AND gro_round_description IS NOT NULL) OR (gto_round_description IS NOT NULL AND gro_round_description IS NULL) ) AND gto_id_respondent_track = ?"; $stmt = $this->db->query($sql, array($respTrackId)); return $stmt->rowCount(); }
Checks all existing tokens and updates any changes to the original rounds (when necessary) @param \Gems_Tracker_RespondentTrack $respTrack The respondent track to check @param int $userId Id of the user who takes the action (for logging) @return int The number of tokens changed by this code
entailment
public function checkRoundsFor(\Gems_Tracker_RespondentTrack $respTrack, $userId, \Gems_Task_TaskRunnerBatch $batch = null) { if (null === $batch) { $batch = new \Gems_Task_TaskRunnerBatch('tmp-tack-' . $respTrack->getRespondentTrackId()); } // Step one: update existing tokens $i = $batch->addToCounter('roundChangeUpdates', $this->checkExistingRoundsFor($respTrack, $userId)); $batch->setMessage('roundChangeUpdates', sprintf($this->_('Round changes propagated to %d tokens.'), $i)); // Step two: deactivate inactive rounds $i = $batch->addToCounter('deletedTokens', $this->removeInactiveRounds($respTrack, $userId)); $batch->setMessage('deletedTokens', sprintf($this->_('%d tokens deleted by round changes.'), $i)); // Step three: create lacking tokens $i = $batch->addToCounter('createdTokens', $this->addNewTokens($respTrack, $userId)); $batch->setMessage('createdTokens', sprintf($this->_('%d tokens created to by round changes.'), $i)); // Step four: set the dates and times //$changed = $this->checkTokensFromStart($respTrack, $userId); $changed = $respTrack->checkTrackTokens($userId); $ica = $batch->addToCounter('tokenDateCauses', $changed ? 1 : 0); $ich = $batch->addToCounter('tokenDateChanges', $changed); $batch->setMessage('tokenDateChanges', sprintf($this->_('%2$d token date changes in %1$d tracks.'), $ica, $ich)); $i = $batch->addToCounter('checkedRespondentTracks'); $batch->setMessage('checkedRespondentTracks', sprintf($this->_('Checked %d tracks.'), $i)); }
Check for the existence of all tokens and create them otherwise @param \Gems_Tracker_RespondentTrack $respTrack The respondent track to check @param int $userId Id of the user who takes the action (for logging) @param \Gems_Task_TaskRunnerBatch $changes batch for counters
entailment
public function copyTrack($oldTrackId) { $trackModel = $this->tracker->getTrackModel(); $roundModel = $this->getRoundModel(true, 'rounds'); $fieldModel = $this->getFieldsMaintenanceModel(); // First load the track $trackModel->applyParameters(array('id' => $oldTrackId)); $track = $trackModel->loadFirst(); // Create an empty track $newTrack = $trackModel->loadNew(); unset($track['gtr_id_track'], $track['gtr_changed'], $track['gtr_changed_by'], $track['gtr_created'], $track['gtr_created_by']); $track['gtr_track_name'] .= $this->_(' - Copy'); $newTrack = $track + $newTrack; // Now save (not done yet) $savedValues = $trackModel->save($newTrack); $newTrackId = $savedValues['gtr_id_track']; // Now copy the fields $fieldModel->applyParameters(array('id' => $oldTrackId)); $fields = $fieldModel->load(); if ($fields) { $oldIds = array(); $numFields = count($fields); $newFields = $fieldModel->loadNew($numFields); foreach ($newFields as $idx => $newField) { $field = $fields[$idx]; $oldIds[$idx] = $field['gtf_id_field']; unset($field['gtf_id_field'], $field['gtf_changed'], $field['gtf_changed_by'], $field['gtf_created'], $field['gtf_created_by']); $field['gtf_id_track'] = $newTrackId; $newFields[$idx] = $field + $newFields[$idx]; } // Now save (not done yet) $savedValues = $fieldModel->saveAll($newFields); foreach($savedValues as $idx => $field) { $oldNewFieldMap[$oldIds[$idx]] = $field['gtf_id_field']; } } else { $numFields = 0; } // Now copy the rounds and map the gro_id_relation to the right field $roundModel->applyParameters(array('id' => $oldTrackId)); $rounds = $roundModel->load(); if ($rounds) { $numRounds = count($rounds); $newRounds = $roundModel->loadNew($numRounds); foreach ($newRounds as $idx => $newRound) { $round = $rounds[$idx]; unset($round['gro_id_round'], $round['gro_changed'], $round['gro_changed_by'], $round['gro_created'], $round['gro_created_by']); $round['gro_id_track'] = $newTrackId; if (array_key_exists('gro_id_relationfield', $round) && $round['gro_id_relationfield']>0) { $round['gro_id_relationfield'] = $oldNewFieldMap[$round['gro_id_relationfield']]; } $newRounds[$idx] = $round + $newRounds[$idx]; } // Now save (not done yet) $savedValues = $roundModel->saveAll($newRounds); } else { $numRounds = 0; } //MUtil_Echo::track($track, $copy); //MUtil_Echo::track($rounds, $newRounds); //MUtil_Echo::track($fields, $newFields); Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->addMessage(sprintf($this->_('Copied track, including %s round(s) and %s field(s).'), $numRounds, $numFields)); return $newTrackId; }
Copy a track and all it's related data (rounds/fields etc) @param inte $oldTrackId The id of the track to copy @return int The id of the copied track
entailment
public function getConversionTargets(array $options) { $classParts = explode('_', get_class($this)); $className = end($classParts); return array($className => $options[$className]); }
Returns a list of classnames this track engine can be converted into. Should always contain at least the class itself. @see convertTo() @param array $options The track engine class options available in as a "track engine class names" => "descriptions" array @return array Filter or adaptation of $options
entailment
public function getFieldBeforeUpdateEvent() { if (isset($this->_trackData['gtr_beforefieldupdate_event']) && $this->_trackData['gtr_beforefieldupdate_event']) { return $this->events->loadBeforeTrackFieldUpdateEvent($this->_trackData['gtr_beforefieldupdate_event']); } }
Get the FieldUpdateEvent for this trackId @return \Gems\Event\TrackBeforeFieldUpdateEventInterface | null
entailment
public function getFieldUpdateEvent() { if (isset($this->_trackData['gtr_fieldupdate_event']) && $this->_trackData['gtr_fieldupdate_event']) { return $this->events->loadTrackFieldUpdateEvent($this->_trackData['gtr_fieldupdate_event']); } }
Get the FieldUpdateEvent for this trackId @return \Gems_Event_TrackFieldUpdateEventInterface | null
entailment
public function getNextRoundId($roundId) { $this->_ensureRounds(); if ($this->_rounds && $roundId) { $next = false; foreach ($this->_rounds as $currentRoundId => $round) { if ($next) { return $currentRoundId; } if ($currentRoundId == $roundId) { $next = true; } } return null; } elseif ($this->_rounds) { end($this->_rounds); return key($this->_rounds); } }
Look up the round id for the next round @param int $roundId Gems round id @return int Gems round id
entailment
public function getPreviousRoundId($roundId, $roundOrder = null) { $this->_ensureRounds(); if ($this->_rounds && $roundId) { $returnId = null; foreach ($this->_rounds as $currentRoundId => $round) { if (($currentRoundId == $roundId) || ($roundOrder && ($round['gro_id_order'] >= $roundOrder))) { // Null is returned when querying this function with the first round id. return $returnId; } $returnId = $currentRoundId; } throw new \Gems_Exception_Coding("Requested non existing previous round id for round $roundId."); } elseif ($this->_rounds) { end($this->_rounds); $key = key($this->_rounds); if (empty($key) && !is_null($key)) { // The last round (with empty index) is the current round, step back one more round prev($this->_rounds); } return key($this->_rounds); } }
Look up the round id for the previous round @param int $roundId Gems round id @param int $roundOrder Optional extra round order, for when the current round may have changed. @return int Gems round id
entailment
public function getRound($roundId) { $this->_ensureRounds(); if (! isset($this->_rounds[$roundId])) { return null; } if (! isset($this->_roundObjects[$roundId])) { $this->_roundObjects[$roundId] = $this->tracker->createTrackClass('Round', $this->_rounds[$roundId]); } return $this->_roundObjects[$roundId]; }
Get the round object @param int $roundId Gems round id @return \Gems\Tracker\Round
entailment
public function getRoundAnswerSnippets(\Gems_Tracker_Token $token) { $this->_ensureRounds(); $roundId = $token->getRoundId(); if (isset($this->_rounds[$roundId]['gro_display_event']) && $this->_rounds[$roundId]['gro_display_event']) { $event = $this->events->loadSurveyDisplayEvent($this->_rounds[$roundId]['gro_display_event']); return $event->getAnswerDisplaySnippets($token); } }
Returns a snippet name that can be used to display the answers to the token or nothing. @param \Gems_Tracker_Token $token @return array Of snippet names
entailment
public function getRoundChangedEvent($roundId) { $this->_ensureRounds(); if (isset($this->_rounds[$roundId]['gro_changed_event']) && $this->_rounds[$roundId]['gro_changed_event']) { return $this->events->loadRoundChangedEvent($this->_rounds[$roundId]['gro_changed_event']); } }
Return the Round Changed event name for this round @param int $roundId @return \Gems_Event_RoundChangedEventInterface event instance or null
entailment
public function getRoundDefaults() { $this->_ensureRounds(); if ($this->_rounds) { $defaults = end($this->_rounds); unset($defaults['gro_id_round'], $defaults['gro_id_survey']); $defaults['gro_id_order'] = $defaults['gro_id_order'] + 10; } else { // Rest of defaults come form model $defaults = array('gro_id_track' => $this->_trackId); } return $defaults; }
Get the defaults for a new round @return array Of fieldname => default
entailment
public function getRoundDescriptions() { $this->_ensureRounds(); $output = array(); foreach ($this->getRounds() as $roundId => $round) { if ($round instanceof Round) { $output[$roundId] = $round->getFullDescription(); } } return $output; }
The round descriptions for this track @return array roundId => string
entailment
public function getRoundModel($detailed, $action) { $model = $this->createRoundModel(); $translated = $this->util->getTranslated(); // Set the keys to the parameters in use. $model->setKeys(array(\MUtil_Model::REQUEST_ID => 'gro_id_track', \Gems_Model::ROUND_ID => 'gro_id_round')); if ($detailed) { $model->set('gro_id_track', 'label', $this->_('Track'), 'elementClass', 'exhibitor', 'multiOptions', $this->util->getTrackData()->getAllTracks ); } $model->set('gro_id_survey', 'label', $this->_('Survey'), 'multiOptions', $this->util->getTrackData()->getAllSurveysAndDescriptions() ); $model->set('gro_icon_file', 'label', $this->_('Icon')); $model->set('gro_id_order', 'label', $this->_('Order'), 'default', 10, 'required', true, 'validators[uni]', $model->createUniqueValidator(array('gro_id_order', 'gro_id_track')) ); $model->set('gro_round_description', 'label', $this->_('Description'), 'size', '30' ); //, 'minlength', 4, 'required', true); $list = $this->events->listRoundChangedEvents(); if (count($list) > 1) { $model->set('gro_changed_event', 'label', $this->_('After change'), 'multiOptions', $list); } $list = $this->events->listSurveyDisplayEvents(); if (count($list) > 1) { $model->set('gro_display_event', 'label', $this->_('Answer display'), 'multiOptions', $list ); } $model->set('gro_active', 'label', $this->_('Active'), 'elementClass', 'checkbox', 'multiOptions', $translated->getYesNo() ); $model->setIfExists('gro_code', 'label', $this->_('Round code'), 'description', $this->_('Optional code name to link the field to program code.'), 'size', 10 ); $model->addColumn( "CASE WHEN gro_active = 1 THEN '' ELSE 'deleted' END", 'row_class'); $model->addColumn( "CASE WHEN gro_organizations IS NULL THEN 0 ELSE 1 END", 'org_specific_round'); $model->addColumn('gro_organizations', 'organizations'); $model->set('organizations', 'label', $this->_('Organizations'), 'elementClass', 'MultiCheckbox', 'multiOptions', $this->util->getDbLookup()->getOrganizations(), 'data-source', 'org_specific_round' ); $tp = new \MUtil_Model_Type_ConcatenatedRow('|', $this->_(', ')); $tp->apply($model, 'organizations'); $model->set('gro_condition', 'label', $this->_('Condition'), 'elementClass', 'Select', 'multiOptions', $this->loader->getConditions()->getConditionsFor(Gems\Conditions::ROUND_CONDITION) ); $model->set('condition_display', 'label', $this->_('Condition help'), 'elementClass', 'Hidden', 'no_text_search', true, 'noSort', true); $model->addDependency('Condition\\RoundDependency'); switch ($action) { case 'create': $this->_ensureRounds(); if ($this->_rounds && ($round = end($this->_rounds))) { $model->set('gro_id_order', 'default', $round['gro_id_order'] + 10); } // Intentional fall through // break; case 'edit': case 'show': $model->set('gro_icon_file', 'multiOptions', $translated->getEmptyDropdownArray() + $this->_getAvailableIcons() ); $model->set('org_specific_round', 'label', $this->_('Organization specific round'), 'default', 0, 'multiOptions', $translated->getYesNo(), 'elementClass', 'radio' ); break; default: $model->set('gro_icon_file', 'formatFunction', array('MUtil_Html_ImgElement', 'imgFile')); break; } return $model; }
Returns a model that can be used to retrieve or save the data. @param boolean $detailed Create a model for the display of detailed item data or just a browse table @param string $action The current action @return \MUtil_Model_ModelAbstract
entailment
public function getRounds() { $this->_ensureRounds(); foreach ($this->_rounds as $roundId => $roundData) { if (! isset($this->_roundObjects[$roundId])) { $this->_roundObjects[$roundId] = $this->tracker->createTrackClass('Round', $roundData); } } return $this->_roundObjects; }
Get all the round objects @return array of roundId => \Gems\Tracker\Round
entailment
public function getTrackCalculationEvent() { if (isset($this->_trackData['gtr_calculation_event']) && $this->_trackData['gtr_calculation_event']) { return $this->events->loadTrackCalculationEvent($this->_trackData['gtr_calculation_event']); } }
Get the TrackCompletedEvent for this trackId @return \Gems_Event_TrackCalculationEventInterface | null
entailment
public function getTrackCompletionEvent() { if (isset($this->_trackData['gtr_completed_event']) && $this->_trackData['gtr_completed_event']) { return $this->events->loadTrackCompletionEvent($this->_trackData['gtr_completed_event']); } }
Get the TrackCompletedEvent for this trackId @return \Gems_Event_TrackCompletedEventInterface|null
entailment
protected function removeInactiveRounds(\Gems_Tracker_RespondentTrack $respTrack, $userId) { $qTrackId = $this->db->quote($this->_trackId); $qRespTrackId = $this->db->quote($respTrack->getRespondentTrackId()); $orgId = $this->db->quote($respTrack->getOrganizationId()); $where = "gto_start_time IS NULL AND gto_id_respondent_track = $qRespTrackId AND gto_id_round != 0 AND gto_id_round IN (SELECT gro_id_round FROM gems__rounds WHERE (gro_active = 0 OR gro_organizations NOT LIKE CONCAT('%|',$orgId,'|%')) AND gro_id_track = $qTrackId)"; return $this->db->delete('gems__tokens', $where); }
Remove the unanswered tokens for inactive rounds. @param \Gems_Tracker_RespondentTrack $respTrack The respondent track to check @param int $userId Id of the user who takes the action (for logging) @return int The number of tokens changed by this code
entailment
public function addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model) { $model->set('gr2o_patient_nr', 'label', $this->_('Respondent')); $model->set('gto_round_description', 'label', $this->_('Round / Details')); $model->set('gto_valid_from', 'label', $this->_('Valid from')); $model->set('gto_valid_until', 'label', $this->_('Valid until')); $model->set('gto_mail_sent_date', 'label', $this->_('Contact date')); $model->set('respondent_name', 'label', $this->_('Name')); $HTML = \MUtil_Html::create(); if ($this->showActionLinks) { $rowClass = \MUtil_Html_TableElement::createAlternateRowClass('even', 'even', 'odd', 'odd'); } else { $rowClass = 'odd'; } $bridge->setDefaultRowClass($rowClass); if ($this->showActionLinks) { $bridge->addColumn($this->getTokenLinks($bridge), ' ')->rowspan = 2; // Space needed because TableElement does not look at rowspans } else { $bridge->tr(array('onlyWhenChanged' => true, 'class' => 'even')); $bridge->addColumn(' '); } $bridge->addSortable('gto_valid_from'); $bridge->addSortable('gto_valid_until'); $bridge->addMultiSort('gr2o_patient_nr', $HTML->raw('; '), 'respondent_name'); if ($this->showActionLinks) { $bridge->addMultiSort('ggp_name', array($this->getActionLinks($bridge))); } else { $bridge->addSortable('ggp_name'); } $bridge->tr(); if (!$this->showActionLinks) { $bridge->addColumn($this->getTokenLinks($bridge), ' '); } $bridge->addSortable('gto_mail_sent_date'); $bridge->addSortable('gto_completion_time'); if ($this->escort instanceof \Gems_Project_Tracks_SingleTrackInterface) { $bridge->addMultiSort('gto_round_description', $HTML->raw('; '), 'gsu_survey_name'); } else { $model->set('gr2t_track_info', 'tableDisplay', 'smallData'); $model->set('gto_round_description', 'tableDisplay', 'smallData'); $bridge->addMultiSort( 'gtr_track_name', 'gr2t_track_info', $bridge->gtr_track_name->if($HTML->raw(' &raquo; ')), 'gsu_survey_name', 'gto_round_description'); } $bridge->addSortable('assigned_by'); }
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
entailment
public function execute($context, $toLevel = null, $fromLevel = null) { if(is_null($toLevel)) { $toLevel = $this->getMaxLevel($context); } if(is_null($fromLevel)) { $fromLevel = $this->getNextLevel($context); if ($fromLevel > $toLevel) { $this->addMessage($this->_('Already at max. level.')); return $toLevel; } } $fromLevel = max(1, intval($fromLevel)); $toLevel = intval($toLevel); $this->addMessage(sprintf($this->_('Trying upgrade for %s from level %s to level %s'), $context, $fromLevel, $toLevel)); $success = false; $upgrades = $this->_upgradeStack[$context]; ksort($upgrades); foreach($upgrades as $level => $upgrade) { if (($level >= $fromLevel && $level <= $toLevel)) { $this->addMessage(sprintf($this->_('Trying upgrade for %s to level %s: %s'), $context, $level, $upgrade['info'])); if (call_user_func($upgrade['upgrade'])) { $success = $level; } else { $this->addMessage('FAILED'); break; } } } if ($success) { $this->setLevel($context, $success); } return $success; }
Execute upgrades for the given $context When no $to or $from are given, the given $context will be upgraded from the current level to the max level. Otherwise the $from and/or $to will be used to determine what upgrades to execute. @param string $context The context to execute the upgrades for @param int|null $toLevel The level to upgrade to @param int|null $fromLevel The level to start the upgrade on @return false|int The achieved upgrade level or false on failure
entailment
public function getLevel($context) { if(isset($this->_info->$context)) { return intval($this->_info->$context); } else { $level = $this->getMaxLevel($context); $this->setLevel($context, $level); return $level; } }
Get the current upgrade level for the given $context @param string $context @return int
entailment
public function getMaxLevel($context = null) { if (! $context) { $context = $this->getContext(); } if (isset($this->_upgradeStack[$context])) { $values = array_keys($this->_upgradeStack[$context]); $values[] = 0; $index = intval(max($values)); return $index; } else { return 0; } }
Get the highest level for the given $context @param string|null $context @return int
entailment
public function getNextLevel($context = null, $level = null) { if (is_null($context)) { $context = $this->getContext(); } if (is_null($level)) { $level = $this->getLevel($context); } //Get all the levels $currentContext = $this->_upgradeStack[$context]; ksort($currentContext); $levels = array_keys($currentContext); //Find the index of the current one $current = array_search($level, $levels); //And if it is present, return the next level if ($current !== false) { $current++; if (isset($levels[$current])) return $levels[$current]; } //Else return current level +1 (doesn't exist anyway) return ++$level; }
Get the next level for a given level and context When context is null, it will get the current context When level is null, it will get the current level @param type $level @param type $context @return type
entailment
public function getUpgrades($context = null) { if (! $context) { $context = $this->getContext(); } if (isset($this->_upgradeStack[$context])) { return $this->_upgradeStack[$context]; } return array(); }
Retrieve the upgrades for a certain context, will return an empty array when nothing present. @param string $context @return array
entailment
public function getUpgradesInfo($requestedContext = null) { $result = array(); foreach(array_keys($this->_upgradeStack) as $context) { $row = array(); $row['context'] = $context; $row['maxLevel'] = $this->getMaxLevel($context); $row['level'] = $this->getLevel($context); $result[$context] = $row; } if (is_null($requestedContext)) { return $result; } else { if (isset($result[$requestedContext])) { return $result[$requestedContext]; } } }
Retrieve info about the $requestedContext or all contexts when omitted @param string $requestedContext @return array
entailment
protected function initUpgradeFile() { touch($this->upgradeFile); $this->_info = new \Zend_Config_Ini($this->upgradeFile, null, array('allowModifications' => true)); foreach(array_keys($this->_upgradeStack) as $context) { $maxLevel = $this->getMaxLevel($context); $this->setLevel($context, $maxLevel, true); } }
When upgrade file does not exist, create it and default to the max level since no upgrades should be needed after a clean install
entailment
public function register($callback, $info = null, $index = null, $context = null) { if (is_string($callback)) { $callback = array($this, $callback); } if (!is_callable($callback)) { return false; } if (!$context) { $context = $this->getContext(); } if (!isset($this->_upgradeStack[$context])) { $this->_upgradeStack[$context] = array(); } if (is_null($index)) { $index = $this->getMaxLevel($context); $index++; } $this->_upgradeStack[$context][$index]['upgrade'] = $callback; $this->_upgradeStack[$context][$index]['info'] = $info; return true; }
Register an upgrade in the stack, it can be executed by using $this->execute Index and context are optional and will be generated when omitted. For the user interface to be clear $info should provide a good description of what the upgrade does. @param array|string $callback A valid callback, either string for a method of the current class or array otherwise @param string $info A descriptive message about what this upgrade does @param int $index The number of the upgrade @param string $context The context to which this upgrade applies @return boolean
entailment