Exemplo n.º 1
0
 public function getModel()
 {
     if (!static::$model) {
         static::$model = User::model()->findByPk($this->id);
     }
     return static::$model;
 }
 /**
  * Loads routes in from the cache or database
  *
  * @return bool
  */
 protected static function _loadDynamicRoutes()
 {
     if (static::$options['cache']) {
         static::$_routes = Cache::read(static::$options['cacheKey']);
         if (static::$_routes) {
             return self::_loadRoutes();
         }
     }
     if (is_object(static::$options['model'])) {
         static::$model = static::$options['model'];
     } else {
         static::$model = ClassRegistry::init(static::$options['model']);
     }
     if (!is_object(static::$model)) {
         CakeLog::write('dynamic_route', 'Unable to load dynamic_route model');
         return false;
     }
     static::$_routes = static::$model->find('load');
     if (static::$_routes) {
         if (static::$options['cache']) {
             Cache::write(static::$options['cacheKey'], static::$_routes);
         }
         return self::_loadRoutes();
     }
     CakeLog::write('dynamic_route', 'No routes available');
     return false;
 }
Exemplo n.º 3
0
 /**
  * Create and return instance of Select Statement for entity. If entity
  * has defined select, the return object will be this instance.
  *
  * @return Juborm\Select Statement of select
  */
 public static function select($columns = null)
 {
     if (is_string($columns)) {
         // zostala podana tylko jedna kolumna wiec zamieniam na arraya
         $columns = array($columns);
     }
     // wczytuje klase select
     $select = is_null(static::$select) ? ORMSelect::class : static::$select;
     $cleanEntity = new static();
     $select = $cleanEntity->adapter()->dml(MidataDML::SELECT);
     $select->from(static::$table)->entity(static::class)->model($cleanEntity->model())->source($cleanEntity->source());
     if (is_null($columns)) {
         $columns = static::fields();
     }
     // columns of primary key are added to each entity
     $pks = static::pkDefinition();
     foreach ($pks as $pk) {
         if (!in_array($pk, $columns)) {
             $columns[] = $pk;
         }
     }
     foreach ($columns as $alias => $value) {
         if (is_int($alias)) {
             $select->column($value);
         } else {
             $select->column($value, $alias);
         }
     }
     // the last step is prepare the select to use
     $select->prepare();
     // endtodo
     return $select;
 }
Exemplo n.º 4
0
 public static function buildModel()
 {
     $model['title'] = new \Phlex\RedFox\Model\Field\StringField('title', false);
     $model['title']->maxLength = 255;
     $model['lead'] = new \Phlex\RedFox\Model\Field\StringField('lead', false);
     $model['lead']->maxLength = 65536;
     $model['type'] = new \Phlex\RedFox\Model\Field\EnumField('type', false);
     $model['enum']->values = array('news', 'article', 'feature', 'blogpost');
     $model['publishDate'] = new \Phlex\RedFox\Model\Field\DateTimeField('publishDate', false);
     $model['authorId'] = new \Phlex\RedFox\Model\Field\IntegerField('authorId', true);
     $model['authorId']->min = 0;
     $model['authorId']->max = 65536;
     $model['authorId']->referenceTo('\\Entity\\User');
     static::$model = static::polishModel($model);
 }
Exemplo n.º 5
0
 public static function model($model, array $attributes = NULL)
 {
     static::$model = $model;
     static::$model_name = $model->object_name();
     static::$model_id = $model->pk();
     $prefix = 'edit_';
     $postfix = '_' . static::$model_id;
     if (!$model->loaded()) {
         $prefix = 'new_';
         $postfix = '';
     }
     if (!isset($attributes['class'])) {
         $attributes['class'] = $prefix . static::$model_name;
     }
     if (!isset($attributes['id'])) {
         $attributes['id'] = $prefix . static::$model_name . $postfix;
     }
     if (isset($attributes['url'])) {
         $url = $attributes['url'];
     } else {
         $url = Route::url_for($model);
     }
     return Form::open($url, $attributes);
 }
Exemplo n.º 6
0
 /**
  * Sets the current model, so \CMF::currentModel() will return this one.
  * 
  * @param object $model
  */
 public static function setCurrentModel($model)
 {
     $model_class = get_class($model);
     static::$template = $model_class::template();
     if (property_exists($model, 'url') && ($urlItem = $model->get('url'))) {
         static::$currentUrl = $urlItem;
     }
     return static::$model = $model;
 }
Exemplo n.º 7
0
 /**
  * Class constructor
  *
  * @param object $constants
  * @param object $cooker
  * @param object $injector
  * @param object $crypt
  * @param object $databaseService
  * @param object $repository
  * @param object $eventDispatcher
  *
  */
 public function __construct(Constants $constants, CookerInterface $cooker, Injector $injector, CryptInterface $crypt, DatabaseServiceInterface $databaseService, SessionHandlerInterface $repository, Dispatcher $eventDispatcher)
 {
     static::$constants = $constants;
     static::$injector = $injector;
     static::$repository = $repository;
     static::$cooker = $cooker;
     static::$eventDispatcher = $eventDispatcher;
     static::$crypt = $crypt;
     static::$eventDispatcher->setInstance(static::getInstance());
     static::$model = $databaseService->get(static::$injector->get('db'));
     static::$env = php_sapi_name();
     static::setSession(static::$repository);
 }
Exemplo n.º 8
0
 static function SetModel($model)
 {
     static::$model = $model;
 }
Exemplo n.º 9
0
 /**
  * Set the model class name to authenticate user
  * @param $model
  */
 public static function model($model)
 {
     static::$model = $model;
     $class = '\\' . get_called_class();
     return $class::make();
 }