Code Duplication    Length = 53-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 = \''.addslashes(get_class($this->BO)).'\' ORDER BY '.$orderBy.' '.$order.';';
487
            } else {
488
                $sqlQuery = 'SELECT OID FROM '.$this->BO->getTableName().' WHERE classname = \''.addslashes(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

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