Exemple #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();
             }
         }
     }
 }
Exemple #2
0
 private function _moveComments(ActiveRecord $sourceModel)
 {
     if (GO::modules()->isInstalled('comments') && $this->hasLinks()) {
         $findParams = FindParams::newInstance()->ignoreAcl()->order('id', 'DESC')->criteria(FindCriteria::newInstance()->addCondition('model_id', $sourceModel->id)->addCondition('model_type_id', $sourceModel->modelTypeId()));
         $stmt = \GO\Comments\Model\Comment::model()->find($findParams);
         while ($comment = $stmt->fetch()) {
             $comment->model_type_id = $this->modelTypeId();
             $comment->model_id = $this->id;
             $comment->save();
         }
     }
 }