sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
public function getLoginLinkElement()
{
$element = $this->getElement($this->_tokenFieldName);
if (! $element) {
// Login link
if ($link = $this->getLoginLink()) {
$element = new \MUtil_Form_Element_Html($this->_loginLinkFieldName);
// $element->br();
$element->setValue($link);
$this->addElement($element);
}
return $element;
}
} | Returns a link to the login page
@return \MUtil_Form_Element_Html | entailment |
public function getUserNameElement()
{
$element = $this->getElement($this->usernameFieldName);
if (! $element) {
$element = parent::getUserNameElement();
$element->addValidator(new \Gems_User_Validate_ResetRequestValidator($this, $this->translate));
}
return $element;
} | Returns/sets a login name element.
@return \Zend_Form_Element_Text | entailment |
public function loadDefaultElements()
{
$this->getOrganizationElement();
$this->getUserNameElement();
$this->getSubmitButton();
$this->getLoginLinkElement();
return $this;
} | The function that determines the element load order
@return \Gems_User_Form_LoginForm (continuation pattern) | entailment |
public function autofilterAction($resetMvc = true)
{
if ($resetMvc && $this->enableScreens) {
$group = $this->currentUser->getGroup();
if ($group) {
$browse = $group->getRespondentBrowseScreen();
if ($browse) {
// All are arrays, so easy to set
$this->autofilterParameters = $browse->getAutofilterParameters() + $this->autofilterParameters;
$autoSnippets = $browse->getAutofilterSnippets();
if (false !== $autoSnippets) {
$this->autofilterSnippets = $autoSnippets;
}
}
}
}
parent::autofilterAction($resetMvc);
} | The automatically filtered result
@param $resetMvc When true only the filtered resulsts | entailment |
public function changeOrganizationAction()
{
if ($this->changeOrganizationSnippets) {
$params = $this->_processParameters(
$this->changeOrganizationParameters +
$this->editParameters +
$this->createEditParameters +
['createData' => false]);
$this->addSnippets($this->changeOrganizationSnippets, $params);
}
} | Action to change a users | entailment |
public function createAction()
{
if ($this->enableScreens) {
$edit = false;
$org = $this->getRespondent()->getOrganization();
if (! $org) {
$org = $this->currentOrganization;
}
if ($org) {
$edit = $org->getRespondentEditScreen();
}
if (! $edit) {
$group = $this->currentUser->getGroup();
if ($group) {
$edit = $group->getRespondentEditScreen();
}
}
if ($edit ) {
if ($edit instanceof ProcessModelInterface) {
$edit->processModel($this->getModel());
}
// All are arrays, so easy to set
$this->createParameters = $edit->getCreateParameters() + $this->createParameters;
$editSnippets = $edit->getSnippets();
if (false !== $editSnippets) {
$this->createEditSnippets = $editSnippets;
}
}
}
parent::createAction();
} | Action for showing a create new item page | entailment |
public function editAction()
{
if ($this->enableScreens) {
$edit = false;
$org = $this->getRespondent()->getOrganization();
if ($org) {
$edit = $org->getRespondentEditScreen();
}
if (! $edit) {
$group = $this->currentUser->getGroup();
if ($group) {
$edit = $group->getRespondentEditScreen();
}
}
if ($edit) {
if ($edit instanceof ProcessModelInterface) {
$edit->processModel($this->getModel());
}
// All are arrays, so easy to set
$this->editParameters = $edit->getEditParameters() + $this->editParameters;
$editSnippets = $edit->getSnippets();
if (false !== $editSnippets) {
$this->createEditSnippets = $editSnippets;
}
}
}
parent::editAction();
} | Action for showing a edit item page with extra title | entailment |
public function exportArchiveAction()
{
$params = $this->_processParameters($this->showParameters);
$this->addSnippets($this->exportSnippets, $params);
$this->html->h2($this->_('Export respondent archive'));
//Now show the export form
$export = $this->loader->getRespondentExport();
$form = $export->getForm();
$div = $this->html->div(array('id' => 'mainform'));
$div[] = $form;
$request = $this->getRequest();
$form->populate($request->getParams());
if ($request->isPost()) {
$respondent = $this->getRespondent();
$patients = array(
array(
'gr2o_id_organization' => $respondent->getOrganizationId(),
'gr2o_patient_nr' => $respondent->getPatientNumber()
)
);
$export->render($patients, $request->getParam('group'), $request->getParam('format'));
}
} | Action for dossier export | entailment |
public function getEditLink()
{
$request = $this->getRequest();
$item = $this->menu->find(array(
$request->getControllerKey() => $request->getControllerName(),
$request->getActionKey() => 'edit',
'allowed' => true));
if ($item) {
return $item->toHRefAttribute($request);
}
} | Get the link to edit respondent
@return \MUtil_Html_HrefArrayAttribute | entailment |
public function getEditTitle()
{
$respondent = $this->getRespondent();
if ($respondent->exists) {
if ($this->currentUser->areAllFieldsMaskedWhole('grs_first_name', 'grs_last_name')) {
return sprintf($this->_('Edit respondent nr %s'), $respondent->getPatientNumber());
}
return sprintf(
$this->_('Edit respondent nr %s: %s'),
$respondent->getPatientNumber(),
$respondent->getName()
);
}
return parent::getEditTitle();
} | Helper function to get the title for the edit action.
@return $string | entailment |
public function getItemUrlArray()
{
return array(
\MUtil_Model::REQUEST_ID1 => $this->_getParam(\MUtil_Model::REQUEST_ID1),
\MUtil_Model::REQUEST_ID2 => $this->_getParam(\MUtil_Model::REQUEST_ID2),
);
} | Return the array with items that should be used to find this item
@return array | entailment |
public function getRespondentId()
{
// The actions do not set an respondent id
if (in_array($this->getRequest()->getActionName(), $this->summarizedActions)) {
return null;
}
return parent::getRespondentId();
} | Retrieve the respondent id
(So we don't need to repeat that for every snippet.)
@return int | entailment |
public function getSearchData($useRequest = true)
{
$data = parent::getSearchData($useRequest);
if (isset($data[\MUtil_Model::REQUEST_ID2])) {
$orgs = intval($data[\MUtil_Model::REQUEST_ID2]);
} else {
$orgs = $this->currentUser->getRespondentOrgFilter();
}
$activeTracks = $this->util->getTrackData()->getActiveTracks($orgs);
// Cache used by RespondentSearchSnippet and $this->getSearchFilter()
$data['__active_tracks'] = $activeTracks;
return $data;
} | Get the data to use for searching: the values passed in the request + any defaults
used in the search form (or any other search request mechanism).
It does not return the actual filter used in the query.
@see getSearchFilter()
@param boolean $useRequest Use the request as source (when false, the session is used)
@return array | entailment |
public function getSearchDefaults()
{
if (! isset($this->defaultSearchData[\MUtil_Model::REQUEST_ID2])) {
if ($this->currentUser->hasPrivilege('pr.respondent.multiorg') &&
(! $this->currentOrganization->canHaveRespondents())) {
$this->defaultSearchData[\MUtil_Model::REQUEST_ID2] = '';
} else {
$this->defaultSearchData[\MUtil_Model::REQUEST_ID2] = $this->currentOrganization->getId();
}
}
$this->defaultSearchData['gr2t_id_track'] = 'show_all';
return parent::getSearchDefaults();
} | Function to allow the creation of search defaults in code
@see getSearchFilter()
@return array | entailment |
public function getSearchFilter($useRequest = true)
{
$filter = parent::getSearchFilter($useRequest);
if (isset($filter['gr2t_id_track']) && $filter['gr2t_id_track']) {
switch ($filter['gr2t_id_track']) {
case 'show_without_track':
$filter[] = "NOT EXISTS (SELECT * FROM gems__respondent2track
WHERE gr2o_id_user = gr2t_id_user AND gr2o_id_organization = gr2t_id_organization)";
// Intentional fall through
case 'show_all':
unset($filter['gr2t_id_track']);
break;
case 'show_with_track':
default:
$model = $this->getModel();
if (! $model->hasAlias('gems__respondent2track')) {
$model->addTable(
'gems__respondent2track',
array('gr2o_id_user' => 'gr2t_id_user', 'gr2o_id_organization' => 'gr2t_id_organization')
);
}
if (! $model->hasAlias('gems__tracks')) {
$model->addTable('gems__tracks', array('gr2t_id_track' => 'gtr_id_track'));
}
if (! isset($filter['__active_tracks'], $filter['__active_tracks'][$filter['gr2t_id_track']])) {
unset($filter['gr2t_id_track']);
}
}
}
if (! isset($filter['show_with_track'])) {
$filter['show_with_track'] = 1;
}
unset($filter['__active_tracks']);
return $filter;
} | Get the filter to use with the model for searching including model sorts, etc..
@param boolean $useRequest Use the request as source (when false, the session is used)
@return array or false | entailment |
public function indexAction()
{
$group = $this->currentUser->getGroup();
if ($group && $this->enableScreens) {
$browse = $group->getRespondentBrowseScreen();
if ($browse) {
if ($browse instanceof ProcessModelInterface) {
$browse->processModel($this->getModel());
}
// All are arrays, so easy to set
$this->autofilterParameters = $browse->getAutofilterParameters() + $this->autofilterParameters;
$this->indexParameters = $browse->getStartStopParameters() + $this->indexParameters;
$autoSnippets = $browse->getAutofilterSnippets();
if (false !== $autoSnippets) {
$this->autofilterSnippets = $autoSnippets;
}
$startSnippets = $browse->getStartSnippets();
if (false !== $startSnippets) {
$this->indexStartSnippets = $startSnippets;
}
$stopSnippets = $browse->getStopSnippets();
if (false !== $stopSnippets) {
$this->indexStopSnippets = $stopSnippets;
}
}
}
if ($this->currentUser->hasPrivilege('pr.respondent.multiorg') ||
$this->currentOrganization->canHaveRespondents()) {
parent::indexAction();
} else {
$this->addSnippet('Organization\\ChooseOrganizationSnippet');
}
} | Overrule default index for the case that the current
organization cannot have users. | entailment |
public function overviewAction() {
if ($this->overviewSnippets) {
$params = $this->_processParameters($this->overviewParameters);
$menuList = $this->menu->getMenuList();
$menuList->addParameterSources($this->request, $this->menu->getParameterSource());
$menuList->addCurrentParent($this->_('Cancel'));
$params['buttons'] = $menuList;
$this->addSnippets($this->overviewSnippets, $params);
}
} | Action for showing overview for a patient | entailment |
public function showAction()
{
if ($this->enableScreens) {
$show = false;
$org = $this->getRespondent()->getOrganization();
if ($org) {
$show = $org->getRespondentShowScreen();
}
if (! $show) {
$group = $this->currentUser->getGroup();
if ($group) {
$show = $group->getRespondentShowScreen();
}
}
if ($show) {
if ($show instanceof ProcessModelInterface) {
$show->processModel($this->getModel());
}
// All are arrays, so easy to set
$this->showParameters = $show->getParameters() + $this->showParameters;
$showSnippets = $show->getSnippets();
if (false !== $showSnippets) {
$this->showSnippets = $showSnippets;
}
}
}
parent::showAction();
} | Action for showing an item page with title | entailment |
public function simpleApiAction()
{
$this->disableLayout();
$data = $this->getRequest()->getParams();
$importLoader = $this->loader->getImportLoader();
$model = $this->getModel();
$translator = new \Gems_Model_Translator_RespondentTranslator($this->_('Direct import'));
$this->source->applySource($translator);
$translator->setTargetModel($model)
->startImport();
$raw = $translator->translateRowValues($data, 1);
$errors = array();
// First check if we need to merge
if (array_key_exists('oldpid', $raw)) {
$oldPid = $raw['oldpid'];
if (array_key_exists('gr2o_patient_nr', $raw) && array_key_exists('gr2o_id_organization', $raw)) {
$newPid = $raw['gr2o_patient_nr'];
$orgId = (int) $raw['gr2o_id_organization'];
$result = $model->merge($newPid, $oldPid, $orgId);
switch ($result) {
case \Gems\Model\MergeResult::BOTH:
echo sprintf("%s merged to %s\n", $oldPid, $newPid);
break;
case \Gems\Model\MergeResult::FIRST:
echo sprintf("%s not found, nothing to merge\n", $oldPid);
break;
case \Gems\Model\MergeResult::SECOND:
echo sprintf("%s renamed to %s\n", $oldPid, $newPid);
// After a rename, we need to refetch the ids
$raw = $translator->translateRowValues($data, 1);
break;
default:
break;
}
} else {
$errors[] = 'To merge you need at least oldpid, gr2o_patient_nr and gr2o_id_organization.';
}
}
$row = $translator->validateRowValues($raw, 1);
$errors = array_merge($errors, $translator->getRowErrors(1));
if ($errors) {
echo "ERRORS Occured:\n" . implode("\n", $errors);
exit(count($errors));
} else {
$output = $model->save($row);
$changed = $model->getChanged();
// print_r($output);
$patientId = $output['gr2o_patient_nr'];
if ($changed) {
echo "Changes to patient $patientId saved.";
} else {
echo "No changes to patient $patientId.";
}
return;
}
} | Action for a simple - usually command line - import | entailment |
public function undeleteAction()
{
if ($this->deleteSnippets) {
$params = $this->_processParameters($this->deleteParameters);
$this->addSnippets($this->deleteSnippets, $params);
}
} | Action for showing a delete item page | entailment |
public function getSqlWhereBoth($toApps)
{
$appWheres = array();
$epiWheres = array();
foreach ($this->_subFilters as $filterObject) {
if ($filterObject instanceof AppointmentFilterInterface) {
$toApp = $filterObject->preferAppointmentSql();
if ($toApp) {
$where = $filterObject->getSqlAppointmentsWhere();
} else {
$where = $filterObject->getSqlEpisodeWhere();
}
if ($where == parent::MATCH_ALL_SQL) {
return parent::MATCH_ALL_SQL;
} elseif ($where !== parent::NO_MATCH_SQL) {
if ($toApp) {
$appWheres[] = $where;
} else {
$epiWheres[] = $where;
}
}
}
}
if ($toApps) {
$wheres = $appWheres;
if ($epiWheres) {
$wheres[] = sprintf(
"gap_id_episode IN (SELECT gec_episode_of_care_id FROM gems__episodes_of_care WHERE %s)",
implode($this->glue, $epiWheres)
);
}
} else {
$wheres = $epiWheres;
if ($appWheres) {
$wheres[] = sprintf(
"gec_episode_of_care_id IN (SELECT gap_id_episode FROM gems__appointments WHERE %s)",
implode($this->glue, $appWheres)
);
}
}
if ($wheres) {
if (1 == count($wheres)) {
return reset($wheres);
}
return '(' . implode($this->glue, $wheres) . ')';
} else {
return parent::NO_MATCH_SQL;
}
} | Generate a where statement to filter the appointment model
@param boolean $toApps Whether to return appointment or episode SQL
@return string | entailment |
public function matchAppointment(\Gems_Agenda_Appointment $appointment)
{
foreach ($this->_subFilters as $filterObject) {
if ($filterObject instanceof AppointmentFilterInterface) {
if ($filterObject->matchAppointment($appointment)) {
return true;
}
}
}
return false;
} | Check a filter for a match
@param \Gems\Agenda\Gems_Agenda_Appointment $appointment
@return boolean | entailment |
public function matchEpisode(EpisodeOfCare $episode)
{
foreach ($this->_subFilters as $filterObject) {
if ($filterObject instanceof AppointmentFilterInterface) {
if ($filterObject->matchEpisode($episode)) {
return true;
}
}
}
return false;
} | Check a filter for a match
@param \Gems\Agenda\EpisodeOfCare $episode
@return boolean | entailment |
public function checkRegistryRequestsAnswers()
{
if (! $this->db instanceof \Zend_Db_Adapter_Abstract) {
return false;
}
$select = $this->db->select();
$select->from(['nw'=> 'gems__tokens'], [
'gtrp_id_token_new' => 'gto_id_token',
'gtrp_created' => 'gto_created',
'gtrp_created_by' => 'gto_created_by',
])->joinInner(
['pr' => 'gems__tokens'],
"nw.gto_id_respondent_track = pr.gto_id_respondent_track AND
nw.gto_id_round = pr.gto_id_round AND
nw.gto_round_order = pr.gto_round_order AND
nw.gto_created > pr.gto_created
",
['gtrp_id_token_old' => 'gto_id_token',]
)
->where('nw.gto_id_token NOT IN (SELECT gtrp_id_token_new FROM gems__token_replacements)')
->order('nw.gto_id_token')
->order('pr.gto_created');
$this->_stmt = $this->db->query($select);
return parent::checkRegistryRequestsAnswers();
} | 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 |
public function execute()
{
$row = $this->_stmt->fetch();
$batch = $this->getBatch();
$count = $batch->getCounter('inserted_token_replacements');
if ($row['gtrp_id_token_new'] == $this->_lastTokenId) {
if (! $count) {
$batch->addMessage($this->_('No token replacements to create'));
}
$this->_stopped = true;
return;
}
$this->db->insert('gems__token_replacements', $row);
$count = $batch->addToCounter('inserted_token_replacements');
$batch->setMessage('inserted_replacements', sprintf(
$this->plural('Created %d token replacement', 'Created %d token replacements', $count),
$count
));
$this->_lastTokenId = $row['gtrp_id_token_new'];
} | Should handle execution of the task, taking as much (optional) parameters as needed
The parameters should be optional and failing to provide them should be handled by
the task | entailment |
public function getDiagnosisData()
{
if (! isset($this->_gemsData['gec_diagnosis'])) {
return [];
}
if (is_string($this->_gemsData['gec_diagnosis'])) {
$this->_gemsData['gec_diagnosis'] = json_decode($this->_gemsData['gec_diagnosis'], true);
}
return $this->_gemsData['gec_diagnosis'];
} | The diagnosis data of the episode translated from Json
@return array of Json data | entailment |
public function getDisplayString()
{
$results[] = $this->getStartDate()->toString($this->agenda->episodeDisplayFormat);
$results[] = $this->getSubject();
$results[] = $this->getDiagnosis();
return implode($this->_('; '), array_filter($results));
} | Get a general description of this appointment
@see \Gems_Agenda->getAppointmentDisplay()
@return string | entailment |
public function getExtraData()
{
if (! isset($this->_gemsData['gec_extra_data'])) {
return [];
}
if (is_string($this->_gemsData['gec_extra_data'])) {
$this->_gemsData['gec_extra_data'] = json_decode($this->_gemsData['gec_extra_data'], true);
}
return $this->_gemsData['gec_extra_data'];
} | The extra data of the episode translated from Json
@return array of Json data | entailment |
public function getStartDate()
{
if (isset($this->_gemsData['gec_startdate']) && $this->_gemsData['gec_startdate']) {
if (! $this->_gemsData['gec_startdate'] instanceof \MUtil_Date) {
$this->_gemsData['gec_startdate'] =
new \MUtil_Date($this->_gemsData['gec_startdate'], \Gems_Tracker::DB_DATE_FORMAT);
}
return $this->_gemsData['gec_startdate'];
}
} | Return the start date
@return \MUtil_Date Start date as a date or null | entailment |
public function processTokenInsertion(\Gems_Tracker_Token $token)
{
if ($token->hasSuccesCode() && (! $token->isCompleted())) {
// Preparation for a more general object class
$code = $token->getSurvey()->getCode();
$prev = $token;
while ($prev = $prev->getPreviousToken()) {
if ($prev->hasSuccesCode() && $prev->isCompleted()) {
// Check first on survey id and when that does not work by name.
if ($prev->getSurvey()->getCode() == $code) {
return $prev->getRawAnswers();
}
}
}
}
} | Process the data and return the answers that should be filled in beforehand.
Storing the changed values is handled by the calling function.
@param \Gems_Tracker_Token $token Gems token object
@return array Containing the changed values | entailment |
protected function getAutoSearchElements(array $data)
{
$elements = $this->getSurveySelectElements($data);
$elements[] = null;
$organizations = $this->currentUser->getRespondentOrganizations();
if (count($organizations) > 1) {
$elements[] = $this->_createMultiCheckBoxElements('gto_id_organization', $organizations);
$elements[] = null;
}
$dates = array(
'gr2t_start_date' => $this->_('Track start'),
'gr2t_end_date' => $this->_('Track end'),
'gto_valid_from' => $this->_('Valid from'),
'gto_valid_until' => $this->_('Valid until'),
'gto_start_time' => $this->_('Start date'),
'gto_completion_time' => $this->_('Completion date'),
);
// $dates = 'gto_valid_from';
$this->_addPeriodSelectors($elements, $dates, 'gto_valid_from');
$elements[] = null;
$element = $this->form->createElement('textarea', 'ids');
$element->setLabel($this->_('Respondent id\'s'))
->setAttrib('cols', 60)
->setAttrib('rows', 4)
->setDescription($this->_("Not respondent nr, but respondent id as exported here. Separate multiple id's with , or ;"));
$elements['ids'] = $element;
$elements[] = null;
$elements['export_trackfield_codes'] = $this->form->createElement('text', 'export_trackfield_codes',
[
'size' => 50,
'label' => 'Export trackfield codes',
'description' => 'Export specific trackfield codes. This works without selecting a track. The columnname will be the code. Use , as a separator between codes.'
]
);
$elements[] = null;
$elements[] = $this->_('Output');
$elements['incomplete'] = $this->_createCheckboxElement(
'incomplete',
$this->_('Include incomplete surveys'),
$this->_('Include surveys that have been started but have not been checked as completed')
);
$elements['column_identifiers'] = $this->_createCheckboxElement(
'column_identifiers',
$this->_('Column Identifiers'),
$this->_('Prefix the column labels with an identifier. (A) Answers, (TF) Trackfields, (D) Description')
);
$elements[] = $this->_(' For subquestions ');
$elements['subquestions'] = $this->_createRadioElement(
'subquestions', [
'show_parent' => $this->_('show parent as separate question'),
'prefix_child' => $this->_('add parent to each subquestion')
])->setSeparator(' ');
/*$elements['show_parent'] = $this->_createCheckboxElement(
'show_parent',
$this->_('Show parent'),
$this->_('Show the parent column even if it doesn\'t have answers')
);
$elements['prefix_child'] = $this->_createCheckboxElement(
'prefix_child',
$this->_('Prefix child'),
$this->_('Prefix the child column labels with parent question label')
);
*/
$elements[] = null;
$extraFields = $this->getExtraFieldElements($data);
if ($extraFields) {
$elements[] = $this->_('Add to export');
$elements = $elements + $extraFields;
$elements[] = null;
}
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 |
protected function createModel($detailed, $action)
{
$model = $this->loader->getModels()->createLogModel();
if ($detailed) {
$model->applyDetailSettings();
} else {
$model->applyBrowseSettings();
}
return $model;
} | 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 | entailment |
public function getSearchDefaults()
{
if (! $this->defaultSearchData) {
$from = new \MUtil_Date();
$from->subWeek(2);
$until = new \MUtil_Date();
$until->addDay(1);
$this->defaultSearchData = array(
'datefrom' => $from,
'dateuntil' => $until,
'dateused' => 'gla_created',
);
}
return parent::getSearchDefaults();
} | Function to allow the creation of search defaults in code
@see getSearchFilter()
@return array | entailment |
protected function _ensureSettings()
{
$this->_settings = [
'name' => [
'label' => $this->_('Mask respondent name'),
'description' => $this->_('Hide name and e-mail address.'),
'class' => 'NameMasker',
'maskFields' => $this->_getNameFields(),
],
'gender' => [
'label' => $this->_('Mask gender'),
'description' => $this->_('Hide gender'),
'class' => 'AnyMasker',
'maskFields' => $this->_getGenderFields(),
],
'birthday' => [
'label' => $this->_('Mask birthday'),
'description' => $this->_('Hide (parts of) a birthday'),
'class' => 'BirthdayMasker',
'maskFields' => $this->_getBirthdayFields(),
],
'address' => [
'label' => $this->_('Mask address'),
'description' => $this->_('Hide (parts of) the address'),
'class' => 'AddressMasker',
'maskFields' => $this->_getAddressFields(),
],
'phone' => [
'label' => $this->_('Mask phones'),
'description' => $this->_('Mask phone fields'),
'class' => 'AnyMasker',
'maskFields' => $this->_getPhoneFields(),
],
'healthdata' => [
'label' => $this->_('Mask health data'),
'description' => $this->_('Mask healt data, e.g. scores and health comments'),
'class' => 'AnyMasker',
'maskFields' => $this->_getHealthDataFields(),
],
];
} | Set $this->_settings to array of [groupname => [label, description, class, maskFields]
@return void | entailment |
public function afterRegistry()
{
parent::afterRegistry();
$this->initTranslateable();
$this->_ensureSettings();
// Load the masker classes
foreach ($this->_settings as $name => $setting) {
if (isset($setting['class'], $setting['maskFields'])) {
$this->_settings[$name]['masker'] = $this->_loadClass(
$setting['class'],
true,
array($setting['maskFields'])
);
}
}
// Create the fieldlist
$this->_fieldList = array();
foreach ($this->_settings as $name => $setting) {
if (isset($setting['class'], $setting['maskFields'])) {
foreach ($setting['maskFields'] as $field => $type) {
$this->_fieldList[$field] = $name;
}
}
}
} | Called after the check that all required registry values
have been set correctly has run.
@return void | entailment |
public function decodeSettings($value, $isNew = false, $name = null, array $context = array(), $isPost = false)
{
if (is_array($value)) {
return $value;
}
if ($value) {
return json_decode($value, true);
}
return $this->defaultData;
} | A ModelAbstract->setOnLoad() function that takes care of decoding the json settings
to an array value
@see \MUtil_Model_ModelAbstract
@param mixed $value The value being saved
@param boolean $isNew True when a new item is being saved
@param string $name The name of the current field
@param array $context Optional, the other values being saved
@param boolean $isPost True when passing on post data
@return string|null | entailment |
public function getSettingsField($key)
{
$pos = strpos($key, $this->keySeparator);
if ($pos) {
return substr($key, $pos + strlen($this->keySeparator));
}
return null;
} | Get the settings field name from a combined field name
@param string $key
@return string The settings name or null when not a key name | entailment |
public function getStorageField($key)
{
$pos = strpos($key, $this->keySeparator);
if ($pos) {
return substr($key, 0, $pos);
}
return null;
} | Get the storage field name from a combined field name
@param string $key
@return string The storage name or null when not a key name | entailment |
public function loadSettings($value, $isNew = false, $name = null, array $context = array(), $isPost = false)
{
if ($value) {
return $value;
}
$setting = $this->getSettingsField($name);
$storage = $this->getStorageField($name);
if (isset($context[$storage])) {
$decoded = $this->decodeSettings($context[$storage]);
} else {
$decoded = $this->defaultData;
}
if (isset($decoded[$setting])) {
return $decoded[$setting];
}
return $value;
} | A ModelAbstract->setOnLoad() function that takes care of transforming settings
to values
@see \MUtil_Model_ModelAbstract
@param mixed $value The value being saved
@param boolean $isNew True when a new item is being saved
@param string $name The name of the current field
@param array $context Optional, the other values being saved
@param boolean $isPost True when passing on post data
@return string|null | entailment |
public function saveSettings($value, $isNew = false, $name = null, array $context = array())
{
$output = [];
foreach ($context as $key => $value) {
$setting = $this->getSettingsField($key);
if ($setting) {
// \MUtil_Echo::track($setting, $value);
$output[$setting] = $value;
}
}
// \MUtil_Echo::track($name, $output, json_encode($output));
return json_encode($output);
} | A ModelAbstract->setOnSave() function that returns fields as a single storage string
@see \MUtil_Model_ModelAbstract
@param mixed $value The value being saved
@param boolean $isNew True when a new item is being saved
@param string $name The name of the current field
@param array $context Optional, the other values being saved
@return string | entailment |
protected function addCompletionBlock(\Gems_Model_Bridge_ThreeColumnTableBridge $bridge, \MUtil_Model_ModelAbstract $model, \Gems_Menu_MenuList $links)
{
// COMPLETION DATE
$fields = array();
if ($this->token->getReceptionCode()->hasDescription()) {
$bridge->addMarkerRow();
$fields[] = 'grc_description';
}
$fields[] = 'gto_completion_time';
if ($this->token->isCompleted()) {
$fields[] = 'gto_duration_in_sec';
}
if ($this->token->hasResult()) {
$fields[] = 'gto_result';
}
$controller = $this->request->getControllerName();
$fields[] = $links->getActionLinks(true, $controller, 'correct', $controller, 'delete');
$bridge->addWithThird($fields);
return true;
} | Adds third block to fifth group group of rows showing completion data
Overrule this function to add different columns to the browse table, without
having to recode the core table building code.
@param \Gems_Model_Bridge_ThreeColumnTableBridge $bridge
@param \MUtil_Model_ModelAbstract $model
@param \Gems_Menu_MenuList $links
@return boolean True when there was row output | entailment |
protected function addHeaderGroup(\Gems_Model_Bridge_ThreeColumnTableBridge $bridge, \MUtil_Model_ModelAbstract $model, \Gems_Menu_MenuList $links)
{
$controller = $this->request->getControllerName();
$tData = $this->util->getTokenData();
$bridge->addItem('gto_id_token', null, array('colspan' => 1.5));
$copiedFrom = $this->token->getCopiedFrom();
if ($copiedFrom) {
$bridge->tr();
$bridge->tdh($this->_('Token copied from'));
$bridge->td(array('colspan' => 2, 'skiprowclass' => true))
->a([\MUtil_Model::REQUEST_ID => $copiedFrom], $copiedFrom);
}
$copiedTo = $this->token->getCopiedTo();
if ($copiedTo) {
$bridge->tr();
$bridge->tdh($this->_('Token copied to'));
$td = $bridge->td(array('colspan' => 2, 'skiprowclass' => true));
foreach ($copiedTo as $copy) {
$td->a([\MUtil_Model::REQUEST_ID => $copy], $copy);
$td->append(' ');
}
}
// Token status
$bridge->tr();
$bridge->tdh($this->_('Status'));
$td = $bridge->td(
['colspan' => 2, 'skiprowclass' => true],
$tData->getTokenStatusShowForBridge($bridge),
' ',
$tData->getTokenStatusDescriptionForBridge($bridge)
);
// Buttons
$bridge->gto_in_source;
$buttons = $links->getActionLinks(true,
'ask', 'take',
'pdf', 'show',
$controller, 'questions',
$controller, 'answer',
$controller, 'answer-export'
);
if (count($buttons)) {
if (isset($buttons['ask.take']) && ($buttons['ask.take'] instanceof \MUtil_Html_HtmlElement)) {
if ('a' == $buttons['ask.take']->tagName) {
$buttons['ask.take'] = $tData->getTokenAskButtonForBridge($bridge, true, true);
}
}
if (isset($buttons['track.answer']) && ($buttons['track.answer'] instanceof \MUtil_Html_HtmlElement)) {
if ('a' == $buttons['track.answer']->tagName) {
$buttons['track.answer'] = $tData->getTokenAnswerLinkForBridge($bridge, true);
}
}
$bridge->tr();
$bridge->tdh($this->_('Actions'));
$bridge->td($buttons, array('colspan' => 2, 'skiprowclass' => true));
}
return true;
} | Adds first group of rows showing token specific data
Overrule this function to add different columns to the browse table, without
having to recode the core table building code.
@param \Gems_Model_Bridge_ThreeColumnTableBridge $bridge
@param \MUtil_Model_ModelAbstract $model
@param \Gems_Menu_MenuList $links
@return boolean True when there was row output | entailment |
protected function addLastitems(\Gems_Model_Bridge_ThreeColumnTableBridge $bridge, \MUtil_Model_ModelAbstract $model, \Gems_Menu_MenuList $links)
{
if ($links->count()) {
$bridge->tfrow($links, array('class' => 'centerAlign'));
}
foreach ($bridge->tbody() as $row) {
if (isset($row[1]) && ($row[1] instanceof \MUtil_Html_HtmlElement)) {
if (isset($row[1]->skiprowclass)) {
unset($row[1]->skiprowclass);
} else {
$row[1]->appendAttrib('class', $bridge->row_class);
}
}
}
return true;
} | Adds last group of rows cleaning up whatever is left to do in adding links etc.
Overrule this function to add different columns to the browse table, without
having to recode the core table building code.
@param \Gems_Model_Bridge_ThreeColumnTableBridge $bridge
@param \MUtil_Model_ModelAbstract $model
@param \Gems_Menu_MenuList $links
@return boolean True when there was row output | entailment |
protected function addRespondentGroup(\Gems_Model_Bridge_ThreeColumnTableBridge $bridge, \MUtil_Model_ModelAbstract $model, \Gems_Menu_MenuList $links)
{
$item = $this->menu->findAllowedController('respondent', 'show');
if ($item) {
$href = $item->toHRefAttribute($bridge, $this->request);
$model->set('gr2o_patient_nr', 'itemDisplay', \MUtil_Html::create('a', $href));
}
// ThreeColumnTableBridge->add()
$bridge->add('gr2o_patient_nr');
if (! $this->currentUser->isFieldMaskedWhole('respondent_name')) {
$bridge->add('respondent_name');
}
return true;
} | Adds second group of rows showing patient specific data
Overrule this function to add different columns to the browse table, without
having to recode the core table building code.
@param \Gems_Model_Bridge_ThreeColumnTableBridge $bridge
@param \MUtil_Model_ModelAbstract $model
@param \Gems_Menu_MenuList $links
@return boolean True when there was row output | entailment |
protected function addRoundGroup(\Gems_Model_Bridge_ThreeColumnTableBridge $bridge, \MUtil_Model_ModelAbstract $model, \Gems_Menu_MenuList $links)
{
$bridge->add('gsu_survey_name');
$bridge->add('gto_round_description');
$bridge->add('ggp_name');
return true;
} | Adds forth group of rows showing round specific data
Overrule this function to add different columns to the browse table, without
having to recode the core table building code.
@param \Gems_Model_Bridge_ThreeColumnTableBridge $bridge
@param \MUtil_Model_ModelAbstract $model
@param \Gems_Menu_MenuList $links
@return boolean True when there was row output | entailment |
protected function addShowTableRows(\MUtil_Model_Bridge_VerticalTableBridge $bridge, \MUtil_Model_ModelAbstract $model)
{
// \MUtil_Model::$verbose = true;
// Don't know why, but is needed now
$bridge->getRow();
$links = $this->getMenuList();
$links->addParameterSources($this->request, $bridge);
if ($this->addHeaderGroup($bridge, $model, $links)) {
$bridge->addMarkerRow();
}
if ($this->addRespondentGroup($bridge, $model, $links)) {
$bridge->addMarkerRow();
}
if ($this->addTrackGroup($bridge, $model, $links)) {
$bridge->addMarkerRow();
}
if ($this->addRoundGroup($bridge, $model, $links)) {
$bridge->addMarkerRow();
}
$this->addValidFromBlock($bridge, $model, $links);
$this->addContactBlock($bridge, $model, $links);
$this->addCompletionBlock($bridge, $model, $links);
$this->addLastitems($bridge, $model, $links);
} | 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 |
protected function addValidFromBlock(\Gems_Model_Bridge_ThreeColumnTableBridge $bridge, \MUtil_Model_ModelAbstract $model, \Gems_Menu_MenuList $links)
{
// Editable part (INFO / VALID FROM / UNTIL / E-MAIL
$button = $links->getActionLink($this->request->getControllerName(), 'edit', true);
$bridge->addWithThird(
'gto_valid_from_manual',
'gto_valid_from',
'gto_valid_until_manual',
'gto_valid_until',
'gto_comment',
$button
);
return true;
} | Adds first block to fifth group group of rows showing valid from data
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
@param \Gems_Menu_MenuList $links
@return boolean True when there was row output | entailment |
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
continue;
}
$_itemlabel = $label . ($item->get('label') ?: $item->get('privilege'));
if ($_privilege = $item->get('privilege')) {
if (isset($privileges[$_privilege])) {
$privileges[$_privilege] .= "<br/> + " . $_itemlabel;
} else {
$privileges[$_privilege] = $_itemlabel;
}
}
$item->_addUsedPrivileges($privileges, $_itemlabel . '->');
}
} | Adds privileges that are used in this menu item to the array
@param array $privileges | entailment |
protected function _getOriginalRequest()
{
$request = $this->escort->request;
$handler = $request->getParam('error_handler');
if ($handler) {
return $handler->request;
}
return $request;
} | Get tge request to use for menu building
@return \Zend_Controller_Request_Abstract | entailment |
protected function _toNavigationArray(\Gems_Menu_ParameterCollector $source)
{
$this->sortByOrder();
$lastParams = null;
$pageIdx = 0;
$pages = array();
foreach ($this->_subItems as $item) {
// Skip button_only items
if ($item->get('button_only')) {
continue;
}
$page = $item->_toNavigationArray($source);
if (($this instanceof \Gems_Menu_SubMenuItem) &&
(!$this->notSet('controller', 'action')) &&
isset($page['params'])) {
$params = $page['params'];
unset($params['reset']); // Ignore this setting
$class = [];
if (isset($page['class'])) {
$class[] = $page['class'];
}
if (empty($params)) {
$class[] = 'noParameters';
}
if ((null !== $lastParams) && ($lastParams !== $params)) {
$class[] = 'breakBefore';
}
if (!empty($class)) {
$page['class'] = join(' ', $class);
}
$lastParams = $params;
}
$pages[$pageIdx] = $page;
$pageIdx++;
}
return $pages;
} | Returns a \Zend_Navigation creation array for this menu item, with
sub menu items in 'pages'
@param \Gems_Menu_ParameterCollector $source
@return array | entailment |
protected function add($argsArray)
{
// Process parameters.
$args = \MUtil_Ra::args(func_get_args(), 0,
array('visible' => true, // All menu items are initally visible unless stated otherwise
'allowed' => true, // Same as with visible, need this for t_oNavigationArray()
));
if (! isset($args['label'])) {
$args['visible'] = false;
}
if (! isset($args['order'])) {
$args['order'] = 10 * (count($this->_subItems) + 1);
}
$page = new \Gems_Menu_SubMenuItem($this->escort, $this, $args);
$this->_subItems[] = $page;
return $page;
} | Add a sub item to this item.
The argumenets can be any of those used for \Zend_Navigation_Page as well as some Gems specials.<ul>
<li>'action' The name of the action.</li>
<li>'allowed' Is the user allowed to access this menu item. Is checked against ACL using 'privilige'.</li>
<li>'button_only' Never in the menu, only shown as a button by the program.</li>
<li>'class' Display class for the menu link.</li>
<li>'controller' What controller to use.</li>
<li>'icon' Icon to display with the label.</li>
<li>'label' The label to display for the menu item.</li>
<li>'privilege' The privilege needed to choose the item.</li>
<li>'target' Optional target attribute for the link.</li>
<li>'type' Optional content type for the link</li>
<li>'visible' Is the item visible. Is checked against ACL using 'privilige'.</li>
</ul>
@see \Zend_Navigation_Page
@param array $argsArray \MUtil_Ra::args array with defaults 'visible' and 'allowed' true.
@return \Gems_Menu_SubMenuItem | entailment |
public function addAgendaSetupMenu($label)
{
$setup = $this->addContainer($label);
$setup->addAgendaSetupPage($this->_('Activities'), 'pr.agenda-activity', 'agenda-activity');
$setup->addAgendaSetupPage($this->_('Procedures'), 'pr.agenda-procedure', 'agenda-procedure');
$setup->addAgendaSetupPage($this->_('Diagnoses'), 'pr.agenda-diagnosis', 'agenda-diagnosis');
$setup->addAgendaSetupPage($this->_('Locations'), 'pr.locations', 'location');
$setup->addAgendaSetupPage($this->_('Healthcare staff'), 'pr.agenda-staff', 'agenda-staff');
$setup->addBrowsePage( $this->_('Track field filters'), 'pr.agenda-filters', 'agenda-filter');
return $setup;
} | Add a agenda setup menu tree to the menu
@param string $label
@param array $other
@return \Gems_Menu_SubMenuItem | entailment |
public function addAgendaSetupPage($label, $privilege, $controller, array $other = array())
{
$page = $this->addPage($label, $privilege, $controller, 'index', $other);
$page->addAutofilterAction();
$page->addCreateAction();
$page->addExportAction();
$page->addImportAction();
$show = $page->addShowAction();
$show->addEditAction();
$show->addDeleteAction();
$show->addAction($this->_('Clean up'), $privilege . '.cleanup', 'cleanup')
->setModelParameters(1);
return $page;
} | Add a browse / ceate / edit / show / / sleanup etc.. menu item
@param string $label
@param string $privilege
@param string $controller
@param array $other
@return \Gems_Menu_SubMenuItem | entailment |
public function addBrowsePage($label, $privilege, $controller, array $other = array())
{
$page = $this->addPage($label, $privilege, $controller, 'index', $other);
$page->addAutofilterAction();
$page->addCreateAction();
$page->addExportAction();
$page->addImportAction();
$show = $page->addShowAction();
$show->addEditAction();
$show->addDeleteAction();
return $page;
} | Add a browse / ceate / edit / show / etc.. menu item
@param string $label
@param string $privilege
@param string $controller
@param array $other
@return \Gems_Menu_SubMenuItem | entailment |
public function addButtonOnly($label, $privilege, $controller, $action = 'index', array $other = array())
{
$other['button_only'] = true;
return $this->addPage($label, $privilege, $controller, $action, $other);
} | Add a menu item that is never added to the navigation tree and only shows up as a button.
@param string $label
@param string $privilege
@param string $controller
@param string $action
@param array $other
@return \Gems_Menu_SubMenuItem | entailment |
public function addCalendarPage($label)
{
$page = $this->addPage($label, 'pr.calendar', 'calendar');
$page->addAutofilterAction();
$page->addExportAction();
$page->addImportAction();
$page->addAction(null, 'pr.calendar.simple-api', 'simple-api');
return $page;
} | Add a calendar page to the menu
@param string $label
@param array $other
@return \Gems_Menu_SubMenuItem | entailment |
public function addCommSetupMenu($label)
{
$setup = $this->addContainer($label);
// AUTOMATIC COMMUNICATION CONTROLLER
$page = $setup->addBrowsePage($this->_('Automatic mail'), 'pr.comm.job', 'comm-job');
$page->addButtonOnly($this->_('Turn Automatic Mail Jobs OFF'), 'pr.comm.job', 'cron', 'cron-lock');
$page->addButtonOnly($this->_('Monitor'), 'pr.comm.job', 'comm-job', 'monitor');
$page->addPage($this->_('Run all'), 'pr.cron.job', 'comm-job', 'execute-all');
$show = $page->findItem(array('controller' => 'comm-job', 'action' => 'show'));
$show->addPage($this->_('Preview'), 'pr.cron.job', 'comm-job', 'preview')
->setModelParameters(1);
$show->addPage($this->_('Run'), 'pr.cron.job', 'comm-job', 'execute')
->setModelParameters(1);
$ajaxPage = $this->addPage($this->_('Round Selection'), 'pr.comm.job', 'comm-job', 'roundselect', array('visible' => false));
$ajaxPage = $this->addPage($this->_('Sort jobs'), 'pr.comm.job.edit', 'comm-job', 'sort', array('visible' => false));
// MAIL SERVER CONTROLLER
$page = $setup->addBrowsePage($this->_('Servers'), 'pr.mail.server', 'mail-server');
// COMMUNICATION TEMPLATE CONTROLLER
$setup->addBrowsePage($this->_('Templates'), 'pr.comm.template', 'comm-template');
// COMMUNICATION ACTIVITY CONTROLLER
//$setup->addBrowsePage();
$page = $setup->addPage($this->_('Communication log'), 'pr.mail.log', 'mail-log');
$page->addAutofilterAction();
$page->addExportAction();
$page->addShowAction();
return $setup;
} | Add a Mail menu tree to the menu
@param string $label
@param array $other
@return \Gems_Menu_SubMenuItem | entailment |
public function addExportContainer($label)
{
$export = $this->addContainer($label);
// EXPORT
$surveyExport = $export->addPage($this->_('Single survey answers'), 'pr.export', 'export-survey', 'index');
$surveyExport->addAutofilterAction();
$surveyExport->addExportAction();
//$export->addButtonOnly('', 'pr.export', 'export', 'handle-export');
//$export->addButtonOnly('', 'pr.export', 'export', 'download');
$batchExport = $export->addPage(
$this->_('Multiple surveys answers'),
'pr.export',
'export-multi-surveys',
'index'
);
$batchExport->addAutofilterAction();
// EXPORT TO HTML
$export->addPage($this->_('Respondent archives'), 'pr.export-html', 'respondent-export', 'index');
return $export;
} | Shortcut function to create the export container.
@param string $label Label for the container
@return \Gems_Menu_MenuAbstract The new contact page | entailment |
public function addFilePage($label, $privilege, $controller, array $other = array())
{
$page = $this->addPage($label, $privilege, $controller, 'index', $other);
$page->addAutofilterAction();
// $page->addCreateAction();
// $page->addExcelAction();
$page = $page->addShowAction();
$page->addEditAction();
$onDelete = new \MUtil_Html_OnClickArrayAttribute();
$onDelete->addConfirm($this->_("Are you sure you want to delete this file?"));
$page->addButtonOnly($this->_('Delete'), $privilege . '.delete', $controller, 'delete', array(
'onclick' => $onDelete,
))->setModelParameters(1);
$page->addButtonOnly($this->_('Download'), $privilege . '.download', $controller, 'download')
->setModelParameters(1);
return $page;
} | Add a file upload/download page to the menu
@param string $label The label to display for the menu item, null for access without display
@param string $privilege The privilege for the item, null is always, 'pr.islogin' must be logged in, 'pr.nologin' only when not logged in.
@param string $controller What controller to use
@param string $action The name of the action
@param array $other Array of extra options for this item, e.g. 'visible', 'allowed', 'class', 'icon', 'target', 'type', 'button_only'
@return \Gems_Menu_SubMenuItem | entailment |
public function addImportContainer($label)
{
$import = $this->addContainer($label);
$page = $import->addPage($this->_('Answers'), 'pr.survey-maintenance.answer-import', 'file-import', 'answers-import');
$uplPage = $import->addFilePage($this->_('Importable'), 'pr.file-import', 'file-import');
// $page->addButtonOnly($this->_('Auto import'), 'pr.file-import.auto', 'file-import', 'auto');
$uplPage->addImportAction('pr.file-import.import', array('label' => $this->_('Import file')))
->setModelParameters(1);
$impPage = $import->addFilePage($this->_('Imported files'), 'pr.file-import', 'imported-files');
$impPage->addImportAction('pr.file-import.import', array('label' => $this->_('Reimport file')))
->setModelParameters(1);
$errPage = $import->addFilePage($this->_('Imported failures'), 'pr.file-import', 'imported-failures');
$errPage->addImportAction('pr.file-import.import', array('label' => $this->_('Retry import')))
->setModelParameters(1);
return $import;
} | Shortcut function to create the import container.
@param string $label Label for the container
@return \Gems_Menu_MenuAbstract The new contact page | entailment |
public function addLogControllers()
{
// LOG SETUP CONTROLLER
$this->addBrowsePage($this->_('Log Setup'), 'pr.log.maintenance', 'log-maintenance');
// LOG CONTROLLER
$page = $this->addPage($this->_('Log'), 'pr.log', 'log', 'index');
$page->addAutofilterAction();
$page->addExportAction();
$page->addShowAction()
->setNamedParameters(\Gems_Model::LOG_ITEM_ID, 'gla_id');
// LOG FILES CONTROLLER
$this->addFilePage($this->_('Log files'), 'pr.log.files', 'log-file');
} | Add the log menu items | entailment |
public function addPage($label, $privilege, $controller, $action = 'index', array $other = array())
{
$other['label'] = $label;
$other['controller'] = $controller;
$other['action'] = $action;
if ($privilege) {
$other['privilege'] = $privilege;
}
return $this->add($other);
} | Add a page to the menu
@param string $label The label to display for the menu item, null for access without display
@param string $privilege The privilege for the item, null is always, 'pr.islogin' must be logged in, 'pr.nologin' only when not logged in.
@param string $controller What controller to use
@param string $action The name of the action
@param array $other Array of extra options for this item, e.g. 'visible', 'allowed', 'class', 'icon', 'target', 'type', 'button_only'
@return \Gems_Menu_SubMenuItem | entailment |
public function addPlanPage($label)
{
$infoPage = $this->addContainer($label);
$page = $infoPage->addPage($this->_('Track Summary'), 'pr.plan.summary', 'summary', 'index');
$page->addAutofilterAction();
$page->addExportAction();
$page = $infoPage->addPage($this->_('Track Compliance'), 'pr.plan.compliance', 'compliance', 'index');
$page->addAutofilterAction();
$page->addExportAction();
$page = $infoPage->addPage($this->_('Track Field Utilization'), 'pr.plan.fields', 'field-report', 'index');
$page->addAutofilterAction();
$page->addExportAction();
$page = $infoPage->addPage($this->_('Track Field Content'), 'pr.plan.fields', 'field-overview', 'index');
$page->addAutofilterAction();
$page->addExportAction();
$plans[] = $infoPage->addPage($this->_('By period'), 'pr.plan.overview', 'overview-plan', 'index');
$plans[] = $infoPage->addPage($this->_('By token'), 'pr.plan.token', 'token-plan', 'index');
$plans[] = $infoPage->addPage($this->_('By respondent'), 'pr.plan.respondent', 'respondent-plan', 'index');
foreach ($plans as $plan) {
$plan->addAutofilterAction();
$plan->addAction($this->_('Bulk mail'), 'pr.token.bulkmail', 'email', array('routeReset' => false));
$plan->addExportAction();
}
$page = $infoPage->addPage($this->_('Respondent status'), 'pr.plan.consent', 'consent-plan', 'index');
$page->addShowAction();
$page->addExportAction();
return $infoPage;
} | Add a list of report pages
@param string $label The label to display for the menu item, null for access without display
@return \Gems_Menu_SubMenuItem | entailment |
public function addProjectInfoPage($label)
{
$page = $this->addPage($label, 'pr.project-information', 'project-information');
$page->addAction($this->_('Errors'), null, 'errors');
$page->addAction($this->_('PHP'), null, 'php');
$page->addAction($this->_('PHP Errors'), null, 'php-errors');
$page->addAction($this->_('Project'), null, 'project');
$page->addAction($this->_('Session'), null, 'session');
$page->addButtonOnly($this->_('Maintenance mode'), 'pr.maintenance.maintenance-mode', 'project-information', 'maintenance');
$page->addButtonOnly($this->_('Monitor'), 'pr.maintenance.maintenance-mode', 'project-information', 'monitor');
$page->addButtonOnly($this->_('Clean cache'), 'pr.maintenance.clean-cache', 'project-information', 'cacheclean');
// TEMPLATES CONTROLLER
$templates = $page->addPage($this->_('Templates'), 'pr.templates', 'template');
$templates->addAutofilterAction();
$edit = $templates->addEditAction();
$reset = $edit->addAction($this->_('Reset to default values'), 'pr.templates.reset', 'reset');
$reset->setModelParameters(1);
// UPGRADES CONTROLLER
$upage = $page->addPage($this->_('Upgrade'), 'pr.upgrade', 'upgrade', 'index');
$show = $upage->addAction($this->_('Show'), null, 'show')
->setNamedParameters('id','context');
$upage->addAction($this->_('Execute all'), 'pr.upgrade.all', 'execute-all')
->setModelParameters(1);
$show->addActionButton($this->_('Execute this'), 'pr.upgrade.one', 'execute-one')
->setModelParameters(1)
->addNamedParameters('from','from','to','to');
$show->addActionButton($this->_('Execute from here'), 'pr.upgrade.from', 'execute-from')
->setModelParameters(1)
->addNamedParameters('from','from');
$show->addActionButton($this->_('Execute to here'), 'pr.upgrade.to', 'execute-to')
->setModelParameters(1)
->addNamedParameters('to','to');
$show->addAction(null, 'pr.upgrade.to', 'execute-last');
$upage->addAction(
$this->_('Code compatibility report'),
'pr.upgrade',
'compatibility-report'
);
$upage->addPage(
sprintf($this->_('Changelog %s'), 'GemsTracker'),
'pr.upgrade',
'project-information',
'changelog-gems'
);
$upage->addPage(
sprintf($this->_('Changelog %s'), $this->escort->project->getName()),
'pr.upgrade',
'project-information',
'changelog'
);
return $page;
} | Add pages that show the user technical information about the installation
in the project.
@param string $label
@param array $other
@return \Gems_Menu_SubMenuItem | entailment |
public function addProjectPage($label)
{
if ($this->escort instanceof \Gems_Project_Tracks_SingleTrackInterface) {
if ($trackId = $this->escort->getTrackId()) {
$infoPage = $this->addPage($label, 'pr.project', 'project-tracks', 'show')
->addHiddenParameter(\MUtil_Model::REQUEST_ID, $trackId);
$trackSurveys = $infoPage;
} else {
$infoPage = $this->addPage($label, 'pr.project', 'project-tracks');
$trackSurveys = $infoPage->addShowAction('pr.project');
}
$trackSurveys->addAction($this->_('Preview'), 'pr.project.questions', 'questions')
->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gro_id_track', \Gems_Model::SURVEY_ID, 'gsu_id_survey');
$infoPage->addAutofilterAction();
// \MUtil_Echo::track($infoPage->_toNavigationArray(array($this->_getOriginalRequest())));
} else {
$infoPage = $this->addContainer($label);
$tracksPage = $infoPage->addPage($this->_('Tracks'), 'pr.project', 'project-tracks');
$tracksPage->addAutofilterAction();
$trackSurveys = $tracksPage->addShowAction('pr.project');
$trackSurveys->addAction($this->_('Preview'), 'pr.project.questions', 'questions')
->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gro_id_track', \Gems_Model::SURVEY_ID, 'gsu_id_survey');
$surveysPage = $infoPage->addPage($this->_('Surveys'), 'pr.project', 'project-surveys');
$surveysPage->addAutofilterAction();
$surveysPage->addShowAction('pr.project');
}
return $infoPage;
} | Add pages that show the user an overview of the tracks / surveys used
in the project.
@param string $label
@param array $other
@return \Gems_Menu_SubMenuItem | entailment |
public function addStaffPage($label, array $other = array())
{
if ($this->user->hasPrivilege('pr.staff.edit.all')) {
$filter = array_keys($this->escort->getUtil()->getDbLookup()->getOrganizations());
} else {
$filter = array_keys($this->user->getAllowedOrganizations());
}
$page = $this->addPage($label, 'pr.staff', 'staff', 'index', $other);
$page->addAutofilterAction();
$createPage = $page->addCreateAction();
$showPage = $page->addShowAction();
$pages[] = $showPage->addEditAction();
$pages[] = $showPage->addAction($this->_('Reset password'), 'pr.staff.edit', 'reset')
->setModelParameters(1)
->addParameterFilter('gsf_active', 1);
$pages[] = $showPage->addAction($this->_('Reset 2FA'), 'pr.staff.edit', 'reset2fa')
->setModelParameters(1)
->addParameterFilter('gsf_active', 1, 'has_2factor', 2);
$showPage->addAction($this->_('Send Mail'), 'pr.staff.edit', 'mail')
->setModelParameters(1)
->addParameterFilter('can_mail', 1, 'gsf_active', 1, 'gsf_id_organization', $filter);
$pages = $pages + $showPage->addDeReactivateAction('gsf_active', 1, 0);
// LOG CONTROLLER
$logPage = $showPage->addPage($this->_('Activity overview'), 'pr.staff-log', 'staff-log', 'index')
->setModelParameters(1)
->addParameterFilter('gsf_id_organization', $filter);
$logPage->addAutofilterAction();
$logPage->addShowAction()->setModelParameters(1)->addNamedParameters('log', 'gla_id');
$page->addExportAction();
$page->addImportAction();
if (! $this->user->hasPrivilege('pr.staff.edit.all')) {
foreach ($pages as $subPage) {
$subPage->addParameterFilter('gsf_id_organization', $filter, 'accessible_role', 1);
}
}
return $page;
} | Add a staff browse edit page to the menu,
@param string $label
@param array $other
@return \Gems_Menu_SubMenuItem | entailment |
public function addTrackBuilderMenu($label, array $other = array())
{
$setup = $this->addContainer($label);
// SURVEY SOURCES CONTROLLER
$page = $setup->addPage($this->_('Survey Sources'), 'pr.source', 'source');
$page->addAutofilterAction();
$page->addCreateAction();
$page->addExportAction();
$page->addImportAction();
$show = $page->addShowAction();
$show->addEditAction();
$show->addDeleteAction();
$show->addAction($this->_('Check status'), null, 'ping')
->addParameters(\MUtil_Model::REQUEST_ID);
$show->addAction($this->_('Synchronize surveys'), 'pr.source.synchronize', 'synchronize')
->addParameters(\MUtil_Model::REQUEST_ID);
$show->addAction($this->_('Check is answered'), 'pr.source.check-answers', 'check')
->addParameters(\MUtil_Model::REQUEST_ID);
$show->addAction($this->_('Check attributes'), 'pr.source.check-attributes', 'attributes')
->addParameters(\MUtil_Model::REQUEST_ID);
$page->addAction($this->_('Synchronize all surveys'), 'pr.source.synchronize-all', 'synchronize-all');
$page->addAction($this->_('Check all is answered'), 'pr.source.check-answers-all', 'check-all');
$page->addAction($this->_('Check all attributes'), 'pr.source.check-attributes-all', 'attributes-all');
// ADD CHART SETUP CONTROLLER
$setup->addBrowsePage($this->_('Charts setup'), 'pr.chartsetup', 'chartconfig');
// ADD CONDITIONS CONTROLLER - do not include import/export as this is handled by track import/export
$conditions = $setup->addPage($this->_('Conditions'), 'pr.conditions', 'condition');
$conditions->addAutofilterAction();
$conditions->addCreateAction();
$show = $conditions->addShowAction();
$show->addEditAction();
$show->addDeleteAction();
// SURVEY MAINTENANCE CONTROLLER
$page = $setup->addPage($this->_('Surveys'), 'pr.survey-maintenance', 'survey-maintenance');
$page->addAutofilterAction();
$page->addExportAction();
$showPage = $page->addShowAction();
$showPage->addEditAction();
$showPage->addAction($this->_('Check is answered'), 'pr.survey-maintenance.check', 'check')
->addParameters(\MUtil_Model::REQUEST_ID)
->setParameterFilter('gsu_active', 1);
$showPage->addAction($this->_('Import answers'), 'pr.survey-maintenance.answer-import', 'answer-import')
->addParameters(\MUtil_Model::REQUEST_ID)
->setParameterFilter('gsu_active', 1);
$showPage->addPdfButton($this->_('PDF'), 'pr.survey-maintenance')
->addParameters(\MUtil_Model::REQUEST_ID)
->setParameterFilter('gsu_has_pdf', 1);
// Multi survey
$page->addAction($this->_('Check all is answered'), 'pr.survey-maintenance.check-all', 'check-all');
$page->addAction($this->_('Import answers'), 'pr.survey-maintenance.answer-import', 'answer-imports');
$page->addPage($this->_('Update to new survey'), 'pr.track-maintenance.edit', 'update-survey', 'run');
// TRACK MAINTENANCE CONTROLLER
$page = $setup->addPage($this->_('Tracks'), 'pr.track-maintenance', 'track-maintenance', 'index');
$page->addAutofilterAction();
$page->addCreateAction();
//$page->addExportAction();
$page->addImportAction();
$showPage = $page->addShowAction();
$showPage->addEditAction();
$showPage->addDeleteAction();
/*$showPage->addButtonOnly($this->_('Copy'), 'pr.track-maintenance.copy', 'track-maintenance', 'copy')
->setModelParameters(1);*/
$showPage->addAction($this->_('Export'), 'pr.track-maintenance.export', 'export')
->addParameters(\MUtil_Model::REQUEST_ID);
$showPage->addAction($this->_('Check rounds'), 'pr.track-maintenance.check', 'check-track')
->addParameters(\MUtil_Model::REQUEST_ID)
->setParameterFilter('gtr_active', 1);
$showPage->addAction($this->_('Recalculate fields'), 'pr.track-maintenance.check', 'recalc-fields')
->addParameters(\MUtil_Model::REQUEST_ID)
->setParameterFilter('gtr_active', 1);
// Fields
$fpage = $showPage->addPage($this->_('Fields'), 'pr.track-maintenance', 'track-fields')
->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gtf_id_track');
$fpage->addAutofilterAction();
$fpage->addCreateAction('pr.track-maintenance.create')
->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gtf_id_track');
$fpage = $fpage->addShowAction()
->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gtf_id_track', \Gems_Model::FIELD_ID, 'gtf_id_field', 'sub', 'sub');
$fpage->addEditAction('pr.track-maintenance.edit')
->addNamedParameters(\Gems_Model::FIELD_ID, 'gtf_id_field', \MUtil_Model::REQUEST_ID, 'gtf_id_track', 'sub', 'sub');
$fpage->addDeleteAction('pr.track-maintenance.delete')
->addNamedParameters(\Gems_Model::FIELD_ID, 'gtf_id_field', \MUtil_Model::REQUEST_ID, 'gtf_id_track', 'sub', 'sub');
// Rounds
$rpage = $showPage->addPage($this->_('Rounds'), 'pr.track-maintenance', 'track-rounds')
->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gro_id_track');
$rpage->addAutofilterAction();
$rpage->addCreateAction('pr.track-maintenance.create')
->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gro_id_track');
$spage = $rpage->addShowAction()
->addNamedParameters(\MUtil_Model::REQUEST_ID, 'gro_id_track', \Gems_Model::ROUND_ID, 'gro_id_round');
$spage->addEditAction('pr.track-maintenance.edit')
->addNamedParameters(\Gems_Model::ROUND_ID, 'gro_id_round', \MUtil_Model::REQUEST_ID, 'gro_id_track');
$spage->addDeleteAction('pr.track-maintenance.delete')
->addNamedParameters(\Gems_Model::ROUND_ID, 'gro_id_round', \MUtil_Model::REQUEST_ID, 'gro_id_track');
$ajaxPage = $this->addPage($this->_('Sort rounds'), 'pr.track-maintenance.edit', 'track-rounds', 'sort', array('visible' => false));
$overviewPage = $page->addPage($this->_('Tracks per org'), 'pr.track-maintenance.trackperorg', 'track-overview', 'index');
$overviewPage->addExportAction();
$overviewPage->addAutofilterAction();
$page->addAction($this->_('Check all rounds'), 'pr.track-maintenance.check-all', 'check-all');
$page->addAction($this->_('Recalculate all fields'), 'pr.track-maintenance.check-all', 'recalc-all-fields');
return $setup;
} | Add a Trackbuilder menu tree to the menu
@param string $label
@param array $other
@return \Gems_Menu_SubMenuItem | entailment |
protected function applyAcl(\MUtil_Acl $acl, $userRole)
{
foreach ($this->_subItems as $item) {
$allowed = $item->get('allowed', true);
if ($allowed && ($privilege = $item->get('privilege'))) {
$allowed = $acl->isAllowed($userRole, null, $privilege);
}
if ($allowed) {
$item->applyAcl($acl, $userRole);
} else {
// As an item can be invisible but allowed,
// but not disallowed but visible we need to
// set both.
$item->set('allowed', false);
$item->set('visible', false);
$item->setForChildren('allowed', false);
$item->setForChildren('visible', false);
}
}
return $this;
} | Set the visibility of the menu item and any sub items in accordance
with the specified user role.
@param \Zend_Acl $acl
@param string $userRole
@return \Gems_Menu_MenuAbstract (continuation pattern) | entailment |
protected function setBranchVisible(array $activeBranch)
{
$current = array_pop($activeBranch);
foreach ($this->_subItems as $item) {
if ($item->isVisible()) {
if ($item === $current) {
$item->set('active', true);
$item->setBranchVisible($activeBranch);
} else {
$item->setForChildren('visible', false);
}
}
}
return $this;
} | Make sure only the active branch is visible
@param array $activeBranch Of \Gems_Menu_Menu Abstract items
@return \Gems_Menu_MenuAbstract (continuation pattern) | entailment |
public static function sortOrder($aItem, $bItem)
{
$a = $aItem->get('order');
$b = $bItem->get('order');
if ($a == $b) {
return 0;
}
return $a > $b ? 1 : -1;
} | uasort() function for sortByOrder()
@see sortByOrder();
@param self $aItem
@param self $bItem
@return int | entailment |
public function formatDateForever($dateValue)
{
if ($dateValue) {
return $this->formatDateTime($dateValue);
} else {
return \MUtil_Html::create()->span($this->_('forever'), array('class' => 'disabled'));
}
} | Get a readable version of date / time object with nearby days translated in text
or 'forever' when null
@param \MUtil_Date $dateValue
@return string|\MUtil_Html_HtmlElement | entailment |
public function formatDateNa($dateValue)
{
if ($dateValue) {
return $this->formatDateTime($dateValue);
} else {
return \MUtil_Html::create()->span($this->_('n/a'), array('class' => 'disabled'));
}
} | Get a readable version of date / time object with nearby days translated in text
or 'n/a' when null
@param \MUtil_Date $dateValue
@return string|\MUtil_Html_HtmlElement | entailment |
public function formatDateNever($dateValue)
{
if ($dateValue) {
return $this->formatDateTime($dateValue);
} else {
return \MUtil_Html::create()->span($this->_('never'), array('class' => 'disabled'));
}
} | Get a readable version of date / time object with nearby days translated in text
or 'never' when null
@param \MUtil_Date $dateValue
@return string|\MUtil_Html_HtmlElement | entailment |
public function formatDateUnknown($dateValue)
{
if ($dateValue) {
return $this->formatDateTime($dateValue);
} else {
return \MUtil_Html::create()->span($this->_('unknown'), array('class' => 'disabled'));
}
} | Get a readable version of date / time object with nearby days translated in text
or 'unknown' when null
@param \MUtil_Date $dateValue
@return string|\MUtil_Html_HtmlElement | entailment |
public function formatDateTime($dateTimeValue)
{
if (! $dateTimeValue) {
return null;
}
//$dateTime = strtotime($dateTimeValue);
// \MUtil_Echo::track($dateTimeValue, date('c', $dateTime), $dateTime / 86400, date('c', time()), time() / 86400);
// TODO: Timezone seems to screw this one up
//$days = floor($dateTime / 86400) - floor(time() / 86400); // 86400 = 24*60*60
if ($dateTimeValue instanceof \MUtil_Date) {
$dateTime = $dateTimeValue;
} else{
$dateTime = \MUtil_Date::ifDate(
$dateTimeValue,
array(\Gems_Tracker::DB_DATETIME_FORMAT, \Gems_Tracker::DB_DATE_FORMAT, \Zend_Date::ISO_8601)
);
if (! $dateTime) {
return null;
}
}
$days = $dateTime->diffDays();
switch ($days) {
case -2:
return $this->_('2 days ago');
case -1:
return $this->_('Yesterday');
case 0:
return $this->_('Today');
case 1:
return $this->_('Tomorrow');
case 2:
return $this->_('Over 2 days');
default:
if (($days > -14) && ($days < 14)) {
if ($days > 0) {
return sprintf($this->_('Over %d days'), $days);
} else {
return sprintf($this->_('%d days ago'), -$days);
}
}
return $dateTime->getDateTime()->format($this->phpDateFormatString);
}
} | Get a readable version of date / time object with nearby days translated in text
@param \MUtil_Date $dateTimeValue
@return string | entailment |
public function formatTime($dateTimeValue)
{
if ($dateTimeValue instanceof \Zend_Date) {
$dateTimeValue = $dateTimeValue->getTimestamp();
}
$seconds = str_pad($dateTimeValue % 60, 2, '0', STR_PAD_LEFT);
$rest = intval($dateTimeValue / 60);
$minutes = str_pad($rest % 60, 2, '0', STR_PAD_LEFT);
$hours = intval($rest / 60);
$days = intval($hours / 24);
if ($hours > 48) {
$hours = $hours % 24;
return sprintf($this->_('%d days %d:%s:%s'), $days, $hours, $minutes, $seconds);
} elseif ($hours) {
return sprintf($this->_('%d:%s:%s'), $hours, $minutes, $seconds);
} else {
return sprintf($this->_('%d:%s'), $minutes, $seconds);
}
} | Returns the time in seconds as a display string
@param int $dateTimeValue
@return string | entailment |
public function formatTimeUnknown($dateTimeValue)
{
if (null === $dateTimeValue) {
return \MUtil_Html::create()->span($this->_('unknown'), array('class' => 'disabled'));
} else {
return $this->formatTime($dateTimeValue);
}
} | Returns the time in seconds as a display string or unknown when null
@param int $dateTimeValue
@return string | entailment |
public function getGenders($locale = null)
{
return array('M' => $this->_('Male', $locale), 'F' => $this->_('Female', $locale), 'U' => $this->_('Unknown', $locale));
} | Returns the functional description of a gender for use in e.g. interface elements
@param string $locale
@return array gender => string | entailment |
public function getGenderGreeting($locale = null)
{
return array('M' => $this->_('mr.', $locale), 'F' => $this->_('mrs.', $locale), 'U' => $this->_('mr./mrs.', $locale));
} | Returns the gender for use as part of a sentence, e.g. Dear Mr/Mrs
In practice: starts lowercase
@param string $locale
@return array gender => string | entailment |
public function getGenderHello($locale = null)
{
return array('M' => $this->_('Mr.', $locale), 'F' => $this->_('Mrs.', $locale), 'U' => $this->_('Mr./Mrs.', $locale));
} | Returns the gender for use in stand-alone name display
In practice: starts uppercase
@param string $locale
@return array gender => string | entailment |
public function getPeriodUnits()
{
return array(
'S' => $this->translate->_('Seconds'),
'N' => $this->translate->_('Minutes'),
'H' => $this->translate->_('Hours'),
'D' => $this->translate->_('Days'),
'W' => $this->translate->_('Weeks'),
'M' => $this->translate->_('Months'),
'Q' => $this->translate->_('Quarters'),
'Y' => $this->translate->_('Years')
);
} | Get an array of translated labels for the date period units
@return array date_unit => label | entailment |
public function markEmpty($value)
{
if (empty($value)) {
$em = \MUtil_Html::create('em');
$em->raw($this->_('«empty»'));
return $em;
}
return $value;
} | Mark empty data as empty
@param string $subject
@return mxied | entailment |
public function setOption($varname, $varvalue=null)
{
$keys = array_keys($this->_options);
if(gettype($varname) === 'array')
{
foreach($varname as $name=>$value)
{
$this->setOption($name, $value);
}
}
else
{
if(in_array($varname, $keys) === true)
{
$this->_options[$varname] = $varvalue;
}
switch($varname)
{
case 'template_directory' :
self::$template_directory_base = $varvalue;
break;
case 'tag_directory' :
self::$tag_directory_base = $varvalue;
break;
case 'missing_tags_error_mode' :
self::$error_mode = $varvalue;
break;
case 'custom_cache_tag_class' :
if(class_exists($varvalue) === false)
{
$this->_options['cache_tags'] = false;
}
break;
case 'cache_directory' :
if(is_dir($varvalue) === false || is_writable($varvalue) === false)
{
$this->_options['cache_tags'] = false;
}
break;
}
}
} | Sets an option in the option array();
@access public
@param mixed $varname Can take the form of an array of options to set a string of an option name.
@param mixed $varvalue The value of the option you are setting. | entailment |
public function parse($source=false, $parse_collections=false, $_internal_loop=false)
{
// increment the parse count so it has unique identifiers
self::$_instance += 1;
// capture the source from the buffer
if($source === false)
{
$source = ob_get_clean();
$this->_buffer_in_use = true;
$parse_collections = true;
}
// collect the tags for processing
$tags = $this->collectTags($source);
if(count($tags) > 0)
{
// there are tags so process them
$output = $this->_parseTags($tags);
if($output && $parse_collections === true)
{
// parse any collected tags if required
$output = $this->_processCollectedTags($output);
}
if($this->_options['echo_output'] === true)
{
echo $output;
}
return $output;
}
return $source;
} | Parses the source for any custom tags.
@access public
@param mixed|boolean|string $source If false then it will capture the output buffer, otherwise if a string
it will use this value to search for custom tags.
@param boolean $parse_collections If true then any collected tags will be parsed after the tags are parsed.
@return string The parsed $source value. | entailment |
private function _parseTag($tag)
{
// return nothing if the tag is disabled
if(isset($tag['attributes']->disabled) === true && $tag['attributes']->disabled === 'true')
{
return '';
}
$tag_data = false;
$caching_tag = isset($tag['attributes']->cache) && $tag['attributes']->cache === 'false' ? false : true;
if($this->_options['cache_tags'] === true && $caching_tag === true)
{
if($this->_options['custom_cache_tag_class'] !== false)
{
$tag_data = call_user_func_array(array($this->_options['custom_cache_tag_class'], 'getCache'), array($tag));
}
else
{
$cache_file = $this->_options['cache_directory'].md5(serialize($tag));
if(is_file($cache_file) === true)
{
$tag_data = file_get_contents($cache_file);
}
}
if($tag_data)
{
$tag['cached'] = true;
return $tag_data;
}
}
// look for and load tag function file
$tag_func_name = ucwords(str_replace(array('_', '-'), ' ', $tag['name']));
$tag_func_name = strtolower(substr($tag_func_name, 0, 1)).substr($tag_func_name, 1);
$func_name = str_replace(' ', '', $this->_options['tag_callback_prefix'].$tag_func_name);
$tag_data = '';
$collect_tag = false;
$tag_order = false;
if(function_exists($func_name) === false)
{
$has_resource = false;
if(is_array($this->_options['tag_directory']) === false)
{
$this->_options['tag_directory'] = array($this->_options['tag_directory']);
}
foreach ($this->_options['tag_directory'] as $directory)
{
$tag_file = rtrim($directory, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$tag['name'].DIRECTORY_SEPARATOR.'tag.php';
if(is_file($tag_file) === true)
{
if(isset(self::$_required[$tag['name']]) === false)
{
self::$_required[$tag['name']] = true;
$collect = false;
if(function_exists($func_name) === false)
{
include_once $tag_file;
}
self::$_tags_to_collect[$tag['name']] = $collect;
if(function_exists($func_name) === false)
{
return self::throwError($tag['name'], 'tag resource "'.$directory.DIRECTORY_SEPARATOR.'tag.php" found but callback "'.$func_name.'" wasn\'t.');
}
$has_resource = true;
}
}
}
if($has_resource === false)
{
return self::throwError($tag['name'], 'tag resource not found.');
}
}
// do we have to collect this tag for parsing at a later point
if(self::$_tags_to_collect[$tag['name']] !== false)
{
if(isset(self::$tag_collections[$tag['name']]) === false)
{
self::$tag_collections[$tag['name']] = array();
}
$tag['collected'] = true;
$index = array_push(self::$tag_collections[$tag['name']], $tag)-1;
if($tag_order !== false)
{
if(isset(self::$_tag_order[$block['name']]) === false)
{
self::$_tag_order[$block['name']] = array();
}
self::$_tag_order[$block['name']] = $tag_order;
}
return self::$tag_collections[$tag['name']][$index]['tag'] = '------@@%'.self::$_instance.'-'.$tag['name'].'-'.$index.'-'.uniqid(time().'-').'%@@------';
}
// excecute the tag callback
if($this->_options['tag_global_callback'] !== false)
{
$tag_data = trim(call_user_func($this->_options['tag_global_callback'], 'tag', $func_name, $tag));
}
else
{
$tag_data = trim(call_user_func($func_name, $tag));
}
// this is where we sniff for buried tags within the returned content
if(empty($tag_data) === false)
{
if($this->_options['sniff_for_buried_tags'] === true && strpos($tag_data, self::$tag_open.$this->_options['tag_name'].':') !== false)
{
// we have the possibility of buried tags so lets parse
// but first make sure the output isn't echoed out
$old_echo_value = $this->_options['echo_output'];
$this->_options['echo_output'] = false;
// parse the tag_data
$tag_data = $this->parse($tag_data, false, true);
// restore the echo_output value back to what it was originally
$this->_options['echo_output'] = $old_echo_value;
}
if($this->_options['cache_tags'] === true && $caching_tag === true)
{
if($this->_options['custom_cache_tag_class'] !== false)
{
call_user_func_array(array($this->_options['custom_cache_tag_class'], 'cache'), array($tag, $tag_data));
}
else
{
file_put_contents($this->_options['cache_directory'].md5(serialize($tag)), $tag_data, LOCK_EX);
}
}
}
return $tag_data;
} | Processes a tag by loading
@access private
@param array $tag The tag to parse.
@return string The content of the tag. | entailment |
public static function throwError($tag, $message)
{
if(self::$error_mode === self::ERROR_EXCEPTION && !$this->_buffer_in_use)
{
throw new CustomTagsException('<strong>'.$tag.'</strong> '.$message.'.');
}
else if(self::$error_mode !== self::ERROR_SILENT)
{
return '<strong>['.self::$name.' Error]</strong>: '.ucfirst($tag).' Tag - '.$message.'<br />';
}
return '';
} | Produces an error.
@access public
@param string $tag The name of the tag producing an error.
@param string $message The message of the error.
@return mixed|error|string Either a string or thrown error is returned dependent
on the 'missing_tags_error_mode' option. | entailment |
private function _parseTags($tags)
{
if(count($tags) > 0)
{
// loop through the tags
foreach($tags as $key=>$tag)
{
// if a tag is delayed, it is rendered after everything else and it's has to be re parsed.
if(isset($tag['attributes']) === true && isset($tag['attributes']->delayed) === true && $tag['attributes']->delayed === 'true')
{
continue;
}
// check for buried preserved tags, so they can be replaced.
// NOTE: this only works with no collected tags. Collected tags are a massive pain in the rectum.
if(($has_buried = preg_match_all('!------@@%([0-9\-]+)%@@------!', $tag['content'], $info)) > 0)
{
$containers = $info[0];
$indexs = $info[1];
$replacements = array();
foreach ($indexs as $key2=>$index)
{
$index_parts = explode('-', $index);
$tag_index = array_pop($index_parts);
if(isset($tags[$tag_index]['parsed']) === true)
{
$replacements[$key2] = $tags[$tag_index]['parsed'];
}
else
{
if(isset($tags[$tag_index]['block']) === true)
{
$block = preg_replace('/ delayed="true"/', '', $tags[$tag_index]['block'], 1);
if(isset($tag['block']) === true)
{
$tag['block'] = str_replace($containers[$key2], $block, $tag['block']);
}
$tag['content'] = str_replace($containers[$key2], $block, $tag['content']);
}
}
}
$tags[$key]['buried_source_markers'] = $tag['buried_source_markers'] = $containers;
}
// if the tag is a nocahe tag then the block must be replaced as is for later processing
if($tag['name'] === 'nocache')
{
array_push(self::$nocache_tags, $tag);
$tags[$key]['parsed'] = $tag['source_marker'];
// $tags[$key]['parsed'] = $tag['block'];
}
// if the tag is just plain text then just shove the content back into the parsed as it doesn't require processing
else if($tag['name'] === '___text')
{
$tags[$key]['parsed'] = $tag['content'];
}
// otherwise we have a tag and must post process
else
{
$tags[$key]['parsed'] = $this->_parseTag($tag);
}
// update any buried tags within the parsed content
$tags[$key]['parsed'] = $has_buried > 0 ? str_replace($containers, $replacements, $tags[$key]['parsed']) : $tags[$key]['parsed'];
}
// // if there are items within the nocache elements, parse the contents to pull them out
// $tagname = $this->_options['tag_name'];
// if(substr_count($tags[$key]['parsed'], self::$tag_open.$tagname.':') > substr_count($tags[$key]['parsed'], self::$tag_open.$tagname.':nocache'))
// {
// $tags[$key]['parsed'] = $this->parse($tags[$key]['parsed'], true, true);
// // $tags[$key]['parsed'] = $this->_processTags($tags[$key]['parsed'], true);
// }
// Debug::info($tags[$key]);
return $tags[$key]['parsed'];
}
return false;
} | Loops and parses the found custom tags.
@access private
@param array $tags An array of found custom tag data.
@return mixed|string|boolean Returns false if there are no tags, string otherwise. | entailment |
function _processCollectedTags($source)
{
$to_replace = array();
$ordered = array();
foreach(self::$tag_collections as $tag_name=>$tags)
{
// if this block has a collection order use it
if(isset(self::$_tag_order[$tag_name]) === true)
{
$pos = self::$_tag_order[$tag_name];
$ordered[$pos] = $tags;
continue;
}
// the source should be modified by the collection script
$tag_func_name = ucwords(str_replace(array('_', '-'), ' ', $tag_name));
$tag_func_name = strtolower(substr($tag_func_name, 0, 1)).substr($tag_func_name, 1);
$tag_func_name = str_replace(' ', '', $this->_options['tag_callback_prefix'].$tag_func_name);
if($this->_options['tag_global_callback'] !== false)
{
$tags = call_user_func($this->_options['tag_global_callback'], 'collection', $tag_func_name, $tags, $source);
}
else
{
$tags = call_user_func($tag_func_name, $tags, $source);
}
if($tags === -1)
{
$source = self::throwError($tag_name, 'tag collection parsed however callback "'.$tag_func_name.'" returned -1.');
}
else if(is_array($tags) === false)
{
$source = self::throwError($tag_name, 'tag collection parsed however callback "'.$tag_func_name.'" did not return the array of process tags.');
}
else if(count($tags) > 0)
{
// input the parsed tags back into the source or store for re-intergration
foreach ($tags as $key => $tag)
{
if(strpos($source, $tag['tag']) !== false)
{
$source = str_replace($tag['tag'], $tag['parsed'], $source);
}
else
{
// do a reverse tag lookup here as the tag was not found in the source, thus it must be buried and un processed
array_push($to_replace, $tag);
}
}
}
}
foreach($ordered as $key=>$tags)
{
// the source should be modified by the collection script
$tag_func_name = ucwords(str_replace(array('_', '-'), ' ', $tag_name));
$tag_func_name = strtolower(substr($tag_func_name, 0, 1)).substr($tag_func_name, 1);
$tag_func_name = str_replace(' ', '', $this->_options['tag_callback_prefix'].$tag_func_name);
$tags = call_user_func($tag_func_name, $tags);
if($tags === -1)
{
$source = self::throwError($tag['name'], 'tag collection parsed however callback "'.$tag_func_name.'" returned -1.');
}
}
return $this->_doBuriedReplacements($to_replace, $source);
} | Process collected blocks. These are different types of block that are required to be processed as a group.
Usual reasons for doing this are to reduce resources and sql queries.
@param string $source The source of the output.
@return string | entailment |
public function collectTags($source, $tag_name=false)
{
$tagname = $tag_name === false ? $this->_options['tag_name'] : $tag_name;
$tags = $tag_names = array();
$tag_count = 0;
$inner_tag_open_pos = $source_len = strlen($source);
$opener = self::$tag_open.$tagname.':';
$opener_len = strlen($opener);
$closer = self::$tag_open.'/'.$tagname.':';
$closer_len = strlen($closer);
$closer_end = self::$tag_close;
while ($inner_tag_open_pos !== false)
{
// start getting the last found opener tag
$open_tag_look_source = substr($source, 0, $inner_tag_open_pos);
$open_tag_look_len = strlen($open_tag_look_source);
$inner_tag_open_pos = strrpos($open_tag_look_source, $opener);
// if there is no last tag then the rest is the final text
if($inner_tag_open_pos === false)
{
array_push($tags, array('content'=>$source, 'name'=>'___text'));
break;
}
else
{
// get the source from the start of that last tag
$tag_look_source = substr($source, $inner_tag_open_pos);
$open_bracket_pos = strpos($tag_look_source, self::$tag_open, 1);
$short_tag_close_pos = strpos($tag_look_source, '/'.self::$tag_close);
if($short_tag_close_pos !== false && $short_tag_close_pos < $open_bracket_pos)
{
$inner_tag_close_pos = $short_tag_close_pos + 2;
}
else
{
$inner_tag_close_pos_begin = strpos($tag_look_source, $closer);
$inner_tag_close_pos = strpos($tag_look_source, $closer_end, $inner_tag_close_pos_begin)+1;
}
// get the content of the block
$tag_source = substr($tag_look_source, 0, $inner_tag_close_pos);
$tag = $this->_buildTag($tag_source, $tagname);
$index = count($tags);
$tag['source_marker'] = '------@@%'.self::$_instance.'-'.$index.'%@@------';
array_push($tags, $tag);
// modify the source so it doesn't get repeated
$source = substr($source, 0, $inner_tag_open_pos).$tag['source_marker'].substr($source, $inner_tag_open_pos+$inner_tag_close_pos);
// $source = str_replace($tag_source, '------@@%'.$index.'%@@------', $source);
}
}
return $tags;
} | Searches and parses a source for custom tags.
@access public
@param string $source The source to search for custom tags in.
@param mixed|boolean|string $tag_name If false then the default option 'tag_name' is used
when searching for custom tags, if not and $tag_name is a string then a custom tag beginning
with that prefix will be looked for.
@return array An array of found tags. | entailment |
private function _buildTag($str, $tagname)
{
// $tagname = $this->_options['tag_name'];
$tag = array(
'block' => $str,
'content' => '',
'name' => '',
'attributes' => array()
);
$begin_len = strlen(self::$tag_open.$tagname.':');
// echo substr($str, 0, $begin_len)."\r\n";
if(substr($str, 0, $begin_len) !== self::$tag_open.$tagname.':')
{
// closing tag
$tag['name'] = '___text';
return $tag;
}
else if(substr($str, 1, 1) === '/')
{
// closing tag
$tag['name'] = '---ERROR---';
return $tag;
}
else
{
// opening tag
$matches = array();
// check to see if this is a full tag or an openclose tag
$has_closing_tag = substr($tag['block'], -2) !== '/'.self::$tag_close;
// perform data matches
if($has_closing_tag === true)
{
$preg = '!(\\'.self::$tag_open.$tagname.':([_\-A-Za-z0-9]*)[^\\'.self::$tag_close.']*\\'.self::$tag_close.'| \/\\'.self::$tag_close.').*\\'.self::$tag_open.'\/'.$tagname.':[_\-A-Za-z0-9]*\\'.self::$tag_close.'!is';
// $preg = '!(\<'.$tagname.':([_\-A-Za-z0-9]*)[^\>]*\>| \/\>).*\<\/'.$tagname.':[_\-A-Za-z0-9]*\>!is';
}
else
{
$preg = '!(\\'.self::$tag_open.$tagname.':([_\-A-Za-z0-9]*)([^\\'.self::$tag_close.']*))!is';
// $preg = '!(\<'.$tagname.':([_\-A-Za-z0-9]*)([^\/\>]*))!is';
}
if(preg_match_all($preg, $tag['block'], $matches) > 0)
{
// get the tag type
$tag['name'] = $matches[2][0];
// get the tag inner content
$tag['content'] = '';
$tag['vars'] = false;
$attribute_string = $matches[1][0];
if($has_closing_tag === true)
{
$begin_len = strlen($matches[1][0]);
$end_len = $has_closing_tag ? strlen(self::$tag_open.'/'.$tagname.':'.$tag['name'].self::$tag_close) : 0;
$tag['content'] = substr($str, $begin_len, strlen($matches[0][0])-$begin_len-$end_len);
// get hash tags vars?
if($this->_options['hash_tags'] === true && preg_match_all('/#{([^}]+)?}/i', $tag['content'], $vars) > 0)
{
$variables = array();
foreach ($vars[0] as $key => $var)
{
$variables[$var] = $vars[1][$key];
}
$tag['vars'] = $variables;
}
}
else
{
$attribute_string = rtrim($attribute_string, '/ ');
}
// get the attributes
$attributes = array();
// preg_match_all("/([_\-A-Za-z0-9]*)((=\"|='))([\w\W\s]*)(\"|')/", $opener, $attributes);
// preg_match_all("/([_\-A-Za-z0-9]*)((=\"|='))([_\-A-Za-z0-9]*)(\"|')/", $opener, $atts);
// $result = preg_match_all("!([_\-A-Za-z0-9]*)(=\"|=')([\#\s\:\.\?\&\=\%\+\,\@\_\-A-Za-z0-9]*)(\"|')!is", $matches[1][0], $attributes);
if(preg_match_all("!([_\-A-Za-z0-9]*)(=\")([^\"]*)(\")!is", $attribute_string, $attributes) > 0)
{
foreach($attributes[0] as $key=>$row)
{
$tag['attributes'][$attributes[1][$key]] = $attributes[3][$key];
}
if(isset($tag['attributes']['template']) === true)
{
$template = $this->_options['template_directory'].$tag['name'].DIRECTORY_SEPARATOR.$tag['attributes']['template'].'.html';
if(is_file($template) === false)
{
// $tag['attributes']['template'] = false;
$tag['attributes']['_template'] = $template;
}
else
{
$tag['attributes']['template'] = $template;
}
}
}
}
$tag['attributes'] = (object) $tag['attributes'];
return $tag;
}
} | Parses a tag for the tag attributes and inner content.
@access private
@param string $str The tag string to be parsed.
@param string $tagname The prefix of the custom tag being parsed.
@return array The tag | entailment |
public static function getTemplate($tag, $produce_error=true)
{
// get the template
$template_name = isset($tag['attributes']['template']) === true ? $tag['attributes']['template'] : 'default';
if(is_array(CustomTags::$tag_directory_base) === false)
{
CustomTags::$tag_directory_base = array(CustomTags::$tag_directory_base);
}
foreach (CustomTags::$tag_directory_base as $directory)
{
$template = rtrim($directory, DIRECTORY_SEPARATOR).$tag['name'].DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template_name.'.html';
if(is_file($template) === true)
{
return file_get_contents($template);
}
}
// template doesn't exist so produce error if required
if($produce_error === true)
{
CustomTags::throwError($tag['name'], 'tag template resource not found.');
}
return false;
} | Returns the content of a template.
@access public
@param array $tag The tag array.
@param boolean $produce_error If there is an error with the template and this is set to true then an error is produced. | entailment |
public static function parseTemplate($tag, $replacements)
{
// get template
$template = self::getTemplate($tag);
$search = $replace = array();
// compile search and replace values for replacement
foreach ($replacements as $varname => $varvalue)
{
array_push($search, '%'.strtolower($varname).'%');
array_push($replace, $varvalue);
}
return str_replace($search, $replace, $template);
} | A simple templater, replaces %VARNAME% with the value.
@access public
@param array $tag The tag array.
@param array $replacements The array of search and replace values. | entailment |
public function isValid($value, $context = array())
{
$this->_message = null;
$user = $this->_userSource->getUser();
If (! ($user->isActive() && $user->canResetPassword() && $user->isAllowedOrganization($context['organization']))) {
$this->_message = $this->translate->_('User not found or no e-mail address known or user cannot be reset.');
} | Returns true if and only if $value meets the validation requirements
If $value fails validation, then this method returns false, and
getMessages() will return an array of messages that explain why the
validation failed.
@param mixed $value
@param mixed $content
@return boolean
@throws \Zend_Validate_Exception If validation of $value is impossible | entailment |
public function execute($respondentId = null, $organizationId = null)
{
$sql = "SELECT gcj_id_job
FROM gems__comm_jobs
WHERE gcj_active = 1";
if ($organizationId) {
$sql .= $this->db->quoteInto(
" AND (gcj_id_organization IS NULL OR gcj_id_organization = ?)",
$organizationId
);
}
$sql .= "
ORDER BY gcj_id_order,
CASE WHEN gcj_id_survey IS NULL THEN 1 ELSE 0 END,
CASE WHEN gcj_round_description IS NULL THEN 1 ELSE 0 END,
CASE WHEN gcj_id_track IS NULL THEN 1 ELSE 0 END,
CASE WHEN gcj_id_organization IS NULL THEN 1 ELSE 0 END";
$jobs = $this->db->fetchAll($sql);
$batch = $this->getBatch();
if ($jobs) {
foreach ($jobs as $job) {
$batch->addTask('Mail\\ExecuteMailJobTask', $job['gcj_id_job'], $respondentId, $organizationId);
}
} else {
$this->getBatch()->addMessage($this->_('Nothing to do, please create a mail job first.'));
}
// When manually running the jobs, we do not start the monitortask
if ($batch->getId() == 'cron') {
$batch->addTask('Mail\\CronMailMonitorTask');
}
} | Adds all jobs to the queue
@param $respondentId Optional, execute for just one respondent
@param $organizationId Optional, execute for just one organization | entailment |
public function afterRegistry()
{
parent::afterRegistry();
if (! $this->tokenLibrary instanceof \Gems_Tracker_Token_TokenLibrary) {
$this->tokenLibrary = $this->loader->getTracker()->getTokenLibrary();
}
} | Called after the check that all required registry values
have been set correctly has run.
@return void | entailment |
protected function findTokenFor(array $row)
{
if (isset($row['token']) && $row['token']) {
return $this->tokenLibrary->filter($row['token']);
}
return null;
} | Find the token id using the passed row data and
the other translator parameters.
@param array $row
@return string|null | entailment |
public function getFieldsTranslations()
{
if (! $this->_targetModel instanceof \MUtil_Model_ModelAbstract) {
throw new \MUtil_Model_ModelTranslateException(sprintf('Called %s without a set target model.', __FUNCTION__));
}
$this->_targetModel->set('gto_id_token', 'label', $this->_('Token'),
'import_descr', $this->loader->getTracker()->getTokenLibrary()->getFormat(),
'required', true,
'order', 2
);
return array('token' => 'gto_id_token') + parent::getFieldsTranslations();
} | Get information on the field translations
@return array of fields sourceName => targetName
@throws \MUtil_Model_ModelException | entailment |
public function execute()
{
//Now load all patches, and save the resulting changed patches for later (not used yet)
$changed = $this->patcher->uploadPatches($this->loader->getVersions()->getBuild());
if ($changed) {
$this->getBatch()->addMessage(sprintf($this->_('%d new or changed patch(es).'), $changed));
}
} | Should handle execution of the task, taking as much (optional) parameters as needed
The parameters should be optional and failing to provide them should be handled by
the task | entailment |
public function getSearchDefaults()
{
if (! $this->defaultSearchData) {
$from = new \MUtil_Date();
$from->subWeek(2);
$until = new \MUtil_Date();
$until->addDay(1);
$this->defaultSearchData = array(
\Gems_Snippets_AutosearchFormSnippet::PERIOD_DATE_USED => 'grco_created',
'grco_organization' => $this->loader->getOrganization()->getId(),
'datefrom' => $from,
'dateuntil' => $until,
);
}
return parent::getSearchDefaults();
} | Function to allow the creation of search defaults in code
@see getSearchFilter()
@return array | entailment |
public function checkRegistryRequestsAnswers()
{
if (! $this->organizationId) {
if ($this->respondent) {
$this->organizationId = $this->respondent->getOrganizationId();
}
if (! $this->organizationId) {
$this->organizationId = $this->request->getParam(\MUtil_Model::REQUEST_ID2);
}
}
if ($this->organizationId && (! $this->respondentId)) {
if ($this->respondent) {
$this->respondentId = $this->respondent->getId();
}
if (! $this->respondentId) {
$this->respondentId = $this->util->getDbLookup()->getRespondentId(
$this->request->getParam(\MUtil_Model::REQUEST_ID1),
$this->organizationId
);
}
}
return $this->organizationId && $this->respondentId && $this->db && $this->model;
} | 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 are missing. | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.