コード例 #1
0
ファイル: module.php プロジェクト: robchett/framework
 public function get_push_state()
 {
     $push_state = new push_state();
     $push_state->url = isset($this->current) ? $this->current->get_url() : '/' . _get::__namespace($this, 0) . ($this->view != '_default' ? '/' . $this->view : '');
     if ($this->page > 1) {
         $push_state->url .= 'page/' . $this->page;
     }
     $push_state->title = $this->page_object->title;
     $push_state->data->url = $push_state->url;
     $push_state->data->module = get_class($this);
     $push_state->data->act = isset($_REQUEST['ajax_act']) ? $_REQUEST['ajax_act'] : 'ajax_load';
     $push_state->data->request = $_REQUEST;
     $push_state->data->id = '#' . $this->view_object->get_page_selector();
     $push_state->push = !isset($_REQUEST['is_popped']) ? true : !$_REQUEST['is_popped'];
     return $push_state;
 }
コード例 #2
0
ファイル: table_array.php プロジェクト: robchett/framework
 /**
  * @param string $class
  * @param array $fields_to_retrieve
  * @param array $options
  */
 public function get_all($class, array $fields_to_retrieve, $options = [])
 {
     $this->fields = $fields_to_retrieve;
     $this->options = $options;
     $this->class = $class;
     /** @var table $obj */
     $obj = new $class();
     $links = [];
     $mlinks = [];
     $obj->set_default_retrieve($fields_to_retrieve, $options);
     table::organise_links($obj, $fields_to_retrieve, $links, $mlinks);
     $dependencies = [get::__class_name($class)];
     foreach ($links as $module => $link_info) {
         $field = $link_info['field'];
         $retrieves = $link_info['retrieve'];
         $dependencies[] = get::__class_name($module);
         $options['join'][$module] = $module . '.' . $field->field_name . '=' . $obj->class_name() . '.' . $field->field_name;
         foreach ($retrieves as $retrieve) {
             $fields_to_retrieve[] = $module . '.' . $retrieve;
         }
     }
     $key = 'get_all_' . $class . '_fetch_' . implode(',', $fields_to_retrieve) . '_options_' . serialize($options);
     $elements = \classes\cache::grab($key, function () use($class, $fields_to_retrieve, $options, $links, $mlinks, $obj) {
         if (!isset($options['order'])) {
             $options['order'] = get::__class_name($class) . '.position';
         }
         $select = _db::get_query($class, $fields_to_retrieve, $options);
         $res = $select->execute();
         if (_db::num($res)) {
             $row = _db::fetch($res, null);
             $mappings = $obj->get_field_mappings(array_keys($row));
             do {
                 /** @var table $class */
                 $object = new $class();
                 $object->set_from_row($row, $links, $mappings);
                 foreach ($mlinks as $module => $blah) {
                     $object->{$module . '_elements'} = new \classes\table_array();
                     $object->{$module} = new _collection();
                 }
                 $this[] = $object;
             } while ($row = _db::fetch($res, null));
         }
         $this->reset_iterator();
         foreach ($mlinks as $module => $link_info) {
             /** @var \form\field_link $field */
             $field = $link_info['field'];
             $retrieves = $link_info['retrieve'];
             $retrieves[] = 'l.' . $obj->get_primary_key_name() . ' AS linked_id';
             $sub_class = $field->get_link_object();
             $classes = $sub_class::get_all($retrieves, ['join' => [get::__class_name($class) . '_link_' . get::__class_name($sub_class) . ' l' => 'l.link_' . $sub_class->get_primary_key_name() . '=' . get::__class_name($sub_class) . '.' . $sub_class->get_primary_key_name()], 'where' => 'l.' . $obj->get_primary_key_name() . ' IN(' . implode(',', $this->get_table_keys()) . ')']);
             /** @var table $sub_object */
             foreach ($classes as $sub_object) {
                 $object = $this->find_table_key($sub_object->linked_id);
                 if ($object) {
                     $object->{$module . '_elements'}->push($sub_object);
                     $object->{$module}->push($sub_object->get_primary_key());
                 }
             }
         }
         return $this->exchangeArray([]);
     }, $dependencies);
     $this->exchangeArray($elements);
 }
コード例 #3
0
ファイル: table_form.php プロジェクト: robchett/framework
 public function __construct(table $table)
 {
     $this->source_table = $table;
     parent::__construct($table->get_fields()->getArrayCopy());
 }
コード例 #4
0
ファイル: table.php プロジェクト: robchett/framework
 /**
  * @param array $fields
  * @param array $options
  *
  * @return bool
  */
 public function do_retrieve(array $fields, array $options)
 {
     self::set_cms_modules();
     $options['limit'] = 1;
     $this->set_default_retrieve($fields, $options);
     $links = $mlinks = [];
     table::organise_links($this, $fields, $links, $mlinks);
     foreach ($links as $module => $link_info) {
         $field = $link_info['field'];
         $retrieves = $link_info['retrieve'];
         $options['join'][$module] = $module . '.' . $field->field_name . '=' . $this->class_name() . '.' . $field->field_name;
         foreach ($retrieves as $retrieve) {
             $fields[] = $module . '.' . $retrieve;
         }
     }
     $query = _db::get_query(get_class($this), $fields, $options);
     $res = $query->execute();
     if (_db::num($res)) {
         $row = _db::fetch($res, null);
         $this->set_from_row($row, $links, $this->get_field_mappings(array_keys($row)));
     }
     /** @var field_link $field */
     foreach ($mlinks as $module => $fields) {
         $this->retrieve_link($fields['field'], $fields['retrieve']);
     }
     return $this->get_primary_key();
 }