Ejemplo n.º 1
0
 /**
  * Return the position
  *
  * @return integer
  */
 public function getPosition()
 {
     if (is_null($this->position)) {
         $attributes = [];
         if (method_exists($this, 'getAttributes')) {
             $attributes = $this->getAttributes();
         }
         $this->position = zbase_data_get($attributes, 'position', 0);
     }
     return $this->position;
 }
Ejemplo n.º 2
0
/**
 * Render The Module Contents
 * @param array $contents
 * @return html
 */
function zbase_module_widget_render_contents($contents, $groupId = null)
{
    $str = [];
    if (!empty($contents)) {
        foreach ($contents as $content) {
            $gId = !empty($content['groupId']) ? $content['groupId'] : null;
            if (!empty($groupId) && !empty($gId)) {
                if ($gId == $groupId) {
                    $str[] = zbase_data_get($content, 'content', null);
                }
                continue;
            }
            $str[] = zbase_data_get($content, 'content', null);
        }
    }
    return implode(PHP_EOL, $str);
}
Ejemplo n.º 3
0
 /**
  * @return void
  * @test
  */
 public function testzbase_data_get()
 {
     $config = ['key' => ['keyTwo' => ['keyThree' => ['keyFour' => 'keyFourValue']]]];
     $this->assertEquals('keyFourValue', zbase_data_get($config, 'key.keyTwo.keyThree.keyFour'));
     $this->assertSame(['keyThree' => ['keyFour' => 'keyFourValue']], zbase_data_get($config, 'key.keyTwo'));
     // Test configReplace
     $arrOne = ['template' => ['someTag' => ['configReplace' => 'view.template.otherTag', 'front' => ['package' => 'someThemePackage', 'theme' => 'someThemeName']], 'otherTag' => ['front' => ['package' => 'someOtherTagThemePackage', 'theme' => 'someOtherTagThemeName']]]];
     zbase_config_set('view', $arrOne);
     $expected = ['front' => ["package" => "someOtherTagThemePackage", "theme" => "someOtherTagThemeName"]];
     $this->assertSame($expected, zbase_config_get('view.template.someTag'));
     // Test configMerge
     $arrOne = ['template' => ['someTag' => ['configMerge' => 'view.template.otherTag', 'front' => ['package' => 'someThemePackage', 'theme' => 'someThemeName']], 'otherTag' => ['front' => ['package' => 'someOtherTagThemePackage', 'theme' => 'someOtherTagThemeName']]]];
     zbase_config_set('view', $arrOne);
     $expected = ['front' => ["package" => ["someThemePackage", "someOtherTagThemePackage"], "theme" => ["someThemeName", "someOtherTagThemeName"]]];
     $this->assertSame($expected, zbase_config_get('view.template.someTag'));
     // Test inheritedValue
     $arrOne = ['template' => ['someTag' => ['front' => ['package' => 'someThemePackage', 'theme' => 'inheritValue::view.template.otherTag.front.theme']], 'otherTag' => ['front' => ['package' => 'someOtherTagThemePackage', 'theme' => 'someOtherTagThemeName']]]];
     zbase_config_set('view', $arrOne);
     $this->assertSame('someOtherTagThemeName', zbase_config_get('view.template.someTag.front.theme'));
 }
Ejemplo n.º 4
0
/**
 * Create a route
 * @param string $name The Route Name
 * @param array $route The Route configuration
 * @return Response
 */
function zbase_route_response($name, $route)
{
    if (!empty(zbase_is_maintenance())) {
        return zbase_response(view(zbase_view_file('maintenance')));
    }
    $redirect = zbase_value_get($route, 'redirect', false);
    if (!empty($redirect)) {
        return redirect()->to($redirect);
    }
    $response = zbase_value_get($route, 'response', false);
    if (!empty($response)) {
        return $response;
    }
    /**
     * If we are using username in routes,
     * 	we have to check if the username exists in DB.
     * 	This is checked in zbase_route_username_get()
     * 	if the zbase_route_username_get() returns false, means
     * 	that the route is not a username or username didn't exists.
     * 	Here we check against all other Routes  if the prefix is in our
     * 	list of routes, if not found, throw NotFoundHttpException
     */
    $useUsernameRoute = zbase_route_username();
    $usernameRoute = zbase_route_username_get();
    $usernameRouteCheck = zbase_data_get($route, 'usernameRouteCheck', true);
    if (empty($usernameRouteCheck)) {
        /**
         * Will not check for username route
         */
        $useUsernameRoute = false;
    }
    //if($usernameRoute === false && !empty($useUsernameRoute))
    if ($name == 'index' && zbase_auth_has() && !empty($useUsernameRoute)) {
        return redirect()->to('/' . zbase_auth_real()->username);
    }
    if ($usernameRoute === false && !empty($useUsernameRoute)) {
        $uri = zbase_url_uri();
        $adminKey = zbase_admin_key();
        if (!empty($uri)) {
            $uriEx = explode('/', $uri);
            if (!empty($uriEx)) {
                foreach ($uriEx as $uriV) {
                    if (!empty($uriV)) {
                        /**
                         * If it isn't an admin key, check it against given Routes
                         */
                        if ($uriV !== $adminKey) {
                            $routes = zbase_config_get('routes', []);
                            if (!empty($routes)) {
                                foreach ($routes as $rName => $r) {
                                    if (!empty($r['enable']) && !empty($r['url'])) {
                                        $urlEx = explode('/', $r['url']);
                                        if (!empty($urlEx)) {
                                            foreach ($urlEx as $urlExV) {
                                                if (!empty($urlExV)) {
                                                    if ($uriV == $urlExV) {
                                                        /**
                                                         * Found it, valid URL
                                                         */
                                                        $validUrlPrefix = true;
                                                    }
                                                    /**
                                                     * Will deal only with the first not empty value so break it.
                                                     */
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    if (!empty($validUrlPrefix)) {
                                        /**
                                         * Found it, break it
                                         */
                                        $name = $rName;
                                        $route = $r;
                                        break;
                                    }
                                }
                            }
                        } else {
                            return redirect(zbase_url_from_route('home'));
                        }
                        /**
                         * Will deal only with the first not empty value so break it.
                         */
                        break;
                    }
                }
                if (empty($validUrlPrefix)) {
                    /**
                     * Only if routeName is not the index
                     */
                    if ($name != 'index') {
                        // $response = new \Zbase\Exceptions\NotFoundHttpException();
                        // return $response->render(zbase_request(), $response);
                    }
                }
            }
        }
    }
    $usernameRoutePrefix = zbase_route_username_prefix();
    $originalRouteName = str_replace($usernameRoutePrefix, '', $name);
    zbase()->setCurrentRouteName($name);
    $guest = true;
    $authed = false;
    $guestOnly = false;
    $middleware = !empty($route['middleware']) ? $route['middleware'] : false;
    $backend = !empty($route['backend']) ? $route['backend'] : false;
    if ($name == 'password-reset' && zbase_auth_has()) {
        \Auth::guard()->logout();
        return redirect(zbase_url_from_current());
    }
    if (!empty($backend)) {
        //		zbase_in_back();
    }
    if (preg_match('/\\?usernameroute/', zbase_url_uri()) > 0 && !empty($useUsernameRoute) && zbase_auth_has()) {
        return redirect()->to('/' . zbase_auth_user()->username() . '/home');
    }
    if (!empty($useUsernameRoute) && zbase_auth_has() && $usernameRoute != zbase_auth_user()->username()) {
        return redirect(zbase_url_from_route($originalRouteName, [$usernameRoutePrefix => zbase_auth_user()->username()]));
    }
    if (!empty($middleware)) {
        if (is_array($middleware)) {
            $access = isset($middleware['access']) ? $middleware['access'] : false;
            if (!empty($access) && is_array($access)) {
                if (!zbase_auth_has()) {
                    zbase_session_set('__loginRedirect', zbase_url_from_current());
                    return redirect(zbase_url_from_route('login'));
                }
                if (zbase_auth_has() && !zbase_auth_is($access)) {
                    return zbase_abort(401, ucfirst($access) . ' is needed to access the page.');
                }
            } else {
                $guest = isset($middleware['guest']) ? $middleware['guest'] : false;
                $authed = isset($middleware['auth']) ? $middleware['auth'] : false;
                $adminAuthed = isset($middleware['admin']) ? $middleware['admin'] : false;
                if ($adminAuthed) {
                    $authed = true;
                }
                $guestOnly = isset($middleware['guestOnly']) ? $middleware['guestOnly'] : false;
            }
        }
    }
    if (empty($access)) {
        if (!empty($backend)) {
            if (!empty($usernameRoute)) {
                /**
                 * If user is loggedIn and this is admin side and this is not logIn page,
                 * redirect to users dashboard.
                 * User can only access his own dashboard via /{usernameroute?}/admin
                 */
                if (zbase_auth_has() && zbase_auth_is(zbase_route_username_minimum_access()) && zbase_is_back() && $usernameRoute != zbase_auth_user()->username()) {
                    return redirect(zbase_url_from_route('admin', [$usernameRoutePrefix => zbase_auth_user()->username]));
                }
                if ((empty(zbase_auth_has()) || !zbase_auth_is('user')) && $name != $usernameRoutePrefix . 'admin.login') {
                    zbase_session_set('__loginRedirect', zbase_url_from_current());
                    return redirect(zbase_url_from_route('admin.login'));
                }
            } else {
                if ((empty(zbase_auth_has()) || !zbase_auth_is('admin')) && $name != 'admin.login') {
                    zbase_session_set('__loginRedirect', zbase_url_from_current());
                    return redirect(zbase_url_from_route('admin.login'));
                }
            }
        } else {
            if (!empty($guestOnly) && zbase_auth_has()) {
                return redirect(zbase_url_from_route('home'));
            }
            if (!empty($usernameRoute)) {
                if (!empty($authed) && !zbase_auth_has() && $name != $usernameRoutePrefix . 'login') {
                    zbase_session_set('__loginRedirect', zbase_url_from_current());
                    return redirect(zbase_url_from_route('login'));
                }
            } else {
                if (!empty($authed) && !zbase_auth_has() && $name != 'login') {
                    zbase_session_set('__loginRedirect', zbase_url_from_current());
                    return redirect(zbase_url_from_route('login'));
                }
            }
        }
    }
    $params = zbase_route_inputs();
    $requestMethod = zbase_request_method();
    $controller = !empty($route['controller']) ? $route['controller'] : null;
    $command = !empty($route['command']) ? $route['command'] : false;
    if (!empty($command) && $command instanceof \Closure) {
        $command();
        exit;
    }
    if (!empty($controller) && !empty($controller['name']) && !empty($route['controller']['enable'])) {
        $controllerName = !empty($route['controller']['name']) ? $route['controller']['name'] : null;
        $controllerMethod = !empty($route['controller']['method'][$requestMethod]) ? $route['controller']['method'][$requestMethod] : (!empty($route['controller']['method']) ? $route['controller']['method'] : 'index');
        if (!empty($controllerName)) {
            $controllerConfig = zbase_config_get('controller.class.' . $controllerName, null);
            if (!empty($controllerConfig) && !empty($controllerConfig['enable'])) {
                $controllerClass = zbase_controller_create_name(zbase_config_get('controller.class.' . $controllerName . '.name', Zbase\Http\Controllers\__FRAMEWORK__\PageController::class));
                $controllerObject = zbase_object_factory($controllerClass, !empty($route['controller']['params']) ? $route['controller']['params'] : []);
                zbase()->setController($controllerObject->setName($controllerName)->setActionName($controllerMethod)->setRouteParameters($params));
                zbase_view_page_details($route);
                return zbase_response($controllerObject->{$controllerMethod}());
            }
        }
    }
    $view = !empty($route['view']) ? $route['view'] : null;
    if (!empty($view) && !empty($view['name']) && !empty($route['view']['enable'])) {
        zbase_view_page_details($route);
        if (!empty($route['view']['content'])) {
            $params['content'] = zbase_data_get($route['view']['content'], null);
        }
        if ($view['name'] == 'type.js') {
            zbase_response_format_set('javascript');
        }
        return zbase_response(zbase_view_render(zbase_view_file($view['name']), $params));
    }
}
Ejemplo n.º 5
0
		<input type="text" required="required" minlength="1" class="form-control" id="address" name="address" value="<?php 
echo zbase_data_get($dataShipping, 'address');
?>
" placeholder="Block/Lot/Purok/Street" />
	</div>
	<div class="form-group">
		<label for="address">Subdivision/Village</label>
		<input type="text" minlength="1" class="form-control" id="addressb" name="addressb" value="<?php 
echo zbase_data_get($dataShipping, 'addressb');
?>
" placeholder="Subdivision/Village" />
	</div>
	<div class="form-group">
		<label for="city">City/Municipality</label>
		<input type="text" minlength="1" required="required" class="form-control" id="city" value="<?php 
echo zbase_data_get($dataShipping, 'city');
?>
" name="city" placeholder="City/Municipality" />
	</div>
	<label for="courier">Select Courier</label>
	<div class="radio">
		<label>
			<input type="radio" name="courier" required="required" value="lbc" checked>LBC
		</label>
		<label>
			<input type="radio" name="courier" required="required" value="jrs">JRS
		</label>
	</div>
	<label for="courier">Delivery  Mode</label>
	<div class="radio">
		<label>
Ejemplo n.º 6
0
 /**
  * Seed Related tables/models
  * @param array $relations
  * @param array $f
  */
 protected function _relations($relations, $f)
 {
     if (!empty($relations)) {
         foreach ($relations as $rEntityName => $rEntityConfig) {
             $rInverse = !empty($rEntityConfig['inverse']) ? true : false;
             if ($rInverse) {
                 continue;
             }
             $rEntityName = !empty($rEntityConfig['entity']) ? $rEntityConfig['entity'] : $rEntityName;
             $rEntity = zbase_config_get('entity.' . $rEntityName, []);
             if (!empty($rEntity)) {
                 $type = zbase_data_get($rEntityConfig, 'type', []);
                 $fData = [];
                 if ($type == 'onetoone') {
                     /**
                      * https://laravel.com/docs/5.2/eloquent-relationships#one-to-many
                      */
                     $foreignKey = zbase_data_get($rEntityConfig, 'keys.foreign', []);
                     $localKey = zbase_data_get($rEntityConfig, 'keys.local', []);
                     if (!empty($f[$localKey])) {
                         $fData[$foreignKey] = $f[$localKey];
                     }
                     $this->_rows($rEntityName, $rEntity, $fData, true);
                 }
                 if ($type == 'manytomany') {
                     /**
                      * We need to run factory for the related entity
                      */
                     $this->_defaults($rEntityName, $rEntity, true);
                     $this->_factory($rEntityName, $rEntity, true);
                     /**
                      * https://laravel.com/docs/5.2/eloquent-relationships#many-to-many
                      *
                      * Data will be inserted into the pivot table
                      */
                     $pivot = zbase_data_get($rEntityConfig, 'pivot', []);
                     $pivotTableName = zbase_config_get('entity.' . $pivot . '.table.name', []);
                     /**
                      * the foreign key name of the model on which you are defining the relationship
                      */
                     $localKey = zbase_data_get($rEntityConfig, 'keys.foreign', []);
                     /**
                      * the foreign key name of the model that you are joining to
                      * We will select random data from this entity
                      */
                     $foreignKey = zbase_data_get($rEntityConfig, 'keys.local', []);
                     $fTableName = zbase_data_get($rEntity, 'table.name', null);
                     // dd($foreignKey, $fTableName);
                     $foreignTwoValue = collect(\DB::table($fTableName)->lists($foreignKey))->random();
                     \DB::table($pivotTableName)->insert([$localKey => $f[$localKey], $foreignKey => $foreignTwoValue]);
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Create an action button
  * @param string $actionName The Action index name update|create|delete|ddelete|restore
  * @param \Zbase\Interfaces\EntityInterface $row
  * @param array $actionConfig Action config
  * @param boolean $template If we will have to generate a template
  * @return \Zbase\Ui\UiInterface
  */
 public function createActionBtn($actionName, $row, $actionConfig, $template = false)
 {
     if (!$row instanceof \Zbase\Interfaces\EntityInterface && !$template) {
         return null;
     }
     if (empty($actionConfig)) {
         return null;
     }
     $rowTrashed = false;
     if ($this->_entity->hasSoftDelete() && !empty($row)) {
         $rowTrashed = $row->trashed();
     }
     if ($actionName == 'delete' || $actionName == 'update') {
         if ($rowTrashed) {
             return null;
         }
     }
     if ($actionName == 'restore' || $actionName == 'ddelete') {
         if (empty($rowTrashed)) {
             return null;
         }
     }
     $label = !empty($actionConfig['label']) ? $actionConfig['label'] : ucfirst($actionName);
     if (strtolower($label) == 'ddelete') {
         $label = _zt('Forever Delete');
     }
     $actionConfig['type'] = 'component.button';
     $actionConfig['size'] = 'extrasmall';
     $actionConfig['label'] = _zt($label);
     $actionConfig['tag'] = 'a';
     if (!empty($actionConfig['route']['name'])) {
         if (!empty($actionConfig['route']['params'])) {
             foreach ($actionConfig['route']['params'] as $paramName => $paramValue) {
                 if (preg_match('/row::/', $paramValue)) {
                     $rowIndex = str_replace('row::', '', $paramValue);
                     if (!empty($row)) {
                         $id = $actionConfig['route']['params'][$paramName] = zbase_data_get($row, $rowIndex);
                     } else {
                         if (!empty($template)) {
                             $id = $actionConfig['route']['params'][$paramName] = '__' . $rowIndex . '__';
                         }
                     }
                 }
             }
         }
         $actionConfig['routeParams'] = $actionConfig['route']['params'];
         $actionConfig['route'] = $actionConfig['route']['name'];
     }
     $actionConfig['id'] = $this->getWidgetPrefix() . 'Action' . $actionName . (!empty($id) ? $id : null);
     if ($actionName == 'create') {
         $actionConfig['color'] = 'blue';
     }
     if ($actionName == 'update') {
         $actionConfig['color'] = 'green';
     }
     if ($actionName == 'view') {
         $actionConfig['color'] = 'blue';
     }
     if ($actionName == 'delete') {
         $actionConfig['color'] = 'red';
     }
     if ($actionName == 'restore') {
         $actionConfig['color'] = 'warning';
     }
     if ($actionName == 'ddelete') {
         $actionConfig['color'] = 'red';
     }
     $btn = \Zbase\Ui\Ui::factory($actionConfig);
     if ($actionName == 'create') {
         if (!$this->_actionCreateButton instanceof \Zbase\Ui\UiInterface) {
             $this->_actionCreateButton = $btn;
         }
     }
     return $btn;
 }
Ejemplo n.º 8
0
/**
 * Retrieve the value of the dot-notated key from the application configuration
 *
 * First, it will check for ENV value,
 * 	then the configuration
 * 	else will return the value of the $default
 *
 *  example:		view.config.name = theValue
 * 				Config: [view => [
 * 							config => [
 * 									name => theConfigValue
 * 								]
 * 							]
 * 						]
 * 				ENV: VIEW_CONFIG_NAME = theEnvValue
 *
 * @param string $key dot-notated key
 * @param mixed $default The Default value to return
 * @return mixed
 */
function zbase_config_get($key, $default = null)
{
    $path = zbase_tag() . '.' . $key;
    $envPath = strtoupper(str_replace('.', '_', $path));
    return env($envPath, zbase_data_get(null, $path, $default));
}
Ejemplo n.º 9
0
<?php

$sortables = $ui->getSortableColumns();
$currentSorting = $ui->getRequestSorting();
$hasSortables = false;
$sortingOptions = [];
if (!empty($sortables)) {
    foreach ($sortables as $column => $sortable) {
        $sort = zbase_data_get($sortable, 'options.sort');
        if (!empty($sort) && is_array($sort)) {
            foreach ($sort as $s) {
                if (!empty($s['label'])) {
                    $selected = '';
                    if (!empty($currentSorting) && array_key_exists($column, $currentSorting)) {
                        $selected = ' selected="selected"';
                        $currentDir = $currentSorting[$column];
                        $params = ['sort' => [$column => strtolower($currentDir) == 'asc' ? 'desc' : 'asc']];
                    } else {
                        $params = ['sort' => [$column => 'asc']];
                    }
                    $url = zbase_url_from_current($params);
                    $sortingOptions[] = '<option ' . $selected . ' value="' . $url . '">' . $s['label'] . '</option>';
                }
            }
        }
    }
}
if (!empty($sortingOptions)) {
    ?>
	<div class="form-group">
		<select class="form-control" onchange="window.location = jQuery(this).val();">
Ejemplo n.º 10
0
 /**
  * Add multiple view
  *
  * @param type $configs
  */
 public function multiAdd($configs)
 {
     if (!empty($configs)) {
         foreach ($configs as $id => $config) {
             foreach ($config as $k => $v) {
                 $config[$k] = zbase_data_get($config, $k);
             }
             if (!empty($config['type'])) {
                 if ($config['type'] == self::SCRIPT) {
                     $config['script'] = str_replace(array('<script type="text/javascript">', '</script>', '<style type="text/css">', '</style>'), '', $config['script']);
                 }
                 if ($config['type'] == self::STYLE) {
                     $config['style'] = str_replace(array('<style type="text/css">', '</style>'), '', $config['style']);
                 }
                 $config['id'] = $id;
                 $this->add($config['type'], $config);
             }
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * Extract validation
  * validations.type = configuration
  * validations.required = configuration
  *
  * validations.required
  * validations.required.message
  */
 protected function _validation($action = null)
 {
     $section = zbase_section();
     if (empty($action)) {
         $action = zbase_route_input('action');
     }
     $validations = $this->_v('validations.' . $action . '.' . $section, $this->_v('validations.' . $action, $this->_v('validations', [])));
     $this->_fixValidation = true;
     if (!empty($validations)) {
         foreach ($validations as $type => $config) {
             $enable = zbase_data_get($config, 'enable');
             // $enable = $enable ? true : false;
             if (!empty($enable)) {
                 if (!empty($config['text'])) {
                     $this->_validationRules[] = zbase_data_get($config, 'text');
                 } else {
                     if (!in_array($type, $this->_validationRules)) {
                         $this->_validationRules[] = $type;
                     }
                 }
                 if (!empty($config['message'])) {
                     $this->_validationMessages[$this->name() . '.' . $type] = zbase_data_get($config, 'message');
                 }
             }
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * Return an entity attribute
  * @param string $key
  * @return array
  */
 public function entityAttributes($key = null)
 {
     if (empty($this->entityAttributes)) {
         $this->entityAttributes = zbase_config_get('entity.' . $this->entityName);
     }
     if (!empty($key)) {
         return zbase_data_get($this->entityAttributes, $key);
     }
     return $this->entityAttributes;
 }
Ejemplo n.º 13
0
 /**
  * Set the Multi Options
  * @param array $multiOptions
  * @return \Zbase\Ui\Form\Type\Multi
  */
 public function setMultiOptions($multiOptions)
 {
     $this->_multiOptions = zbase_data_get($multiOptions, null, $multiOptions);
     return $this;
 }
Ejemplo n.º 14
0
 /**
  * Return the label
  * @return string
  */
 public function label()
 {
     return zbase_data_get($this->_label, null, ucfirst($this->id()), $this);
 }
Ejemplo n.º 15
0
 /**
  * Extract value from row
  */
 protected function _value()
 {
     if (!empty($this->_templateMode)) {
         return;
     }
     $noUiDataTypes = ['integer', 'string'];
     /**
      * Classname and will call className::columnValue
      */
     $dataCallback = zbase_data_get($this->data, 'callback', null);
     $dataType = $this->getDataType();
     $valueIndex = $this->getValueIndex();
     if (!empty($dataCallback)) {
         $value = $dataCallback::entityDataValue($this->getRow(), $this);
     } else {
         $value = zbase_data_get($this->getRow(), $valueIndex);
     }
     if (in_array($dataType, $noUiDataTypes)) {
         $this->_value = $value;
     } else {
         $dataTypeConfiguration = ['id' => $dataType, 'type' => 'data.' . $dataType, 'enable' => true, 'value' => $value, 'hasAccess' => true, 'options' => $this->getAttribute('options')];
         $this->_value = \Zbase\Ui\Ui::factory($dataTypeConfiguration);
     }
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     // $migrateCommand = app('command.migrate');
     if (!zbase_is_dev()) {
         // $migrateCommand->info('You are in PRODUCTION Mode. Cannot drop tables.');
         return false;
     }
     //echo " - Dropping\n";
     //$migrateCommand->info('- Dropping');
     $entities = zbase_config_get('entity', []);
     if (!empty($entities)) {
         \DB::statement('SET FOREIGN_KEY_CHECKS = 0');
         foreach ($entities as $entity) {
             $enable = zbase_data_get($entity, 'enable', false);
             $model = zbase_data_get($entity, 'model', null);
             if (is_null($model)) {
                 continue;
             }
             $modelName = zbase_class_name($model);
             $isPostModel = zbase_data_get($entity, 'post', false);
             if (!empty($isPostModel)) {
                 $postModel = zbase_object_factory($modelName);
                 if ($postModel instanceof \Zbase\Post\PostInterface) {
                     $entity = $postModel->postTableConfigurations($entity);
                 }
             } else {
                 if (method_exists($modelName, 'entityConfiguration')) {
                     $entity = $modelName::entityConfiguration($entity);
                 }
             }
             $tableName = zbase_data_get($entity, 'table.name', null);
             if (!empty($enable) && !empty($tableName)) {
                 if (Schema::hasTable($tableName)) {
                     Schema::drop($tableName);
                     // echo " -- Dropped " . $tableName . "\n";
                     //$migrateCommand->info(' -- Dropped ' . $tableName);
                 }
             }
         }
         \DB::statement('SET FOREIGN_KEY_CHECKS = 1');
     }
 }
Ejemplo n.º 17
0
 /**
  * Retrieves a value from the configuration
  * @param string $key
  * @param mixed $default
  * @return mixed
  */
 public function _v($key, $default = null)
 {
     return zbase_data_get($this->getAttributes(), $key, $default);
 }
Ejemplo n.º 18
0
 /**
  *
  * $filter = [
  * 		// Callable
  * 		// Result: AND (`column` is null OR `column` = 'value')
  * 		function($query){
  * 				return $query
  * 					->whereNull('column')
  * 					->orWhere('column', '=', 'value');
  * 		}
  * 		'columnName' => [
  * 			['gt' => [
  * 				'field' => 'columnName',
  * 				'value' => 0
  * 			]
  * 		],
  * 		['gt' => [
  * 				'field' => 'columnName',
  * 				'value' => 0
  * 			]
  * 		],
  * 		['between' => [
  * 				'field' => 'columnName',
  * 				'from' => 0
  * 				'to' => 0
  * 			]
  * 		],
  * 		['in' => [
  * 				'field' => 'columnName',
  * 				'values' => [values, values,....]
  * 			]
  * 		],
  * 		['notin' => [
  * 				'field' => 'columnName',
  * 				'values' => [values, values,....]
  * 			]
  * 		],
  * 		['like' => [
  * 				'field' => 'columnName',
  * 				'value' => value
  * 			]
  * 		],
  * 		['raw' => [
  * 				'statement' => 'columnName',
  * 			]
  * 		],
  * 		field_name REGEXP '"key_name":"([^"])key_word([^"])"'
  * 		['json' => [
  * 				'field' => 'columnName',
  * 				'value' => value,
  * 				'keyName' => 'key_name',
  * 			]
  * 		],
  * ];
  *
  * @param string $sort desc|asc
  * @return Illuminate\Database\Eloquent\Builder
  */
 public function scopeFilter($query, $filters = null)
 {
     if (!empty($filters) && is_array($filters)) {
         foreach ($filters as $attribute => $filter) {
             if (is_callable($filter)) {
                 $query->where($filter);
                 continue;
             }
             if (!is_array($filter)) {
                 $query->where($attribute, '=', $filter);
                 continue;
             }
             foreach ($filter as $k => $v) {
                 $k = zbase_data_get($k);
                 if (is_array($v)) {
                     foreach ($v as $vK => $vV) {
                         if ($vV instanceof \Closure) {
                             $v[$vK] = zbase_data_get($vV);
                         } else {
                             $v[$vK] = $vV;
                         }
                     }
                 }
                 switch (strtolower($k)) {
                     case 'between':
                         if (!empty($v['field']) && isset($v['from']) && isset($v['to'])) {
                             $query->whereBetween($v['field'], array($v['from'], $v['to']));
                         }
                         break;
                     case 'in':
                         if (!empty($v['field']) && is_array($v['values'])) {
                             $query->whereIn($v['field'], $v['values']);
                         }
                         break;
                     case 'notin':
                         if (!empty($v['field']) && is_array($v['values'])) {
                             $query->whereNotIn($v['field'], $v['values']);
                         }
                         break;
                     case 'like':
                         if (!empty($v['field']) && isset($v['value'])) {
                             $query->where($v['field'], 'LIKE', $v['value']);
                         }
                         break;
                     case 'gt':
                         if (!empty($v['field']) && isset($v['value'])) {
                             $query->where($v['field'], '>', $v['value']);
                         }
                         break;
                     case 'gte':
                         if (!empty($v['field']) && isset($v['value'])) {
                             $query->where($v['field'], '>=', $v['value']);
                         }
                         break;
                     case 'lt':
                         if (!empty($v['field']) && isset($v['value'])) {
                             $query->where($v['field'], '<', $v['value']);
                         }
                         break;
                     case 'lte':
                         if (!empty($v['field']) && isset($v['value'])) {
                             $query->where($v['field'], '<=', $v['value']);
                         }
                         break;
                     case 'eq':
                         if (!empty($v['field']) && isset($v['value'])) {
                             $query->where($v['field'], '=', $v['value']);
                         }
                         break;
                     case 'neq':
                         if (!empty($v['field']) && isset($v['value'])) {
                             $query->where($v['field'], '!=', $v['value']);
                         }
                         break;
                     case 'json':
                         if (!empty($v['field']) && isset($v['value']) && isset($v['keyName'])) {
                             $query->where($v['field'], 'REGEXP', '"' . $v['keyName'] . '":"' . $v['value'] . '"');
                             // $query->where($v['field'], 'RLIKE', '"' . $v['keyName'] . '":"[[:<:]]' . $v['value'] . '[[:>:]]"');
                         }
                         break;
                     case 'raw':
                         if (!empty($v['statement'])) {
                             $query->whereRaw($v['statement']);
                         }
                         break;
                     default:
                 }
             }
         }
     }
     return $query;
 }
Ejemplo n.º 19
0
 /**
  * Export Filters
  * @param array $exportFilters
  * @return array
  */
 public function postExportQueryFilters($exportFilters)
 {
     if (method_exists($this, 'exportQueryFilters')) {
         return $this->exportQueryFilters($exportFilters);
     }
     $exportFilterValueMap = $this->postTableColumns();
     if (property_exists($this, 'exportFilterValueMap')) {
         $exportFilterValueMap = $this->exportFilterValueMap;
     }
     $queryFilters = [];
     $tableName = $this->postTableName();
     foreach ($exportFilters as $index => $value) {
         if (array_key_exists($index, $exportFilterValueMap)) {
             $column = zbase_data_get($exportFilterValueMap, $index . '.column', $tableName . '.' . $index);
             $value = zbase_data_get($exportFilterValueMap, $index . '.value.' . $value, $value);
             if (strtolower($value) != 'all') {
                 $queryFilters[$column] = ['eq' => ['field' => $column, 'value' => $value]];
             }
         }
     }
     return $queryFilters;
 }
Ejemplo n.º 20
0
 /**
  * Filter Query
  * @param array $filters Array of Filters
  * @param array $sorting Array of Sorting
  * @param array $options some options
  * @return array
  */
 public function queryFilters($filters, $sorting = [], $options = [])
 {
     $queryFilters = [];
     if (!empty($filters)) {
         /**
          * run through a given filters, possibly valid query filters
          */
         if (!empty($filters)) {
             foreach ($filters as $fK => $fV) {
                 if (!empty($fV['eq']) && !empty($fV['eq']['field']) && !empty($fV['eq']['value'])) {
                     if (!preg_match('/' . static::$nodeNamePrefix . '\\./', $fV['eq']['field'])) {
                         $fV['eq']['field'] = static::$nodeNamePrefix . '.' . $fV['eq']['field'];
                     }
                     $queryFilters[$fK] = $fV;
                 }
             }
         }
         $isPublic = !empty($filters['public']) ? true : false;
         if (!empty($isPublic)) {
             $queryFilters['status'] = ['eq' => ['field' => static::$nodeNamePrefix . '.status', 'value' => 2]];
         }
         $currentUser = !empty($filters['currentUser']) ? true : false;
         if (!empty($currentUser)) {
             $queryFilters['user'] = ['eq' => ['field' => static::$nodeNamePrefix . '.user_id', 'value' => zbase_auth_user()->id()]];
         }
         if (!empty($filters['category'])) {
             $categoryObject = zbase_entity(static::$nodeNamePrefix . '_category', [], true);
             /**
              * We have category as a filter,
              * 	Then search for the selected category
              * @var strings[]|integers[]|EntityInterface[]
              */
             $filterCategories = $filters['category'];
             /**
              * We need category Ids To be able to do a cross-table-pivot search
              * Examine the given filter if its an array of strings or integers or just a string or an integer
              */
             $filterCategoryIds = [];
             if (is_array($filterCategories)) {
                 foreach ($filterCategories as $filterCategory) {
                     if (!$filterCategory instanceof Interfaces\EntityInterface) {
                         $filterCategory = $categoryObject::searchCategory(trim($filterCategory), $isPublic);
                     }
                     if ($filterCategory instanceof Interfaces\EntityInterface && !$filterCategory->isRoot()) {
                         $filterCategoryIds[] = $filterCategory->id();
                         continue;
                     }
                 }
             } else {
                 $filterCategory = $categoryObject::searchCategory(trim($filterCategories), $isPublic);
                 if ($filterCategory instanceof Interfaces\EntityInterface && !$filterCategory->isRoot()) {
                     $filterCategoryIds[] = $filterCategory->id();
                 }
             }
             if (!empty($filterCategoryIds)) {
                 $queryFilters['pivot.category_id'] = ['in' => ['field' => 'pivot.category_id', 'values' => $filterCategoryIds]];
             }
             unset($filters['category']);
         }
         if (!empty($this->filterableColumns)) {
             $processedFilters = [];
             foreach ($filters as $filterName => $filterValue) {
                 if (empty($filterValue)) {
                     continue;
                 }
                 if (in_array($filterName, $processedFilters)) {
                     continue;
                 }
                 if (array_key_exists($filterName, $this->filterableColumns)) {
                     $column = $this->filterableColumns[$filterName]['column'];
                     $filterType = $this->filterableColumns[$filterName]['filterType'];
                     $options = $this->filterableColumns[$filterName]['options'];
                     $columnType = $this->filterableColumns[$filterName]['type'];
                     if ($filterType == 'between') {
                         $startValue = $filterValue;
                         $endValue = null;
                         if (preg_match('/\\:/', $filterType)) {
                             $filterTypeEx = explode(':', $filterType);
                             if (!empty($filterTypeEx[1])) {
                                 $endFilterName = $filterTypeEx[1];
                                 $processedFilters[] = $endFilterName;
                                 if (!empty($filters[$endFilterName])) {
                                     $endValue = $filters[$endFilterName];
                                 }
                             }
                         }
                         if ($columnType == 'timestamp') {
                             $timestampFormat = zbase_data_get($options, 'timestamp.format', 'Y-m-d');
                             $startValue = zbase_date_from_format($timestampFormat, $startValue);
                             if ($startValue instanceof \DateTime) {
                                 $startValue->hour = 0;
                                 $startValue->minute = 0;
                                 $startValue->second = 0;
                             }
                             if (empty($endValue)) {
                                 $endValue = clone $startValue;
                                 $endValue->hour = 23;
                                 $endValue->minute = 59;
                                 $endValue->second = 59;
                             } else {
                                 $endValue = zbase_date_from_format($timestampFormat, $endValue);
                             }
                             /**
                              * Argument is the other end of the between
                              */
                             $queryFilters[$filterName] = [$filterType => ['field' => static::$nodeNamePrefix . '.' . $column, 'from' => $startValue->format(DATE_FORMAT_DB), 'to' => $endValue->format(DATE_FORMAT_DB)]];
                         }
                     } else {
                         $queryFilters[$filterName] = [$filterType => ['field' => static::$nodeNamePrefix . '.' . $column, 'value' => $filterValue]];
                     }
                     $processedFilters[] = $filterName;
                 }
             }
         }
     }
     return $queryFilters;
 }
Ejemplo n.º 21
0
 protected function validateApi()
 {
     if (!empty($this->apiConfiguration['params'])) {
         $notParams = [];
         if (!empty($this->apiConfiguration['notParams'])) {
             $notParams = $this->apiConfiguration['notParams'];
         }
         $inputs = zbase_route_inputs();
         unset($inputs['username']);
         unset($inputs['key']);
         unset($inputs['format']);
         unset($inputs['module']);
         unset($inputs['object']);
         unset($inputs['method']);
         $rules = array();
         $messages = array();
         if (zbase_request_is_post()) {
             $inputs = zbase_request_inputs();
         }
         foreach ($this->apiConfiguration['params'] as $paramName => $param) {
             $pRules = array();
             if (!empty($param['validations'])) {
                 foreach ($param['validations'] as $ruleName => $ruleConfig) {
                     $enable = true;
                     $rule = $ruleName;
                     if (isset($ruleConfig['enable'])) {
                         $enable = $ruleConfig['enable'];
                     }
                     if (!empty($enable)) {
                         if (!empty($ruleConfig['text'])) {
                             $rule = zbase_data_get($ruleConfig, 'text');
                         }
                         $pRules[] = $rule;
                         if (!empty($ruleConfig['message'])) {
                             $messages[$paramName . '.' . $ruleName] = $ruleConfig['message'];
                         }
                     }
                 }
             }
             if (!empty($pRules)) {
                 $rules[$paramName] = implode('|', $pRules);
             }
             if (isset($inputs[$paramName])) {
                 if (!empty($param['varname'])) {
                     $this->params[$param['varname']] = $inputs[$paramName];
                 } else {
                     $this->params[$paramName] = $inputs[$paramName];
                 }
             }
         }
         if (!empty($notParams)) {
             foreach ($notParams as $nParam) {
                 if (isset($this->params[$nParam])) {
                     unset($this->params[$nParam]);
                 }
             }
         }
         $validator = \Validator::make($inputs, $rules, $messages);
         if ($validator->fails()) {
             foreach ($validator->errors()->all() as $msg) {
                 $this->apiErrors[] = $msg;
             }
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 22
0
 /**
  * Set/Get the entity
  * @param \Zbase\Widgets\EntityInterface $entity
  */
 public function entity(\Zbase\Widgets\EntityInterface $entity = null)
 {
     if (!is_null($entity)) {
         $this->_entity = $entity;
         if (!$this->hasError()) {
             $entityProperty = $this->_v('entity.property', null);
             if (!is_null($entityProperty)) {
                 if (!$this->wasPosted()) {
                     // $this->setValue($this->_entity->getAttribute($entityProperty));
                     $this->setValue(zbase_data_get($this->_entity, $entityProperty));
                 }
             }
             $entityOptionsProperty = $this->_v('entity.dataoptions', null);
             if (!is_null($entityOptionsProperty)) {
                 if (!$this->wasPosted()) {
                     $options = $this->_entity->getDataOptions();
                     if (isset($options[$entityOptionsProperty])) {
                         $this->setValue($options[$entityOptionsProperty]);
                     }
                 }
             }
         }
         return $this;
     }
     return $this->_entity;
 }
Ejemplo n.º 23
0
 /**
  * Add a module
  * 	Module will be created only f they are called.
  * @param string $path Path to module folder with a module.php returning an array
  * @retur Zbase
  */
 public function addModule($name, $path)
 {
     if (zbase_file_exists($path . '/module.php')) {
         $config = (require zbase_directory_separator_fix($path . '/module.php'));
         $name = !empty($config['id']) ? $config['id'] : null;
         if (empty($name)) {
             throw new Exceptions\ConfigNotFoundException('Module configuration ID not found.');
         }
         if (!empty($name)) {
             $enable = zbase_data_get($config, 'enable');
             if (empty($this->modules[$name]) && $enable) {
                 $config['path'] = $path;
                 $this->modules[$name] = $config;
             }
             return $this;
         }
     }
     // throw new Exceptions\ConfigNotFoundException('Module ' . $path . ' folder or ' . zbase_directory_separator_fix($path . '/module.ph') . ' not found.');
 }
Ejemplo n.º 24
0
            }
        }
    }
    $moduleControllers = $module->_v('angular.mobile.' . $section . '.controllers', $module->_v('angular.' . $section . '.controllers', []));
    if (!empty($moduleControllers)) {
        foreach ($moduleControllers as $moduleController) {
            $auth = zbase_data_get($moduleController, 'auth', true);
            if (empty($auth) && !empty($hasAuth)) {
                continue;
            }
            if (!empty($auth) && empty($hasAuth)) {
                continue;
            }
            $controller = $moduleController['controller'];
            if (!empty($moduleController['view']['file'])) {
                $controllerString = zbase_data_get($moduleController, 'view.file', null);
            }
            if (!empty($controller) && !empty($controllerString)) {
                if (strtolower($controller) == 'maincontroller') {
                    $mainControllerString[] = $controllerString;
                } else {
                    $controllers[] = $controllerString;
                }
            }
        }
    }
}
?>
<script type="text/javascript">

/* ng-infinite-scroll - v1.0.0 - 2013-02-23 */
Ejemplo n.º 25
0
 /**
  * Return the HTML Conditions
  * @return string
  */
 public function getHtmlConditions()
 {
     if (is_null($this->htmlConditions)) {
         $attributes = [];
         if (method_exists($this, 'getAttributes')) {
             $attributes = $this->getAttributes();
         }
         if (!empty($attributes)) {
             $this->htmlConditions = zbase_data_get($attributes, 'html.conditions', []);
         } else {
             $this->htmlConditions = '';
         }
     }
     return $this->htmlConditions;
 }
Ejemplo n.º 26
0
 /**
  * UI Factory
  * @param array $configuration
  * @return \Zbase\Ui\UiInterface
  */
 public static function factory($configuration)
 {
     // $configuration = zbase_data_get($configuration);
     if (!is_array($configuration)) {
         $configuration = zbase_data_get($configuration);
         if (empty($configuration)) {
             return null;
         }
     }
     $type = !empty($configuration['type']) ? $configuration['type'] : 'ui';
     $prefix = '';
     if (!empty(preg_match('/component./', $type))) {
         $prefix = '\\Component';
         $type = zbase_string_camel_case(str_replace('component.', '', $type));
     }
     if (!empty(preg_match('/data./', $type))) {
         $prefix = '\\Data';
         $type = zbase_string_camel_case(str_replace('data.', '', $type));
     }
     $id = !empty($configuration['id']) ? $configuration['id'] : null;
     if (is_null($id)) {
         throw new Exceptions\ConfigNotFoundException('Index:id is not set on Ui Factory');
     }
     if (!empty($type)) {
         $className = zbase_model_name(null, 'class.ui.' . strtolower($type), '\\Zbase\\Ui' . $prefix . '\\' . ucfirst($type));
         $element = new $className($configuration);
         return $element;
     }
     return null;
 }
Ejemplo n.º 27
0
 /**
  * Retrieves a value from the configuration
  * @param string $key
  * @param mixed $default
  * @return mixed
  */
 public function _v($key, $default = null)
 {
     return zbase_data_get($this->getConfiguration(), $key, $default);
 }
Ejemplo n.º 28
0
/**
 * Return the value of the given arguments
 *
 * @param mixed|Closure|array|object  $target
 * @param string $key Dot notated key or string
 * @param mixed $default Default value to return
 * @return mixed
 */
function zbase_value_get($target, $key = null, $default = null)
{
    return zbase_data_get($target, $key, $default);
}
Ejemplo n.º 29
0
 /**
  * Prepare the Actions
  */
 protected function _actions()
 {
     if (!empty($this->_actions)) {
         foreach ($this->_actions as $actionName => $action) {
             $enable = !empty($action['enable']) ? true : false;
             if (!empty($enable)) {
                 $label = !empty($action['label']) ? $action['label'] : ucfirst($actionName);
                 $action['type'] = 'component.button';
                 $action['id'] = $this->id() . 'Action' . $actionName;
                 $action['size'] = 'extrasmall';
                 $action['label'] = _zt($label);
                 $action['tag'] = 'a';
                 if (!empty($action['route']['name'])) {
                     if (!empty($action['route']['params'])) {
                         foreach ($action['route']['params'] as $paramName => $paramValue) {
                             if (preg_match('/row::/', $paramValue)) {
                                 $rowIndex = str_replace('row::', '', $paramValue);
                                 if (!empty($row)) {
                                     $action['route']['params'][$paramName] = zbase_data_get($row, $rowIndex);
                                 }
                             }
                         }
                     }
                     $action['routeParams'] = $action['route']['params'];
                     $action['route'] = $action['route']['name'];
                 }
                 $btn = \Zbase\Ui\Ui::factory($action);
                 if ($actionName == 'create') {
                     if (!$this->_actionCreateButton instanceof \Zbase\Ui\UiInterface) {
                         $this->_actionCreateButton = $btn;
                     }
                     continue;
                 }
             }
         }
     }
 }