Ejemplo n.º 1
0
 public static function save(\Rebond\Core\ModelInterface $model)
 {
     $db = new Util\Data();
     if ($model->getId() === 0) {
         $query = 'INSERT INTO cms_gadget (page_id, component_id, `col`, filter_id, `custom_filter`, `display_order`, `status`, `created_date`, `modified_date`) VALUES (?,?,?,?,?,?,?,?,?)';
         $params = [$model->getPageId(), $model->getComponentId(), $model->getCol(), $model->getFilterId(), $model->getCustomFilter(), $model->getDisplayOrder(), $model->getStatus(), $model->getCreatedDate('sqlDatetime'), Util\Format::date(time(), 'sqlDatetime')];
         $id = $db->execute($query, $params);
         $model->setId($id);
         return $id;
     } else {
         $query = 'UPDATE cms_gadget SET ';
         $params = [];
         if ($model->getPageId() !== null) {
             $query .= 'page_id = ?, ';
             $params[] = $model->getPageId();
         }
         if ($model->getComponentId() !== null) {
             $query .= 'component_id = ?, ';
             $params[] = $model->getComponentId();
         }
         if ($model->getCol() !== null) {
             $query .= '`col` = ?, ';
             $params[] = $model->getCol();
         }
         if ($model->getFilterId() !== null) {
             $query .= 'filter_id = ?, ';
             $params[] = $model->getFilterId();
         }
         if ($model->getCustomFilter() !== null) {
             $query .= '`custom_filter` = ?, ';
             $params[] = $model->getCustomFilter();
         }
         if ($model->getDisplayOrder() !== null) {
             $query .= '`display_order` = ?, ';
             $params[] = $model->getDisplayOrder();
         }
         if ($model->getStatus() !== null) {
             $query .= '`status` = ?, ';
             $params[] = $model->getStatus();
         }
         $query .= '`modified_date` = ?, ';
         $params[] = Util\Format::date(time(), 'sqlDatetime');
         $query = rtrim(trim($query), ',');
         $query .= ' WHERE id = ?';
         $params[] = $model->getId();
         return $db->execute($query, $params);
     }
 }