Example #1
0
 /**
  * Only the currently loaded record will be processed by scheduler.
  *
  * $processor->scheduleOne($books, 'sendEmail'); // will delete all books
  *
  * @return Queue model (so that you can track it by ID)
  */
 function scheduleOne(\Model $model, $method = 'process')
 {
     if (!$model->loaded()) {
         throw $this->exception('Model must be loaded');
     }
     if ($model instanceof \SQL_Model) {
         $model->setActualFields(array('id', $model->title_field));
     }
     $class = get_class($model);
     $caption = $model->caption ?: $class;
     $q = $this->queue;
     $id = $model->id;
     $q->set('model_id', $id);
     $q->set('model_class', $class);
     $q->set('model_method', $method);
     $q->set('name', $method . ' ' . ' (' . $caption . ') #' . $id);
     $q->set('status', 'scheduled');
     // skip draft
     $q->saveAndUnload();
 }
Example #2
0
 /**
  * Import model fields in form.
  *
  * @param Model $model
  * @param array|string|bool $fields
  *
  * @return void|$this
  */
 public function importFields($model, $fields = UNDEFINED)
 {
     $this->model = $model;
     $this->grid = $this->owner;
     if ($fields === false) {
         return;
     }
     if (!$fields || $fields === UNDEFINED) {
         $fields = 'visible';
     }
     if (!is_array($fields)) {
         // note: $fields parameter only useful if model is SQL_Model
         $fields = $model->getActualFields($fields);
     }
     // import fields one by one
     foreach ($fields as $field) {
         $this->importField($field);
     }
     $model->setActualFields($fields);
     return $this;
 }