Beispiel #1
0
 /**
  * Univeral checker for workflow triggers
  * This function should work for all ActiveRecords
  * 
  * @param \GO\Base\Db\ActiveRecord $model 
  */
 public static function save(&$model, $wasNew)
 {
     if ($wasNew) {
         // Check for a trigger for this model
         $triggers = Model\Trigger::model()->findByAttribute('model_type_id', $model->modelTypeId());
         \GO::debug('CHECK FOR WORKFLOW TRIGGER ON THIS MODEL');
         while ($trigger = $triggers->fetch()) {
             if ($trigger->model_attribute_value == $model->{$trigger->model_attribute}) {
                 \GO::debug('TRIGGER FOUND!, START NEW WORKFLOW PROCESS');
                 $process = Model\Process::model()->findByPk($trigger->process_id);
                 $step = $process->getNextStep();
                 $wfModel = new Model\Model();
                 $wfModel->model_id = $model->id;
                 $wfModel->model_type_id = $model->modelTypeId();
                 $wfModel->process_id = $trigger->process_id;
                 $wfModel->step_id = $step->id;
                 //$wfModel->ctime = 0;
                 $wfModel->due_time = $wfModel->calculateDueTime($step);
                 $wfModel->shift_due_time = 0;
                 $wfModel->save();
             }
         }
     }
 }