示例#1
0
 /**
  * Redeclare constructor, generate keys and data
  *
  * @access public
  *
  * @param array $args Arguments
  *
  * @result void
  * @throws \Micro\base\Exception
  */
 public function __construct(array $args = [])
 {
     parent::__construct($args);
     if (empty($args['data'])) {
         throw new Exception('Argument "data" not initialized into DetailViewWidget');
     }
     switch (gettype($args['data'])) {
         case 'array':
             $this->data = (object) $args['data'];
             $this->keys = array_keys($args['data']);
             break;
         case 'object':
             if ($args['data'] instanceof IQuery) {
                 if ($args['data']->objectName) {
                     /** @var IModel $cls */
                     $cls = $args['data']->objectName;
                     $args['data']->table = $cls::tableName();
                 } elseif (!$args['data']->table) {
                     throw new Exception('Data query not set table or objectName');
                 }
                 $this->data = $args['data']->run();
             } elseif (is_subclass_of($args['data'], 'Micro\\mvc\\models\\IModel')) {
                 $this->data = $args['data'];
             } else {
                 throw new Exception('Argument "model" not supported type into DetailViewWidget');
             }
             $this->keys = $this->data->getAttributes();
             break;
         default:
             throw new Exception('Argument "model" not supported type into DetailViewWidget');
     }
     if (empty($args['columns'])) {
         $this->columns = $this->keys;
     }
 }
 /**
  * Redeclare widget constructor
  *
  * @access public
  *
  * @param array $args Widget arguments
  *
  * @result void
  * @throws Exception
  */
 public function __construct(array $args = [])
 {
     parent::__construct($args);
     if (empty($args['data'])) {
         throw new Exception('Argument "data" not initialized into ListViewWidget');
     }
     if (empty($args['pathView'])) {
         throw new Exception('Argument "pathView" not initialized into ListViewWidget');
     }
     if (!is_int($this->page)) {
         $this->page = (int) $this->page;
     }
     if ($this->limit < 10) {
         $this->limit = 10;
     }
     if ($this->page < 0) {
         $this->page = 0;
     }
     /** @var IQuery|array $data */
     $data = $args['data'];
     if ($data instanceof IQuery) {
         /** @var IQuery $data */
         if ($data->objectName) {
             /** @var IModel $cls */
             $cls = $data->objectName;
             /** @noinspection PhpUndefinedFieldInspection */
             $data->table = $cls::$tableName;
         } elseif (!$data->table) {
             throw new Exception('Data query not set table or objectName');
         }
         $select = $data->select;
         $orderBy = $data->order;
         $data->select = 'COUNT(*)';
         $data->order = '';
         $data->single = true;
         $this->totalCount = $data->run(\PDO::FETCH_BOTH)[0];
         $data->select = $select;
         $data->order = $orderBy;
         $data->offset = $this->page * $this->limit;
         $data->limit = $this->limit;
         $data->single = false;
         $data = $data->run();
     } else {
         $this->totalCount = count($data);
         $this->page = $this->page === 0 ? 1 : $this->page;
         $data = array_slice($data, $this->page * $this->limit, $this->limit);
     }
     /** @noinspection ForeachSourceInspection */
     foreach ($data as $model) {
         $this->rows[] = is_subclass_of($model, 'Micro\\Mvc\\Models\\IModel') ? $model : (object) $model;
     }
 }
 /**
  * Re-declare widget constructor
  *
  * @access public
  *
  * @param array $args arguments
  *
  * @result void
  * @throws Exception
  */
 public function __construct(array $args = [])
 {
     parent::__construct($args);
     if (!array_key_exists('data', $args)) {
         throw new Exception('Argument "data" not initialized into GridViewWidget');
     }
     $this->limit = $this->limit < 10 ? 10 : $this->limit;
     $this->page = $this->page < 0 ? 0 : $this->page;
     /** @var IQuery|array $data */
     $data = $args['data'];
     if ($data instanceof IQuery) {
         if ($data->objectName) {
             /** @var IModel $cls */
             $cls = $data->objectName;
             /** @noinspection PhpUndefinedFieldInspection */
             $data->table = $cls::$tableName;
         } elseif (!$args['data']->table) {
             throw new Exception('Data query not set table or objectName');
         }
         if ($data->having || $data->group) {
             $res = new Query((new Injector())->getDriver());
             $res->select = 'COUNT(*)';
             $res->table = '(' . $data->getQuery() . ') micro_count';
             $res->single = true;
         } else {
             /** @var Query $res */
             $res = clone $data;
             $res->objectName = null;
             $res->select = 'COUNT(*)';
             $res->single = true;
         }
         /** @var array $a */
         $this->totalCount = ($a = $res->run(\PDO::FETCH_NUM)) ? $a[0] : 0;
         $this->filterPrefix = $data->table;
         $data->offset = $this->page * $this->limit;
         $data->limit = $this->limit;
         $data = $data->run($data->objectName ? \PDO::FETCH_CLASS : \PDO::FETCH_ASSOC);
     } else {
         // array
         $this->totalCount = count($data);
         $data = array_slice($data, $this->page * $this->limit, $this->limit);
     }
     /** @noinspection ForeachSourceInspection */
     foreach ($data as $model) {
         $this->rows[] = is_subclass_of($model, 'Micro\\Mvc\\Models\\Model') ? $model : (object) $model;
     }
 }
示例#4
0
 /**
  * Redeclare widget constructor
  *
  * @access public
  *
  * @param array $args Widget arguments
  *
  * @result void
  * @throws Exception
  */
 public function __construct(array $args = [])
 {
     parent::__construct($args);
     if (empty($args['data'])) {
         throw new Exception('Argument "data" not initialized into ListViewWidget');
     }
     if (empty($args['pathView'])) {
         throw new Exception('Argument "pathView" not initialized into ListViewWidget');
     }
     if (!is_int($this->page)) {
         $this->page = (int) $this->page;
     }
     if ($this->limit < 10) {
         $this->limit = 10;
     }
     if ($this->page < 0) {
         $this->page = 0;
     }
     if ($args['data'] instanceof IQuery) {
         /** @var |Query $args ['data'] */
         if ($args['data']->objectName) {
             /** @var IModel $cls */
             $cls = $args['data']->objectName;
             $args['data']->table = $cls::tableName();
         } elseif (!$args['data']->table) {
             throw new Exception('Data query not set table or objectName');
         }
         $select = $args['data']->select;
         $args['data']->select = 'COUNT(id)';
         $args['data']->single = true;
         $this->totalCount = $args['data']->run(\PDO::FETCH_BOTH)[0];
         $args['data']->select = $select;
         $args['data']->ofset = $this->page * $this->limit;
         $args['data']->limit = $this->limit;
         $args['data']->single = false;
         $args['data'] = $args['data']->run();
     } else {
         $this->totalCount = count($args['data']);
         $this->page = $this->page === 0 ? 1 : $this->page;
         $args['data'] = array_slice($args['data'], $this->page * $this->limit, $this->limit);
     }
     foreach ($args['data'] as $model) {
         $this->rows[] = is_subclass_of($model, 'Micro\\mvc\\models\\IModel') ? $model : (object) $model;
     }
 }
示例#5
0
 /**
  * Re-declare widget constructor
  *
  * @access public
  *
  * @param array $args arguments
  *
  * @result void
  * @throws Exception
  */
 public function __construct(array $args = [])
 {
     parent::__construct($args);
     if (empty($args['data'])) {
         throw new Exception('Argument "data" not initialized into GridViewWidget');
     }
     $this->limit = $this->limit < 10 ? 10 : $this->limit;
     $this->page = $this->page < 0 ? 0 : $this->page;
     if ($args['data'] instanceof IQuery) {
         if ($args['data']->objectName) {
             /** @var IModel $cls */
             $cls = $args['data']->objectName;
             $args['data']->table = $cls::tableName();
         } elseif (!$args['data']->table) {
             throw new Exception('Data query not set table or objectName');
         }
         if ($args['data']->having || $args['data']->group) {
             $res = new Query($this->container->db);
             $res->select = 'COUNT(*)';
             $res->table = '(' . $args['data']->getQuery() . ') micro_count';
             $res->single = true;
         } else {
             /** @var Query $res */
             $res = clone $args['data'];
             $res->objectName = null;
             $res->select = 'COUNT(*)';
             $res->single = true;
         }
         /** @var array $a */
         $this->totalCount = ($a = $res->run()) ? $a[0] : 0;
         $this->filterPrefix = $args['data']->table;
         $args['data']->ofset = $this->page * $this->limit;
         $args['data']->limit = $this->limit;
         $args['data'] = $args['data']->run($args['data']->objectName ? \PDO::FETCH_CLASS : \PDO::FETCH_ASSOC);
     } else {
         // array
         $this->totalCount = count($args['data']);
         $args['data'] = array_slice($args['data'], $this->page * $this->limit, $this->limit);
     }
     foreach ($args['data'] as $model) {
         $this->rows[] = is_subclass_of($model, 'Micro\\db\\Model') ? $model : (object) $model;
     }
 }