Example #1
0
 /**
  * Prepare create-table action
  *
  * @param Model $model
  *
  * @return void
  */
 function createTable(\Model $model)
 {
     if ($this->is_default_id_field) {
         // default ID field
         $type = 'integer';
         $auto = '';
     } else {
         // custom ID field
         $field = $model->getElement($model->id_field);
         $type = $this->mapFieldType($field);
         $auto = '';
     }
     // register action
     $this->actions['create-table'] = array('template' => $this->templates['create-table'], 'tags' => array('table' => $model->table, 'field' => $model->id_field, 'type' => $type, 'auto_incr' => $auto, 'engine' => $this->engine));
 }
Example #2
0
 /**
  * @return string
  */
 public function calculateSubQuery()
 {
     if (!$this->model) {
         $this->getModel();
         //$this->model=$this->add($this->model_name);
     }
     /** @type SQL_Model $this->model */
     if ($this->display_field) {
         $title = $this->model->dsql()->del('fields');
         $this->model->getElement($this->display_field)->updateSelectQuery($title);
     } elseif ($this->model->hasMethod('titleQuery')) {
         $title = $this->model->titleQuery();
     } else {
         // possibly references non-sql model, so just display field value
         return $this->owner->dsql()->bt($this->short_name);
     }
     $title->del('order')->where($this, $title->getField($this->model->id_field));
     return $title;
 }
Example #3
0
 /**
  * Produces expression which calculates full URL of image
  * 
  * @param Model $m
  * @param DSQL $q
  *
  * @return DSQL
  */
 function getURLExpr($m, $q)
 {
     return $q->concat(@$m->api->pm->base_path, $m->getElement('dirname'), "/", $m->getElement('filename'));
 }
Example #4
0
 /**
  * Produces expression which calculates full URL of image
  * 
  * @param Model $m
  * @param DSQL $q
  *
  * @return DSQL
  */
 function getURLExpr($m, $q)
 {
     return $q->concat(@$m->api->pm->base_path, "websites", "/", $m->app->current_website_name, "/", $m->getElement('dirname'), "/", $m->getElement('filename'));
 }
Example #5
0
 /**
  * Will apply conditions defined inside $m onto query $q.
  *
  * @param Model            $m
  * @param \atk4\dsql\Query $q
  *
  * @return \atk4\dsql\Query
  */
 public function initQueryConditions($m, $q)
 {
     if (!isset($m->conditions)) {
         // no conditions are set in the model
         return $q;
     }
     foreach ($m->conditions as $cond) {
         // Options here are:
         // count($cond) == 1, we will pass the only
         // parameter inside where()
         if (count($cond) == 1) {
             $q->where($cond[0]);
             continue;
         }
         if (is_string($cond[0])) {
             $cond[0] = $m->getElement($cond[0]);
         }
         if (count($cond) == 2) {
             if ($cond[0] instanceof Field) {
                 $cond[1] = $this->typecastSaveField($cond[0], $cond[1]);
             }
             $q->where($cond[0], $cond[1]);
         } else {
             if ($cond[0] instanceof Field) {
                 $cond[2] = $this->typecastSaveField($cond[0], $cond[2]);
             }
             $q->where($cond[0], $cond[1], $cond[2]);
         }
     }
     return $q;
 }