public static function newLog($type, $msg) { $log = new Log(); $log->type = $type; $log->msg = $msg; $log->created_time = time(); return $log->save(); }
public function actionMessage() { $model = new Log(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect($model->goal->url(['#' => 'log'])); } else { throw new ErrorException('Cannot add message'); } }
public function updateLog() { $model = Log::findOne($this->id); if (!$model) { $model = new Log(); $model->source_id = $this->id; } $model->updated = date("Y-m-d H:i:s"); return $model->save(); }
public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); $this->calculateItemsLeft($changedAttributes); $log = new Log(); if ($insert) { $log->saveDatabaseOperation('create', $this->tableName(), $this->id); } else { $log->saveDatabaseOperation('update', $this->tableName(), $this->id); } }
public function post_edit_log_event(Request $request, Log $log, LogEvent $log_event, Admin $admin) { $validation_rules = $log->getValidationRules(); $validation_messages = $admin->getValidationMessagesEditUser(); $this->validate($request, $validation_rules, $validation_messages); $log_event = $log_event->find($request->log_event_id); $log_event->name = $request->name; $arr_request = array(); $arr_request['name'] = $request->name; $log_event->save(); $log_event_id = $log_event->id; $data = $log->getDataArray($arr_request, Auth::id(), $log_event_id, $this->arr_logged_in_user); return view('log/edit_log_event_results')->with('data', $data); }
/** * @return string */ public function actionIndex() { $low_stock_items = Item::find()->where('quantity >= 1 AND quantity <= 10')->all(); $empty_stock_items = Item::find()->where('quantity = 0')->all(); $logs = Log::find()->orderBy('created_at DESC')->limit(10)->all(); return $this->render('index', ['low_stock_items' => $low_stock_items, 'empty_stock_items' => $empty_stock_items, 'logs' => $logs]); }
public static function boot() { parent::boot(); static::creating(function ($model) { $model->effectivefrom = date('Y-m-d', strtotime($model->effectivefrom)); $model->effectiveto = date('Y-m-d', strtotime($model->effectiveto)); $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::updating(function ($model) { $model->effectivefrom = date('Y-m-d', strtotime($model->effectivefrom)); $model->effectiveto = date('Y-m-d', strtotime($model->effectiveto)); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); }
public static function boot() { parent::boot(); static::creating(function ($model) { if ($model->carsubmodelid == 0) { CommissionExtraCar::where('commissionextraid', $model->commissionextraid)->where('carmodelid', $model->carmodelid)->delete(); } $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::updating(function ($model) { if ($model->carsubmodelid == 0) { CommissionExtraCar::where('id', '!=', $model->id)->where('commissionextraid', $model->commissionextraid)->where('carmodelid', $model->carmodelid)->delete(); } $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); }
public static function boot() { parent::boot(); static::creating(function ($model) { $carpreemption = CarPreemption::find($model->carpreemptionid); $model->provinceid = $carpreemption->provinceid; $model->branchid = $carpreemption->branchid; $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); $carpreemption = CarPreemption::find($model->carpreemptionid); $carpreemption->status = 2; $carpreemption->save(); }); static::updating(function ($model) { $carpreemption = CarPreemption::find($model->carpreemptionid); $model->provinceid = $carpreemption->provinceid; $model->branchid = $carpreemption->branchid; $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); $carpreemption = CarPreemption::find($model->carpreemptionid); $carpreemption->status = 0; $carpreemption->save(); }); }
public static function boot() { parent::boot(); static::creating(function ($model) { $carpayment = CarPayment::find($model->carpaymentid); $model->provinceid = $carpayment->provinceid; $model->branchid = $carpayment->branchid; $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::updating(function ($model) { $carpayment = CarPayment::find($model->carpaymentid); $model->provinceid = $carpayment->provinceid; $model->branchid = $carpayment->branchid; $model->accountingDetailReceiveAndPays()->delete(); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::deleting(function ($model) { $model->accountingDetailReceiveAndPays()->delete(); }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); }
/** * Finds the Log model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Log the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Log::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function calculateSum() { /** @var Collection $lastSuccessCollection */ $lastSuccessCollection = Collection::find()->where(['is_fulfilled' => true])->orderBy(['date' => SORT_DESC])->limit(1)->one(); if (is_null($lastSuccessCollection)) { return Log::calculateSum(); } return Log::calculateSum($lastSuccessCollection->date); }
/** * Updates an existing Equipment model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $model->room_id = $model->location->room_id; if ($model->load(Yii::$app->request->post()) && $model->save()) { //Las siguientes líneas de código almacenan en la tabla Log información de acerca de las actualizaciones en los equipos $modelLog = new Log(); $modelLog->user_id = Yii::$app->user->id; $modelLog->date = new \yii\db\Expression('NOW()'); $modelLog->log_type_id = 3; $modelLog->equipment_id = $model->id; $modelLog->location_id = $model->location_id; $modelLog->equipment_status_id = $model->equipment_status_id; $modelLog->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }
/** * Given the test category name we return the test category ID * * @param $testcategory - the name of the test category */ public static function getTestCatIdByName($testCategory) { try { $testCatId = TestCategory::where('name', 'like', $testCategory)->firstOrFail(); return $testCatId->id; } catch (ModelNotFoundException $e) { Log::error("The test category ` {$testCategory} ` does not exist: " . $e->getMessage()); //TODO: send email? return null; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Log::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'equipment_id' => $this->equipment_id, 'user_id' => $this->user_id, 'status_id' => $this->status_id, 'date' => $this->date, 'room_id' => $this->room_id, 'log_type_id' => $this->log_type_id]); $query->andFilterWhere(['like', 'location', $this->location]); return $dataProvider; }
/** * @return string */ protected function getArticleAttribute() { $path = $this->path; $file = $this->file; try { return app('files')->get("{$path}/{$file}"); } catch (\Exception $e) { \Log::error($e->getMessage()); } return ''; }
public static function boot() { parent::boot(); static::creating(function ($model) { if ($model->isadmin) { $model->branchid = null; $model->departmentid = null; $model->teamid = null; } else { if ($model->branchid == '') { $model->branchid = null; } if ($model->departmentid == '') { $model->departmentid = null; } if ($model->teamid == '') { $model->teamid = null; } } $model->password = bcrypt("nissanhippro"); $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::updating(function ($model) { if ($model->isadmin) { $model->branchid = null; $model->departmentid = null; $model->teamid = null; } else { if ($model->branchid == '') { $model->branchid = null; } if ($model->departmentid == '') { $model->departmentid = null; } if ($model->teamid == '') { $model->teamid = null; } } $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); }
/** * Handle an authentication attempt. * * @return Response */ public function authenticate(Request $request) { $email = Input::get('email'); $password = Input::get('password'); $remember = Input::get('remember'); if (Auth::attempt(['email' => $email, 'password' => $password], $remember)) { Log::create(['action' => '登录系统', 'userid' => Auth::user()->id, 'username' => Auth::user()->name]); return redirect()->intended('orders'); } return Redirect::to('/auth/login')->with('errors', array($this->loginUsername() => '用户名或密码错误')); }
public function passportDecline($id, $log) { $user = User::findOrFail($id); $profile = $user->profile; $profile->confirmed_passport = false; $profile->passport = null; $profile->save(); $log = Log::findOrFail($log); LogMapper::reviewed($log); return Redirect::back(); }
public static function type($type, $onlyFresh = true, $limit = 50) { if (is_string($type)) { $type = [$type]; } $logs = Log::whereIn('type', $type); if ($onlyFresh) { $logs->where('review_date', null); } $logs = $logs->paginate($limit); return $logs; }
public static function boot() { parent::boot(); static::creating(function ($model) { $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); if ($model->isheadquarter) { for ($i = 1; $i <= $model->keyslot; $i++) { $m = new KeySlot(); $m->provinceid = $model->provinceid; $m->no = $i; $m->active = true; $m->save(); } } }); static::updating(function ($model) { $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); if ($model->isheadquarter) { $max = KeySlot::where('provinceid', $model->provinceid)->max('no'); if ($max == null) { $max = 0; } if ($model->keyslot > $max) { for ($i = $max + 1; $i <= $model->keyslot; $i++) { $m = new KeySlot(); $m->provinceid = $model->provinceid; $m->no = $i; $m->active = true; $m->save(); } } elseif ($model->keyslot < $max) { KeySlot::where('provinceid', $model->provinceid)->where('no', '>', $model->keyslot)->delete(); } } }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); if ($model->isheadquarter) { KeySlot::where('provinceid', $model->provinceid)->delete(); } }); }
public function actionIndex() { $data = Log::find()->orderBy('time DESC'); $pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '10']); $model = $data->offset($pages->offset)->limit($pages->limit)->all(); if ($page = \Yii::$app->request->get('page')) { if (intval(ceil($data->count() / 10)) < $page) { return false; } return $this->renderAjax('_list', ['model' => $model]); } return $this->render('index', ['model' => $model]); }
public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); $oLog = new Log(); $oLog->message = $this->log_message; $oLog->goal_id = $this->id; $aChanged = []; foreach ($changedAttributes as $sName => $sVal) { $mNewVal = $this->getAttribute($sName); if (is_int($sVal)) { $mNewVal = (int) $mNewVal; } if ($sVal != $this->getAttribute($sName)) { $aChanged[$sName] = [$sVal, $mNewVal]; } } if (isset($aChanged['updated_at'])) { unset($aChanged['updated_at']); } $oLog->data = json_encode($aChanged); $oLog->save(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Log::find()->orderBy(['id' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 200]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'login', $this->login])->andFilterWhere(['like', 'action', $this->action])->andFilterWhere(['like', 'date', $this->date]); return $dataProvider; }
public static function boot() { parent::boot(); static::creating(function ($model) { $model->issold = false; $model->isregistered = false; $model->isdelivered = false; $model->dodate = date('Y-m-d', strtotime($model->dodate)); $model->receiveddate = date('Y-m-d', strtotime($model->receiveddate)); $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); $rs = DB::select('call running_number("' . $model->provinceid . date("Y") . '","' . $model->receivetype . '")'); $model->no = $rs[0]->no; $min = KeySlot::where('provinceid', $model->provinceid)->where('active', true)->min('no'); if ($min == null) { $branch = Branch::where('provinceid', $model->provinceid)->where('isheadquarter', true)->first(); $branch->keyslot = $branch->keyslot + 1; $branch->save(); $model->keyno = $branch->keyslot; } else { $model->keyno = $min; } $model->save(); KeySlot::where('provinceid', $model->provinceid)->where('no', $model->keyno)->update(['active' => false]); }); static::updating(function ($model) { $model->dodate = date('Y-m-d', strtotime($model->dodate)); $model->receiveddate = date('Y-m-d', strtotime($model->receiveddate)); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); if ($model->receivecarfilepath != '') { File::delete(public_path() . $model->receivecarfilepath); } if ($model->deliverycarfilepath != '') { File::delete(public_path() . $model->deliverycarfilepath); } KeySlot::where('provinceid', $model->provinceid)->where('no', $model->keyno)->update(['active' => true]); }); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Log::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'goal_id' => $this->goal_id]); $query->andFilterWhere(['like', 'data', $this->data])->andFilterWhere(['like', 'message', $this->message])->andFilterWhere(['like', 'created_at', $this->created_at]); return $dataProvider; }
/** * Return field ID given the name * @param $name the name of the field */ public static function idByName($name = NULL) { if ($name) { try { $field = Field::where('field_name', $name)->orderBy('field_name', 'asc')->firstOrFail(); return $field->id; } catch (ModelNotFoundException $e) { Log::error("The field ` {$name} ` does not exist: " . $e->getMessage()); //TODO: send email? return null; } } else { return null; } }
public static function boot() { parent::boot(); static::updating(function ($model) { if ($model->returncashpledgedate != null && $model->returncashpledgedate != '') { $model->returncashpledgedate = date('Y-m-d', strtotime($model->returncashpledgedate)); } else { $model->returncashpledgedate = null; } $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); }
public static function boot() { parent::boot(); static::creating(function ($model) { if ($model->occupationid == '') { $model->occupationid = null; } if ($model->districtid == '') { $model->districtid = null; } if ($model->amphurid == '') { $model->amphurid = null; } if ($model->addprovinceid == '') { $model->addprovinceid = null; } $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::updating(function ($model) { if ($model->occupationid == '') { $model->occupationid = null; } if ($model->districtid == '') { $model->districtid = null; } if ($model->amphurid == '') { $model->amphurid = null; } if ($model->addprovinceid == '') { $model->addprovinceid = null; } $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); }
public function log(Request $request, $code) { header('Access-Control-Allow-Origin:*'); # Check if there is a running log $current = Log::where('employee_code', $code)->where('image_out', '')->first(); $image = $request->get('image'); if (empty($current)) { # Create time in $log = new Log(['image_in' => $image]); Employee::where('code', $code)->first()->logs()->save($log); } else { # Create time out $log = Log::where('id', $current->id)->first(); $log->image_out = $image; $log->save(); } $this->dispatch(new NotifyJob($log)); return $log; }