コード例 #1
0
 /**
  * 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
  */
 public function execute($lineNr = null, $fieldId = null, $fieldSub = null, $fieldCalc = null)
 {
     $batch = $this->getBatch();
     $import = $batch->getVariable('import');
     if (!(isset($import['trackId']) && $import['trackId'] && $fieldId)) {
         // Do nothing
         return;
     }
     $tracker = $this->loader->getTracker();
     $trackEngine = $tracker->getTrackEngine($import['trackId']);
     $fieldCodes = $import['fieldCodes'];
     $fieldModel = $trackEngine->getFieldsMaintenanceModel(true, 'edit');
     $roundOrders = $import['roundOrders'];
     $saveData['gtf_id_field'] = $fieldId;
     $saveData['sub'] = $fieldSub;
     $saveData['gtf_id_track'] = $import['trackId'];
     $calcFields = is_array($fieldCalc) ? $fieldCalc : explode('|', trim($fieldCalc, '|'));
     if (!$calcFields) {
         return;
     }
     foreach ($calcFields as $field) {
         if (isset($fieldCodes[$field]) && $fieldCodes[$field]) {
             $saveData['gtf_calculate_using'][] = $fieldCodes[$field];
         } else {
             // Actually this code currently is PULSE specific
             if (\MUtil_String::startsWith($field, '{r')) {
                 $roundOrder = substr($field, 2, -1);
                 if (isset($roundOrders[$roundOrder]) && $roundOrders[$roundOrder]) {
                     $saveData['gtf_calculate_using'][] = $roundOrders[$roundOrder];
                 } else {
                     $saveData['gtf_calculate_using'][] = $field;
                 }
             }
         }
     }
     \MUtil_Echo::track($saveData, $fieldId);
     $fieldModel->save($saveData);
 }
コード例 #2
0
 /**
  * Do a recursive find of the changes
  *
  * @param array $switches Current level of switches array
  * @param array $dependsOn Current level of $dependsOn array
  * @param array $context Context
  * @return array name => array(setting => value)
  */
 protected function _findChanges(array $switches, array $dependsOn, array $context)
 {
     // Found it when depends on is empty
     if (!$dependsOn) {
         return $switches;
     }
     $name = array_shift($dependsOn);
     // When there is no data, return no changes
     if (!array_key_exists($name, $context)) {
         if (\MUtil_Model::$verbose) {
             $names = array_diff_key($this->_dependentOn, $context);
             \MUtil_Echo::r(implode(', ', $names), 'Name(s) not found in ' . get_class($this));
         }
         return array();
     }
     $value = $context[$name];
     if ($value) {
         // All true cases
         foreach ($switches as $key => $rest) {
             if ($value == $key) {
                 return $this->_findChanges($rest, $dependsOn, $context);
             }
         }
     } else {
         // For non-true value we use exact type comparison, except when both are zero's
         if (null === $value) {
             foreach ($switches as $key => $rest) {
                 if (null === $key) {
                     return $this->_findChanges($rest, $dependsOn, $context);
                 }
             }
         } elseif (0 === $value || "0" === $value) {
             foreach ($switches as $key => $rest) {
                 if (0 === $key || "0" === $key) {
                     return $this->_findChanges($rest, $dependsOn, $context);
                 }
             }
         } elseif ("" === $value) {
             foreach ($switches as $key => $rest) {
                 if ("" === $key) {
                     return $this->_findChanges($rest, $dependsOn, $context);
                 }
             }
         }
     }
     if (\MUtil_Model::$verbose) {
         \MUtil_Echo::track($this->_switches, $this->_dependentOn, $this->_effecteds);
         \MUtil_Echo::r("Value '{$value}' not found for field {$name} among the values: " . implode(', ', array_keys($switches)), 'Value not found in ' . get_class($this));
     }
     return array();
 }
コード例 #3
0
 /**
  * Adds which settings are effected by a value
  *
  * Overrule this function, e.g. when a sub class changed a fixed setting,
  * but for diverse fields.
  *
  * @param string $effectedField A field name
  * @param mixed $effectedSettings A single setting or an array of settings
  * @return \MUtil\Model\Dependency\DependencyAbstract (continuation pattern)
  */
 public function addEffected($effectedField, $effectedSettings)
 {
     foreach ((array) $effectedSettings as $setting) {
         if (is_array($setting)) {
             \MUtil_Echo::track($setting);
         }
         $this->_effecteds[$effectedField][$setting] = $setting;
     }
     return $this;
 }