| 1 |
efrain |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Mapper;
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
use LeadersLinked\Mapper\Common\MapperCommon;
|
|
|
8 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
9 |
use LeadersLinked\Model\Application;
|
|
|
10 |
use LeadersLinked\Model\ApplicationVariant;
|
|
|
11 |
use Laminas\Db\Sql\Expression;
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
class ApplicationVariantMapper extends MapperCommon
|
|
|
15 |
{
|
|
|
16 |
const _TABLE = 'tbl_application_variants';
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
*
|
|
|
20 |
* @var ApplicationMapper
|
|
|
21 |
*/
|
|
|
22 |
private static $_instance;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
*
|
|
|
26 |
* @param AdapterInterface $adapter
|
|
|
27 |
*/
|
|
|
28 |
private function __construct($adapter)
|
|
|
29 |
{
|
|
|
30 |
parent::__construct($adapter);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
*
|
|
|
35 |
* @param AdapterInterface $adapter
|
|
|
36 |
* @return ApplicationVariantMapper
|
|
|
37 |
*/
|
|
|
38 |
public static function getInstance($adapter)
|
|
|
39 |
{
|
|
|
40 |
if(self::$_instance == null) {
|
|
|
41 |
self::$_instance = new ApplicationVariantMapper($adapter);
|
|
|
42 |
}
|
|
|
43 |
return self::$_instance;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/*
|
|
|
47 |
**
|
|
|
48 |
*
|
|
|
49 |
* @param int $application_id
|
|
|
50 |
* @param int $variant_id
|
|
|
51 |
* @return ApplicationVariant
|
|
|
52 |
*/
|
|
|
53 |
public function fetchCountActiveByCompanyId($company_id)
|
|
|
54 |
{
|
|
|
55 |
|
|
|
56 |
$select = $this->sql->select(self::_TABLE);
|
|
|
57 |
$select->columns(['total' => new Expression('COUNT(*)')]);
|
|
|
58 |
$select->where->equalTo('company_id', $company_id);
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
$row = $this->executeFetchOneArray($select);
|
|
|
63 |
return $row['total'];
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
*
|
|
|
69 |
* @param int $application_id
|
|
|
70 |
* @param int $variant_id
|
|
|
71 |
* @return ApplicationVariant
|
|
|
72 |
*/
|
|
|
73 |
public function fetchOneByApplicationIdAndVariantId($application_id, $variant_id)
|
|
|
74 |
{
|
|
|
75 |
|
|
|
76 |
$select = $this->sql->select(self::_TABLE);
|
|
|
77 |
$select->where->equalTo('application_id', $application_id);
|
|
|
78 |
$select->where->equalTo('variant_id', $variant_id);
|
|
|
79 |
|
|
|
80 |
$prototype = new ApplicationVariant();
|
|
|
81 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
*
|
|
|
86 |
* @param int $application_id
|
|
|
87 |
* @return ApplicationVariant
|
|
|
88 |
*/
|
|
|
89 |
public function fetchOneByApplicationIdAndDefault($application_id)
|
|
|
90 |
{
|
|
|
91 |
|
|
|
92 |
$select = $this->sql->select(self::_TABLE);
|
|
|
93 |
$select->where->equalTo('application_id', $application_id);
|
|
|
94 |
$select->where->equalTo('default', ApplicationVariant::DEFAULT_YES);
|
|
|
95 |
|
|
|
96 |
$prototype = new ApplicationVariant();
|
|
|
97 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
}
|