/** * Testing the getInstance() method with bad parameters. * * @since 1.2.1 */ public function testGetInstanceBad() { try { $provider = ActiveRecordProviderFactory::getInstance('Alpha\\Model\\ActiveRecordProviderDoesNotExist', new Person()); $this->fail('testing the getInstance() method with bad parameters'); } catch (IllegalArguementException $e) { $this->assertEquals('The class [Alpha\\Model\\ActiveRecordProviderDoesNotExist] is not defined anywhere!', $e->getMessage(), 'testing the getInstance() method with bad parameters'); } try { $provider = ActiveRecordProviderFactory::getInstance('Alpha\\Model\\ActiveRecordProviderFactory', new Person()); $this->fail('testing the getInstance() method with bad parameters'); } catch (IllegalArguementException $e) { $this->assertEquals('The class [Alpha\\Model\\ActiveRecordProviderFactory] does not implement the expected ActiveRecordProviderInterface interface!', $e->getMessage(), 'testing the getInstance() method with bad parameters'); } }
/** * This custom version provides the left/right class names to the business object constructor, required * for RelationLookup objects. * * (non-PHPdoc) * * @see Alpha\Model\ActiveRecord::loadAllByAttributes() */ public function loadAllByAttributes($attributes = array(), $values = array(), $start = 0, $limit = 0, $orderBy = 'OID', $order = 'ASC', $ignoreClassType = false) { self::$logger->debug('>>loadAllByAttributes(attributes=[' . var_export($attributes, true) . '], values=[' . var_export($values, true) . '], start=[' . $start . '], limit=[' . $limit . '], orderBy=[' . $orderBy . '], order=[' . $order . '], ignoreClassType=[' . $ignoreClassType . ']'); if (method_exists($this, 'before_loadAllByAttributes_callback')) { $this->before_loadAllByAttributes_callback(); } $config = ConfigProvider::getInstance(); if (!is_array($attributes) || !is_array($values)) { throw new IllegalArguementException('Illegal arrays attributes=[' . var_export($attributes, true) . '] and values=[' . var_export($values, true) . '] provided to loadAllByAttributes'); } $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); $objects = $provider->loadAllByAttributes($attributes, $values, $start, $limit, $orderBy, $order, $ignoreClassType, array($this->leftClassName, $this->rightClassName)); if (method_exists($this, 'after_loadAllByAttributes_callback')) { $this->after_loadAllByAttributes_callback(); } self::$logger->debug('<<loadAllByAttributes [' . count($objects) . ']'); return $objects; }
/** * Drops the configured database. * * @throws Alpha\Exception\AlphaException * * @since 2.0 */ public static function dropDatabase() { $config = ConfigProvider::getInstance(); $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), new Person()); $provider->dropDatabase(); }
/** * Gets the count from the database of the DEnumItems associated with this object. * * @return int * * @since 1.0 * * @throws Alpha\Exception\AlphaException */ public function getItemCount() { $config = ConfigProvider::getInstance(); $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); $sqlQuery = 'SELECT COUNT(OID) AS item_count FROM DEnumItem WHERE DEnumID = \'' . $this->getID() . '\';'; $this->setLastQuery($sqlQuery); $result = $provider->query($sqlQuery); if (count($result) > 0 && isset($result[0]['item_count'])) { return $result[0]['item_count']; } else { throw new AlphaException('Failed to get the item count for the DEnum. Database error string is [' . $provider->getLastDatabaseError() . ']'); } }
/** * Returns a hash array of the most popular tags based on their occurence in the database, * ordered by alphabet and restricted to the a count matching the $limit supplied. The * returned has array uses the tag content as a key and the database value as a value. * * @param $limit * * @return array * * @since 1.0 * * @throws Alpha\Exception\AlphaException */ public static function getPopularTagsArray($limit) { $config = ConfigProvider::getInstance(); $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), new self()); $sqlQuery = 'SELECT content, count(*) as count FROM ' . self::TABLE_NAME . " GROUP BY content ORDER BY count DESC LIMIT {$limit}"; try { $result = $provider->query($sqlQuery); } catch (CustomQueryException $e) { throw new AlphaException('Failed to query the tags table, error is [' . $e->getMessage() . ']'); return array(); } // now build an array of tags to be returned $popTags = array(); foreach ($result as $row) { $popTags[$row['content']] = $row['count']; } // sort the array by content key before returning ksort($popTags); return $popTags; }
/** * Loads all of the items for the given parent DEnum ID. * * @param int $EnumID The ID of the parent DEnum object. * * @return array * * @since 1.0 * * @throws Alpha\Exception\AlphaException */ public function loadItems($EnumID) { $config = ConfigProvider::getInstance(); $this->DEnumID->setValue($EnumID); $sqlQuery = 'SELECT OID FROM ' . self::TABLE_NAME . ' WHERE DEnumID = \'' . $EnumID . '\';'; $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); try { $result = $provider->query($sqlQuery); } catch (CustomQueryException $e) { throw new AlphaException('Failed to load objects, error is [' . $e->getMessage() . ']'); return array(); } // now build an array of objects to be returned $objects = array(); $count = 0; foreach ($result as $row) { $obj = new self(); $obj->load($row['OID']); $objects[$count] = $obj; ++$count; } return $objects; }