예제 #1
0
 /**
  * Bootstrap the module
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     $resources = $application->config()['resources'];
     $params = $application->services()->getParams('nav.phire');
     $config = $application->module('phire-entities');
     $models = isset($config['models']) ? $config['models'] : null;
     $types = Table\EntityTypes::findAll(['order' => 'order ASC']);
     foreach ($types->rows() as $type) {
         if (null !== $models) {
             if (!isset($models['Phire\\Entities\\Model\\Entity'])) {
                 $models['Phire\\Entities\\Model\\Entity'] = [];
             }
             $models['Phire\\Entities\\Model\\Entity'][] = ['type_field' => 'type_id', 'type_value' => $type->id, 'type_name' => $type->name];
         }
         $resources['entity-type-' . $type->id . '|entity-type-' . str_replace(' ', '-', strtolower($type->name))] = ['index', 'add', 'edit', 'export', 'remove'];
         if (!isset($params['tree']['entities']['children'])) {
             $params['tree']['entities']['children'] = [];
         }
         $params['tree']['entities']['children']['entity-type-' . $type->id] = ['name' => $type->name, 'href' => '/entities/' . $type->id, 'acl' => ['resource' => 'entity-type-' . $type->id, 'permission' => 'index']];
     }
     $application->mergeConfig(['resources' => $resources]);
     $application->services()->setParams('nav.phire', $params);
     if (null !== $models) {
         $application->module('phire-entities')->mergeConfig(['models' => $models]);
     }
 }
예제 #2
0
 /**
  * Get entity by type
  *
  * @param  string $type
  * @param  int    $limit
  * @param  int    $page
  * @param  string $sort
  * @return array
  */
 public function getByType($type, $limit = null, $page = null, $sort = null)
 {
     $entityType = is_numeric($type) ? Table\EntityTypes::findById($type) : Table\EntityTypes::findBy(['name' => $type]);
     $rows = [];
     if (isset($entityType->id)) {
         $rows = $this->getAll($entityType->id, $limit, $page, $sort);
     }
     return $rows;
 }
예제 #3
0
 /**
  * Get count of entity types
  *
  * @return int
  */
 public function getCount()
 {
     return Table\EntityTypes::findAll()->count();
 }