Code Duplication    Length = 55-55 lines in 2 locations

Alpha/Model/ActiveRecordProviderMySQL.php 1 location

@@ 473-527 (lines=55) @@
470
     *
471
     * @see Alpha\Model\ActiveRecordProviderInterface::loadAll()
472
     */
473
    public function loadAll($start = 0, $limit = 0, $orderBy = 'OID', $order = 'ASC', $ignoreClassType = false)
474
    {
475
        self::$logger->debug('>>loadAll(start=['.$start.'], limit=['.$limit.'], orderBy=['.$orderBy.'], order=['.$order.'], ignoreClassType=['.$ignoreClassType.']');
476
477
        // ensure that the field name provided in the orderBy param is legit
478
        try {
479
            $field = $this->BO->get($orderBy);
480
        } catch (AlphaException $e) {
481
            throw new AlphaException('The field name ['.$orderBy.'] provided in the param orderBy does not exist on the class ['.get_class($this->BO).']');
482
        }
483
484
        if (!$ignoreClassType && $this->BO->isTableOverloaded()) {
485
            if ($limit == 0) {
486
                $sqlQuery = 'SELECT OID FROM '.$this->BO->getTableName().' WHERE classname = \''.get_class($this->BO).'\' ORDER BY '.$orderBy.' '.$order.';';
487
            } else {
488
                $sqlQuery = 'SELECT OID FROM '.$this->BO->getTableName().' WHERE classname = \''.get_class($this->BO).'\' ORDER BY '.$orderBy.' '.$order.' LIMIT '.
489
                    $start.', '.$limit.';';
490
            }
491
        } else {
492
            if ($limit == 0) {
493
                $sqlQuery = 'SELECT OID FROM '.$this->BO->getTableName().' ORDER BY '.$orderBy.' '.$order.';';
494
            } else {
495
                $sqlQuery = 'SELECT OID FROM '.$this->BO->getTableName().' ORDER BY '.$orderBy.' '.$order.' LIMIT '.$start.', '.$limit.';';
496
            }
497
        }
498
499
        $this->BO->setLastQuery($sqlQuery);
500
501
        if (!$result = self::getConnection()->query($sqlQuery)) {
502
            throw new RecordNotFoundException('Failed to load object OIDs, MySql error is ['.self::getConnection()->error.'], query ['.$this->BO->getLastQuery().']');
503
            self::$logger->debug('<<loadAll [0]');
504
505
            return array();
506
        }
507
508
        // now build an array of objects to be returned
509
        $objects = array();
510
        $count = 0;
511
        $RecordClass = get_class($this->BO);
512
513
        while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
514
            try {
515
                $obj = new $RecordClass();
516
                $obj->load($row['OID']);
517
                $objects[$count] = $obj;
518
                ++$count;
519
            } catch (ResourceNotAllowedException $e) {
520
                // the resource not allowed will be absent from the list
521
            }
522
        }
523
524
        self::$logger->debug('<<loadAll ['.count($objects).']');
525
526
        return $objects;
527
    }
528
529
    /**
530
     * (non-PHPdoc).

Alpha/Model/ActiveRecordProviderSQLite.php 1 location

@@ 472-526 (lines=55) @@
469
     *
470
     * @see Alpha\Model\ActiveRecordProviderInterface::loadAll()
471
     */
472
    public function loadAll($start = 0, $limit = 0, $orderBy = 'OID', $order = 'ASC', $ignoreClassType = false)
473
    {
474
        self::$logger->debug('>>loadAll(start=['.$start.'], limit=['.$limit.'], orderBy=['.$orderBy.'], order=['.$order.'], ignoreClassType=['.$ignoreClassType.']');
475
476
        // ensure that the field name provided in the orderBy param is legit
477
        try {
478
            $field = $this->BO->get($orderBy);
479
        } catch (AlphaException $e) {
480
            throw new AlphaException('The field name ['.$orderBy.'] provided in the param orderBy does not exist on the class ['.get_class($this->BO).']');
481
        }
482
483
        if (!$ignoreClassType && $this->BO->isTableOverloaded()) {
484
            if ($limit == 0) {
485
                $sqlQuery = 'SELECT OID FROM '.$this->BO->getTableName().' WHERE classname = \''.get_class($this->BO).'\' ORDER BY '.$orderBy.' '.$order.';';
486
            } else {
487
                $sqlQuery = 'SELECT OID FROM '.$this->BO->getTableName().' WHERE classname = \''.get_class($this->BO).'\' ORDER BY '.$orderBy.' '.$order.' LIMIT '.
488
                    $limit.' OFFSET '.$start.';';
489
            }
490
        } else {
491
            if ($limit == 0) {
492
                $sqlQuery = 'SELECT OID FROM '.$this->BO->getTableName().' ORDER BY '.$orderBy.' '.$order.';';
493
            } else {
494
                $sqlQuery = 'SELECT OID FROM '.$this->BO->getTableName().' ORDER BY '.$orderBy.' '.$order.' LIMIT '.$limit.' OFFSET '.$start.';';
495
            }
496
        }
497
498
        $this->BO->setLastQuery($sqlQuery);
499
500
        if (!$result = self::getConnection()->query($sqlQuery)) {
501
            throw new RecordNotFoundException('Failed to load object OIDs, SQLite error is ['.self::getLastDatabaseError().'], query ['.$this->BO->getLastQuery().']');
502
            self::$logger->debug('<<loadAll [0]');
503
504
            return array();
505
        }
506
507
        // now build an array of objects to be returned
508
        $objects = array();
509
        $count = 0;
510
        $RecordClass = get_class($this->BO);
511
512
        while ($row = $result->fetchArray()) {
513
            try {
514
                $obj = new $RecordClass();
515
                $obj->load($row['OID']);
516
                $objects[$count] = $obj;
517
                ++$count;
518
            } catch (ResourceNotAllowedException $e) {
519
                // the resource not allowed will be absent from the list
520
            }
521
        }
522
523
        self::$logger->debug('<<loadAll ['.count($objects).']');
524
525
        return $objects;
526
    }
527
528
    /**
529
     * (non-PHPdoc).