Add the elements from the model to the bridge for the current step

@param \MUtil_Model_Bridge_FormBridgeInterface $bridge
@param \MUtil_Model_ModelAbstract $model
508012
protected function addStepGenerateExportFile(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model)
    {
        // Things go really wrong (at the session level) if we run this code
        // while the finish button was pressed
        if ($this->isFinishedClicked()) {
            return;
        }
        $this->displayHeader($bridge, $this->_('Creating the export file'), 'h3');

        $this->nextDisabled = true;

        $batch = $this->getExportBatch();
        $form  = $bridge->getForm();

        $batch->setFormId($form->getId());
        $batch->autoStart = true;

        // \MUtil_Registry_Source::$verbose = true;
        if ($batch->run($this->request)) {
            exit;
        }

        $element = $form->createElement('html', $batch->getId());

        if ($batch->isFinished()) {
            $this->nextDisabled = $batch->getCounter('export_errors');
            $batch->autoStart   = false;

            // Keep the filename after $batch->getMessages(true) cleared the previous
            $downloadName  = \MUtil_File::cleanupName($this->trackEngine->getTrackName()) . '.track.txt';
            $localFilename = $batch->getSessionVariable('filename');

            $this->addMessage($batch->getMessages(true));
            $batch->setSessionVariable('downloadname', $downloadName);
            $batch->setSessionVariable('filename', $localFilename);

            // Log Export
            $data = $this->formData;
            // Remove unuseful data
            unset($data['button_spacer'], $data['current_step'], $data[$this->csrfId]);
            // Add useful data
            $data['localfile']    = '...' . substr($localFilename, -30);
            $data['downloadname'] = $downloadName;
            ksort($data);
            $this->accesslog->logChange($this->request, null, array_filter($data));

            if ($this->nextDisabled) {
                $element->pInfo($this->_('Export errors occurred.'));
            } else {
                $p = $element->pInfo($this->_('Export file generated.'), ' ');
                $p->sprintf(
                        $this->plural(
                                'Click here if the download does not start automatically in %d second:',
                                'Click here if the download does not start automatically in %d seconds:',
                                $this->downloadWaitSeconds
                                ),
                        $this->downloadWaitSeconds
                        );
                $p->append(' ');

                $href = new \MUtil_Html_HrefArrayAttribute(array('file' => 'go', $this->stepFieldName => 'download'));
                $p->a(
                        $href,
                        $downloadName,
                        array('type' => 'application/download')
                        );

                $metaContent = sprintf('%d;url=%s', $this->downloadWaitSeconds, $href->render($this->view));
                $this->view->headMeta($metaContent, 'refresh', 'http-equiv');
            }

        } else {
            $element->setValue($batch->getPanel($this->view, $batch->getProgressPercentage() . '%'));

        }
        $form->activateJQuery();
        $form->addElement($element);
    }
200845
protected function addTableCells(\MUtil_Model_Bridge_VerticalTableBridge $bridge)
    {
        $HTML = \MUtil_Html::create();

        $bridge->caption($this->getCaption());

        $br = $HTML->br();

        // ROW 0
        $label = $this->model->get('gr2o_patient_nr', 'label'); // Try to read label from model...
        if (empty($label)) {
            $label = $this->_('Respondent nr: ');               // ...but have a fall-back
        }
        $bridge->addItem($bridge->gr2o_patient_nr, $label);
        if (! $this->currentUser->areAllFieldsMaskedWhole('grs_last_name', 'grs_first_name', 'grs_gender', 'grs_surname_prefix')) {
            $bridge->addItem(
                $HTML->spaced(
                        $bridge->itemIf('grs_last_name', array($bridge->grs_last_name, ',')),
                        $bridge->grs_gender,
                        $bridge->grs_first_name,
                        $bridge->grs_surname_prefix
                        ),
                $this->_('Respondent'));
        }
        // ROW 1
        if ($this->model->has('grs_birthday') && (! $this->currentUser->isFieldMaskedWhole('grs_birthday'))) {
            $bridge->addItem('grs_birthday');
        }
        if ($this->model->has('grs_phone_1') && (! $this->currentUser->isFieldMaskedWhole('grs_phone_1'))) {
            $bridge->addItem('grs_phone_1');
        }

        // ROW 2
        if ($this->model->has('gr2o_email') && (! $this->currentUser->isFieldMaskedWhole('gr2o_email'))) {
            $bridge->addItem('gr2o_email');
        }
        $address = [];
        if ($this->model->has('grs_address_1') && (! $this->currentUser->isFieldMaskedWhole('grs_address_1'))) {
            $address[] = $bridge->grs_address_1;
            $address[] = $br;
        }
        if ($this->model->has('grs_address_2') && (! $this->currentUser->isFieldMaskedWhole('grs_address_2'))) {
            $address[] = $bridge->grs_address_2;
            $address[] = $bridge->itemIf('grs_address_2', $br);
        }
        if ($this->model->has('grs_zipcode') && (! $this->currentUser->isFieldMaskedWhole('grs_zipcode'))) {
            $address[] = $bridge->grs_zipcode;
            $address[] = $bridge->itemIf('grs_zipcode', new \MUtil_Html_Raw('&nbsp;&nbsp;'));
        }
        if ($this->model->has('grs_city') && (! $this->currentUser->isFieldMaskedWhole('grs_city'))) {
            $address[] = $bridge->grs_city;
        }
        if ($address) {
            $bridge->addItem($address, $this->_('Address'));
        }
    }
856854
public function afterInsert($model, $id)
    {
        if ($this->weak) {
            return;
        }

        $this->save_buffer[$this->foreign_field] =
            isset($this->join) ? $this->join->id : $id;

        $persistence = $this->persistence ?:
            $this->owner->persistence;

        $this->id = $persistence->insert(
            $model,
            $this->save_buffer,
            $this->foreign_table
        );
    }
1350283
protected function setShowTableFooter(\MUtil_Model_Bridge_VerticalTableBridge $bridge, \MUtil_Model_ModelAbstract $model)
    {
        if ($model instanceof \Gems_Tracker_Model_TrackModel) {
            $this->useCount = $model->getStartCount($this->trackId);

            if ($this->useCount) {
                $this->addMessage(sprintf($this->plural(
                        'This track has been started %s time.', 'This track has been started %s times.',
                        $this->useCount
                        ), $this->useCount));
                $this->addMessage($this->_('This track cannot be deleted, only deactivated.'));

                $this->deleteQuestion = $this->_('Do you want to deactivate this track?');
                $this->displayTitle   = $this->_('Deactivate track');
            }
        }

        parent::setShowTableFooter($bridge, $model);
    }
637329
protected function addTableCells(\MUtil_Model_Bridge_VerticalTableBridge $bridge)
    {
        $bridge->setColumnCount(1);

        $HTML = \MUtil_Html::create();

        $bridge->tdh($this->getCaption(), array('colspan' => 2));

        // Caption for tracks
        $trackLabel = $this->_('Assigned tracks');
        if ($menuItem = $this->findMenuItem('track', 'index')) {
            $href = $menuItem->toHRefAttribute($this->request, $bridge);
            $bridge->tdh(array('class' => 'linked'))->a($href, $trackLabel);
        } else {
            $bridge->tdh($trackLabel, array('class' => 'linked'));
        }

        $bridge->tr();

        // ROW 1
        $bridge->addItem($bridge->gr2o_patient_nr, $this->_('Respondent nr: '));

        $rowspan = 10;

        // Column for tracks
        $tracksModel = $this->model->getRespondentTracksModel();
        $tracksData  = \MUtil_Lazy::repeat(
            $tracksModel->load(
                array('gr2o_patient_nr' => $this->repeater->gr2o_patient_nr, 'gr2o_id_organization' => $this->repeater->gr2o_id_organization),
                array('gr2t_created' => SORT_DESC)));
        $tracksList  = $HTML->div($tracksData, array('class' => 'tracksList'));
        $tracksList->setOnEmpty($this->_('No tracks'));
        if ($menuItem = $this->findMenuItem('track', 'show-track')) {
            $href = $menuItem->toHRefAttribute($tracksData, array('gr2o_patient_nr' => $this->repeater->gr2o_patient_nr));
            $tracksTarget = $tracksList->p()->a($href);
        } else {
            $tracksTarget = $tracksList->p();
        }
        $tracksTarget->strong($tracksData->gtr_track_name);
        $tracksTarget[] = ' ';
        $tracksTarget->em($tracksData->gr2t_track_info, array('renderWithoutContent' => false));
        $tracksTarget[] = ' ';
        $tracksTarget[] = \MUtil_Lazy::call($this->util->getTranslated()->formatDate, $tracksData->gr2t_created);
        $bridge->td($tracksList, array('rowspan' => $rowspan, 'class' => 'linked tracksList'));

        // OTHER ROWS
        $bridge->addItem(
            $HTML->spaced($bridge->itemIf('grs_last_name', array($bridge->grs_last_name, ',')), $bridge->grs_first_name, $bridge->grs_surname_prefix),
            $this->_('Respondent'));
        $bridge->addItem('grs_gender');
        $bridge->addItem('grs_birthday');
        $bridge->addItem('gr2o_email');
        $bridge->addItem('gr2o_created');
        $bridge->addItem('gr2o_created_by');

        if ($this->onclick) {
            // TODO: can we not use $repeater?
            $href = array('location.href=\'', $this->onclick, '\';');

            foreach ($bridge->tbody() as $tr) {
                foreach ($tr as $td) {
                    if (strpos($td->class, 'linked') === false) {
                        $td->onclick = $href;
                    } else {
                        $td->onclick = 'event.cancelBubble=true;';
                    }
                }
            }
            $bridge->tbody()->onclick = '// Dummy for CSS';
        }
   }
667120
protected function setDataFromModel(ModelInterface $model): void
    {
        $this->container->set('model', $model);
        
        foreach (get_class_methods($model) as $method) {
            if (0 !== strpos($method, 'get')) {
                continue;
            }
            
            $this->data[strtolower(substr($method, 3))] = $model->$method();
        }
    }
1193229
public function setModel(Model $model)
    {
        $this->model = $model;
        $append = $this->getAppends();

        if ($append instanceof WithModelInterface) {
            $append->setModel($model);
        }

        return $this;
    }
582099
public function insertNode($model)
    {
        $this->validate(['model' => $model]);
        $query = null;

        $data = $this->con->getData($model, $query);
        
        $params = [
            'index' => $this->client->getIndex(),
            'type'  => $model->tableName(),
            'id'    => $data[0][$this->idColumn],
            'body'  => $data[0]
        ];
        $responses = $this->client->getClient()->index($params);
        return $responses['result'];
    }
945173
public function update(Model $model) {

		return $this->_populate(
			$this->_request('put', $this->_getUrl('element', $model->getPrimaryKey()), [
				'json' => $model->getAttributes()
			]),
			false
		);
	}
488479
protected function addStepElementsFor(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model, $step) {
        $this->displayHeader($bridge, $this->_('Survey replace'), 'h1');

        // If we don't copy answers, we skip step 2
        if ($this->formData['copy_answers'] == 0 && $step > 1) {
            $step = $step + 1;
        }

        // To prevent confusion we show a progressbar that jumps from 25% to 50% or 75%
        $element = $bridge->getForm()->createElement('html', 'progress');
        $bridge->addElement($element);
        $element->div(array('class' => 'progress', 'renderClosingTag' => true))->div('', array(
            'class'            => 'progress-bar',
            'style'            => 'width: ' . $step / $this->getStepCount() * 100 . '%;',
            'renderClosingTag' => true));

        switch ($step) {
            case 0:
            case 1:
                $this->addStepElementsForStep1($bridge, $model);
                break;

            case 2:
                $this->addStepElementsForStep2($bridge, $model);
                break;

            case 3:
                $this->addStepElementsForStep3($bridge, $model);
                break;

            default:
                $this->addStepElementsForStep4($bridge, $model);
                break;
        }

        return;
    }
120578
public static function import(Model $model)
    {
        Utils\Utils::arrayPathSet(self::$models, self::getPath($model), $model);
    }
957182
protected function addStepChangeTrack(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model)
    {
        $this->displayHeader($bridge, $this->_('Change track information.'), 'h3');

        // Load the import data form settings
        $this->loadImportData();

        // Always add organization select, even when they were not exported
        $this->addItems($bridge, $model->getColNames('respondentData'));

        // \MUtil_Echo::track($this->formData);
        $all = $this->loader->getUtil()->getTrackData()->getAllSurveys();
        $available = array('' => $this->_('(skip rounds)')) + $all;
        // \MUtil_Echo::track($all);

        $form = $bridge->getForm();

        $surveyHeader = $form->createElement('Html', 'sheader1');
        $surveyHeader->h3($this->_('Survey export code links'));
        $form->addElement($surveyHeader);

        $surveySubHeader = $form->createElement('Html', 'sheader2');
        $surveySubHeader->strong($this->_('Linked survey name'));
        $surveySubHeader->setLabel($this->_('Import survey name'))
                ->setDescription(sprintf($this->_('[%s]'), $this->_('export code')))
                ->setRequired(true);
        $form->addElement($surveySubHeader);

        $this->addItems($bridge, $model->getColNames('isSurvey'));

        // \MUtil_Echo::track($this->_session->uploadFileName, $import->getArrayCopy());
    }
440366
protected function insertModelAsLastRoot(Model $model)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($model);
        $tableName = $class::getTableName();
        /** @var \T4\Dbal\Connection $connection */
        $connection = $class::getDbConnection();

        $query = (new Query())
            ->select('MAX(__rgt)')
            ->from($tableName);
        $maxRgt = (int)$connection->query($query)->fetchScalar();

        if ($model->isNew()) {

            $model->__lft = $maxRgt + 1;
            $model->__rgt = $model->__lft + 1;
            $model->__lvl = 0;
            $model->__prt = null;

        } else {

            $query = (new Query())
                ->update()
                ->table($tableName)
                ->values([
                    '__lft' => '__lft + :max - :lft + 1',
                    '__rgt' => '__rgt + :max - :lft + 1',
                    '__lvl' => '__lvl - :lvl',
                ])
                ->where('__lft>=:lft AND __rgt<=:rgt')
                ->params([':max' => $maxRgt, ':lft' => $model->__lft, ':rgt' => $model->__rgt, ':lvl' => $model->__lvl]);
            $connection->execute($query);

            $this->removeFromTreeByElement($model);

            // TODO: calculate new __lft, __rgt!
            $model->refreshTreeColumns();
            $model->__lvl = 0;
            $model->__prt = null;
        }
    }
1024470
public function push(AbstractModel $model)
    {
        $this->validateAdd($model);
        if (true === $this->willAdd($model)) {
            return $this;
        }
        if (true === $this->willRemove($model)) {
            $this->evict('removed', $model);
            $this->set('models', $model);
            return $this;
        }
        if (true === $this->hasOriginal($model)) {
            return $this;
        }
        $this->set('added', $model);
        $this->set('models', $model);
        return $this;
    }
244350
protected function addStepFileImport(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model)
    {
        // Reset the data
        $this->_session->importData = null;

        $this->displayHeader($bridge, $this->_('Upload a track definition file.'), 'h3');

        $this->addItems($bridge, 'trackFile', 'gtr_id_track');

        $element = $bridge->getForm()->getElement('trackFile');

        if ($element instanceof \Zend_Form_Element_File) {
            if (file_exists($this->_session->localfile)) {
                unlink($this->_session->localfile);
            }
            // Now add the rename filter, the localfile is known only once after loadFormData() has run
            $element->addFilter(new \Zend_Filter_File_Rename(array(
                'target'    => $this->_session->localfile,
                'overwrite' => true
                )));

            $uploadFileName = $element->getFileName();

            // Download the data oon post with filename
            if ($this->request->isPost() && $uploadFileName && $element->isValid(null)) {
                // \MUtil_Echo::track($element->getFileName(), $element->getFileSize());
                if (!$element->receive()) {
                    throw new \MUtil_Model_ModelException(sprintf(
                        $this->_("Error retrieving file '%s'."),
                        $element->getFileName()
                        ));
                }

                $this->_session->importData = null;
                $this->_session->uploadFileName = basename($uploadFileName);
                // \MUtil_Echo::track($this->_session->uploadFileName);
            }
        }
    }
300030
public function add($model)
    {
        if (is_array($model)) {
            // @note: add model type validation.
            $this->collection[] = MarketModel::getInstance($model);
        } elseif (is_object($model) && $model instanceof MarketModel) {
            $this->collection[] = $model;
        }

        return $this;
    }
955303
public function addToPersistModel(ModelInterface $model): RelatedModelManipulationStack
    {
        $this->toPersistModels[$model->getId()] = $model;

        return $this;
    }