Helpme ....... I'am exhausted  Bottom

  • PN .8 for me is too complex!
    But I like to die :)

    I have targeted the news because module is a module very comprehensive and well done.

    The creation of tables at installation of the module are able to do so, but this is really simply.

    I would like to modify it to see how you work with postnuke.
    In particular I would like to add a new table (stories_test) with a field id and one of text field.
    I would also add a text field in all news pages of the module (add news adjusts etc.).

    It is not that there is someone who tells me where do these additions, or better still if someone does me news modules (in version 326) with this add :)

    I thank everyone who wants to help me.
  • Hi, welcome to the postnuke community. Your post is a bit unclear (might be the exhaustion icon_smile ).
    You want to add something to the News functionality, that is clear, but what do you want to add?

    And do you want to do it yourself or would you like it to be added to the basic module? Explain a little bit more on what you aready did and what is not working or not clear



    --
    campertoday.nl, Module development, Dutch Zikula Community
  • I use google to translate from Italian to English :) but may be because I am tired:)

    I would add a further table (stories_test), which contains an (id) field and a (text) field.
    I would like that the text field is run by each news page.
    I would like also that when I save the new the value of text, it must be saved in the stories_test table.

    I need it for myself, to understand how postnuke works.

    Thanks for attenction
  • LOL
    i don't know why do you think that PN is too complex!
    it's just a REQUEST -> Controller -> Model -> View (MVC).
    In PN terms it's; REQUEST -> pnuser.php -> pnuserapi.php -> $pnRender->fetch.
    Let's understand how is the flow of the module function calls.

    Let's create an article from the News Admin Panel:
    URL = /index.php?module=News&type=admin&func=new

    So, you can go to the admin controller of the News module (file: /modules/News/pnadmin.php, that's the admin controller). There you'll find the News_admin_new() function, and follow its code. You'll see that the function call to the 'new' function user controller, that's to avoid repeated code in the News module.

    Please follow the inline documentation of the News_user_new() function. Basically check if the session has the information of a "previewed" news item, and pass it to the pnRender template. The forms are in charge of the 'news_user_new.htm' and 'news_admin_new.htm' depending of the "permissions".

    The form calls to the function News_user_create() to store the article in the database, check it. That function gets the article info and validate it. Then pass the item to the user 'model' (userapi) in the function create (then check the file pnuserapi.php in its function News_userapi_create()).

    The userAPI receive the item info, validate it, format to store, and finally uses DBUtil to insert the Object in the 'stories' table.

    So, as a conclusion of your test requirement, you can add a new textarea in the form template, then include your new field in the item process, and in the userapi creation, extract it and store in the different table.
    Also, to have a new table in the News module, you should define it in the pntables.php, then make a new version, and undate the pninit.php according to the changes.

    Some light now? icon_cool


    --
    - Mateo T. -
    Mis principios... son mis fines
  • Thank Nestor for light, but I see little :)
    I started with the tryed.
    I have create a double table (stories and stories_test) and modules with remove and install work :)

    THE STRING IS NAMED turno !!

    Code

    pntable

    function News_pntables()
    {
        // Initialise table array
        $pntable = array();

        // Full table definition
        $pntable['stories'] = DBUtil::getLimitedTablename('stories');
        $pntable['stories_column'] = array ('sid'              => 'pn_sid',
                                            'aid'              => 'pn_cr_uid',   // for back compat
    ...
        $pntable['stories_column_def'] = array('sid'              => 'I NOTNULL AUTO PRIMARY',
                                               'title'            => 'C(255) DEFAULT NULL',
    ...
        $pntable['stories_test'] = DBUtil::getLimitedTablename('stories_test');
        $pntable['stories_test_column'] = array ('tid'            => 'pn_tid',
                                            'turno'               => 'pn_turno');

        $pntable['stories_test_column_def'] = array('tid'         => 'I NOTNULL AUTO PRIMARY',
                                               'turno'            => 'C(255) DEFAULT NULL');

        // Enable categorization services
        $pntable['stories_db_extra_enable_categorization'] = pnModGetVar('News', 'enablecategorization');
        $pntable['stories_primary_key_column'] = 'sid';
        $pntable['stories_test_primary_key_column'] = 'tid';
       
    ...
        return $pntable;
    }


    Code

    pninit

    function News_init()
    {
        // Create table
        $tables=array('stories','stories_test');
        foreach ($tables as $table) {
            if (!DBUtil::createTable($table)) {
                return false;
            }
        }
    .......
    function News_delete()
    {
        // Create table
        $tables=array('stories','stories_test');
        foreach ($tables as $table) {
            if (!DBUtil::dropTable($table)) {
                return false;
            }
        }


    I have add a this code:

    Code

    <div class="pn-formrow">
    <label for="news_test"><!--[pnml name="_TEST"]--></label>
    <input id="news_test" class="pn-form-text" name="story[turno]" type="text" size="32" maxlength="255" value="<!--[$turno]-->" />
    </div>

    in this templates:
    news_user_new.htm
    news_admin_new.htm
    news_admin_modify.htm

    I have add this code in:

    Code

    pnuserapi.php
    function News_userapi_getArticleInfo($info)
    {
    ---
        list($info['title'],
             $info['hometext'],
             $info['bodytext'],
             $info['notes'],
             $info['turno']) = pnModCallHooks('item', 'transform', '',
                                              array($info['title'],
                                                    $info['hometext'],
                                                    $info['bodytext'],
                                                    $info['notes'],
                                                    $info['turno']));
    ...
        return($info);
    }

    function News_userapi_create($args)
    {
        // Argument check
        if (!isset($args['title']) ||
            !isset($args['hometext']) ||
            !isset($args['hometextcontenttype']) ||
            !isset($args['bodytext']) ||
            !isset($args['bodytextcontenttype']) ||
            !isset($args['notes']) ||
            !isset($args['turno'])) {
            return LogUtil::registerError (_MODARGSERROR);
        }
    ...
        // Return the id of the newly created item to the calling process
        return $args['sid'];
    }


    Code

    In pnadminapi.php

    function News_adminapi_update($args)
    {
        // Argument check
        if (!isset($args['sid']) ||
            !isset($args['title']) ||
            !isset($args['hometext']) ||
            !isset($args['hometextcontenttype']) ||
            !isset($args['bodytext']) ||
            !isset($args['bodytextcontenttype']) ||
            !isset($args['notes']) ||
            !isset($args['turno']) ||        
            !isset($args['published_status']) ||
            !isset($args['from']) ||
            !isset($args['to'])) {
            return LogUtil::registerError (_MODARGSERROR);
        }
    ...
        // Let the calling process know that we have finished successfully
        return true;
    }


    I do not know how to save in the table stories_test the value of turno.
    However I turn in the box but if I create a preview is shown its value.
    So ........ I do not understand anything :(




    edited by: alverman, Mar 27, 2008 - 09:24 PM
  • Ok, you did it well,
    but now you have to understand where the info is processed.
    You've included the turno field in the Argument check section, but it's only a validation.


    Now, go to the News_user_create() and include the turno field in the "Create the item array for processing" (line 153).
    After this, store it in the database! go to the pnuserapi file, in the function News_userapi_create (line 611), and replace this code (line 672):

    Code

    if (!DBUtil::insertObject($args, 'stories', 'sid')) {
            return LogUtil::registerError (_CREATEFAILED);
        }


    this one, to build the new stories_test registry and insert it:

    Code

    // Get the newly generated story id
        $newsid = DBUtil::insertObject($args, 'stories', 'sid');
        // check if the insertion was successful
        if (!$newsid) {
            return LogUtil::registerError (_CREATEFAILED);
        }

        // build the registry with the index of this article
        $test = array('tid' => $newsid, 'turno' => $args['turno'])

        // insert the 'turno' info the second table
        if (!DBUtil::insertObject($test, 'stories_test', 'tid')) {
            return LogUtil::registerError (_CREATEFAILED);
        }


    Also, you have to modify the News_adminapi_update function, to store the turno when you edit the article. Additionally, if you want to display that field, check the News_user_dispaly function and extract if of the 'stories_test' table, bla, bla, bla...


    I think that the News code is a little "advanced", you should try to modify the Pages module to understand the flow better icon_wink

    Happy PostNuking! icon_cool

    --
    - Mateo T. -
    Mis principios... son mis fines
  • I have succeeded to:
    creating an additional table (stories_event) in combination with the table stories :)

    The fields of the table stories_event contain 3 fields:
    eid (ID)
    sid (id of news)
    turno (generic text)

    When I include a new news the field turno of the table takes the value of a textarea in forms.
    In the field sid (stories_event) I put the sid of stories table.

    When I erase a news corresponding record in the table stories_event is erased :)

    Now I wanted to ask, nestor, how can I see the values of the table stories_event in the forms?

    Thank you for your help that you have given me so far and for your patience.

    Alverman
  • I understand that I must act in Function News_userapi_getall($args) and in Function News_userapi_get($args), but I do not know where and how to put things.
    In practice I do not know how to $ObjArray values read from table stories_test.

    Please do not let me right now :(
  • Give me a moment,
    i'll post here a join query that you need to extract the info of the 'stories_event' table in the getall and get functions icon_wink

    --
    - Mateo T. -
    Mis principios... son mis fines
  • Thank you, I avoid a night in white !! icon_biggrin
    Many many thanks
  • Up icon_cool
  • Well, sorry for the delay!


    In the News_userapi_get function, search this code:

    Code

    if (isset($args['sid']) && is_numeric($args['sid'])) {
            $item = DBUtil::selectObjectByID('stories', $args['sid'], 'sid', '', $permFilter);
    $permFilter);
        } elseif (isset($timestring)) {
            $where = "pn_urltitle = '".DataUtil::formatForStore($args['title'])."' AND pn_cr_date LIKE '{$timestring}%'";
            $item = DBUtil::selectObject('stories', $where, null, $permFilter);
        } else {
            $item = DBUtil::selectObjectByID('stories', $args['title'], 'urltitle', '', $permFilter);
    null, $permFilter);
        }


    And replace it for this one with the 'stories_event' join:

    Code

    $joinInfo = array();
        $joinInfo[] = array('join_table'          => 'stories_event',
                            'join_field'          => array('eid','turno'),
                            'object_field_name'   => array('eid','turno'),
                            'compare_field_table' => 'sid',
                            'compare_field_join'  => 'sid');

        if (isset($args['sid']) && is_numeric($args['sid'])) {
            $item = DBUtil::selectExpandedObjectByID('stories', $joinInfo, $args['sid'], 'sid', null, $permFilter);
        } elseif (isset($timestring)) {
            $where = "pn_urltitle = '".DataUtil::formatForStore($args['title'])."' AND pn_cr_date LIKE '{$timestring}%'";
            $item = DBUtil::selectExpandedObject('stories', $joinInfo, $where, null, $permFilter);
        } else {
            $item = DBUtil::selectExpandedObjectByID('stories', $joinInfo, $args['title'], 'urltitle', null, $permFilter);
        }

    basically, we join the SIDs and extract the 'eid' and 'turno' fields. Now you can manipulate those new $item fields ($item['eid'] and $item['turno']).




    Now, in the News_userapi_getall, search this code:

    Code

    $objArray = DBUtil::selectObjectArray ('stories', $where, $orderby, $args['startnum']-1, $args['numitems'], '', $permFilter, $args['catFilter']);


    and insert this join:

    Code

    $joinInfo = array();
        $joinInfo[] = array('join_table'          => 'stories_event',
                            'join_field'          => array('eid','turno'),
                            'object_field_name'   => array('eid','turno'),
                            'compare_field_table' => 'sid',
                            'compare_field_join'  => 'sid');

        $objArray = DBUtil::selectExpandedObjectArray('stories', $joinInfo, $where, $orderby, $args['startnum']-1, $args['numitems'], '', $permFilter, $args['catFilter']);


    Now, the same question.
    You can manage the 'eid' and 'turno' fields in the pnuser.php code in the same way that are used the 'sid', 'title' fields.


    I hope that you insert the correspondent textarea in the new/edit forms with the 'turno' information with no problems, and the modification work as expected icon_wink


    Good luck! icon_cool

    --
    - Mateo T. -
    Mis principios... son mis fines
  • I have a small problem.
    I receive this message:
    Column 'pn_sid' in order clause is ambiguous

    The error is caused by the fact that in stories_test I have a field named sid.
    How do I differentiated in 'handler sort' and in 'where clause'?

    I have try with stories.sid instead of sid but not work.

    Code

    ....
            switch ($args['order']) {
                case 0:
                    $order = 'stories.sid';
    ....

    However if I set $orderby='' it work and show the news with my field compiled :)
    If I try to edit the news I receive the same message but in where clause:
    Column 'pn_sid' in where clause is ambiguous

    I ask you one last little help to move me forward. icon_wink

    Many many thanks nestor icon_biggrin
  • Thanks Nestor ....... WORKS ALL icon_lol
    For the moment I have changed a field name sid fron stories_test in storiesid.
    I have add this code in News_adminapi_update($args) function when modify my news

    Code

    ....
        $eventargs = array('storiesid' => $args['sid'], 'turno' => $args['turno'], 'data' => $args['data']);
       
        // insert the 'turno' info the second table
        if (!DBUtil::updateObject($eventargs, 'stories_event', '', 'storiesid')) {
          return LogUtil::registerError (_CREATEFAILED);    
          }
    ....

    and now work ALL (insert,modify and delete news on all two tables) icon_biggrin
    I have no words to thank you.
    icon_wink
  • 0 users

This list is based on users active over the last 60 minutes.