Ejemplo n.º 1
0
 public static function save(\Rebond\Core\ModelInterface $model)
 {
     $db = new Util\Data();
     if ($model->getId() === 0) {
         $query = 'INSERT INTO cms_user_settings (user_id, `media_view`, `media_paging`, `content_paging`, `paging`) VALUES (?,?,?,?,?)';
         $params = [$model->getUserId(), $model->getMediaView(), $model->getMediaPaging(), $model->getContentPaging(), $model->getPaging()];
         $id = $db->execute($query, $params);
         $model->setId($id);
         return $id;
     } else {
         $query = 'UPDATE cms_user_settings SET ';
         $params = [];
         if ($model->getUserId() !== null) {
             $query .= 'user_id = ?, ';
             $params[] = $model->getUserId();
         }
         if ($model->getMediaView() !== null) {
             $query .= '`media_view` = ?, ';
             $params[] = $model->getMediaView();
         }
         if ($model->getMediaPaging() !== null) {
             $query .= '`media_paging` = ?, ';
             $params[] = $model->getMediaPaging();
         }
         if ($model->getContentPaging() !== null) {
             $query .= '`content_paging` = ?, ';
             $params[] = $model->getContentPaging();
         }
         if ($model->getPaging() !== null) {
             $query .= '`paging` = ?, ';
             $params[] = $model->getPaging();
         }
         $query = rtrim(trim($query), ',');
         $query .= ' WHERE id = ?';
         $params[] = $model->getId();
         return $db->execute($query, $params);
     }
 }