/** * 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 array $row Row to save */ public function execute($row = null) { if ($row) { $batch = $this->getBatch(); $batch->addToCounter('imported'); // \MUtil_Echo::track($row); $this->targetModel->save($row); $batch->addToCounter('changed', $this->targetModel->getChanged()); } }
/** * This transform function performs the actual save (if any) of the transformer data and is called after * the saving of the data in the source model. * * @param \MUtil_Model_ModelAbstract $model The parent model * @param array $row Array containing row * @return array Row array containing (optionally) transformed data */ public function transformRowAfterSave(\MUtil_Model_ModelAbstract $model, array $row) { if (isset($row[$this->respTrackIdField]) && $row[$this->respTrackIdField]) { if (!$this->respTrackIdField || $this->respTrackIdField == 'gr2t_id_respondent_track') { // Load && refresh when using standard gems__respondent2track data $respTrack = $this->tracker->getRespondentTrack($row); } else { $respTrack = $this->tracker->getRespondentTrack($row[$this->respTrackIdField]); } // Field data was already (re)calculated in transformRowBeforeSave // and saveFields() extracts the used field data from the row. $changed = $respTrack->saveFields($row); if ($changed && !$model->getChanged()) { $model->addChanged(1); } } // No changes return $row; }
/** * This transform function performs the actual save (if any) of the transformer data and is called after * the saving of the data in the source model. * * @param \MUtil_Model_ModelAbstract $model The parent model * @param array $row Array containing row * @return array Row array containing (optionally) transformed data */ public function transformRowAfterSave(\MUtil_Model_ModelAbstract $model, array $row) { if (isset($row[$this->respTrackIdField]) && $row[$this->respTrackIdField]) { // Field data was already (re)calculated in transformRowBeforeSave // and saveFields() extracts the used field data from the row. $changed = $this->fieldsDefinition->saveFields($row[$this->respTrackIdField], $row); if ($changed) { $tracker = $this->loader->getTracker(); $respTrack = $tracker->getRespondentTrack($row[$this->respTrackIdField]); $userId = $this->loader->getCurrentUser()->getUserId(); $respTrack->handleFieldUpdate($userId); if (!$model->getChanged()) { $model->addChanged(1); } } } // No changes return $row; }