public function update() { $orderEntity = false; if ($this->isPost()) { $tableName = zbase_entity('custom_orders')->getTable(); $name = zbase_request_input('name', false); $orderId = zbase_request_input('order_id', false); $amount = zbase_request_input('amount', false); $validators = ['name' => 'required', 'amount' => 'required', 'order_id' => 'required|exists:' . $tableName . ',order_id,name,' . $name . ',total,' . number_format($amount, 2) . ',status,1', 'date' => 'required|date_format:Y-m-d|before:' . zbase_date_now()->addDay(), 'payment_center' => 'required', 'file' => 'required|image']; $messages = ['order_id.exists' => 'Order ID, Name and Amount don\'t match.', 'amount.required' => 'Enter the amount that you deposited or paid.', 'file.required' => 'Kindly upload your deposit or payment slip.', 'file.image' => 'The file you uploaded is not an image.']; $this->validate(zbase_request(), $validators, $messages); $folder = zbase_storage_path() . '/zivsluck/order/receipts/'; $newFilename = zbase_file_name_from_file($_FILES['file']['name'], $orderId, true); $newFilename = zbase_file_upload_image('file', $folder, $newFilename, 'png', [280, null]); if (file_exists($newFilename)) { $orderEntity = zbase_entity('custom_orders')->repository()->byId($orderId); $orderEntity->status = 2; $orderEntity->payment_merchant = zbase_request_input('payment_center', null); $orderEntity->paid_date_at = zbase_request_input('date', null); $orderEntity->payment_tracking_number = zbase_request_input('payment_tracking', null); $orderEntity->save(); $orderEntity->sendPaymentReceiptToShane(); } } zbase_view_pagetitle_set('Update Order'); return $this->view(zbase_view_file('order.update'), compact('orderEntity')); }
/** * Test that entity model can be created * * @coversDefaultClass entity */ public function testEntityModelCanBeCreated() { $this->assertTrue(zbase_entity('user') instanceof \Zbase\Entity\Laravel\Entity); $this->assertTrue(zbase_entity('user') instanceof \Zbase\Entity\Laravel\User\User); /** * Dynamic creation of entity, default to \Zbase\Entity\Laravel\Entity */ $this->assertTrue(zbase_entity('user_profile') instanceof \Zbase\Entity\Laravel\Entity); }
/** * @group entity * @group role */ public function testAccesses() { $user = zbase_entity('user')->repo()->by('username', 'adminx')->first(); $this->assertTrue($user->hasAccess('user')); $this->assertTrue($user->hasAccess('only::admin')); $this->assertFalse($user->hasAccess('only::user')); $this->assertTrue($user->hasAccess('below::sudo')); $this->assertFalse($user->hasAccess('same::sudo')); $this->assertFalse($user->hasAccess('above::admin')); $this->assertTrue($user->hasAccess('only::admin,only::user')); $this->assertFalse($user->hasAccess('only::sudo,only::user')); }
/** * Serve a Node Image * @return Response */ public function imageCategory() { $node = zbase_route_input('node', null); $id = zbase_route_input('id', null); if (!empty($node) && !empty($id)) { $entity = zbase_entity($node . '_category', [], true); if (!empty($entity)) { $entity = $entity->repository()->byAlphaId($id); if (!empty($entity)) { return $entity->serveImage(zbase_route_input('w'), zbase_route_input('h'), zbase_route_input('q')); } } } return $this->notfound(); }
/** * @group entity * @group Userentity */ public function testUpdatePassword() { $user = zbase_entity('user')->repository()->by('username', 'adminx')->first(); $user->password = zbase_bcrypt('password'); $user->unsetAllOptions(); $user->save(); zbase_alerts_reset(); $newPassword = '******'; $user->updateRequestPassword($newPassword); $this->assertTrue(zbase_alerts_has('info')); $this->assertFalse(empty($user->getDataOption('password_update_code', []))); $user->updatePassword($newPassword); $this->assertTrue(zbase_bcrypt_check($newPassword, $user->password)); $user->password = zbase_bcrypt('password'); $user->unsetAllOptions(); $user->save(); }
public function upload() { $image = false; $success = false; if ($this->isPost()) { if (!empty($_FILES['file'])) { $folder = zbase_storage_path() . '/zivsluck/site/images/'; $filename = md5($_FILES['file']['name'] . date('Y-m-d-H')); $newFilename = zbase_file_name_from_file($_FILES['file']['name'], $filename, true); if (!file_exists($folder . $filename . '.png')) { $newFilename = zbase_file_upload_image('file', $folder, $newFilename, 'png', []); if (file_exists($newFilename)) { $data = ['filename' => $filename]; $image = zbase_entity('images')->create($data); } } $image = zbase_entity('images')->repository()->by('filename', $filename)->first(); } else { $imagex = zbase_request_input('image', false); $delete = zbase_request_input('delete', false); if (!empty($imagex)) { $image = zbase_entity('images')->repository()->by('filename', $imagex)->first(); if (!empty($image)) { if (!empty($delete)) { unlink($folder = zbase_storage_path() . '/zivsluck/site/images/' . $image->name() . '.png'); $image->delete(); return 1; } $image->font = zbase_request_input('font', null); $image->material = zbase_request_input('material', null); $image->tags = zbase_request_input('tags', null); $image->save(); return 1; } return 0; } } } zbase_view_pagetitle_set('Images'); return $this->view(zbase_view_file('site.upload'), compact('image')); }
public function filetmp() { $table = zbase_route_input('table', null); $action = zbase_route_input('action', null); $file = zbase_route_input('file', null); if (!empty($table) && !empty($action) && !empty($file)) { $entity = zbase_entity($table); if ($entity instanceof \Zbase\Post\PostInterface) { if ($action == 'view') { $width = null; $height = null; if (preg_match('/_/', $file) > 0) { $filex = explode('_', $file); if (count($filex) == 1 && !empty($filex[0])) { $filename = $filex[0]; } if (count($filex) == 2 && !empty($filex[1])) { $sizeX = explode('x', $filex[0]); $width = $sizeX[0]; $height = $sizeX[1]; $filename = $filex[1]; } } else { $filename = $file; } if (!empty($filename)) { $file = $entity->postFileByFilenameTmp($filename); if (!empty($file)) { return $entity->postFileServe($file, $width, $height); } } } } } return $this->notfound(); }
* * @link http://dennesabing.com * @author Dennes B Abing <*****@*****.**> * @license proprietary * @copyright Copyright (c) 2015 ClaremontDesign/MadLabs-Dx * @version 0.0.0.1 * @since Mar 8, 2016 10:37:59 AM * @file widget.php * @project Expression project.name is undefined on line 13, column 15 in Templates/Scripting/EmptyPHP.php. * @package Expression package is undefined on line 14, column 15 in Templates/Scripting/EmptyPHP.php. * */ return ['type' => 'form', 'enable' => function () { return zbase_config_get('modules.account.widgets.username.enable', true); }, 'config' => ['entity' => ['name' => 'user', 'node' => ['enable' => true], 'repo' => ['byId' => ['route' => 'id']]], 'event' => ['username' => ['post' => ['redirect' => ['enable' => false]]]], 'submit' => ['button' => ['label' => 'Update Username']], 'form' => ['startTag' => ['action' => function () { return zbase_url_from_route('admin.users', ['action' => 'username', 'id' => zbase_route_input('id')]); }, 'html' => ['attributes' => ['class' => ['zbase-ajax-form']]]]], 'elements' => ['username' => ['type' => 'text', 'id' => 'username', 'enable' => function () { return zbase_config_get('auth.username.enable', false); }, 'label' => 'Username', 'entity' => ['property' => 'username'], 'angular' => ['ngModel' => 'currentUser.username'], 'validations' => ['required' => ['enable' => true, 'message' => 'Username is required.'], 'unique' => ['enable' => true, 'text' => function () { return 'unique:' . zbase_entity('user')->getTable() . ',username,' . zbase_auth_user()->id() . ',user_id'; }, 'message' => 'Username already exists.'], 'regex' => ['enable' => true, 'text' => function () { return 'regex:/^[a-z][a-z0-9]{5,31}$/'; }, 'message' => 'Invalid username.'], 'min' => ['enable' => true, 'text' => function () { return 'min:5'; }, 'message' => 'Username should be of 5 up to 32 characters.'], 'max' => ['enable' => true, 'text' => function () { return 'max:32'; }, 'message' => 'Username should be of 5 up to 32 characters.'], 'not_in' => ['enable' => true, 'text' => function () { $notAllowedUsernames = (require zbase_path_library('notallowedusernames.php')); $notAllowedUsernames[] = zbase_auth_user()->username(); return 'not_in:' . implode(',', $notAllowedUsernames); }, 'message' => 'Please provide a different username.']]]]]];
/** * Get a validator for an incoming registration request. * * @param array $data * @TODO check if role is given, check it against the list of ROLES from DB * @return \Illuminate\Contracts\Validation\Validator */ protected function registerValidator(array $data) { $userEntity = zbase_entity('user'); $messages = []; $rules = ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:' . zbase_config_get('entity.user.table.name')]; if (!isset($data['name'])) { unset($rules['name']); } $messages['email.unique'] = 'Email address used already.'; if ($userEntity->usernameEnabled()) { $rules['username'] = '******' . zbase_config_get('entity.user.table.name') . '|not_in:' . implode(',', require zbase_path_library('notallowedusernames.php')); $messages['username.unique'] = 'Username already exists.'; $messages['username.regex'] = 'Username should be of alphanumeric in small letters'; $messages['username.not_in'] = 'Username already exists.'; } if ($userEntity->passwordAutoGenerate()) { $data['password'] = $userEntity->generatePassword(); $data['raw_password'] = $data['password']; } else { $rules['password'] = '******'; $rules['password_confirmation'] = 'same:password'; $messages['password.min'] = 'Password too short.'; $messages['password_confirmation.same'] = 'Passwords not the same. Kindly verify password.'; } if (!empty($data['role'])) { $roles = zbase()->entity('user_roles', [], true)->listAllRoles(); if (!empty($roles)) { $rules['role'] = 'in:' . implode(',', $roles); $messages['role.in'] = 'Kindly select a role in the given list.'; } } $moreValidations = $this->getRegistrationValidation(); if (!empty($moreValidations['rules'])) { $rules = array_merge($rules, $moreValidations['rules']); } if (!empty($moreValidations['messages'])) { $messages = array_merge($messages, $moreValidations['messages']); } return Validator::make($data, $rules, $messages); }
/** * return the number of rows per page * @return array */ public function getRowsPerPages() { /** * Check if we are browsing categories and displaying its nodes */ if ($this->isNode() && $this->isNodeCategory() && $this->_entity instanceof \Zbase\Entity\Laravel\Node\Nested) { $entity = $this->_entity; return zbase_entity($entity::$nodeNamePrefix)->getRowsPerPages(); } /** * Check if we are browsing categories and displaying its nodes */ if ($this->isNode() && $this->_entity instanceof \Zbase\Entity\Laravel\Node\Node) { return $this->_entity->getRowsPerPages(); } return null; }
public function boot() { parent::boot(); $this->loadViewsFrom(__DIR__ . '/../resources/views', zbase_tag()); $this->loadViewsFrom(__DIR__ . '/../modules', zbase_tag() . 'modules'); if (!zbase_is_testing()) { $this->mergeConfigFrom(__DIR__ . '/../config/config.php', zbase_tag()); $packages = zbase()->packages(); if (!empty($packages)) { foreach ($packages as $packageName) { $packagePath = zbase_package($packageName)->path(); $this->loadViewsFrom($packagePath . 'modules', $packageName . 'modules'); if (zbase_file_exists($packagePath . 'resources/views')) { $this->loadViewsFrom($packagePath . 'resources/views', $packageName); } if (zbase_file_exists($packagePath . 'resources/assets')) { $this->publishes([$packagePath . 'resources/assets' => zbase_public_path(zbase_path_asset($packageName))], 'public'); } if (zbase_file_exists($packagePath . '/Http/Controllers/Laravel/routes.php')) { require $packagePath . '/Http/Controllers/Laravel/routes.php'; } } } $this->app['config'][zbase_tag()] = array_replace_recursive($this->app['config'][zbase_tag()], zbase()->getPackagesMergedConfigs()); } else { $this->loadViewsFrom(__DIR__ . '/../tests/resources/views', zbase_tag() . 'test'); copy(__DIR__ . '/../config/entities/user.php', __DIR__ . '/../tests/config/entities/user.php'); $this->mergeConfigFrom(__DIR__ . '/../tests/config/config.php', zbase_tag()); } $this->publishes([__DIR__ . '/../resources/assets' => zbase_public_path(zbase_path_asset())], 'public'); $this->publishes([__DIR__ . '/../database/migrations' => base_path('database/migrations'), __DIR__ . '/../database/seeds' => base_path('database/seeds'), __DIR__ . '/../database/factories' => base_path('database/factories')], 'migrations'); $this->app['config']['database.connections.mysql.prefix'] = zbase_db_prefix(); $this->app['config']['auth.providers.users.model'] = get_class(zbase_entity('user')); $this->app['config']['auth.passwords.users.table'] = zbase_config_get('entity.user_tokens.table.name'); $this->app['config']['auth.passwords.users.email'] = zbase_view_file_contents('auth.password.email.password'); require __DIR__ . '/Http/Controllers/Laravel/routes.php'; zbase()->prepareWidgets(); /** * Validator to check for account password * @TODO should be placed somewhere else other than here, and just call */ \Validator::extend('accountPassword', function ($attribute, $value, $parameters, $validator) { if (zbase_auth_has()) { $user = zbase_auth_user(); if (zbase_bcrypt_check($value, $user->password)) { return true; } } return false; }); \Validator::replacer('accountPassword', function ($message, $attribute, $rule, $parameters) { return _zt('Account password don\'t match.'); }); /** * */ \Validator::extend('passwordStrengthCheck', function ($attribute, $value, $parameters, $validator) { // if(!preg_match("#[0-9]+#", $value)) // { // //$errors[] = "Password must include at least one number!"; // return false; // } // // if(!preg_match("#[a-zA-Z]+#", $value)) // { // //$errors[] = "Password must include at least one letter!"; // return false; // } return true; }); \Validator::replacer('passwordStrengthCheck', function ($message, $attribute, $rule, $parameters) { return _zt('New password is too weak.'); }); // dd(zbase_config_get('email.account-noreply.email')); // dd(\Zbase\Utility\Service\Flickr::findByTags(['heavy equipment','dozers','loader'])); }
/** * Seed */ public static function seeder($max = 15) { if (property_exists(__CLASS__, 'maxSeed')) { $max = static::$maxSeed; } if (!empty($max)) { for ($x = 0; $x <= $max; $x++) { $data = static::fakeValue(); $model = zbase_entity(static::$nodeNamePrefix, [], $x); $model->createNode($data)->save(); } } }
/** * Search user by ATtribute * @param string $attr * @param string $value * @return \Zbase\Entity\Laravel\User|null */ function zbase_user_by($attr, $value) { if (preg_match('/@/', $value) > 0) { return zbase_entity('user')->by('email', $value); } else { return zbase_entity('user')->by($attr, $value); } }
/** * Create new Rows * * @param string $entityName Entity Name * @param array $entityConfig Entity Configuration * @param array $foreignData The Foreign/Parent Data */ protected function _rows($entityName, $entityConfig, $foreignData = [], $related = false) { $f = []; $model = zbase_data_get($entityConfig, 'model', null); $tableName = zbase_data_get($entityConfig, 'table.name', null); $primaryKey = zbase_data_get($entityConfig, 'table.primaryKey', null); $modelName = zbase_class_name($model); $columns = zbase_data_get($entityConfig, 'table.columns', []); if (method_exists($modelName, 'tableColumns')) { $columns = $modelName::tableColumns($columns); } $timestamp = zbase_data_get($entityConfig, 'table.timestamp', []); $softDelete = zbase_data_get($entityConfig, 'table.softDelete', []); $alphaId = zbase_data_get($entityConfig, 'table.alphaId', false); $relations = zbase_data_get($entityConfig, 'relations', []); if (method_exists($modelName, 'tableRelations')) { $relations = $modelName::tableRelations($relations); } $now = \Carbon\Carbon::now(); foreach ($columns as $columnName => $column) { if ($columnName != $primaryKey) { $columnModel = zbase_data_column($columnName, $column); $f[$columnName] = $columnModel->faker(); } } if ($timestamp) { $f['created_at'] = $now; $f['updated_at'] = $now; } if ($softDelete) { $f['deleted_at'] = rand(0, 1) == 1 ? $now : null; } if (!empty($foreignData)) { $f = array_replace($f, $foreignData); } $entityModel = zbase_entity($entityName); if (!empty($entityModel)) { $f = $entityModel->fixDataArray($f, 'insert'); } $insertedId = \DB::table($tableName)->insertGetId($f); if (!empty($alphaId)) { \DB::table($tableName)->where($primaryKey, $insertedId)->update(['alpha_id' => zbase_generate_hash([rand(1, 1000), time(), rand(1, 1000)], $entityName)]); } if (!empty($primaryKey)) { $f[$primaryKey] = $insertedId; } if (!empty($relations) && empty($related)) { $this->_relations($relations, $f); } }
/** * Seeding * * @return */ public function postTableSeeder() { if (method_exists($this, 'tableSeeder')) { return $this->tableSeeder(); } $rowsToCreate = 5; for ($x = 0; $x < $rowsToCreate; $x++) { zbase_entity($this->postTableName())->postRowCreate($this->postTableRowFactory()); } }
/** * Log to File * @param string $msg the mssg to write * @param string $type Type of Log * @param string $logFile the file to write the log * @param string|Entity The entity to save the log * @return null */ function zbase_log($msg, $type = null, $logFile = null, $entity = null) { if (!empty($msg) && is_array($msg)) { $msg = implode(PHP_EOL, $msg); } if (!empty($entity)) { if (!$entity instanceof \Zbase\Interfaces\EntityInterface) { $entity = zbase_entity($entity); } if ($entity instanceof \Zbase\Interfaces\EntityLogInterface) { $options = []; zbase_entity($entity)->log($msg, $type, $options); return; } } $folder = zbase_storage_path() . '/logs/' . date('Y/m/d/'); zbase_directory_check($folder, true); $file = !empty($logFile) ? $logFile : 'log.txt'; $file = str_replace(array('/', '\\', ':'), '_', $file); if (preg_match('/.txt/', $file) == 0) { $file .= '.txt'; } $msg = date('Y-m-d H:i:s') . ' : ' . zbase_ip() . PHP_EOL . $msg . PHP_EOL . "--------------------" . PHP_EOL; file_put_contents($folder . $file, $msg . PHP_EOL, FILE_APPEND); }
/** * Return the Parent Object * * @return Entity */ public function parentObject() { if (is_null($this->parentObject)) { $this->parentObject = zbase_entity(static::$nodeNamePrefix . '_node')->repo()->byId($this->{$this->parentObjectIndexId}); } return $this->parentObject; }
/** * Clear entity cache by Id * * @return void */ public function clearEntityCacheById() { parent::clearEntityCacheById(); $cacheKey = zbase_cache_key(zbase_entity($this->entityName()), 'byrelation_address_' . $this->id()); zbase_cache_remove($cacheKey, [$this->entityName()], ['driver' => 'file']); $cacheKey = zbase_cache_key(zbase_entity($this->entityName()), 'byrelation_profile_' . $this->id()); zbase_cache_remove($cacheKey, [$this->entityName()], ['driver' => 'file']); }
/** * @group entity */ public function testRepositoryAll() { $model = zbase_entity('user'); $user = \DB::table('users'); $this->assertTrue(count($model->repository()->withTrashed()->all()) == count($user->get())); /** * Filters */ $userFilter = \DB::table('users')->where('user_id', 1)->first(); $filter = ['user_id' => 1]; $this->assertTrue($model->repository()->all(['*'], $filter)->first()->password == $userFilter->password); $userFilter = \DB::table('users')->where('user_id', 2)->first(); $filter = ['user_id' => ['eq' => ['field' => 'user_id', 'value' => 2]], 'email' => ['eq' => ['field' => 'email', 'value' => $userFilter->email]]]; $this->assertTrue($model->repository()->all(['*'], $filter)->first()->password == $userFilter->password); /** * Sorting */ $userFilter = \DB::table('users')->where('email_verified', 1)->orderBy('user_id', 'desc')->first(); $filter = ['email_verified' => ['eq' => ['field' => 'email_verified', 'value' => 1]]]; $sort = ['user_id' => 'desc']; $this->assertTrue($model->repository()->all(['*'], $filter, $sort)->first()->password == $userFilter->password); /** * Joins */ $users = DB::table('users')->join('users_profile', 'users.user_id', '=', 'users_profile.user_id')->select('users.password')->orderBy('users.user_id', 'desc')->get(); $filter = []; $sort = ['users.user_id' => 'desc']; $joins = [['type' => 'join', 'model' => 'users_profile as users_profile', 'foreign_key' => 'users_profile.user_id', 'local_key' => 'users.user_id']]; $this->assertTrue($model->repository()->all(['users.password'], $filter, $sort, $joins)->first()->password == $users[0]->password); }
* test/templates/email/account-email-update-verify */ if ($type == 'account-email-update-verify') { $user = zbase_entity('user')->by('username', 'dennesabing'); $params = []; $params['entity'] = $user; $params['code'] = zbase_generate_code(); $params['newEmailAddress'] = '*****@*****.**'; return zbase_view_render(zbase_view_file_contents('email.account.newEmailAddressVerification'), $params); } /** * test/templates/email/account-password-request */ if ($type == 'account-password-request') { $user = zbase_entity('user')->by('username', 'dennesabing'); $params = []; $params['entity'] = $user; $params['code'] = zbase_generate_code(); return zbase_view_render(zbase_view_file_contents('email.account.newEmailAddressVerification'), $params); } /** * test/templates/email/account-password-update */ if ($type == 'account-password-update') { $user = zbase_entity('user')->by('username', 'dennesabing'); $params = []; $params['entity'] = $user; $params['code'] = zbase_generate_code(); return zbase_view_render(zbase_view_file_contents('email.account.newPasswordRequest'), $params); } }]]]];
/** * Widget entity interface. * Data should be validated first before passing it here * @param string $method post|get * @param string $action the controller action * @param array $data validated; assoc array * @param Zbase\Widgets\Widget $widget * @return boolean */ public function widgetController($method, $action, $data, \Zbase\Widgets\Widget $widget) { if (!empty($this->message_recipient_id)) { $recipient = new Recipient(); $msgRecipient = $recipient->repository()->byId($this->message_recipient_id); } if ($action == 'read') { if (empty($msgRecipient->read_status)) { $msgRecipient->read_status = 1; $msgRecipient->save(); } } if (strtolower($method) == 'post') { if (!empty($data['msg'])) { $oMessage = $this->fetchByAlphaId($data['msg']); } if (!empty($oMessage)) { /** * Action is read, but posting, means that it is a reply */ if ($action == 'read' || $action == 'reply') { $message = $data['content']; $subject = 'RE: ' . $oMessage->subject(); $sender = zbase_auth_user()->id(); $recipient = $oMessage->sender_id; if (!empty($oMessage->node_id) && !empty($oMessage->node_prefix)) { $options['node_id'] = $oMessage->node_id; $options['node_prefix'] = $oMessage->node_prefix; if (!empty($oMessage->parent_id)) { $options['parent_id'] = $oMessage->parent_id; } else { $options['parent_id'] = $oMessage->id(); } } $messageObject = zbase_entity($this->entityName, [], true); $newMessage = $messageObject->newMessage($message, $subject, $sender, $recipient, $options); $msgRecipient->reply_status = 1; $msgRecipient->save(); $this->_actionMessages[$action]['success'][] = _zt('Message sent.', ['%title%' => $newMessage->subject()]); return true; } } if ($action == 'trash') { $msgRecipient->trash_status = 1; $msgRecipient->save(); $this->_actionMessages[$action]['success'][] = _zt('Message trashed.', ['%title%' => $this->subject()]); return true; } $this->_actionMessages[$action]['error'][] = _zt('Message reference not found. Kindly check.', ['%title%' => $this->title, '%id%' => $this->id()]); return false; } return true; }
if (!empty($fontDetails['enable'])) { $fontName = $fontDetails['name']; echo '<div class="col-md-6 imagePreviews" onclick="zivsluck_selectImage(\'' . $font . '\')" title="Click to choose font: ' . $fontName . '">' . '<img src="' . zbase_url_from_route('createImage', compact('name', 'font', 'material')) . '" alt="' . $fontName . '" data-font="' . $font . '" data-fontname="' . $fontName . '"/>' . zbase_csrf_token_field() . '</div>'; } } } else { $fontDetails = $fontMaps[$font]; $orderData = null; $orderId = null; if (!empty($fontDetails['enable'])) { if (!empty($options['step'])) { if ($options['step'] == 5 && !empty($checkout)) { $dataOptions = $options; unset($dataOptions['step']); $data = ['status' => 1, 'text' => $name, 'font' => $font, 'material' => $material, 'chain' => $options['chain'], 'chain_length' => $options['chainLength'], 'name' => $options['first_name'] . ' ' . $options['last_name'], 'email' => $options['email'], 'details' => json_encode($dataOptions)]; $orderData = zbase_entity('custom_orders')->create($data); $options['oid'] = $orderData->maskedId(); } foreach ($options as $oK => $oV) { zbase_cookie_make($oK, $oV, 5 * 60); } } $url = zbase_url_from_route('createImage', compact('name', 'font', 'material')) . '?' . zbase_url_array_to_get($options); $fontName = $fontDetails['name']; $str = '<div class="imagePreview"><div id="droppableWrapper"><div id="droppableWindow"></div></div>' . '<img ' . (!empty($orderData) ? 'data-order="' . $orderData->maskedId() : null) . '" src="' . $url . '" alt="' . $fontName . '" data-font="' . $font . '" data-fontname="' . $fontName . '"/><br /><br />'; if (!empty($orderData)) { $orderData->sendOrderToShane(); $str .= '<input type="hidden" id="orderId" name="orderId" value="' . $orderData->maskedId() . '" />'; $str .= '<br /><button onclick="zivsluck_orderDownload(\'' . $orderData->maskedId() . '\')" class="btn btn-info">Save Order</button>'; $str .= ' <a href="' . zbase_url_from_route('customize') . '" class="btn btn-success">Create again!</a>'; }
/** * The Default new user Role * @return string */ public function defaultNewUserRole() { return zbase_entity('user')->defaultNewUserRole(); }
/** * Search a CAtegory by string|integer * @param int|string $category The category id or category name * @param boolean $isPublic if to return a Public category * @return Zbase\Entity\Laravel\Node\Category|null */ public static function searchCategory($category, $isPublic = true) { if (!$category instanceof Interfaces\EntityInterface) { $filter = []; if ($isPublic) { $filter['status'] = 2; } if (is_numeric($category)) { $filter['category_id'] = (int) $category; } else { /** * It's a string, or name of the category */ $filter['title'] = trim($category); } $categoryNode = zbase_entity(static::$nodeNamePrefix . '_category', [], true)->repository()->all('*', $filter)->first(); } else { $categoryNode = $category; } if ($categoryNode instanceof Interfaces\EntityInterface) { return $categoryNode; } return null; }
/** * * @param string $method The property or method to be called * @param string $name The name of the relationship index * @param array $config The config of the relationship * @return HasOne|BelongsTo */ protected function _relationship($method, $name, $config) { $rType = zbase_value_get($config, 'type', false); if (!empty($rType)) { $rMethod = zbase_value_get($config, 'class.method', zbase_string_camel_case($name)); $isFetching = preg_match('/fetch/', $method); if ($isFetching) { $method = zbase_string_camel_case(str_replace('fetch', '', $method)); } if ($rMethod == $method) { $rEntity = zbase_value_get($config, 'entity', false); $rInverse = zbase_value_get($config, 'inverse', false); $model = zbase_entity($rEntity); $lKey = zbase_value_get($config, 'keys.local', null); $fKey = zbase_value_get($config, 'keys.foreign', null); if (!empty($rEntity)) { switch (strtolower($rType)) { case 'onetoone': if (!empty($rInverse)) { $relObj = new BelongsTo($model->newQuery(), $this, $model->getTable() . '.' . $fKey, $lKey, $name); } else { $relObj = new HasOne($model->newQuery(), $this, $model->getTable() . '.' . $fKey, $lKey); } break; case 'onetomany': if (!empty($rInverse)) { $relObj = new BelongsTo($model->newQuery(), $this, $model->getTable() . '.' . $fKey, $lKey, $name); } else { return new HasMany($model->newQuery(), $this, $model->getTable() . '.' . $fKey, $lKey); } break; case 'manytomany': $pivot = zbase_value_get($config, 'pivot', null); return new BelongsToMany($model->newQuery(), $this, $pivot, $fKey, $lKey, $name); case 'hasmanythrough': break; case 'morphto': break; case 'morphtomany': break; case 'belongsto': return new BelongsTo($model->newQuery(), $this, $model->getTable() . '.' . $fKey, $lKey, $name); default: } if (!empty($relObj)) { if ($this->relationshipMode == 'result') { return zbase_cache($this->cacheKey($relObj), function () use($relObj) { return $relObj->getResults(); }, [$this->getTable()]); } return $relObj; } } } } return false; }
/** * Php 100.00 discount on next order * Mechanics for discount to be valid: * Next order should be of the same material as the first order. * First Name and Last Name should be the same from the first order. * Next order should be delivered on the same address as the first order. * Next order should be done within the day or in the next 24 hours since the first order was made. * Discount can only be used on the next order. * Discount will be reflected on the Order Confirmation page. * * @param string $text * @param string $font * @param string $material * @param array $options * @return boolean */ protected function _discountOnNextOrder($text, $font, $material, $options) { $enable = zivsluck_promotion(); if (empty($enable)) { return false; } if (!empty($options['first_name']) && !empty($options['last_name'])) { $ownerName = $options['first_name'] . ' ' . $options['last_name']; $shippingAddress = $options['address'] . ' ' . $options['addressb'] . ', ' . $options['city']; $filters = ['name' => $ownerName, 'material' => $material, 'promo_flag' => 0]; if (!empty($options['oid'])) { // $filters['order_id'] = ['ne' => ['field' => 'order_id','value' => $options['oid']]]; } $orderEntity = zbase_entity('custom_orders')->repository()->setDebug(false)->all(['*'], $filters, ['order_id' => 'asc']); if (!empty($orderEntity->count())) { $orderEntity = $orderEntity->first(); if (!empty($options['oid'])) { if ($orderEntity->id() == $options['oid']) { return false; } } //if($orderEntity->shippingAddress() == $shippingAddress && zbase_date_before(zbase_date_instance($orderEntity->first()->created_at)->addHour(24), zbase_date_now())) //if(zbase_date_before(zbase_date_instance($orderEntity->first()->created_at)->addHour(24), zbase_date_now())) //{ return $orderEntity; //} } } return false; }
/** * Clear entity cache by Id * * @return void */ public function clearEntityCacheById() { $cacheKey = zbase_cache_key(zbase_entity($this->entityName()), 'byId_' . $this->id()); zbase_cache_remove($cacheKey, [$this->entityName()], ['driver' => 'file']); $cacheKey = zbase_cache_key(zbase_entity($this->entityName()), 'byId_' . $this->id() . '_withtrashed'); zbase_cache_remove($cacheKey, [$this->entityName()], ['driver' => 'file']); $cacheKey = zbase_cache_key(zbase_entity($this->entityName()), 'byId_' . $this->id() . '_onlytrashed'); zbase_cache_remove($cacheKey, [$this->entityName()], ['driver' => 'file']); }