| @@ 1606-1647 (lines=42) @@ | ||
| 1603 | * |
|
| 1604 | * @see Alpha\Model\ActiveRecordProviderInterface::getCount() |
|
| 1605 | */ |
|
| 1606 | public function getCount($attributes = array(), $values = array()) |
|
| 1607 | { |
|
| 1608 | self::$logger->debug('>>getCount(attributes=['.var_export($attributes, true).'], values=['.var_export($values, true).'])'); |
|
| 1609 | ||
| 1610 | if ($this->BO->isTableOverloaded()) { |
|
| 1611 | $whereClause = ' WHERE classname = \''.get_class($this->BO).'\' AND'; |
|
| 1612 | } else { |
|
| 1613 | $whereClause = ' WHERE'; |
|
| 1614 | } |
|
| 1615 | ||
| 1616 | $count = count($attributes); |
|
| 1617 | ||
| 1618 | for ($i = 0; $i < $count; ++$i) { |
|
| 1619 | $whereClause .= ' '.$attributes[$i].' = \''.$values[$i].'\' AND'; |
|
| 1620 | self::$logger->debug($whereClause); |
|
| 1621 | } |
|
| 1622 | // remove the last " AND" |
|
| 1623 | $whereClause = mb_substr($whereClause, 0, -4); |
|
| 1624 | ||
| 1625 | if ($whereClause != ' WHERE') { |
|
| 1626 | $sqlQuery = 'SELECT COUNT(OID) AS class_count FROM '.$this->BO->getTableName().$whereClause; |
|
| 1627 | } else { |
|
| 1628 | $sqlQuery = 'SELECT COUNT(OID) AS class_count FROM '.$this->BO->getTableName(); |
|
| 1629 | } |
|
| 1630 | ||
| 1631 | $this->BO->setLastQuery($sqlQuery); |
|
| 1632 | ||
| 1633 | $result = self::getConnection()->query($sqlQuery); |
|
| 1634 | ||
| 1635 | if ($result) { |
|
| 1636 | $row = $result->fetch_array(MYSQLI_ASSOC); |
|
| 1637 | ||
| 1638 | self::$logger->debug('<<getCount ['.$row['class_count'].']'); |
|
| 1639 | ||
| 1640 | return $row['class_count']; |
|
| 1641 | } else { |
|
| 1642 | throw new AlphaException('Failed to get the count for the class ['.get_class($this->BO).'] from the table ['.$this->BO->getTableName().'], query is ['.$this->BO->getLastQuery().']'); |
|
| 1643 | self::$logger->debug('<<getCount [0]'); |
|
| 1644 | ||
| 1645 | return 0; |
|
| 1646 | } |
|
| 1647 | } |
|
| 1648 | ||
| 1649 | /** |
|
| 1650 | * (non-PHPdoc). |
|
| @@ 1659-1699 (lines=41) @@ | ||
| 1656 | * |
|
| 1657 | * @see Alpha\Model\ActiveRecordProviderInterface::getCount() |
|
| 1658 | */ |
|
| 1659 | public function getCount($attributes = array(), $values = array()) |
|
| 1660 | { |
|
| 1661 | self::$logger->debug('>>getCount(attributes=['.var_export($attributes, true).'], values=['.var_export($values, true).'])'); |
|
| 1662 | ||
| 1663 | if ($this->BO->isTableOverloaded()) { |
|
| 1664 | $whereClause = ' WHERE classname = \''.get_class($this->BO).'\' AND'; |
|
| 1665 | } else { |
|
| 1666 | $whereClause = ' WHERE'; |
|
| 1667 | } |
|
| 1668 | ||
| 1669 | $count = count($attributes); |
|
| 1670 | ||
| 1671 | for ($i = 0; $i < $count; ++$i) { |
|
| 1672 | $whereClause .= ' '.$attributes[$i].' = \''.$values[$i].'\' AND'; |
|
| 1673 | self::$logger->debug($whereClause); |
|
| 1674 | } |
|
| 1675 | // remove the last " AND" |
|
| 1676 | $whereClause = mb_substr($whereClause, 0, -4); |
|
| 1677 | ||
| 1678 | if ($whereClause != ' WHERE') { |
|
| 1679 | $sqlQuery = 'SELECT COUNT(OID) AS class_count FROM '.$this->BO->getTableName().$whereClause; |
|
| 1680 | } else { |
|
| 1681 | $sqlQuery = 'SELECT COUNT(OID) AS class_count FROM '.$this->BO->getTableName(); |
|
| 1682 | } |
|
| 1683 | ||
| 1684 | $this->BO->setLastQuery($sqlQuery); |
|
| 1685 | ||
| 1686 | if (!$result = self::getConnection()->query($sqlQuery)) { |
|
| 1687 | throw new AlphaException('Failed to get the count for the class ['.get_class($this->BO).'] from the table ['.$this->BO->getTableName().'], query is ['.$this->BO->getLastQuery().']'); |
|
| 1688 | ||
| 1689 | self::$logger->debug('<<getCount [0]'); |
|
| 1690 | ||
| 1691 | return 0; |
|
| 1692 | } else { |
|
| 1693 | $row = $result->fetchArray(SQLITE3_ASSOC); |
|
| 1694 | ||
| 1695 | self::$logger->debug('<<getCount ['.$row['class_count'].']'); |
|
| 1696 | ||
| 1697 | return $row['class_count']; |
|
| 1698 | } |
|
| 1699 | } |
|
| 1700 | ||
| 1701 | /** |
|
| 1702 | * (non-PHPdoc). |
|