Esempio n. 1
0
 public function getObject($primary_key_value)
 {
     $m2o_object_name = $this->object_name;
     $object = ObjectLoader::get($m2o_object_name);
     $object->sync($primary_key_value);
     return $object;
 }
Esempio n. 2
0
 public function generateQuerySet(QuerySet $query_set, $field_name)
 {
     $object_name = $this->object_name;
     // Load objects
     $object = ObjectLoader::get($object_name);
     // Handle One2Many
     return $object::all()->associate($this->foreign_key, $query_set, $field_name);
 }
Esempio n. 3
0
 public function getDelete($object_id)
 {
     $object_name = $this->objectName();
     ObjectLoader::load($object_name);
     $object = $object_name::get($object_id);
     if ($object->delete()) {
         $this->flash()->success($object_name . ' deleted!');
         return $this->response()->redirect(substr(strtolower(get_called_class()), 0, -strlen('Controller')));
     }
     $this->flash()->error('Unable to delete the ' . $object_name . '!');
     return $this->response()->redirect();
 }
Esempio n. 4
0
 /**
  * @description Print SQL code needed to create all the tables corresponding to the models.
  */
 public function showCreateTable()
 {
     $objects = ObjectLoader::getObjects();
     /**
      * For each models, generate create table.
      */
     foreach ($objects as $object_name => $object) {
         $sql_inspector = new SQLModelInspector();
         $object->inspectModel($sql_inspector);
         $query = $sql_inspector->generate();
         echo $query, PHP_EOL;
     }
 }
Esempio n. 5
0
 public function generateQuerySet(QuerySet $query_set, $field_name)
 {
     $lnk_object_name = $this->link_object_name;
     $m2m_object_name = $this->object_name;
     // Load objects
     $lnk_object = ObjectLoader::load($lnk_object_name);
     $m2m_object = ObjectLoader::load($m2m_object_name);
     // Handle One2Many
     $lnk_attribute_name = $this->link_foreign_key;
     $lnk_qs = $lnk_object_name::all()->associate($lnk_attribute_name, $query_set, $field_name);
     // Handle Many2Many
     $m2m_attribute_name = $this->foreign_key;
     return $m2m_object_name::all()->associate($m2m_attribute_name, $lnk_qs, $m2m_attribute_name);
 }
Esempio n. 6
0
 public function __get($attribute_name)
 {
     if (!isset($this->map[$attribute_name])) {
         throw new \Exception('No mapping defined in collection ' . get_class() . ' for attribute ' . $attribute_name . '!');
     }
     if (!isset($this->_instances[$attribute_name])) {
         if (is_string($this->map[$attribute_name])) {
             $this->_instances[$attribute_name] = ObjectLoader::get($this->map[$attribute_name]);
         } else {
             $this->_instances[$attribute_name] = $this->map[$attribute_name];
         }
     }
     return $this->_instances[$attribute_name];
 }
Esempio n. 7
0
 /**
  * @description Create the Administrator role with all the access rights.
  */
 public function createAdminRole()
 {
     try {
         $admin = Role::get(1);
         $this->output->writeln('The administrator role already exists!');
     } catch (\Exception $e) {
         $admin = new Role();
         $admin->role_id = 1;
     }
     $rights = \Biome\Biome::getService('rights');
     /**
      * Routes allowing.
      */
     $router = \Biome\Biome::getService('router');
     foreach ($router->getRoutes() as $route) {
         $method = $route['method'];
         $controller = $route['controller'];
         $action = $route['action'];
         $rights->setRoute($method, $controller, $action);
     }
     /**
      * Objects allowing.
      */
     $objects = \Biome\Core\ORM\ObjectLoader::getObjects();
     foreach ($objects as $object_name => $object) {
         $rights->setObject($object_name);
         foreach ($object->getFieldsName() as $attribute_name) {
             $rights->setAttribute($object_name, $attribute_name);
         }
     }
     $admin->role_name = 'Administrator';
     $admin->role_rights = $rights->exportToJSON();
     if (!$admin->save()) {
         $this->output->writeln('Unable to create the administrator role!');
         $this->output->writeln(print_r($admin->getErrors(), TRUE));
         return FALSE;
     }
     $this->output->writeln('Administrator role created!');
     return TRUE;
 }
Esempio n. 8
0
 protected function parameterInjection($type, $name, $required, $args)
 {
     $request = \Biome\Biome::getService('request');
     $value = NULL;
     if (empty($type)) {
         return $args[$name];
     }
     switch ($type) {
         // Default PHP type
         case 'string':
         case 'int':
             return $value;
             break;
         default:
             // Class injection
     }
     /**
      * Collection injection
      */
     if (substr($type, -strlen('Collection')) == 'Collection') {
         // Instanciate the collection
         $collection_name = strtolower(substr($type, 0, -strlen('Collection')));
         $value = Collection::get($collection_name);
         // Check if data are sent
         foreach ($request->request->keys() as $key) {
             if (strncmp($collection_name . '/', $key, strlen($collection_name . '/')) == 0) {
                 $raw = explode('/', $key);
                 $total = count($raw);
                 $iter = $value;
                 for ($i = 1; $i < $total - 1; $i++) {
                     $iter = $iter->{$raw[$i]};
                 }
                 $v = $request->request->get($key);
                 $iter->{$raw[$i]} = $v;
             }
         }
     } else {
         $object_name = strtolower($type);
         $value = ObjectLoader::get($object_name);
         // Check if data are sent
         foreach ($request->request->keys() as $key) {
             if (strncmp($object_name . '/', $key, strlen($object_name . '/')) == 0) {
                 $raw = explode('/', $key);
                 $total = count($raw);
                 $iter = $value;
                 for ($i = 1; $i < $total - 1; $i++) {
                     $iter = $iter->{$raw[$i]};
                 }
                 $v = $request->request->get($key);
                 $iter->{$raw[$i]} = $v;
             }
         }
     }
     return $value;
 }
Esempio n. 9
0
 /**
  * From the longest to the smallest.
  */
 protected function rec_fetchValue($var, &$inner_context = 'global')
 {
     $ctx = NULL;
     $result = $this->getContext($var, $ctx);
     if ($result !== NULL) {
         return $result;
     }
     /* Remove one item, save the name of the last one. */
     $raw = explode('.', $var);
     if (count($raw) > 1) {
         $end = array_pop($raw);
         $result = $this->rec_fetchValue(join('.', $raw), $ctx);
         /* We find the preceding item, fetch the next. */
         if (method_exists($result, 'get' . $end)) {
             $end = 'get' . $end;
             $result = $result->{$end}();
         } else {
             if (method_exists($result, $end)) {
                 $result = $result->{$end}();
             } else {
                 if (is_array($result) && isset($result[$end])) {
                     $result = $result[$end];
                 } else {
                     $result = $result->{$end};
                 }
             }
         }
         $this->setContext($var, $result, $ctx);
         return $result;
     }
     /* No item found, check view. */
     $view = \Biome\Biome::getService('view');
     $result = $view->{$raw[0]};
     if ($result !== NULL) {
         return $result;
     }
     /* No item found, check collections. */
     $result = Collection::get($raw[0]);
     if ($result !== NULL) {
         return $result;
     }
     /* No item found, check objects. */
     $result = ObjectLoader::get($raw[0]);
     if ($result !== NULL) {
         return $result;
     }
     throw new \Exception('Unable to find the variable ' . $var . ' in the context!');
 }
Esempio n. 10
0
<?php

$objects = \Biome\Core\ORM\ObjectLoader::getObjects();
$router = \Biome\Biome::getService('router');
$routes = $router->getRoutes();
$rights = \Biome\Core\Rights\AccessRights::loadFromJSON($this->getValue());
?>
<div id="<?php 
echo $this->getId();
?>
">
<ul class="nav nav-tabs" role="tablist">
	<li role="presentation" class="active"><a href="#role_routes" aria-controls="role_routes" role="tab" data-toggle="tab">Routes</a></li>
	<li role="presentation"><a href="#role_objects" aria-controls="role_objects" role="tab" data-toggle="tab">Objects</a></li>
</ul>
<div class="tab-content">

<div role="tabpanel" class="tab-pane fade in active" id="role_routes">
<table id="table_routes" class="table table-striped table-hover table-condensed">
	<thead>
		<tr>
			<th>Method</th>
			<th>Route</th>
			<th>Description</th>
			<th><input type="checkbox" onClick="toggleCheckboxColumn(this, 'table_routes', 'rights-routes');"/> <span> Access</span></th>
		</tr>
	</thead>
	<tbody>
		<?php 
foreach ($routes as $r) {
    $method = $r['method'];