grubix

Topic: Admin page to show all active jobs

Have searched forum hard but (surprisingly) not founded anyone else who wanted to do this.
The list of inactive jobs (under Home) when you load the admin section is really useful.

What would be doubly useful for me would be to have a list on the admin section of ALL the ACTIVE jobs, without having to guess blindly and keep going to check out different categories one by one.

This can't be too hard but I'm not confident because I don't really get the url-rewrite settings, such as causing the root of the admin page to show all inactive jobs and so on.

Ideally once I've done this I can add a link to the active jobs page on the admin menu bar, and then just change 'Home' for 'Inactive jobs' on that same menu.

putypuruty

Re: Admin page to show all active jobs

This is a pretty useful feature request - I'll take the time and implement it in about 2 weeks.

grubix

Re: Admin page to show all active jobs

Thanks so much Puty. On a personal level, I probably need to get round to it before 2 weeks, so if I have any luck I'll post what I discover here in this thread - though it's likely to come down to whether I fix my other big problem, eek!

Thanks again for your help, as ever.

grubix

Re: Admin page to show all active jobs

Made a start on this today.

Firstly, add into /admin/_templates/header.tpl:

Code:
<li><a {if $CURRENT_PAGE == ''}class="selected"{/if} href="{$BASE_URL_ADMIN}">Inactive jobs</a></li>
<li><a {if $CURRENT_PAGE == 'active-jobs'}class="selected"{/if} href="{$BASE_URL_ADMIN}active-jobs">Active jobs</a></li>

So what I've done there is changed "Home" to "Inactive jobs" (just for clarity) and added the second line which makes a menu link to our new "Active jobs" page.

in /admin/_templates/header.tpl, add:

Code:
        case 'active-jobs':
            if(!isset($_SESSION['AdminId']))
            {
                redirect_to(BASE_URL);
                exit;
            }
            require_once 'page_jobs_active.php';
            $flag = 1;
            break;

somewhere in the $page switch. I added it after case 'home': just cos the order made sense.

Now create a new page, admin/page_jobs_active.php, with the following contents:

Code:
<?php
    $the_jobs = array();
    
    $jobCount = $job->getActiveJobCount();
    
    $paginator = new Paginator($jobCount, JOBS_PER_PAGE, @$_REQUEST['p']);
    $paginator->setLink(BASE_URL.'home');
    $paginator->paginate();
    
    $firstLimit = $paginator->getFirstLimit();
    $lastLimit = $paginator->getLastLimit();
    
    $the_jobs = $job->GetPaginatedJobs($firstLimit, JOBS_PER_PAGE);
    
    $smarty->assign("pages",$paginator->pages_link);

    $smarty->assign('jobs', $the_jobs);
    
    $template = 'index-active.tpl';
?>

This is based on the page_home.php file which obviously is the one that shows the Inactive jobs.
There isn't much I've changed, only three bits: getInactiveJobCount() has become getActiveJobCount(), GetInactiveJobs has become GetPaginatedJobs, and index.tpl has become index-active.tpl.

Time for another new file, the new template. Create a copy of admin/_templates/index.tpl and name it index-active.tpl (as above). All you need to change in this one is change the <h2> title from "Inactive jobs" to "Active jobs".

Now to add the new function that we call in page_jobs_active.php. Add this code to _includes/class.Job.php:

Code:
    public function getActiveJobCount()
    {
        global $db;
        $sql = 'SELECT COUNT(id) AS total FROM '.DB_PREFIX.'jobs WHERE is_temp = 0 AND is_active = 1';
    
        $result = $db->query($sql);
        $row = $result->fetch_assoc();
        return $row['total'];    
    }

This is just a copy of the getInactiveJobCount() function where we're querying the database for jobs with is_active = 1 rather than = 0.

So that's your lot - you'll now have a page for viewing ALL active jobs in the admin section, just like you have always had a page for inactive jobs.

It's not done though, and hopefully one of you (probably Puty!) can give me some help!
Problems:
- I don't think GetPaginatedJobs is the right function to call, it's not an equivalent to GetInactiveJobs where it probably needs to be. There's some other stuff that already deals with pagination in there so I don't know if the pagination is getting repeated.
- As such, I'm not sure if this will work properly when there is need for pagination. Can't test at the moment as my site only has 7 active jobs on at the moment.
- Additionally, and importantly, the posts-loop.tpl file is not displaying the details of applications on the job listings where I want it to be doing so. I know why these aren't being shown, because {if $statisticalData[$job.id]} does not return true, I just don't know why it isn't returning true.

Look forward to someone helping me build on this, and hope it's useful as a start point.

putypuruty

Re: Admin page to show all active jobs

Hi, grubix!

I'll give it my best to implement this feature after the middle of July - I can't find the time until then.

grubix

Re: Admin page to show all active jobs

Ok, worked out what needed adding to provide the application data, wasn't too hard to work out in the end!

Open up your new page_jobs_active.php file, and after the line

Code:
    $the_jobs = $job->GetPaginatedJobs($firstLimit, JOBS_PER_PAGE);

add the following block:

Code:
    $statisticalData = array();
    $spamReportStatisticalData = array();
    
    if (count($the_jobs))
    {
        $jobIDs = array();
        
        foreach ($the_jobs as $index => $aJob)
            $jobIDs[] = $aJob['id'];
        
        $statisticalData = $job->GetApplicationsStatistics($jobIDs);
        $spamReportStatisticalData = $job->GetSpamReportStatistics($jobIDs);
    }

    $smarty->assign('statisticalData', $statisticalData);
    $smarty->assign('spamReportStatisticalData', $spamReportStatisticalData);

Job done! Now you've got all your application data on this Active jobs page too. Beautiful.

putypuruty

Re: Admin page to show all active jobs

@grubix

As I found out today, something similar (if not exactly what you want) is implemented in jobberbase 2.0 - if you have a little bit of SVN knowledge, you can get the latest code from our google code repository http://code.google.com/p/jobberbase/source/checkout

grubix

Re: Admin page to show all active jobs

Thanks puty!

No knowledge of SVN here at all! I think I have my page working fine - just gotta wait and see if pagification breaks it or not, but it's working sweet for now!

Great news that you're putting it in JB2.0 - it's just sad that with such a heavily-upgraded site as mine I'll probably never get the chance to upgrade, ah well!

travisbutterfield

Re: Admin page to show all active jobs

Thanks for your hard work on this, grubix! I'm very new to PHP, but your instructions were easy enough for me to follow that I got it to work!  This is a really great hack!

travisbutterfield

Re: Admin page to show all active jobs

p.s.  I just tested the pagination thing by changing my pagination settings in "Settings>Search/Pagination," and it works pretty good, except that when you click on the link to a new page it takes you to the admin "home" (inactive jobs) page, instead of the admin/active-jobs page.

For example, I have 12 jobs, and I changed the settings to paginate at 10 jobs per page.  So, when I view the admin/active-jobs page, it has the following links at the bottom: "1 2 »". When I click on any of these links, they go to admin/home?p=x (where x = the page number).  So, we just need to figure out why the current page thing isn't being applied to the new active-jobs page.

I'm sure there's a pretty simple fix to this issue, but, as I said, I'm really new to PHP.  Sorry if my terminology isn't as accurate as it could be, or whatever. :-)

Anyhoo.  I'll see if I can figure it out and will keep you posted on my progress (or lack thereof).

Last edited by travisbutterfield (2011-07-22 20:56:59)

travisbutterfield

Re: Admin page to show all active jobs

I solved it.

on page_jobs_active.php the code was copied from page_home.php, but one item wasn't updated.

To fix it, open page_jobs_active.php and replace

Code:
$paginator->setLink(BASE_URL.'home');

with this:

Code:
$paginator->setLink(BASE_URL.'active-jobs');

The links should work now.

Last edited by travisbutterfield (2011-07-22 22:04:03)

dynaz

Re: Admin page to show all active jobs

hi i follow every step but i found this

Fatal error: Call to a member function getActiveJobCount() on a non-object in /home/hiphuket/domains/hiphuket.info/public_html/job/admin/page_jobs_active.php on line 4

on /admin/page_jobs_active.php

how i solve this ? Thank you

Last edited by dynaz (2011-12-30 10:03:00)

Looking for information travel in Phuket Thailand HiPhuket.Info Update everything aorund Phuket Thailand

www.hiphuket.info

dynaz

Re: Admin page to show all active jobs

on line 4 error is

$jobCount = $job->getActiveJobCount();

Looking for information travel in Phuket Thailand HiPhuket.Info Update everything aorund Phuket Thailand

www.hiphuket.info

dynaz

Re: Admin page to show all active jobs

for

Code:

Code:
        case 'active-jobs':
            if(!isset($_SESSION['AdminId']))
            {
                redirect_to(BASE_URL);
                exit;
            }
            require_once 'page_jobs_active.php';
            $flag = 1;
            break;

i put on admin/index.php

Looking for information travel in Phuket Thailand HiPhuket.Info Update everything aorund Phuket Thailand

www.hiphuket.info

dynaz

Re: Admin page to show all active jobs

o.k. now it look fine Thank you

Looking for information travel in Phuket Thailand HiPhuket.Info Update everything aorund Phuket Thailand

www.hiphuket.info