Ejemplo n.º 1
0
 public static function save(\Rebond\Core\ModelInterface $model)
 {
     $db = new Util\Data();
     if ($model->getId() === 0) {
         $query = 'INSERT INTO core_site (`title`, `google_analytics`, `keywords`, `description`, `css`, `js`, `sign_in_url`, `environment`, `sql_log`, `timezone`, `is_cms`, `cache_time`, `use_device_template`, `skin`, `send_mail_on_error`, `mail_list_on_error`, `status`, `created_date`, `modified_date`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
         $params = [$model->getTitle(), $model->getGoogleAnalytics(), $model->getKeywords(), $model->getDescription(), $model->getCss(), $model->getJs(), $model->getSignInUrl(), $model->getEnvironment(), $model->getSqlLog(), $model->getTimezone(), $model->getIsCms(), $model->getCacheTime(), $model->getUseDeviceTemplate(), $model->getSkin(), $model->getSendMailOnError(), $model->getMailListOnError(), $model->getStatus(), $model->getCreatedDate('sqlDatetime'), Util\Format::date(time(), 'sqlDatetime')];
         $id = $db->execute($query, $params);
         $model->setId($id);
         return $id;
     } else {
         $query = 'UPDATE core_site SET ';
         $params = [];
         if ($model->getTitle() !== null) {
             $query .= '`title` = ?, ';
             $params[] = $model->getTitle();
         }
         if ($model->getGoogleAnalytics() !== null) {
             $query .= '`google_analytics` = ?, ';
             $params[] = $model->getGoogleAnalytics();
         }
         if ($model->getKeywords() !== null) {
             $query .= '`keywords` = ?, ';
             $params[] = $model->getKeywords();
         }
         if ($model->getDescription() !== null) {
             $query .= '`description` = ?, ';
             $params[] = $model->getDescription();
         }
         if ($model->getCss() !== null) {
             $query .= '`css` = ?, ';
             $params[] = $model->getCss();
         }
         if ($model->getJs() !== null) {
             $query .= '`js` = ?, ';
             $params[] = $model->getJs();
         }
         if ($model->getSignInUrl() !== null) {
             $query .= '`sign_in_url` = ?, ';
             $params[] = $model->getSignInUrl();
         }
         if ($model->getEnvironment() !== null) {
             $query .= '`environment` = ?, ';
             $params[] = $model->getEnvironment();
         }
         if ($model->getSqlLog() !== null) {
             $query .= '`sql_log` = ?, ';
             $params[] = $model->getSqlLog();
         }
         if ($model->getTimezone() !== null) {
             $query .= '`timezone` = ?, ';
             $params[] = $model->getTimezone();
         }
         if ($model->getIsCms() !== null) {
             $query .= '`is_cms` = ?, ';
             $params[] = $model->getIsCms();
         }
         if ($model->getCacheTime() !== null) {
             $query .= '`cache_time` = ?, ';
             $params[] = $model->getCacheTime();
         }
         if ($model->getUseDeviceTemplate() !== null) {
             $query .= '`use_device_template` = ?, ';
             $params[] = $model->getUseDeviceTemplate();
         }
         if ($model->getSkin() !== null) {
             $query .= '`skin` = ?, ';
             $params[] = $model->getSkin();
         }
         if ($model->getSendMailOnError() !== null) {
             $query .= '`send_mail_on_error` = ?, ';
             $params[] = $model->getSendMailOnError();
         }
         if ($model->getMailListOnError() !== null) {
             $query .= '`mail_list_on_error` = ?, ';
             $params[] = $model->getMailListOnError();
         }
         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);
     }
 }