New Profiles

4 posts by 2 authors in: Forums > CMS Builder
Last Post: August 18, 2009   (RSS)

Re: [kcmedia] New Profiles

By Chris - August 18, 2009

Hi kcmedia,

If your records are created at the same time as staff members are hired, there's a really easy solution: you can have PHP check the "createdDate" of the record and display some HTML if the record was created in the past 30 days:

<?php if (strtotime(date('Y-m-d'))-strtotime($record['createdDate']) < 60*60*24*30): ?>
<span style="color:red;font-weight:bold;text-decoration:blink;">NEW</span>
<?php endif; ?>


If you can't rely on the createdDate, a simple alternative would involve adding a new date field "hiredDate". You could use a checkbox field, but you'd need to manually update it. Or you could combine the two: a checkbox which decides which date should be used to determine how new the staff member is.

I hope this helps you! Please let us know if you have any more questions or comments.
All the best,
Chris

Re: [chris] New Profiles

By KCMedia - August 18, 2009

Hi Chris

Thanks for that.

it worked great but the problem is how can i sort the listings at the moment they are sorted by alpha but i want it so that new ones go to the top above the alpha and then the not new ones below it.
Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Re: [kcmedia] New Profiles

By Chris - August 18, 2009 - edited: August 18, 2009

Hi kcmedia,

No problem. :)

For the next issue, add this code to the top of the page in STEP 1 (after the getRecord(...); call, but before ?>)

foreach ( array_keys( $ladiesRecords ) as $key ) {
$record =& $ladiesRecords[$key];
$record['recordIsNew'] = (strtotime(date('Y-m-d'))-strtotime($record['createdDate']) < 60*60*24*30);
}

function customSort($a, $b) {
// if both records are new or not new, sort alphabetically by name
if ( $a['recordIsNew'] == $b['recordIsNew'] ) { return strcmp($a['name'], $b['name']); }
// otherwise, sort new records to the top
if ( $a['recordIsNew'] ) { return -1; }
if ( $b['recordIsNew'] ) { return 1; }
}
usort($ladiesRecords, 'customSort');


Please let us know how it goes.
All the best,
Chris