Skip to content

Instantly share code, notes, and snippets.

@chartjes
Created August 28, 2014 18:10
Show Gist options
  • Save chartjes/18e8c5cc31626319c13d to your computer and use it in GitHub Desktop.
Save chartjes/18e8c5cc31626319c13d to your computer and use it in GitHub Desktop.
<?php
namespace OpenCFP\Entity\Mapper;
use Spot\Mapper;
class User extends Mapper
{
/**
* Return an array that grabs info from the User and Speaker entities
*
* @param integer $user_id
* @return array
*/
public function getDetails($user_id)
{
$user = $this->all()
->where(['id' => $user_id])
->with(['speaker'])
->limit(1);
return [
'photo_path' => $user[0]->photo_path,
'first_name' => $user[0]->first_name,
'last_name' => $user[0]->last_name,
'airport' => $user[0]->airport,
'email' => $user[0]->email,
'twitter' => $user[0]->twitter,
'bio' => $user[0]->speaker->bio,
'info' => $user[0]->speaker->info,
'transportation' => $user[0]->transportation,
'hotel' => $user[0]->hotel
];
}
}
@vlucas
Copy link

vlucas commented Aug 28, 2014

This could probably be better done like this:

<?php

namespace OpenCFP\Entity\Mapper;

use Spot\Mapper;

class User extends Mapper
{
    /**
     * Return an array that grabs info from the User and Speaker entities
     *
     * @param integer $user_id
     * @return array
     */
    public function getDetails($user_id)
    {
        $user = $this->where(['id' => $user_id])
            ->with(['speaker'])
            ->first(); // Will automatically apply the `limit(1)`

        return $user->toArray();
    }
}

@marfillaster
Copy link

If you have access to the statement obj, just do a return $stmt-->fetch()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment