public function create($input) { $primaryKeys = $this->getPrimaryKeys(); $existingModel = $this->find($input); if (!empty($existingModel)) { return $this->update($existingModel, $input); } foreach ($primaryKeys as $primaryKey) { if (!array_key_exists($primaryKey, $input)) { return null; } } $modelClass = $this->getModelClassName(); $now = \DateTimeHelper::now(); if (!array_key_exists('created_at', $input)) { $input['created_at'] = $now; } $input['updated_at'] = $now; \DB::table($modelClass::getTableName())->insert($input); return $this->find($input); }
public function actionCreateGroup() { /* validate all query string param */ $model = new Group('create'); $fileModel = new FileUploadFormModel(); $fileModel->setScenario(FileUploadFormModel::FILE_UPLOAD_MODE_SINGLE); /*define the required variable for the controller base on the query string param */ if (isset($_POST['Group'])) { $model->setAttributes($_POST['Group']); //$fileHandler->LoadUploadedeImageToModel(); //$model->photos = $fileHandler->photos; //$model->photos = CUploadedFile::getInstancesByName(BSMultiFileUploadWidget::fieldName); if ($model->validate()) { $fileModel->LoadUploadedeImage(); if ($fileModel->isUploadedFile()) { if ($fileModel->validate()) { $SavedFileRelativePaths = $fileModel->processImage(get_class($model), $model->group_name, md5(DateTimeHelper::now())); $model->apply_img = ArrayHelper::array2string($SavedFileRelativePaths); if ($model->save()) { $model->addOwnerUser(Yii::app()->user->id); Yii::app()->user->setFlash(FlashMsg::SUCCESS, "已提交組織申請"); $this->redirect(array('index')); } else { Yii::app()->user->setFlash(FlashMsg::ERROR, "提交組織申請失敗"); } } } else { if ($model->save()) { $model->addOwnerUser(Yii::app()->user->id); Yii::app()->user->setFlash(FlashMsg::SUCCESS, "已提交組織申請"); $this->redirect(array('index')); } else { Yii::app()->user->setFlash(FlashMsg::ERROR, "提交組織申請失敗"); } } } } $this->render('createGroup', array('model' => $model, 'fileModel' => $fileModel)); }
/** @private-command-method */ private function addUserViewedIllust($userId) { $relation = new UserViewedIllust(); $relation->illust_id = $this->id; $relation->user_id = $userId; $relation->url_referrer = Yii::app()->request->urlReferrer; $relation->view_datetime = DateTimeHelper::now(); $relation->count = 1; $relation->save(); }
/** @relation-command */ public function addOwnerUser($userID) { $relation = new UserMemberGroup(); $relation->user_id = $userID; $relation->group_id = $this->id; $relation->joinded_datetime = DateTimeHelper::now(); $relation->is_leader = 1; // remember to use 1 for boolean, using true will not make this record saving $relation->is_approved = 1; $relation->save(); }
public function actionJoinGroup() { if (!isset($_POST['id'])) { throw new CHttpException(404, 'The requested page does not exist.'); } $groupIdToJoin = $_POST['id']; $model = $this->loadModel($groupIdToJoin); if ($model->isUserJoined(Yii::app()->user->id)) { /** unexpected that user can call this action if it is either joined or pending*/ throw new CHttpException(404, 'The requested page does not exist.'); } $relation = new UserMemberGroup(); $relation->user_id = Yii::app()->user->id; $relation->group_id = $model->id; $relation->joinded_datetime = DateTimeHelper::now(); $relation->is_leader = 0; // remember to use 1 for boolean, using true will not make this record saving $relation->is_approved = $model->isAutoApprove(); if ($relation->save()) { $this->redirect(Yii::app()->request->urlReferrer); } }
/** * @return string */ private function getNewVersionNumber() { return \DateTimeHelper::now()->format('U'); }
/** @callback */ protected function beforeSave() { if ($this->isNewRecord) { $this->password = $this->createPassword(); $this->created_datetime = DateTimeHelper::now(); } elseif ($this->pwdChanged) { $this->password = $this->createPassword(); } return parent::beforeSave(); }