AutorÃa | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Mapper;
use LeadersLinked\Model\CompanyFollower;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Log\LoggerInterface;
use LeadersLinked\Mapper\Common\MapperCommon;
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
use Laminas\Db\Sql\Expression;
class CompanyFollowerMapper extends MapperCommon
{
const _TABLE = 'tbl_company_followers';
/**
*
* @var CompanyFollowerMapper
*/
private static $_instance;
/**
*
* @param AdapterInterface $adapter
*/
private function __construct($adapter)
{
parent::__construct($adapter);
}
/**
*
* @param AdapterInterface $adapter
* @return CompanyFollowerMapper
*/
public static function getInstance($adapter)
{
if(self::$_instance == null) {
self::$_instance = new CompanyFollowerMapper($adapter);
}
return self::$_instance;
}
/**
*
* @param int $user_id
* @return int
*/
public function getCountFollowers($company_id)
{
$select = $this->sql->select(self::_TABLE);
$select->columns(['total' => new Expression('COUNT(*)')]);
$select->where->equalTo('company_id', $company_id);
$record = $this->executeFetchOneArray($select);
return $record['total'];
}
/**
*
* @param int $user_id
* @return int
*/
public function getCountFollowing($follower_id)
{
$select = $this->sql->select(self::_TABLE);
$select->columns(['total' => new Expression('COUNT(*)')]);
$select->where->equalTo('follower_id', $follower_id);
$record = $this->executeFetchOneArray($select);
return $record['total'];
}
/**
*
* @param int $follower_id
* @return CompanyFollower[]
*/
public function fetchAllByFollowerId($follower_id)
{
$prototype = new CompanyFollower();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('follower_id', $follower_id);
return $this->executeFetchAllObject($select, $prototype);
}
/**
*
* @param int $company_id
* @return CompanyFollower[]
*/
public function fetchAllByCompanyId($company_id)
{
$prototype = new CompanyFollower();
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('company_id', $company_id);
return $this->executeFetchAllObject($select, $prototype);
}
/**
*
* @param int $company_id
* @param int $user_id
* @return CompanyFollower
*/
public function fetchOneByCompanyIdAndUserId($company_id, $user_id)
{
$select = $this->sql->select(self::_TABLE);
$select->where->equalTo('company_id', $company_id)->and->equalTo('follower_id', $user_id);
$prototype = new CompanyFollower();
return $this->executeFetchOneObject($select, $prototype);
}
/**
*
* @param int $company_id
* @param int $user_id
* @return boolean
*/
public function deleteByCompanyIdAndUserId($company_id, $user_id)
{
$delete = $this->sql->delete(self::_TABLE);
$delete->where->equalTo('company_id', $company_id)->and->equalTo('follower_id', $user_id);
return $this->executeDelete($delete);
}
/**
*
* @param CompanyFollower $companyFollower
* @return boolean
*/
public function insert($companyFollower)
{
$hydrator = new ObjectPropertyHydrator();
$values = $hydrator->extract($companyFollower);
$values = $this->removeEmpty($values);
$insert = $this->sql->insert(self::_TABLE);
$insert->values($values);
return $this->executeInsert($insert);
}
}