Rev 3163 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Mapper;
use LeadersLinked\Model\UserProfile;
use LeadersLinked\Mapper\Common\MapperCommon;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Log\LoggerInterface;
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
class UserProfileMapper extends MapperCommon
{
const _TABLE = 'tbl_user_profiles';
/**
*
* @var UserProfileMapper
*/
private static $_instance;
/**
*
* @param AdapterInterface $adapter
*/
private function __construct($adapter)
{
parent::__construct($adapter);
}
/**
*
* @param AdapterInterface $adapter
* @return \LeadersLinked\Mapper\UserProfileMapper
*/
public static function getInstance($adapter)
{
if(self::$_instance == null) {
self::$_instance = new UserProfileMapper($adapter);
}
return self::$_instance;
}
/**
*
* @param int $user_id
* @return UserProfile[]
*/
public function fetchAllByUserId($user_id)
{
$prototype = new UserProfile;
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('user_id', $user_id);
return $this->executeFetchAllObject($select, $prototype);
}
/**
*
* @param int $id
* @return UserProfile
*/
public function fetchOne($id)
{
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('id', $id);
$select->limit(1);
$prototype = new UserProfile();
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param int $uuid
* @return UserProfile
*/
public function fetchOneByUuid($uuid)
{
$prototype = new UserProfile;
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('uuid', $uuid);
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param int $user_id
* @return UserProfile
*/
public function fetchOnePublicByUserId($user_id)
{
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('user_id', $user_id);
$select->limit(1);
$prototype = new UserProfile();
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param UserProfile $userProfile
* @return boolean
*/
public function insert($userProfile)
{
$hydrator = new ObjectPropertyHydrator();
$values = $hydrator->extract($userProfile);
$values = $this->removeEmpty($values);
$insert = $this->sql->insert(self::_TABLE);
$insert->values($values);
$result = $this->executeInsert($insert);
if($result) {
$userProfile->id = $this->lastInsertId;
}
return $result;
}
/**
*
* @param UserProfile $userProfile
* @return boolean
*/
public function updateExtended($userProfile)
{
$values = [
'description' => $userProfile->description,
];
$update = $this->sql->update(self::_TABLE);
$update->set($values);
$update->where->equalTo('id', $userProfile->id);
return $this->executeUpdate($update);
}
/**
*
* @param UserProfile $userProfile
* @return boolean
*/
public function updateImage($userProfile)
{
$values = [
'image' => $userProfile->image,
];
$update = $this->sql->update(self::_TABLE);
$update->set($values);
$update->where->equalTo('id', $userProfile->id);
return $this->executeUpdate($update);
}
/**
*
* @param UserProfile $userProfile
* @return boolean
*/
public function updateCover($userProfile)
{
$values = [
'cover' => $userProfile->cover,
];
$update = $this->sql->update(self::_TABLE);
$update->set($values);
$update->where->equalTo('id', $userProfile->id);
return $this->executeUpdate($update);
}
/**
*
* @param UserProfile $userProfile
* @return boolean
*/
public function updateSocialNetwork($userProfile)
{
$values = [
'facebook' => $userProfile->facebook,
'instagram' => $userProfile->instagram,
'twitter' => $userProfile->twitter,
];
$update = $this->sql->update(self::_TABLE);
$update->set($values);
$update->where->equalTo('id', $userProfile->id);
return $this->executeUpdate($update);
}
/**
*
* @param UserProfile $userProfile
* @return boolean
*/
public function updateLocation($userProfile)
{
$values = [
'location_id' => $userProfile->location_id,
];
$update = $this->sql->update(self::_TABLE);
$update->set($values);
$update->where->equalTo('id', $userProfile->id);
return $this->executeUpdate($update);
}
/**
*
* @param UserProfile $userProfile
* @return boolean
*/
public function delete($userProfile)
{
$delete = $this->sql->delete(self::_TABLE);
$delete->where->equalTo('id', $userProfile->id);
return $this->executeDelete($delete);
}
}