sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
public function getDateUnitsList()
{
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 units used by this engine
@return array date_unit => label
@deprecated since 1.7.1 use Translated->getDatePeriodUnits() | entailment |
public function getInsertableSurveys($organizationId = null)
{
$cacheId = __CLASS__ . '_' . __FUNCTION__ . '_' . $organizationId;
if ($results = $this->cache->load($cacheId)) {
return $results;
}
if (null === $organizationId) {
$orgWhere = '';
} else {
$orgId = intval($organizationId);
$orgWhere = "AND gsu_insert_organizations LIKE '%|$orgId|%'";
}
$select = "SELECT gsu_id_survey, gsu_survey_name
FROM gems__surveys
WHERE gsu_active = 1 AND gsu_insertable = 1 $orgWhere
ORDER BY gsu_survey_name";
$results = $this->db->fetchPairs($select);
$this->cache->save($results, $cacheId, array('surveys'));
return $results;
} | Retrieve an array of key/value pairs for gsu_id_survey and gsu_survey_name
that are active and are insertable
@param int $organizationId Optional organization id
@return array | entailment |
public function getSurveysByCode($code)
{
$cacheId = __CLASS__ . '_' . __FUNCTION__ . '_' . $code;
if ($results = $this->cache->load($cacheId)) {
return $results;
}
$select = $this->db->select();
$select->from('gems__surveys', array('gsu_id_survey', 'gsu_survey_name'))
->where("gsu_code = ?", $code)
->where("gsu_active = 1")
->order('gsu_survey_name');
$results = $this->db->fetchPairs($select);
$this->cache->save($results, $cacheId, array('surveys'));
return $results;
} | Get all the surveys for a certain code
@param string $code
@return array survey id => survey name | entailment |
public function getSurveysFor($organizationId)
{
if ($organizationId !== null) {
$where = "AND EXISTS (SELECT 1 FROM gems__rounds
INNER JOIN gems__tracks ON gro_id_track = gtr_id_track
WHERE gro_id_survey = gsu_id_survey AND
gtr_organizations LIKE '%|" . (int) $organizationId . "|%')";
} else {
$where = "";
}
$sql = "SELECT gsu_id_survey, gsu_survey_name FROM gems__surveys WHERE gsu_active = 1 " .
$where . " ORDER BY gsu_survey_name ASC";
return $this->_getSelectPairsCached(__FUNCTION__. '_' . $organizationId, $sql, array(), 'surveys');
} | Get all the surveys for a certain organization id
@param int $organizationId
@return array survey id => survey name | entailment |
public function getTrackDateFields($trackId)
{
$dateFields = $this->db->fetchPairs("SELECT gtf_id_field, gtf_field_name FROM gems__track_fields WHERE gtf_id_track = ? AND gtf_field_type = 'date' ORDER BY gtf_id_order", $trackId);
if (! $dateFields) {
$dateFields = array();
}
return $dateFields;
} | Returns array (id => name) of the track date fields for this track, sorted by order
@param int $trackId
@return array | entailment |
public function getTracksBySurvey($surveyId)
{
$cacheId = __CLASS__ . '_' . __FUNCTION__ . '_' . $surveyId;
if ($results = $this->cache->load($cacheId)) {
return $results;
}
$select = $this->db->select();
$select->from('gems__tracks', array('gtr_id_track', 'gtr_track_name'))
->joinInner('gems__rounds', 'gtr_id_track = gro_id_track', array())
->where("gro_id_survey = ?", $surveyId)
->where("gtr_active = 1")
->where("gro_active = 1")
->order('gtr_track_name');
$results = $this->db->fetchPairs($select);
$this->cache->save($results, $cacheId, array('surveys', 'tracks'));
return $results;
} | Get all the tracks for a certain survey
@param int $surveyId
@return array survey id => survey name | entailment |
public function getTracksForOrgs(array $orgs)
{
$orgWhere = "(INSTR(gtr_organizations, '|" .
implode("|') > 0 OR INSTR(gtr_organizations, '|", array_keys($orgs)) .
"|') > 0)";
$select = "SELECT gtr_id_track, gtr_track_name
FROM gems__tracks
WHERE gtr_track_class != 'SingleSurveyEngine' AND
$orgWhere
ORDER BY gtr_track_name";
return $this->db->fetchPairs($select);
} | Returns array (id => name) of all tracks accessible by this organization, sorted alphabetically
@param array $orgs orgId => org name
@return array | entailment |
public function getTrackTitle($trackId)
{
$tracks = $this->getAllTracks();
if ($tracks && isset($tracks[$trackId])) {
return $tracks[$trackId];
}
} | Returns title of the track.
@param int $trackId
@return string | entailment |
public function hasHtmlOutput()
{
if (! $this->multiTracks) {
return false;
}
$this->tracker = $this->loader->getTracker();
if (! $this->respondentTrackId) {
$this->respondentTrackId = $this->request->getParam(\Gems_Model::RESPONDENT_TRACK);
}
if ($this->respondentTrackId) {
if (! $this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
$this->respondentTrack = $this->tracker->getRespondentTrack($this->respondentTrackId);
}
}
if ($this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
if (! $this->respondentTrackId) {
$this->respondentTrackId = $this->respondentTrack->getRespondentTrackId();
}
$this->trackId = $this->respondentTrack->getTrackId();
if (! $this->respondentId) {
$this->respondentId = $this->respondentTrack->getRespondentId();
}
if (! $this->organizationId) {
$this->organizationId = $this->respondentTrack->getOrganizationId();
}
$this->caption = $this->_('Other assignments of this track to this respondent.');
$this->onEmpty = $this->_('This track is assigned only once to this respondent.');
} else {
if ($this->respondent instanceof \Gems_Tracker_Respondent) {
if (! $this->respondentId) {
$this->respondentId = $this->respondent->getId();
}
if (! $this->organizationId) {
$this->organizationId = $this->respondent->getOrganizationId();
}
}
$this->caption = $this->_('Existing assignments of this track to this respondent.');
$this->onEmpty = $this->_('This track is not assigned to this respondent.');
}
if (! $this->trackId) {
$this->trackId = $this->request->getParam(\Gems_Model::TRACK_ID);
}
if ((! $this->trackId) && $this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
$this->trackId = $this->trackEngine->getTrackId();
}
return $this->trackId && $this->respondentId && $this->organizationId && parent::hasHtmlOutput();
} | The place to check if the data set in the snippet is valid
to generate the snippet.
When invalid data should result in an error, you can throw it
here but you can also perform the check in the
checkRegistryRequestsAnswers() function from the
{@see \MUtil_Registry_TargetInterface}.
@return boolean | entailment |
protected function processFilterAndSort(\MUtil_Model_ModelAbstract $model)
{
$model->setFilter(array(
'gr2t_id_track' => $this->trackId,
'gr2t_id_user' => $this->respondentId,
'gr2t_id_organization' => $this->organizationId,
));
if ($this->respondentTrackId) {
$model->addFilter(array(sprintf('gr2t_id_respondent_track != %d', intval($this->respondentTrackId))));
}
$model->setSort(array('gr2t_created' => SORT_DESC));
} | Overrule to implement snippet specific filtering and sorting.
@param \MUtil_Model_ModelAbstract $model | entailment |
public function logError(\Exception $exception, \Zend_Controller_Request_Abstract $request = null)
{
$info = array();
$info[] = 'Class: ' . get_class($exception);
$info[] = 'Message: ' . $this->stripHtml($exception->getMessage());
if (($exception instanceof \Gems_Exception) && ($text = $exception->getInfo())) {
$info[] = 'Info: ' . $this->stripHtml($text);
}
if (method_exists($exception, 'getChainedException')) {
$chained = $exception->getChainedException();
if ($chained) {
$info[] = '';
$info[] = 'Chained class: ' . get_class($chained);
$info[] = 'Changed message: ' . $this->stripHtml($chained->getMessage());
if (($chained instanceof \Gems_Exception) && ($text = $chained->getInfo())) {
$info[] = 'Changed info: ' . $this->stripHtml($text);
}
}
}
$previous = $exception->getPrevious();
while ($previous) {
$info[] = '';
$info[] = 'Prevous class: ' . get_class($previous);
$info[] = 'Prevous message: ' . $this->stripHtml($previous->getMessage());
if (($previous instanceof \Gems_Exception) && ($text = $previous->getInfo())) {
$info[] = 'Previous info: ' . $this->stripHtml($text);
}
$previous = $previous->getPrevious();
}
foreach ($info as $line) {
$this->log($line, \Zend_Log::ERR);
}
// Now empty as we are going to log potentially sensitive debug data
// We log this with a \Zend_Log::DEBUG level, so filter can strip it if needed
$info = array();
if (!empty($request)) {
$info[] = 'Request Parameters:';
foreach ($request->getParams() as $key => $value) {
if (!is_array($value)) {
// Make sure a password does not end in the logfile
if (false === strpos(strtolower($key), 'password')) {
$info[] = $key . ' => ' . $value;
} else {
$info[] = $key . ' => ' . str_repeat('*', strlen($value));
}
}
}
}
$info[] = 'Stack trace:';
$info[] = $exception->getTraceAsString();
$priority = \Zend_Log::DEBUG;
if (($exception instanceof \Zend_Db_Exception) ||
($exception instanceof \Gems_Exception_Coding)
){
$priority = \Zend_Log::ERR;
}
foreach ($info as $line) {
$this->log($line, $priority);
}
} | Helper method to log exception and (optional) request information
@param \Exception $exception
@param \Zend_Controller_Request_Abstract $request | entailment |
protected function createModel()
{
$model = $this->token->getModel();
$model->applyFormatting();
if ($this->useFakeForm && $this->token->hasSuccesCode() && (! $this->token->isCompleted())) {
$model->set('gto_id_token', 'formatFunction', array(__CLASS__, 'makeFakeForm'));
} else {
$model->set('gto_id_token', 'formatFunction', 'strtoupper');
}
$model->setBridgeFor('itemTable', 'ThreeColumnTableBridge');
return $model;
} | Creates the model
@return \MUtil_Model_ModelAbstract | entailment |
public function getHtmlOutput(\Zend_View_Abstract $view)
{
if ($this->tokenId) {
if ($this->token->exists) {
$htmlDiv = \MUtil_Html::div();
$htmlDiv->h3($this->getTitle());
$table = parent::getHtmlOutput($view);
$this->applyHtmlAttributes($table);
$htmlDiv[] = $table;
return $htmlDiv;
} else {
$this->addMessage(sprintf($this->_('Token %s not found.'), $this->tokenId));
}
} else {
$this->addMessage($this->_('No token specified.'));
}
} | Create the snippets content
This is a stub function either override getHtmlOutput() or override render()
@param \Zend_View_Abstract $view Just in case it is needed here
@return \MUtil_Html_HtmlInterface Something that can be rendered | entailment |
public static function makeFakeForm($value)
{
$form = new \Gems_Form();
$form->removeDecorator('HtmlTag');
$element = new \Zend_Form_Element_Text('gto_id_token');
$element->class = 'token_copy';
$element->setDecorators(array('ViewHelper', array('HtmlTag', 'Div')));
$form->addElement($element);
$form->isValid(array('gto_id_token' => \MUtil_Lazy::call('strtoupper', $value)));
return $form;
} | Creates a fake form so that it is (slightly) easier to
copy and paste a token.
@param string $value Gems token value
@return \Gems_Form | entailment |
public function execute($patchLevel = null, $ignoreCompleted = true, $ignoreExecuted = false)
{
$batch = $this->getBatch();
$batch->addMessage(sprintf($this->translate->_('Adding patchlevel %d'), $patchLevel));
$this->patcher->uploadPatches($patchLevel);
$this->patcher->loadPatchBatch($patchLevel, $ignoreCompleted, $ignoreExecuted, $batch);
} | 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
@param int $patchLevel Only execute patches for this patchlevel
@param boolean $ignoreCompleted Set to yes to skip patches that where already completed
@param boolean $ignoreExecuted Set to yes to skip patches that where already executed
(this includes the ones that are executed but not completed) | entailment |
protected function addFormElements(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model)
{
$bridge->addHtml('to', 'label', $this->_('To'));
$bridge->addExhibitor('track', array('label' => $this->_('Track')));
$bridge->addExhibitor('round', array('label' => $this->_('Round')));
$bridge->addExhibitor('survey', array('label' => $this->_('Survey')));
$bridge->addExhibitor('last_contact', array('label' => $this->_('Last contact'), 'formatFunction' => $this->util->getTranslated()->formatDateNever));
parent::addFormElements($bridge,$model);
} | Adds elements from the model to the bridge that creates the form.
Overrule this function to add different elements to the browse table, without
having to recode the core table building code.
@param \MUtil_Model_Bridge_FormBridgeInterface $bridge
@param \MUtil_Model_ModelAbstract $model | entailment |
public function onBootstrap(MvcEvent $e)
{
$manager = Container::getDefaultManager();
if (!$manager->sessionExists()) {
return;
}
$app = $e->getApplication();
/** @var \Zend\EventManager\SharedEventManagerInterface $sharedEvm */
$sharedEvm = $app->getEventManager()->getSharedManager();
$sharedEvm->attach(
AbstractActionController::class,
'dispatch',
[$this, 'flashMessengerHandler'],
2
);
} | Bootstrap Handle FlashMessenger session show. | entailment |
private function duplicateFlashMessengerSessionData(Container $container) : void
{
$flashToolbarContainer = new Container('SanSessionToolbarFlashMessenger');
foreach ($container->getArrayCopy() as $key => $row) {
foreach ($row->toArray() as $keyArray => $rowArray) {
if ($keyArray === 0) {
$flashToolbarContainer->$key = new SplQueue();
}
$flashToolbarContainer->$key->push($rowArray);
}
}
} | Used to duplicate flashMessenger data as it shown and gone. | entailment |
public function flashMessengerHandler(EventInterface $e) : void
{
/** @var \Zend\Mvc\Controller\AbstractActionController $controller */
$controller = $e->getTarget();
if (!$controller->getPluginManager()->has('flashMessenger')) {
return;
}
$flash = $controller->plugin('flashMessenger');
$container = $flash->getContainer();
$this->duplicateFlashMessengerSessionData($container);
} | Handle FlashMessenger data to be able to be seen in both "app" and toolbar parts. | entailment |
public function processTokenData(\Gems_Tracker_Token $token)
{
if ($token->getReceptionCode()->isSuccess() && $token->isCompleted()) {
$respTrack = $token->getRespondentTrack();
$fields = $respTrack->getCodeFields();
$answers = $token->getRawAnswers();
$newFields = [];
foreach ($fields as $code => $value) {
if (isset($answers[$code]) && ($answers[$code] != $value)) {
$newFields[$code] = $answers[$code];
}
}
if ($newFields) {
// \MUtil_Echo::track($answers, $newFields);
$respTrack->setFieldData($newFields);
}
}
return false;
} | Process the data and return the answers that should be changed.
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 addBrowseTableColumns(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
{
if ($model->has('row_class')) {
$bridge->getTable()->tbody()->getFirst(true)->appendAttrib('class', $bridge->row_class);
}
if ($editMenuItem = $this->getEditMenuItem()) {
$bridge->addItemLink($editMenuItem->toActionLinkLower($this->request, $bridge));
}
// make sure search results are highlighted
$this->applyTextMarker();
if ($this->columns) {
foreach ($this->columns as $column) {
call_user_func_array(array($bridge, 'addMultiSort'), $column);
}
} elseif ($this->sortableLinks) {
foreach($model->getItemsOrdered() as $name) {
if ($label = $model->get($name, 'label')) {
$bridge->addSortable($name, $label);
}
}
} else {
foreach($model->getItemsOrdered() as $name) {
if ($label = $model->get($name, 'label')) {
$bridge->add($name, $label);
}
}
}
if ($deleteMenuItem = $this->findMenuItem($this->request->getControllerName(), 'delete')) {
$bridge->addItemLink($deleteMenuItem->toActionLinkLower($this->request, $bridge));
}
} | Adds columns from the model to the bridge that creates the browse table.
Overrule this function to add different columns to the browse table, without
having to recode the core table building code.
@param \MUtil_Model_Bridge_TableBridge $bridge
@param \MUtil_Model_ModelAbstract $model
@return void | entailment |
protected function _showTable($caption, $data, $nested = false)
{
$table = \MUtil_Html_TableElement::createArray($data, $caption, $nested);
$table->class = 'browser table';
$div = \MUtil_Html::create()->div(array('class' => 'table-container'));
$div[] = $table;
$this->html[] = $div;
} | Helper function to show a table
@param string $caption
@param array $data
@param boolean $nested | entailment |
public function createModel($detailed, $action)
{
$model = new \MUtil_Model_TableModel('gems__roles');
$model->set('grl_name', 'label', $this->_('Name'),
'size', 15,
'minlength', 4
);
$model->set('grl_description', 'label', $this->_('Description'),
'size', 40);
$model->set('grl_parents', 'label', $this->_('Parents'));
$tpa = new \MUtil_Model_Type_ConcatenatedRow(',', ', ');
$tpa->apply($model, 'grl_parents');
$model->setOnLoad('grl_parents', array(\Gems_Roles::getInstance(), 'translateToRoleNames'));
$model->set('grl_privileges', 'label', $this->_('Privileges'));
$tpr = new \MUtil_Model_Type_ConcatenatedRow(',', '<br/>');
$tpr->apply($model, 'grl_privileges');
if ($detailed) {
$model->set('grl_name',
'validators[unique]', $model->createUniqueValidator('grl_name'),
'validators[nomaster]', new \MUtil_Validate_IsNot(
'master',
$this->_('The name "master" is reserved')
)
);
$model->set('grl_privileges', 'formatFunction', array($this, 'formatPrivileges'));
if ('show' === $action) {
$model->addColumn('grl_parents', 'inherited');
$tpa->apply($model, 'inherited');
$model->set('inherited',
'label', $this->_('Inherited privileges'),
'formatFunction', array($this, 'formatInherited'));
$model->setOnLoad('inherited', array(\Gems_Roles::getInstance(), 'translateToRoleNames'));
// Concatenated field, we can not use onload so handle transaltion to rolenames in the formatFunction
$model->addColumn("CONCAT(COALESCE(grl_parents, ''), '\t', COALESCE(grl_privileges, ''))", 'not_allowed');
$model->set('not_allowed',
'label', $this->_('Not allowed'),
'formatFunction', array($this, 'formatNotAllowed'));
}
} else {
$model->set('grl_privileges', 'formatFunction', array($this, 'formatLongLine'));
}
\Gems_Model::setChangeFieldsByPrefix($model, 'grl');
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 editAction()
{
$model = $this->getModel();
$data = $model->loadFirst();
//If we try to edit master, add an error message and reroute
if (isset($data['grl_name']) && $data['grl_name']=='master') {
$this->addMessage($this->_('Editing `master` is not allowed'));
$this->_reroute(array('action'=>'index'), true);
}
parent::editAction();
} | Action for showing a edit item page with extra title | entailment |
public function formatLongLine(array $privileges)
{
$output = \MUtil_Html::create('div');
if (count($privileges)) {
$privileges = array_combine($privileges, $privileges);
foreach ($this->getUsedPrivileges() as $privilege => $description) {
if (isset($privileges[$privilege])) {
if (count($output) > 11) {
$output->append('...');
return $output;
}
if (\MUtil_String::contains($description, '<br/>')) {
$description = substr($description, 0, strpos($description, '<br/>') - 1);
}
$output->raw($description);
$output->br();
}
}
}
return $output;
} | Output for browsing rols
@param array $privileges
@return array | entailment |
public function formatInherited(array $parents)
{
$privileges = array_keys($this->getInheritedPrivileges($parents));
return $this->formatPrivileges($privileges);
} | Output of not allowed for viewing rols
@param array $parent
@return \MUtil_Html_ListElement | entailment |
public function formatNotAllowed($data)
{
list($parents_string, $privileges_string) = explode("\t", $data, 2);
$parents = explode(',', $parents_string);
$privileges = explode(',', $privileges_string);
if (count($privileges) > 0 ) {
$privileges = array_combine($privileges, $privileges);
}
// Concatenated field, we can not use onload so handle translation here
$parents = \Gems_Roles::getInstance()->translateToRoleNames($parents);
$notAllowed = $this->getUsedPrivileges();
$notAllowed = array_diff_key($notAllowed, $this->getInheritedPrivileges($parents), $privileges);
$output = $this->formatPrivileges(array_keys($notAllowed));
$output->class = 'notallowed deleted';
return $output;
} | Output of not allowed for viewing rols
@param strong $data parents tab privileges
@return \MUtil_Html_ListElement | entailment |
public function formatPrivileges(array $privileges)
{
if (count($privileges)) {
$output = \MUtil_Html_ListElement::ul();
$privileges = array_combine($privileges, $privileges);
$output->class = 'allowed';
foreach ($this->getUsedPrivileges() as $privilege => $description) {
if (isset($privileges[$privilege])) {
$output->li()->raw($description);
}
}
if (count($output)) {
return $output;
}
}
return \MUtil_Html::create('em', $this->_('No privileges found.'));
} | Output for viewing rols
@param array $privileges
@return \MUtil_Html_ListElement | entailment |
protected function getInheritedPrivileges(array $parents)
{
if (! $parents) {
return array();
}
$rolePrivileges = $this->acl->getRolePrivileges();
$inherited = array();
foreach ($parents as $parent) {
if (isset($rolePrivileges[$parent])) {
$inherited = $inherited + array_flip($rolePrivileges[$parent][\Zend_Acl::TYPE_ALLOW]);
$inherited = $inherited +
array_flip($rolePrivileges[$parent][\MUtil_Acl::INHERITED][\Zend_Acl::TYPE_ALLOW]);
}
}
// Sneaks in:
unset($inherited[""]);
return $inherited;
} | Get the privileges for thess parents
@param array $parents
@return array privilege => setting | entailment |
protected function getUsedPrivileges()
{
if (! $this->usedPrivileges) {
$privileges = $this->menu->getUsedPrivileges();
asort($privileges);
//don't allow to edit the pr.nologin and pr.islogin privilege
unset($privileges['pr.nologin']);
unset($privileges['pr.islogin']);
$this->usedPrivileges = $privileges;
}
return $this->usedPrivileges;
} | Get the privileges a role can have.
@return array | entailment |
public function overviewAction()
{
$roles = array();
foreach ($this->acl->getRolePrivileges() as $role => $privileges) {
$roles[$role][$this->_('Role')] = $role;
$roles[$role][$this->_('Parents')] = $privileges[\MUtil_Acl::PARENTS] ? implode(', ', $privileges[\MUtil_Acl::PARENTS]) : null;
$roles[$role][$this->_('Allowed')] = $privileges[\Zend_Acl::TYPE_ALLOW] ? implode(', ', $privileges[\Zend_Acl::TYPE_ALLOW]) : null;
//$roles[$role][$this->_('Denied')] = $privileges[\Zend_Acl::TYPE_DENY] ? implode(', ', $privileges[\Zend_Acl::TYPE_DENY]) : null;
$roles[$role][$this->_('Inherited')] = $privileges[\MUtil_Acl::INHERITED][\Zend_Acl::TYPE_ALLOW] ? implode(', ', $privileges[\MUtil_Acl::INHERITED][\Zend_Acl::TYPE_ALLOW]) : null;
//$roles[$role][$this->_('Parent denied')] = $privileges[\MUtil_Acl::INHERITED][\Zend_Acl::TYPE_DENY] ? implode(', ', $privileges[\MUtil_Acl::INHERITED][\Zend_Acl::TYPE_DENY]) : null;
}
ksort($roles);
$this->html->h2($this->_('Project role overview'));
$this->_showTable($this->_('Roles'), $roles, true);
} | Action to shw overview of all privileges | entailment |
public function privilegeAction()
{
$privileges = array();
foreach ($this->acl->getPrivilegeRoles() as $privilege => $roles) {
$privileges[$privilege][$this->_('Privilege')] = $privilege;
$privileges[$privilege][$this->_('Allowed')] = $roles[\Zend_Acl::TYPE_ALLOW] ? implode(', ', $roles[\Zend_Acl::TYPE_ALLOW]) : null;
$privileges[$privilege][$this->_('Denied')] = $roles[\Zend_Acl::TYPE_DENY] ? implode(', ', $roles[\Zend_Acl::TYPE_DENY]) : null;
}
// Add unassigned rights to the array too
$all_existing = $this->getUsedPrivileges();
$unassigned = array_diff_key($all_existing, $privileges);
$nonexistent = array_diff_key($privileges, $all_existing);
unset($nonexistent['pr.nologin']);
unset($nonexistent['pr.islogin']);
ksort($nonexistent);
foreach ($unassigned as $privilege => $description) {
$privileges[$privilege] = array(
$this->_('Privilege') => $privilege,
$this->_('Allowed') => null,
$this->_('Denied') => null
);
}
ksort($privileges);
$this->html->h2($this->_('Project privileges'));
$this->_showTable($this->_('Privileges'), $privileges, true);
// Nonexistent rights are probably left-overs from old installations, this should be cleaned
if (!empty($nonexistent)) {
$this->_showTable($this->_('Assigned but nonexistent privileges'), $nonexistent, true);
}
// $this->acl->echoRules();
} | Action to show all privileges | entailment |
public function handle($path = null)
{
$path = ltrim($path, '/');
$cleanPrefix = rtrim($this->urlPrefix, '/');
return sprintf('%s/%s', $cleanPrefix, $path);
} | Executes the plugin.
@param string null $path
@return mixed | entailment |
protected function addSynchronizationInformation()
{
$this->html->pInfo($this->_(
'Check source for new surveys, changes in survey status and survey deletion. Can also perform maintenance on some sources, e.g. by changing the number of attributes.'
));
$this->html->pInfo($this->_(
'Run this code when the status of a survey in a source has changed or when the code has changed and the source must be adapted.'
));
} | Displays a textual explanation what synchronization does on the page. | entailment |
public function attributesAction()
{
$sourceId = $this->getSourceId();
$where = $this->db->quoteInto('gsu_id_source = ?', $sourceId);
$batch = $this->loader->getTracker()->refreshTokenAttributes('attributeCheck' . $sourceId, $where);
$title = sprintf($this->_('Refreshing token attributes for %s source.'),
$this->db->fetchOne("SELECT gso_source_name FROM gems__sources WHERE gso_id_source = ?", $sourceId));
$this->_helper->batchRunner($batch, $title, $this->accesslog);
$this->html->pInfo($this->_('Refreshes the attributes for a token as stored in the source.'));
$this->html->pInfo($this->_('Run this code when the number of attributes has changed or when you suspect the attributes have been corrupted somehow.'));
} | Check token attributes for a single source | entailment |
public function attributesAllAction()
{
$batch = $this->loader->getTracker()->refreshTokenAttributes('attributeCheckAll');
$title = $this->_('Refreshing token attributes for all sources.');
$this->_helper->batchRunner($batch, $title, $this->accesslog);
$this->html->pInfo($this->_('Refreshes the attributes for a token as stored in on of the sources.'));
$this->html->pInfo($this->_('Run this code when the number of attributes has changed or when you suspect the attributes have been corrupted somehow.'));
} | Check all token attributes for all sources | entailment |
public function checkAction()
{
$sourceId = $this->getSourceId();
$where = $this->db->quoteInto('gto_id_survey IN (SELECT gsu_id_survey FROM gems__surveys WHERE gsu_id_source = ?)', $sourceId);
$batch = $this->loader->getTracker()->recalculateTokens('sourceCheck' . $sourceId, $this->currentUser->getUserId(), $where);
$title = sprintf($this->_('Checking all surveys in the %s source for answers.'),
$this->db->fetchOne("SELECT gso_source_name FROM gems__sources WHERE gso_id_source = ?", $sourceId));
$this->_helper->batchRunner($batch, $title, $this->accesslog);
$this->addSnippet('Survey\\CheckAnswersInformation',
'itemDescription', $this->_('This task checks all tokens using this source for answers .')
);
} | Check all the tokens for a single source | entailment |
public function createModel($detailed, $action)
{
$tracker = $this->loader->getTracker();
$model = new \MUtil_Model_TableModel('gems__sources');
$model->set('gso_source_name', 'label', $this->_('Name'),
'description', $this->_('E.g. the name of the project - for single source projects.'),
'size', 15,
'minlength', 4,
'validator', $model->createUniqueValidator('gso_source_name')
);
$model->set('gso_ls_url', 'label', $this->_('Source Url'),
'default', 'http://',
'description', $this->_('For creating token-survey url.'),
'size', 50,
'validators[unique]', $model->createUniqueValidator('gso_ls_url'),
'validators[url]', new \MUtil_Validate_Url()
);
$sourceClasses = $tracker->getSourceClasses();
end($sourceClasses);
$model->set('gso_ls_class', 'label', $this->_('Adaptor class'),
'default', key($sourceClasses),
'multiOptions', $sourceClasses
);
$model->set('gso_ls_adapter', 'label', $this->_('Database Server'),
'default', substr(get_class($this->db), strlen('Zend_Db_Adapter_')),
'description', $this->_('The database server used by the source.'),
'multiOptions', $tracker->getSourceDatabaseClasses()
);
$model->set('gso_ls_table_prefix', 'label', $this->_('Table prefix'),
'default', 'ls__',
'description', $this->_('Do not forget the underscores.'),
'size', 15
);
if ($detailed) {
$in_gems = $this->_('Leave empty for the Gems database settings.');
$model->set('gso_ls_dbhost', 'label', $this->_('Database host'),
'description', $in_gems,
'size', 15
);
$model->set('gso_ls_dbport', 'label', $this->_('Database port'),
'description', $in_gems . ' ' . $this->_('Usually port 3306'),
'size', 6,
'validators[int]', 'Int',
'validators[between]', ['Between', true, [0, 65535]]
);
$model->set('gso_ls_database', 'label', $this->_('Database'),
'description', $in_gems,
'size', 15
);
$model->set('gso_ls_username', 'label', $this->_('Database Username'),
'description', $in_gems,
'size', 15
);
$model->set('gso_ls_password', 'label', $this->_('Database Password'),
'elementClass', 'Password',
'repeatLabel', $this->_('Repeat password'),
'required', false,
'size', 15
);
if ('create' == $action) {
$model->set('gso_ls_password', 'description', $in_gems, 'renderPassword', true);
} else {
$model->set('gso_ls_password', 'description', $this->_('Enter only when changing'),
'renderPassword', false);
}
$type = new \Gems_Model_Type_EncryptedField($this->project, true);
$type->apply($model, 'gso_ls_password');
$model->set('gso_ls_charset', 'label', $this->_('Charset'),
'description', $in_gems,
'size', 15
);
$model->set('gso_active', 'label', $this->_('Active'),
'default', 0,
'multiOptions', $this->util->getTranslated()->getYesNo()
);
}
$model->set('gso_status', 'label', $this->_('Status'),
'default', 'Not checked',
'elementClass', 'Exhibitor'
);
$model->set('gso_last_synch', 'label', $this->_('Last synchronisation'),
'elementClass', 'Exhibitor'
);
\Gems_Model::setChangeFieldsByPrefix($model, 'gso');
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 |
private function getSourceById($sourceId = null)
{
if (null === $sourceId) {
$sourceId = $this->getSourceId();
}
return $this->loader->getTracker()->getSource($sourceId);
} | Load a source object
@param int $sourceId
@return \Gems_Tracker_Source_SourceInterface | entailment |
public function pingAction()
{
$source = $this->getSourceById();
try {
if ($source->checkSourceActive($this->currentUser->getUserId())) {
$this->addMessage($this->_('This installation is active.'), 'success');
} else {
$this->addMessage($this->_('Inactive installation.'), 'warning');
}
} catch (\Exception $e) {
$this->addMessage($this->_('Installation error!'), 'danger');
$this->addMessage($e->getMessage(), 'danger');
}
$this->_reroute(array($this->getRequest()->getActionKey() => 'show'));
} | Action to check whether the source is active | entailment |
public function synchronizeAction()
{
$sourceId = $this->getSourceId();
$batch = $this->loader->getTracker()->synchronizeSources($sourceId, $this->currentUser->getUserId());
$title = sprintf($this->_('Synchronize the %s source.'),
$this->db->fetchOne("SELECT gso_source_name FROM gems__sources WHERE gso_id_source = ?", $sourceId));
$this->_helper->batchRunner($batch, $title, $this->accesslog);
$this->addSynchronizationInformation();
} | Synchronize survey status for the surveys in a source | entailment |
public function synchronizeAllAction()
{
$batch = $this->loader->getTracker()->synchronizeSources(null, $this->currentUser->getUserId());
$batch->minimalStepDurationMs = 3000;
$title = $this->_('Synchronize all sources.');
$this->_helper->batchRunner($batch, $title, $this->accesslog);
$this->html->actionLink(array('action' => 'index'), $this->_('Cancel'), array('class' => 'btn-danger'));
$this->addSynchronizationInformation();
} | Synchronize survey status for the surveys in all sources | entailment |
public function answerAction()
{
// Set menu OFF
$this->menu->setVisible(false);
$token = $this->getToken();
$snippets = $token->getAnswerSnippetNames();
if ($snippets) {
$this->setTitle(sprintf($this->_('Token answers: %s'), strtoupper($token->getTokenId())));
$params = $this->_processParameters($this->answerParameters + $this->defaultTokenParameters);
$this->addSnippets($snippets, $params);
}
} | Pops the answers to a survey in a separate window | entailment |
public function answerExportAction()
{
if ($this->answerExportSnippets) {
$params = $this->_processParameters($this->answerExportParameters + $this->defaultTokenParameters);
$this->addSnippets($this->answerExportSnippets, $params);
}
} | Export a single token | entailment |
public function checkAllTracksAction()
{
$respondent = $this->getRespondent();
$where = $this->db->quoteInto('gr2t_id_user = ?', $respondent->getId());
$batch = $this->loader->getTracker()->checkTrackRounds(
'trackCheckRoundsResp_' . $respondent->getId(),
$this->currentUser->getUserId(),
$where
);
$title = sprintf(
$this->_('Checking round assignments for all tracks of respondent %s, %s.'),
$respondent->getPatientNumber(),
$respondent->getFullName()
);
$this->_helper->BatchRunner($batch, $title, $this->accesslog);
$this->addSnippet('Track\\CheckRoundsInformation');
} | Action for checking all assigned rounds for this respondent using a batch | entailment |
public function checkTokenAnswersAction()
{
$token = $this->getToken();
$where = $this->db->quoteInto('gto_id_token = ?', $token->getTokenId());
$batch = $this->loader->getTracker()->recalculateTokens(
'answersCheckToken__' . $token->getTokenId(),
$this->currentUser->getUserId(),
$where
);
$batch->autoStart = true;
$title = sprintf(
$this->_("Checking the token %s for answers."),
$token->getTokenId()
);
$this->_helper->BatchRunner($batch, $title, $this->accesslog);
$this->addSnippet('Survey\\CheckAnswersInformation',
'itemDescription', $this->_('This task checks one token for answers.')
);
} | Check the tokens for a single token | entailment |
public function checkTrackAction()
{
$respondent = $this->getRespondent();
$respTrackId = $this->getRespondentTrackId();
$trackEngine = $this->getTrackEngine();
$where = $this->db->quoteInto('gr2t_id_respondent_track = ?', $respTrackId);
$batch = $this->loader->getTracker()->checkTrackRounds(
'trackCheckRoundsFor_' . $respTrackId,
$this->currentUser->getUserId(),
$where
);
$title = sprintf(
$this->_("Checking round assignments for track '%s' of respondent %s, %s."),
$trackEngine->getTrackName(),
$respondent->getPatientNumber(),
$respondent->getFullName()
);
$this->_helper->BatchRunner($batch, $title, $this->accesslog);
$this->addSnippet('Track\\CheckRoundsInformation');
} | Action for checking all assigned rounds for a single respondent track using a batch | entailment |
public function createAction()
{
if (! $this->isMultiTracks()) {
// Fix for double pressing of create button
$request = $this->getRequest();
$model = $this->getModel();
$model->setFilter(array()) // First clear existing filter
->applyRequest($request);
$data = $model->loadFirst();
if ($data) {
$this->_reroute(array($request->getActionKey() => 'edit-track'));
return;
}
}
if ($this->createSnippets) {
$params = $this->_processParameters($this->createParameters + $this->createEditParameters);
$this->addSnippets($this->createSnippets, $params);
}
} | Action for showing a create new item page
Uses separate createSnippets instead of createEditSnipppets | entailment |
protected function createModel($detailed, $action)
{
$apply = true;
$model = $this->loader->getTracker()->getRespondentTrackModel();
if ($detailed) {
$engine = $this->getTrackEngine();
if ($engine) {
switch ($action) {
case 'export-track':
case 'show-track':
$model->applyDetailSettings($engine);
break;
default:
$model->applyEditSettings($engine);
break;
}
$apply = false;
}
}
if ($apply) {
$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 deleteTrackAction()
{
if ($this->deleteTrackSnippets) {
$params = $this->_processParameters($this->deleteTrackParameters + $this->deleteParameters);
$this->addSnippets($this->deleteTrackSnippets, $params);
}
} | Delete a track | entailment |
public function editAction()
{
$this->editParameters = $this->editParameters + $this->defaultTokenParameters;
$this->createEditSnippets = $this->getToken()->getEditSnippetNames();
parent::editAction();
} | Edit single token | entailment |
public function editTrackAction()
{
if ($this->editTrackSnippets) {
$params = $this->_processParameters($this->editTrackParameters + $this->createEditParameters);
$this->addSnippets($this->editTrackSnippets, $params);
}
} | Edit the respondent track data | entailment |
public function emailAction()
{
if ($this->emailSnippets) {
$params = $this->_processParameters($this->emailParameters + $this->defaultTokenParameters);
$this->addSnippets($this->emailSnippets, $params);
}
} | Email the user | entailment |
public function exportTrackAction()
{
if ($this->exportTrackSnippets) {
$params = $this->_processParameters($this->exportTrackParameters);
$this->addSnippets($this->exportTrackSnippets, $params);
}
} | Export a single track | entailment |
protected function getCorrectTokenTitle()
{
$token = $this->getToken();
return sprintf(
$this->_('Correct answers for survey %s, round %s'),
$token->getSurveyName(),
$token->getRoundDescription()
);
} | Get the title for correcting a token
@return string | entailment |
protected function getCreateTrackTitle()
{
$respondent = $this->getRespondent();
return sprintf(
$this->_('Adding the %s track to respondent %s: %s'),
$this->getTrackEngine()->getTrackName(),
$respondent->getPatientNumber(),
$respondent->getFullName()
);
} | Get the title for creating a track
@return string | entailment |
protected function getTrackTitle()
{
$respondent = $this->getRespondent();
$respTrack = $this->getRespondentTrack();
if ($respTrack) {
$trackEngine = $respTrack->getTrackEngine();
if ($this->currentUser->areAllFieldsMaskedWhole('grs_first_name', 'grs_surname_prefix', 'grs_last_name')) {
// Set params
return sprintf(
$this->_('%s track for respondent nr %s'),
$trackEngine->getTrackName(),
$respondent->getPatientNumber()
);
}
// Set params
return sprintf(
$this->_('%s track for respondent nr %s: %s'),
$trackEngine->getTrackName(),
$respondent->getPatientNumber(),
$respondent->getName()
);
}
} | Get the title describing the track
@return string | entailment |
protected function getTokenTitle()
{
$token = $this->getToken();
$respondent = $token->getRespondent();
// Set params
return sprintf(
$this->_('Token %s in round "%s" in track "%s" for respondent nr %s: %s'),
$token->getTokenId(),
$token->getRoundDescription(),
$token->getTrackName(),
$respondent->getPatientNumber(),
$respondent->getName()
);
} | Get the title describing the token
@return string | entailment |
protected function getEmailTokenTitle()
{
$token = $this->getToken();
$respondent = $token->getRespondent();
// Set params
return sprintf(
$this->_('Send mail to %s respondent nr %s for token %s'),
$token->getEmail(), // When using relations, this is the right email address
$respondent->getPatientNumber(),
$token->getTokenId()
);
} | Get the title for editing a track
@return string | entailment |
public function getIndexTitle()
{
$respondent = $this->getRespondent();
return sprintf(
$this->_('Tracks assigned to %s: %s'),
$respondent->getPatientNumber(),
$respondent->getFullName()
);
} | Helper function to get the title for the index action.
@return $string | entailment |
protected function getInsertInTrackTitle()
{
$respondent = $this->getRespondent();
return sprintf(
$this->_('Inserting a survey in a track for respondent %s: %s'),
$respondent->getPatientNumber(),
$respondent->getFullName()
);
} | Get the title for creating a track
@return string | entailment |
public function getRespondentTrack()
{
static $respTrack;
if ($respTrack instanceof \Gems_Tracker_RespondentTrack) {
return $respTrack;
}
$respTrackId = $this->_getParam(\Gems_Model::RESPONDENT_TRACK);
$tracker = $this->loader->getTracker();
if ($respTrackId) {
$respTrack = $tracker->getRespondentTrack($respTrackId);
} else {
if ($this->isMultiTracks()) {
throw new \Gems_Exception($this->_('No track specified for respondent!'));
}
$respondent = $this->getRespondent();
$respTracks = $tracker->getRespondentTracks(
$respondent->getId(),
$respondent->getOrganizationId(),
array('grc_success DESC', 'gr2t_start_date')
);
$trackId = $this->escort->getTrackId();
if ($trackId) {
foreach ($respTracks as $respTrack) {
if ($respTrack instanceof \Gems_Tracker_RespondentTrack) {
if ($trackId == $respTrack->getTrackId()) {
// Return the right track if it exists
break;
}
}
}
} else {
$respTrack = reset($respTracks);
}
}
if (! $respTrack instanceof \Gems_Tracker_RespondentTrack) {
if ($this->isMultiTracks()) {
throw new \Gems_Exception($this->_('No track found for respondent!'));
} else {
$this->menu->getParameterSource()->offsetSet('track_can_be_created', 1);
return null;
}
}
$respTrack->applyToMenuSource($this->menu->getParameterSource());
// Otherwise return the last created track (yeah some implementations are not correct!)
return $respTrack;
} | Retrieve the respondent track
(So we don't need to repeat that for every snippet.)
@return \Gems_Tracker_RespondentTrack | entailment |
public function getSurveyId()
{
$sid = $this->_getParam(\Gems_Model::SURVEY_ID);
if ($sid) {
return $sid;
}
if ($this->getTokenId()) {
return $this->getToken()->getSurveyId();
}
} | Retrieve the survey ID
@return int | entailment |
public function getToken()
{
static $token;
if ($token instanceof \Gems_Tracker_Token) {
return $token;
}
$token = null;
$tokenId = $this->getTokenId();
if ($tokenId) {
$token = $this->loader->getTracker()->getToken($tokenId);
}
if ($token && $token->exists) {
// Set variables for the menu
$token->applyToMenuSource($this->menu->getParameterSource());
return $token;
}
throw new \Gems_Exception($this->_('No existing token specified!'));
} | Retrieve the token
@return \Gems_Tracker_Token | entailment |
public function getTrackEngine()
{
static $engine;
if ($engine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
return $engine;
}
try {
$respTrack = $this->getRespondentTrack();
if ($respTrack instanceof \Gems_Tracker_RespondentTrack) {
$engine = $respTrack->getTrackEngine();
}
} catch (\Exception $ex) {
}
if (! $engine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
$trackId = $this->_getParam(\Gems_model::TRACK_ID);
if (! $trackId) {
if ($this->isMultiTracks()) {
throw new \Gems_Exception($this->_('No track engine specified!'));
}
$trackId = $this->escort->getTrackId();
if (! $trackId) {
return null;
}
}
$engine = $this->loader->getTracker()->getTrackEngine($trackId);
}
$engine->applyToMenuSource($this->menu->getParameterSource());
return $engine;
} | Retrieve the track engine
@return \Gems_Tracker_Engine_TrackEngineInterface | entailment |
protected function getViewTrackTitle()
{
$trackEngine = $this->getTrackEngine();
if ($this->isMultiTracks()) {
$respondent = $this->getRespondent();
// Set params
return sprintf(
$this->_('%s track assignments for respondent nr %s: %s'),
$trackEngine->getTrackName(),
$this->_getParam(\MUtil_Model::REQUEST_ID1),
$this->getRespondent()->getFullName()
);
} else {
return sprintf(
$this->_('%s track overview'),
$trackEngine->getTrackName()
);
}
} | Get the title for viewing track usage
@return string | entailment |
public function init()
{
parent::init();
$request = $this->getRequest();
if (in_array($request->getActionName(), $this->tokenReturnActions)) {
// Tell the system where to return to after a survey has been taken
$this->currentUser->setSurveyReturn($request);
}
} | Initialize translate and html objects
Called from {@link __construct()} as final step of object instantiation.
@return void | entailment |
public function insertAction()
{
if ($this->insertSnippets) {
$params = $this->_processParameters($this->insertParameters);
$this->addSnippets($this->insertSnippets, $params);
}
} | Insert a single survey into a track | entailment |
public function questionsAction()
{
if (!$this->getTokenId()) {
$params = $this->_processParameters($this->questionsParameters);
} else {
$params = $this->_processParameters($this->questionsParameters + $this->defaultTokenParameters);
}
if ($this->questionsSnippets) {
$params = $this->_processParameters($this->questionsParameters + $this->defaultTokenParameters);
$this->addSnippets($this->questionsSnippets, $params);
}
} | Shows the questions in a survey | entailment |
public function recalcAllFieldsAction()
{
$respondent = $this->getRespondent();
$where = $this->db->quoteInto('gr2t_id_user = ?', $respondent->getId());
$batch = $this->loader->getTracker()->recalcTrackFields(
'trackRecalcFieldsResp_' . $respondent->getId(),
$where
);
$title = sprintf(
$this->_('Recalculating fields for all tracks of respondent %s, %s.'),
$respondent->getPatientNumber(),
$respondent->getFullName()
);
$this->_helper->BatchRunner($batch, $title, $this->accesslog);
$this->addSnippet('Track\\RecalcFieldsInformation');
} | Action for checking all assigned rounds using a batch | entailment |
public function recalcFieldsAction()
{
$respondent = $this->getRespondent();
$respTrackId = $this->getRespondentTrackId();
$trackEngine = $this->getTrackEngine();
$where = $this->db->quoteInto('gr2t_id_respondent_track = ?', $respTrackId);
$batch = $this->loader->getTracker()->recalcTrackFields(
'trackRecalcFieldsFor_' . $respTrackId,
$where
);
$title = sprintf(
$this->_("Recalculating fields for track '%s' of respondent %s, %s."),
$trackEngine->getTrackName(),
$respondent->getPatientNumber(),
$respondent->getFullName()
);
$this->_helper->BatchRunner($batch, $title, $this->accesslog);
$this->addSnippet('Track\\RecalcFieldsInformation');
} | Action for checking all assigned rounds for a single track using a batch | entailment |
public function showAction()
{
$this->showParameters = $this->showParameters + $this->defaultTokenParameters;
$this->showSnippets = $this->getToken()->getShowSnippetNames();
parent::showAction();
} | Show a single token, mind you: it can be a SingleSurveyTrack | entailment |
public function showTrackAction()
{
if ($this->showTrackSnippets) {
$params = $this->_processParameters($this->showTrackParameters);
$this->addSnippets($this->showTrackSnippets, $params);
}
} | Show information on a single track assigned to a respondent | entailment |
public function undeleteAction()
{
$this->deleteParameters = $this->deleteParameters + $this->defaultTokenParameters;
$this->deleteSnippets = $this->getToken()->getDeleteSnippetNames();
parent::deleteAction();
} | Delete a single token | entailment |
public function undeleteTrackAction()
{
if ($this->deleteTrackSnippets) {
$params = $this->_processParameters($this->deleteTrackParameters + $this->deleteParameters);
$this->addSnippets($this->deleteTrackSnippets, $params);
}
} | Undelete a track | entailment |
public function viewAction()
{
if ($this->viewSnippets) {
$params = $this->_processParameters($this->viewParameters);
$this->addSnippets($this->viewSnippets, $params);
}
} | Show information on a single track type assigned to a respondent | entailment |
public function viewSurveyAction()
{
$params = $this->_processParameters($this->viewSurveyParameters);
$this->addSnippets($this->viewSurveySnippets, $params);
} | Used in AddTracksSnippet to show a preview for an insertable survey | entailment |
protected function getResetPasswordMailFields()
{
if ($this->user->getUserId()) {
$result = $this->user->getResetPasswordMailFields();
} else {
$result['reset_key'] = '';
$result['reset_url'] = '';
}
return $result;
} | Return the mailfields for a password reset template
@return array | entailment |
public function setCreateAccountTemplate()
{
$templateId = $this->organization->getCreateAccountTemplate();
if ($templateId) {
$this->setTemplate($this->organization->getCreateAccountTemplate());
return true;
} elseif ($this->project->getEmailCreateAccount()) {
$this->setTemplateByCode($this->project->getEmailCreateAccount());
return true;
} else {
return false;
}
} | Set the create account Mail template from the organization or the project
@return boolean success | entailment |
public function setResetPasswordTemplate()
{
$templateId = $this->organization->getResetPasswordTemplate();
if ($templateId) {
$this->setTemplate($this->organization->getResetPasswordTemplate());
return true;
} elseif ($this->project->getEmailResetPassword()) {
if ($this->setTemplateByCode($this->project->getEmailResetPassword())) {
return true;
} else {
return false;
}
} else {
return false;
}
} | Set the reset password Mail template from the organization or the project
@return boolean success | entailment |
public function getTab()
{
if (!$this->_db)
return 'No adapter';
foreach ($this->_db as $adapter) {
$profiler = $adapter->getProfiler();
$adapterInfo[] = $profiler->getTotalNumQueries() . ' in '
. round($profiler->getTotalElapsedSecs()*1000, 2) . ' ms';
}
$html = implode(' / ', $adapterInfo);
return $html;
} | Gets menu tab for the Debugbar
@return string | entailment |
public function getPanel()
{
if (!$this->_db)
return '';
$html = '<h4>Database queries';
// @TODO: This is always on?
if (Zend_Db_Table_Abstract::getDefaultMetadataCache()) {
$html .= ' – Metadata cache ENABLED';
} else {
$html .= ' – Metadata cache DISABLED';
}
$html .= '</h4>';
return $html . $this->getProfile();
} | Gets content panel for the Debugbar
@return string | entailment |
protected function _getObjectsAllCached($cacheId, $object, $sql, $binds = null, $tags = array())
{
$output = array();
$rows = $this->_getSelectAllCached($cacheId, $sql, $binds, $tags);
if ($rows) {
$this->source->applySource($object);
foreach ($rows as $row) {
$tmp = clone $object;
$tmp->exchangeArray($row);
$output[] = $tmp;
}
}
return $output;
} | Utility function for loading a complete query from cache into objects
@param string $cacheId The class is prepended to this id
@param object $object The object to put the data in
@param mixed $sql string or \Zend_Db_Select
@param array $binds sql paramters
@param mixed $tags atring or array of strings
@return array | entailment |
protected function _getSelectAllCached($cacheId, $sql, $binds = array(), $tags = array(), $natSort = false)
{
$cacheId = strtr(get_class($this) . '_a_' . $cacheId, '\\/', '__');
$result = $this->cache->load($cacheId);
if ($result) {
return $result;
}
try {
$result = $this->db->fetchAll($sql, (array) $binds);
if ($natSort) {
natsort($result);
}
$this->cache->save($result, $cacheId, (array) $tags);
} catch (\Zend_Db_Statement_Mysqli_Exception $e) {
$result = array();
}
return $result;
} | Utility function for loading a complete query from cache
@param string $cacheId The class is prepended to this id
@param mixed $sql string or \Zend_Db_Select
@param array $binds sql paramters
@param mixed $tags atring or array of strings
@param boolean $natSort Perform a natsort over the output
@return array | entailment |
protected function _getSelectPairsCached($cacheId, $sql, $binds = array(), $tags = array(), $sort = null)
{
$cacheId = strtr(get_class($this) . '_p_' . $cacheId, '\\/', '__');
$result = $this->cache->load($cacheId);
if ($result) {
return $result;
}
try {
$result = $this->db->fetchPairs($sql, (array) $binds);
if ($result && $sort) {
$this->_sortResult($result, $sort);
}
$this->cache->save($result, $cacheId, (array) $tags);
} catch (\Zend_Db_Statement_Mysqli_Exception $e) {
$result = array();
}
return $result;
} | Utility function for loading a query paired from cache
@param string $cacheId The class is prepended to this id
@param mixed $sql string or \Zend_Db_Select
@param array $binds sql paramters
@param mixed $tags atring or array of strings
@param string Optional function to sort on, only known functions will do
@return array | entailment |
protected function _getSelectPairsProcessedCached($cacheId, $sql, $function, $binds = array(), $tags = array(), $sort = null)
{
$cacheId = get_class($this) . '_' . $cacheId;
$result = false; //$this->cache->load($cacheId);
if ($result) {
return $result;
}
try {
$result = $this->db->fetchPairs($sql, (array) $binds);
if ($result) {
foreach ($result as $id => & $value) {
$value = call_user_func($function, $value);
}
if ($sort) {
$this->_sortResult($result, $sort);
}
}
$this->cache->save($result, $cacheId, (array) $tags);
} catch (\Zend_Db_Statement_Mysqli_Exception $e) {
$result = array();
}
return $result;
} | Utility function for loading a query from cache
@param string $cacheId The class is prepended to this id
@param mixed $sql string or \Zend_Db_Select
@param callable $function The function called with each row to form the result
@param array $binds sql paramters
@param mixed $tags string or array of strings
@param string Optional function to sort on, only known functions will do
@return array | entailment |
protected function _getSelectProcessedCached($cacheId, $sql, $function, $keyField, $tags = array(), $sort = null)
{
$cacheId = get_class($this) . '_' . $cacheId;
$result = false; //$this->cache->load($cacheId);
if ($result) {
return $result;
}
$result = array();
try {
$rows = $this->db->fetchAll($sql);
if ($rows) {
foreach ($rows as $row) {
if (! isset($result[$row[$keyField]])) {
$result[$row[$keyField]] = call_user_func($function, $row);
}
}
if ($sort) {
$this->_sortResult($result, $sort);
}
}
$this->cache->save($result, $cacheId, (array) $tags);
} catch (\Zend_Db_Statement_Mysqli_Exception $e) {
}
return $result;
} | Utility function for loading a query from cache
@param string $cacheId The class is prepended to this id
@param mixed $sql string or \Zend_Db_Select
@param callable $function The function called with each row to form the result
@param string $keyField The field containing the key for each row
@param mixed $tags string or array of strings
@param string Optional function to sort on, only known functions will do
@return array | entailment |
protected function _sortResult(array &$result, $sort = 'asort')
{
// Sorting
switch ($sort) {
case 'asort':
asort($result);
break;
case 'ksort':
ksort($result);
break;
case 'natsort':
natsort($result);
break;
default:
$sort($result);
}
} | Sort the array using the specified sort function
@param array $result
@param strng $sort | entailment |
public function formatNumber($value, $precision = 2)
{
if (null !== $value) {
return \Zend_Locale_Format::toNumber($value, array('precision' => $precision, 'locale' => $this->locale));
}
} | /*
public function formatDateTime($dateTimeValue, $showRecentTime = false)
{
if ($dateTimeValue) {
$locale = $this->locale;
$dateTime = strtotime($dateTimeValue);
$days = floor($dateTime / 86400) - floor(time() / 86400) + ($showRecentTime ? 0 : 1); // 86400 = 24*60*60
if ($descr = \Zend_Locale_Data::getContent($locale, 'relative', $days)) {
$recentTime = $showRecentTime ? ' ' . date('H:i', $dateTime) : '';
return $descr . $recentTime;
}
$daysDescr = '';
if (($days > -14) && ($days < 14)) {
if ($dayFormat = \Zend_Locale_Data::getContent($locale, 'unit', array('day', (abs($days) == 1) ? 'one' : 'other'))) {
$daysDescr = ' ' . str_replace('{0}', $days, $dayFormat);
}
}
$date = new \Zend_Date($dateTimeValue);
return $date->toString($locale);
return date('d-m-Y', $dateTime) . $daysDescr;
}
return null;
} // | entailment |
public function applyDetailSettings()
{
parent::applyDetailSettings();
$this->setIfExists('grs_surname_prefix', 'description', $this->_('de, van der, \'t, etc...'));
$this->setIfExists('grs_partner_surname_prefix', 'description', $this->_('de, van der, \'t, etc...'));
return $this;
} | Set those settings needed for the detailed display
@return \Gems_Model_RespondentNlModel | entailment |
public function applyEditSettings($create = false)
{
parent::applyEditSettings($create);
$translator = $this->getTranslateAdapter();
if ($this->hashSsn !== parent::SSN_HIDE) {
self::setDutchSsn($this, $translator);
}
$this->setIfExists('grs_iso_lang', 'default', 'nl');
$this->setIfExists('gr2o_treatment', 'description', $this->_('DBC\'s, etc...'));
self::setDutchZipcode($this, $translator);
return $this;
} | Set those values needed for editing
@param boolean $create True when creating
@return \Gems_Model_RespondentModel | entailment |
public static function setDutchSsn(\MUtil_Model_ModelAbstract $model, \Zend_Translate_Adapter $translator, $fieldName = 'grs_ssn')
{
$bsn = new \MUtil_Validate_Dutch_Burgerservicenummer();
$model->set($fieldName,
'size', 10,
'maxlength', 12,
'filter', new \MUtil_Filter_Dutch_Burgerservicenummer(),
'validators[bsn]', $bsn);
if (APPLICATION_ENV !== 'production') {
$num = mt_rand(100000000, 999999999);
while (! $bsn->isValid($num)) {
$num++;
}
$model->set($fieldName, 'description', sprintf($translator->_('Random Example BSN: %s'), $num));
} else {
$model->set($fieldName, 'description', $translator->_('Enter a 9-digit SSN number.'));
}
} | Set the field values for a dutch social security number
@param \MUtil_Model_ModelAbstract $model
@param \Zend_Translate_Adapter $translator
@param string $fieldName | entailment |
public static function setDutchZipcode(\MUtil_Model_ModelAbstract $model, \Zend_Translate_Adapter $translator, $fieldName = 'grs_zipcode')
{
$model->set($fieldName,
'size', 7,
'description', $translator->_('E.g.: 0000 AA'),
'filter', new \Gems_Filter_DutchZipcode()
);
} | Set the field values for a dutch zipcode
@param \MUtil_Model_ModelAbstract $model
@param \Zend_Translate_Adapter $translator
@param string $fieldName | entailment |
protected function getAutoSearchElements(array $data)
{
$elements = parent::getAutoSearchElements($data);
$elements[] = new \Zend_Form_Element_Hidden(\MUtil_Model::REQUEST_ID);
$elements[] = $this->_createSelectElement('gtf_field_type', $this->model, $this->_('(all types)'));
$elements[] = \MUtil_Html::create('br');
return $elements;
} | Returns a text element for autosearch. Can be overruled.
The form / html elements to search on. Elements can be grouped by inserting null's between them.
That creates a distinct group of elements
@param array $data The $form field values (can be usefull, but no need to set them)
@return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks. | entailment |
public function filterAnswers(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Model_ModelAbstract $model, array $currentNames)
{
$currentNames = array_combine($currentNames, $currentNames);
$newOrder = array();
$values = array_filter($this->token->getRawAnswers(), 'is_numeric');
arsort($values);
foreach ($values as $key => $value) {
if (isset($currentNames[$key])) {
unset($currentNames[$key]);
$newOrder[$key] = $key;
}
}
// \MUtil_Echo::track($this->_values, $newOrder, $newOrder + $currentNames);
return $this->restoreHeaderPositions($model, $newOrder + $currentNames);
} | This function is called in addBrowseTableColumns() to filter the names displayed
by AnswerModelSnippetGeneric.
@see \Gems_Tracker_Snippets_AnswerModelSnippetGeneric
@param \MUtil_Model_Bridge_TableBridge $bridge
@param \MUtil_Model_ModelAbstract $model
@param array $currentNames The current names in use (allows chaining)
@return array Of the names of labels that should be shown | entailment |
public function getVersion()
{
$code = $this->runShell('tika --version', $stdout);
// Parse output
if (!$code && preg_match('/Apache Tika (?<version>[\.\d]+)/', $stdout, $matches)) {
return $matches['version'];
}
return 0;
} | Get the version of tika installed, or 0 if not installed
@return mixed float | int The version of tika | entailment |
protected function runShell($command, &$stdout = '', &$stderr = '', $input = '')
{
$descriptorSpecs = [
0 => ["pipe", "r"],
1 => ["pipe", "w"],
2 => ["pipe", "w"]
];
// Invoke command
$pipes = [];
$proc = proc_open($command, $descriptorSpecs, $pipes);
if (!is_resource($proc)) {
return 255;
}
// Send content as input
fwrite($pipes[0], $input);
fclose($pipes[0]);
// Get output
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
// Get result
return proc_close($proc);
} | Runs an arbitrary and safely escaped shell command
@param string $command Full command including arguments
@param string &$stdout Standand output
@param string &$stderr Standard error
@param string $input Content to pass via standard input
@return int Exit code. 0 is success | entailment |
private function _getImportantDecorator($element)
{
$class = get_class($element);
if (strpos($class, 'JQuery')) {
$dec = $element->getDecorator('UiWidgetElement');
}
if (strpos($class, 'File')) {
$dec = $element->getDecorator('File');
}
if (!isset($dec) || $dec == false) {
$dec = $element->getDecorator('ViewHelper');
}
return $dec;
} | Get a ViewHelper or ZendX decorator to add in front of the decorator chain
@param \Zend_Form_Element $element
@return null|\Zend_Form_Decorator_Abstract | entailment |
public function addDisplayGroup(array $elements, $name, $options = null)
{
//Add the group as usual, but skip decorator loading as we don't need that
return parent::addDisplayGroup($elements, $name, (array) $options + array('disableLoadDefaultDecorators' => true));
} | Add a display group to the subform
This allows to render multiple fields in one table cell. Provide a description to set the label for
the group. When the special option showLabels is set to true, inside the tabel cell all fields will
still show their own label.
Example:
<code>
$this->addDisplayGroup(array('firstname', 'infix', 'lastname'), 'name_group', array('description'=>'Name', 'showLabels'=>true);
</code>
This would result in a two cell table row, with first cell the description of the group 'Name' and in the
second cell the three input boxes, with their label in front. If you leave the showLabels out, you will get
just three inputboxes for the name parts.
@param array $elements Array with names of the fields you want to add
@param string $name The (unique) name for this new group
@param array $options An array of key=>value options to set for the group
@return \Gems_Form_TabSubForm | entailment |
public function fixDecorators()
{
//Needed for alternating rows
$this->_alternate = new \MUtil_Lazy_Alternate(array('odd', 'even'));
foreach ($this as $name => $element) {
if ($element instanceof \MUtil_Form_Element_Html) {
$this->_fixDecoratorHtml($element);
} elseif ($element instanceof \Zend_Form_Element_Hidden || $element instanceof \Zend_Form_Element_Submit) {
$this->_fixDecoratorHiddenSubmit($element);
} elseif ($element instanceof \Zend_Form_Element) {
$this->_fixDecoratorElement($element);
} elseif ($element instanceof \Zend_Form_DisplayGroup) {
$this->_fixDecoratorDisplayGroup($element);
}
}
} | Fix the decorators so we get the table layout we want. Normally this is called
only once when rendering the form. | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.