Customization of simple module

edited May 2015 in Modules
Hi,
I have a question, if the following is possible with a simple module.

I have a combination of "normal" pages and pages which get there content from simple modules.
In addition I have a simple module where I can define image stages for the layout.

I have overloaded the pages_model, so that I can add can create a mapping between page and image_stage via the page_id.
My next task is to provide a possibility to add a mapping between a simple module and image_stage.

Do you have any idea how to solve this? As far as I can see, there are no variables in simpel modules... For usability I am looking for a way to integrate this mapping into the backend.

Comments

  • edited 5:54AM
    I'm not entirely sure I understand your issue, in particular, where you say "there are no variables in simple modules" but will give what guidance I can.

    One thought I had was regarding your mapping between module models. For associations between module models, I would look at the various ways to create relationships between models:
    http://docs.getfuelcms.com/general/models#relationships
  • edited 5:54AM
    I will try to clarify my issue :-)
    If you have a look at www.feuerwehr-bs.de in the header of the page you see that big image. This is the image_stage I am talking about.

    So on my site I have a combination of simple content pages (I want to use the pages module for this) and more complex special pages which I want to realize via simple modules.

    My idea is too have a table with the image_stages and a table where I define the relation between content page and image_stage.
    For the normal content pages I have realized this via a hook in the pages_module to save the relation in the table.
    For the special pages my idea is too have an image_stage for the overview page and another for the detail page.
    Now I could make the database entries for this... but I want to have a way to select the image_stage in the backend... So I need to have a global variable in the simple module to save the stage id.
  • edited 5:54AM
    If I understand you correctly, it sounds like you need the ability to assign an image from a separate simple module. This can be done by specifying the "model" property on a select field type in your page layout which will use the model's options_list by default or you can specify a different method on your model as illustrated in the below code example. which would save the image_stages.id. Then, if you create your layout as a class, you can implement the pre_process method to grab the correct images_stages record before it is passed the layout view file:
    $fields['big_image'] = array('type' => 'select', 'model' => array('image_stages_model' => 'my_custom_options'));
    More can be found here about using classes for your layouts:
    http://docs.getfuelcms.com/general/layouts#layouts_custom_classes

    For your generated module pages, I would add a image_stages_id foreign key field in the database table to capture the image_stages.id and then add the following to your simple module's model (assuming the model's name is image_stages_model):
    public $foreign_keys = array('image_stages_id' => 'image_stages_model);

    Also, do the simple modules contain all the information you need to generate the page? If so, the soon to be released develop branch makes this really easy with something called module posts.
    https://github.com/daylightstudio/FUEL-CMS/tree/develop
    The documentation for this can be found in the fuel/modules/fuel/views/_docs/modules/simple.php under the Generated Post Pages section.
  • edited 5:54AM
    hmm ok when I unterstood your point right than I'll have to do the following:
    the simple module is just used for adminstration of the database items.
    The frontendpart will be represented by a "normal" content page with a special layout for the simple module which takes part of all the content grabbing etc. via the custom class.

    I think then I do not need to save the image_stages_id in the simple modules table as foreign key. I would have one content page for the overview and one for the detail page. The layout for the simple module then will have a configuration parameter with a dropdown box for the image_stage_id. This is sufficient because I do not want to have a different image stage id for each simple modules item. They will all have the same image stage id.

    Got it right?
  • edited 5:54AM
    Hi,
    I have chosen another way to select the stage for the content page...
    I have build a custom pages_model my_pages_model and overwritten the form_fields method to add the parameter to the header fields.

    public function form_fields($values = array(), $related = array()) { $fields = parent::form_fields($values = array(), $related = array()); $fields['stage']['type'] = 'select'; $fields['stage']['options'] = $this->_stage_options_list(); return $fields; } private function _stage_options_list() { $CI =& get_instance(); $this->load_model('stages_model'); return $this->stages_model->get_stage_options(); } public function on_after_save($values) { $CI =& get_instance(); $this->load_model('stages_model'); $values = parent::on_after_save($values); $page_id = $values['id']; $stage_id = $_POST['stage']; $this->stages_model->create_update_stage_mapping($page_id, $stage_id); return $values; } public function on_after_delete($where) { parent::on_after_delete($where); $this->db->where(array('page_id' => $where['id'])); $this->db->delete('stage_mapping'); }

    Now the page model takes care about saving and deleting the stage_image mapping for the page.
  • edited May 2015
    Is there a way to get the current page_id in the pre_process method?
    $this->fuel_page->id;
    isnt'working

    Hmpf... got it ;-)
    $CI->fuel_page->id...
    sorry for that...
  • edited 5:54AM
    Try $this->fuel->page->properties('id'); The "$CI->fuel->page" object should be the current page whereas the "$CI->fuel->pages" object has methods to retrieve pages like "$CI->fuel->pages->get('mylocation')"
  • edited 5:54AM
    Thanks, that worked fine for me!
Sign In or Register to comment.