/** * Creates an Audit isntance based on the current enviroment * * @param string $type * @param \Phalcon\Mvc\ModelInterface $model * @return Audit */ public function createAudit($type, ModelInterface $model) { //Skip if it is cli if ($model->getDI()->has('isCli')) { return; } //Get the session service $auth = $model->getDI()->getAuth(); if (!empty($auth->getUserId())) { //Get the request service $request = $model->getDI()->getRequest(); $random = new Random(); $audit = new Audit(); $audit->setId($random->uuid()); $audit->setUserId($auth->getUserId()); //The model who performed the action $audit->setModelname(get_class($model)); //The client IP address $audit->setIpaddress(ip2long($request->getClientAddress())); //Action is an update $audit->setType($type); //Current time $audit->setCreatedAt(date('Y-m-d H:i:s')); return $audit; } }
protected function processUpload(ModelInterface $model) { /* @var $request \Phalcon\Http\Request */ $request = $model->getDI()->getRequest(); if ($request->hasFiles(true)) { foreach ($request->getUploadedFiles() as $file) { if ($file->getKey() != $this->imageField || !in_array($file->getType(), $this->allowedFormats)) { continue; } $uniqueFileName = time() . '-' . uniqid() . '.' . strtolower($file->getExtension()); if (!file_exists($this->uploadPath)) { mkdir($this->uploadPath, 0755, true); } $file_name = rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $uniqueFileName; if (!$file->moveTo($file_name)) { if (!(file_exists($file->getTempName()) && copy($file->getTempName(), $file_name))) { return $this; } } $model->writeAttribute($this->imageField, $uniqueFileName); // Delete old file $this->processDelete(); } } }
/** * Creates an Audit isntance based on the current enviroment * * @param string $type * @param \Phalcon\Mvc\ModelInterface $model * @return Audit */ public function createAudit($type, ModelInterface $model) { //Get the session service $session = $model->getDI()->getSession(); //Get the request service $request = $model->getDI()->getRequest(); $audit = new Audit(); //Get the username from session $audit->user_name = $session->get('userName'); //The model who performed the action $audit->model_name = get_class($model); //The client IP address $audit->ipaddress = $request->getClientAddress(); //Action is an update $audit->type = $type; //Current time $audit->created_at = date('Y-m-d H:i:s'); return $audit; }
/** * Creates an Audit isntance based on the current enviroment * * @param string $type * @param \Phalcon\Mvc\ModelInterface $model * @return Audit */ public function createAudit($type, ModelInterface $model) { // Get the authentication service $auth = $model->getDI()->getAuth(); // Get the request service $request = $model->getDI()->getRequest(); $audit = new Audit(); //Get the user id from session through the auth service $audit->usersId = $auth->getId(); //The model who performed the action $audit->model_name = get_class($model); //The client IP address $audit->ipaddress = $request->getClientAddress(); //Action is an update $audit->type = $type; //Current time $audit->created_at = date('Y-m-d H:i:s'); return $audit; }
protected function processUpload($media, ModelInterface $model) { $request = $model->getDI()->getRequest(); if (true == $request->hasFiles(true)) { foreach ($request->getUploadedFiles() as $file) { $key = $file->getKey(); $type = $file->getType(); // Check extension allowed if (!in_array($type, $this->allowedFormats)) { throw new \Exception(sprintf('File %s has invalid extension. Allowable only: %s', $file->getName(), str_replace('image/', ' ', implode(',', $this->allowedFormats)))); } // Check allowed min size $this->checkMinSize($file, $this->allowMinSize); // Check allowed max size $this->checkMaxsize($file, $this->allowMaxSize); // Create full path image $fullPath = rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath; // Check upload directory if (is_writable($fullPath) === false) { throw new \Exception(sprintf('The specified directory %s is not writable', $fullPath)); } if ($key != $this->imageField) { continue; } $uniqueFileName = md5($file->getName()) . '-' . uniqid() . '.' . strtolower($file->getExtension()); $fullPath .= $uniqueFileName; if ($file->moveTo($fullPath)) { $model->writeAttribute($this->imageField, $this->datePath . $uniqueFileName); // Resize images big $myImageResize = new ImageResize(rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $uniqueFileName, rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $uniqueFileName, $media->imageMaxWidth, $media->imageMaxHeight, '', $media->imageQuality); $myImageResize->output(); unset($myImageResize); // Resize images medium $nameMediumPart = substr($uniqueFileName, 0, strrpos($uniqueFileName, '.')); $nameMedium = $nameMediumPart . '-medium.' . strtolower($file->getExtension()); $myImageResize = new ImageResize(rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $uniqueFileName, rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $nameMedium, $media->imageMediumWidth, $media->imageMediumHeight, '', $media->imageQuality); $myImageResize->output(); unset($myImageResize); // Resize images small $nameThumbPart = substr($uniqueFileName, 0, strrpos($uniqueFileName, '.')); $nameThumb = $nameThumbPart . '-small.' . strtolower($file->getExtension()); $myImageResize = new ImageResize(rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $uniqueFileName, rtrim($this->uploadPath, '/\\') . DIRECTORY_SEPARATOR . $this->datePath, $nameThumb, $media->imageThumbWidth, $media->imageThumbHeight, '', $media->imageQuality); $myImageResize->output(); unset($myImageResize); // Delete old file $this->processDelete(); } } } return $this; }