|
Page 2 of 4 Category editing function. As you perhaps noticed (line 72 and 76), the same function is used for creating new category and for editing existing one. admin.jportfsimple.php /** * Category editing */ function Cat_edit( $option, $uid ) { // build the html select list for ordering $query = 'SELECT ordering AS value, cat_name AS text FROM #__jportfsimple_categories ORDER BY ordering'; $lists['ordering'] = mosAdminMenus::SpecificOrdering( $row, $uid, $query, 1 ); $row = new jportfsimpleCategories($database); if($uid){ $row -> load($uid[0]); } HTML_jportfsimple::Cat_edit( $option, $row, $lists ); }
Lines 258, 259 are needed only if you want to be able to change order of categories during editing. You would also need 'ordering' field in database table. Actual category editing part is in lines 261 to 266: first new object is needed ($row), then if it is in fact editing of an existing category ($uid is not empty) load function loads it from the database. Finally, edit page is displayed (line 266). Cancellation of editing: admin.jportfsimple.php /** * Category editing cancel */ function Cat_cancel( $option, $act ) { mosRedirect( 'index2.php?option='.$option.'&act='.$act ); }
Just redirecting after pressing "Cancel". Category listing: admin.jportfsimple.php /** * Category listing */ function Cat_list( $option ) { global $database, $mainframe, $mosConfig_absolute_path, $mosConfig_list_limit; $limit = intval( $mainframe-> getUserStateFromRequest( 'viewlistlimit', 'limit', $mosConfig_list_limit ) ); $limitstart = intval( $mainframe-> getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ) ); require_once( $mosConfig_absolute_path . '/administrator/includes/pageNavigation.php' ); $query = 'SELECT COUNT(*) FROM #__jportfsimple_categories'; $database->setQuery( $query ); $total = $database->loadResult(); $pageNav = new mosPageNav( $total, $limitstart, $limit ); $database->setQuery('SELECT * FROM #__jportfsimple_categories ORDER BY ordering LIMIT '.$pageNav->limitstart.', '.$pageNav->limit ); $rows = $database -> loadObjectList(); if ($database -> getErrorNum()) { echo $database -> stderr(); return false; } HTML_jportfsimple::Cat_list( $option, $rows, $pageNav ); HTML_jportfsimple::bottom(); }
Main function listing all categories. Lines 285 to 287 - gets current page and number of categories per page, selected by user, and loads required class 289 to 291 - first query, loading just the total number of existing categories (SELECT COUNT), needed for pagination 293 - creates new $pageNav object 295 to 300 - second query, loading just the categories on current page 302, 303 - displaying functions are called
Project functions next are very similar to the above function dealing with categories. I will list only main differences instead of full rest of the code. In Proj_publish, Proj_save and Proj_del (project publishing, saving and deleting functions) redirecting function in last line goes to projects page: admin.jportfsimple.php mosRedirect( 'index2.php?option='.$option.'&act=projects' );
Project editing function: admin.jportfimple.php /** * Project editing */ function Proj_edit( $option, $uid ) { $proj = new jportfsimpleProjects($database); if($uid) { $proj -> load($uid[0]); } else $proj-> date = date( 'Y-m-d H:i:s' ); // creation date, 2006-09-01 10:00:00 $database->setQuery('SELECT * FROM #__jportfsimple_categories ORDER BY cat_name'); $rows = $database -> loadObjectList(); if ($database -> getErrorNum()) { echo $database -> stderr(); return false; } foreach ($rows as $row) { $urow2[]=$row->id; $urow[]=$row->cat_name; } $i=0; $j=0; //$j for Select category text in case of new item if (!$uid) { $categories[$i] = mosHTML::makeOption( '0', _COM_JP_SEL_ALBUM ); $i++; $j=1; } foreach ($urow as $row) { $categories[$i] = mosHTML::makeOption( $urow2[$i-$j], $urow[$i-$j]); $i++; } $size=1; $javascript = ''; $category = mosHTML::selectList( $categories, 'catid', 'class="inputbox" size="'. $size .'" '. $javascript, 'value', 'text', $proj->catid ); $lists['category'] = $category; // build the html select list for ordering $query = 'SELECT ordering AS value, name AS text ' . ' FROM #__jportfsimple_projects' . ' WHERE catid = '.$proj->catid . ' ORDER BY ordering'; $lists['ordering'] = mosAdminMenus::SpecificOrdering( $proj, $uid, $query, 1 ); foreach ($rows as $c) { $c2[$c->id]=$c; } HTML_jportfsimple::Proj_edit( $option, $proj, $base_path, $c2, $lists); }
Lines 376 to 380 - if editing existing project, load it's data, or set a creation date for new project 382 to 408 - this part is used to create a list of categories in HTML select form, for easier selecting a category the project should belong to, instead of entering a category name manually. The challenge here is to select a name, but return a category id. First it gets list of categories, then it creates a $categories array with HTML code for select function, with category id and a name (lines 389 - 402), finally it finishes HTML preparation. It uses functions from Joomla's mosHTML class. 410 to 415 - builds another HTML select list, this one for ordering of a project 419 - calles display function
Project listing function is also similar to category listing, added is the above code for creating HTML select function for filtering projects by a category. Last two functions: ordercat and orderproj - are used whenever reorder arrow is clicked. admin.jportfsimple.php /** * Category ordering */ function ordercat( $uid, $inc, $option, $act ) { $row = new jportfsimpleCategories( $database ); $row->load( $uid ); $row->updateOrder(); $row->move( $inc, 'published >= 0' ); $row->updateOrder(); mosRedirect( 'index2.php?option='. $option .'&act='. $act); }
This is nothing else like using internal Joomla function (updateOrder in this case) to reorder objects.
|