예제 #1
0
 public function saveContent($model)
 {
     $model->removeSpecialAtt();
     $model->user_id = 1;
     $model->user_name = 'admin';
     $model->publish_time = TTimeHelper::getCurrentTime();
     $model->modify_time = TTimeHelper::getCurrentTime();
     $model->title_format = CommonUtility::getTitleFormatValue($model->title_format);
     $model->flag = CommonUtility::getFlagValue($model->flag);
     $uploadedFile = CommonUtility::uploadFile('Content[title_pic]');
     if ($uploadedFile != null) {
         $model->title_pic = $uploadedFile['url'] . $uploadedFile['new_name'];
     }
     if ($model->title_pic == null || empty($model->title_pic)) {
         $model->is_pic = 0;
     } else {
         $model->is_pic = 1;
     }
     if ($model->views == null) {
         $model->views = 0;
     }
     if ($model->commonts == null) {
         $model->commonts = 0;
     }
     if ($model->summary == null || empty($model->summary)) {
         $content = strip_tags($model->content);
         $pattern = '/\\s/';
         //去除空白
         $content = preg_replace($pattern, '', $content);
         $model->summary = TStringHelper::subStr($content, 250);
     }
     $command = LuLu::createCommand();
     if ($model->isNewRecord) {
         $command->insert($this->currentTableName, $model);
     } else {
         $command->update($this->currentTableName, $model, ['id' => $model['id']]);
     }
     $command->execute();
 }
예제 #2
0
 public static function buildContentQuery($tableName, $other = [], $where = null)
 {
     $query = new Query();
     if (isset($other['fields'])) {
         $query->select($other['fields']);
     }
     if (empty($tableName)) {
         // todo
         $tableName = 'model_news';
     }
     $query->from($tableName);
     if ($where !== null) {
         $query->andWhere($where);
     }
     if (isset($other['where'])) {
         $query->andWhere($other['where']);
     }
     if (isset($other['att1']) && is_integer($other['att1'])) {
         $query->andWhere(['att1' => $other['att1']]);
     }
     if (isset($other['att2']) && is_integer($other['att2'])) {
         $query->andWhere(['att2' => $other['att2']]);
     }
     if (isset($other['att3']) && is_integer($other['att3'])) {
         $query->andWhere(['att3' => $other['att3']]);
     }
     if (isset($other['flag'])) {
         $flagValue = CommonUtility::getFlagValue($other['flag']);
         if ($flagValue > 0) {
             $query->andWhere('flag&' . $flagValue . '>0');
         }
     }
     if (isset($other['is_pic']) && $other['is_pic']) {
         $query->andWhere(['is_pic' => 1]);
     }
     if (isset($other['order'])) {
         $query->orderBy($other['order']);
     } else {
         $query->orderBy('publish_time desc');
     }
     if (isset($other['offset'])) {
         $query->offset(intval($other['offset']));
     } else {
         $query->offset(0);
     }
     if (isset($other['limit'])) {
         $query->limit(intval($other['limit']));
     } else {
         $query->limit(10);
     }
     return $query;
 }