Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- internetking created topic »password problem« 25. May
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 25. May
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 25. May
- ehdwma created topic »Hide "Register new account" and change template to 3 col« 25. May
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 25. May
- mdee created topic »How to implement returnpage ?« 25. May
- nestormateo responded to »Fillters in Clip« 24. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
Adding news items from your module?
-
**unknown user**
- Rank: Softmore
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 379
The PTB have decreed that I need to be able to add news items via the module I spend most of my time beating up. I took a look at the "AddStory" module. The biggest problem is that, if I call the postStory function, all I'll get back is a boolean saying if the story was posted. I need the story's ID so I can put it in a table. Short of coding it in my own module, is there a function I can pnMod(API)Func into? -
**unknown user**
- Rank: Senior
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 2330
From adminapi.php in the Example module, there's an example of return the just-inserted id (in the 'create' function):
Code
// Get the ID of the item that we inserted. It is possible, although
// very unlikely, that this is different from $nextId as obtained
// above, but it is better to be safe than sorry in this situation
$tid = $dbconn->PO_Insert_ID($exampletable, $examplecolumn['tid']); -
**unknown user**
- Rank: Softmore
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 379
I could do that, but my concern would be that someone else might have posted a news article in the meantime (if the person entering the information in the module gets interrupted, for example). I ended up coding the function to add the item to the news myself. Now I can borrow the same code for other use in the future, should I need it. -
- Rank: Team Member
- Registered: Mar 18, 2002
- Last visit: Oct 21, 2009
- Posts: 6606
jediping
is there a function I can pnMod(API)Func into?
Not yet... This is one of the main features that will be provided by .80. PostNuke will be fully API compliant allowing all modules to inter-communicate.
-Mark
--
Visit My homepage and Zikula themes. -
**unknown user**
- Rank: Softmore
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 379
I do end up using the PO_Insert_ID thing in my code, but because the AddStory module has a redirect at the end of the adding, I think it would hijack my process. In addition to it not returning the story ID. :)
For those curious, I'll include my function that I ended up creating. Maybe it'll help someone else, until .8 :)
Code
<?php
// add a new travel item to a project in the database
function projects_travelapi_create($args){
// Get arguments from argument array
extract($args);
// Argument check
if ((!isset($projid)) ||
(!isset($dates)) ||
(!isset($locations)) ||
(!isset($people)) ||
(!isset($itin))) {
pnSessionSetVar('errormsg', _MODARGSERROR);
return false;
}
// Security check
if (!pnSecAuthAction(0, 'projects:projects:', "$projid::", ACCESS_EDIT)) {
pnSessionSetVar('errormsg', _MODULENOAUTH);
return false;
}
// Get datbase setup
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
$traveltable = $pntable['project_travel'];
$travelcolumn = &$pntable['project_travel_column'];
$projecttable = $pntable['project_projects'];
$projectcolumn = &$pntable['project_projects_column'];
$storytable=$pntable['stories'];
$storycolumn=&$pntable['stories_column'];
$projectinfo=pnModAPIFunc('projects','projects','get',array('projid'=>$projid));
// Get next ID in table
$nextId = $dbconn->GenId($traveltable);
$username=pnUserGetVar('uname');
$userid=pnUserGetVar('uid');
$projecturl=pnModURL('projects', 'projects', 'display', array ('projid' => $projid));
$bodytext="<b>Travel dates</b><br>".$dates." <br>
<b>Locations</b><br>".$locations." <br>
<b>People</b><br>".$people." <br>
<b>Itinerary</b><br>".$itin."<br>
<a href=\"".$projecturl."\">Project page</a>";
$title='Travel for '. $projectinfo['title'];
//PostNuke-ify the variables.
list($userid, $title, $bodytext) = pnVarPrepForStore($userid, $title, $bodytext);
// Add item to the DB
// change the cid to the travel category id when you upload to the live site.
// change the cid to the travel topic id when you upload to the live site. (or the other way around. I forget now.)
$sql = "INSERT INTO $storytable (
$storycolumn[sid],
$storycolumn[catid],
$storycolumn[aid],
$storycolumn[title],
$storycolumn[time],
$storycolumn[hometext],
$storycolumn[bodytext],
$storycolumn[comments],
$storycolumn[counter],
$storycolumn[topic],
$storycolumn[informant],
$storycolumn[notes],
$storycolumn[ihome],
$storycolumn[themeoverride],
$storycolumn[language],
$storycolumn[withcomm],
$storycolumn[format_type])
VALUES (
'".(int)$nextId."',
'0',
'".$userid."',
'".$title."',
NOW(),
' ',
'".$bodytext."',
'0',
'0',
'8',
'".$username."',
'Please use the project page to update this entry.',
'0',
' ',
' ',
'0',
'0')";
$dbconn->Execute($sql);
// Check for an error with the database code
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _STORYCREATEFAILED);
return false;
}
// Get the ID of the item that we inserted.
$storyid = $dbconn->PO_Insert_ID($storytable, $storycolumn['sid']);
$nextId = $dbconn->GenId($traveltable);
//PostNuke-ify the variables.
list($projid, $storyid) = pnVarPrepForStore($projid, $storyid);
// Add item to the DB
$sql = "INSERT INTO $traveltable (
$travelcolumn[travid],
$travelcolumn[projid],
$travelcolumn[storyid])
VALUES (
'".(int)$nextId."',
'".$projid."',
'".$storyid."')";
$dbconn->Execute($sql);
// Check for an error with the database code
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _TRAVELCREATEFAILED);
return false;
}
// Get the ID of the item that we inserted.
$travid = $dbconn->PO_Insert_ID($traveltable, $travelcolumn['travid']);
// Update the project's last-updated date.
$updated = pnModAPIFunc('projects',
'projects',
'update_lastupdate',
array('projid' => $projid));
if (!$updated) {
pnSessionSetVar('errormsg', _PROJECTUPDATEFAILED);
return false;
}
// Return the id of the newly created item to the calling process
return $travid;
}
?>
- Moderated by:
- Support
