Esempio n. 1
0
 function __construct()
 {
     parent::__construct();
     $this->initSqlMap();
     TActiveRecordManager::getInstance()->setDbConnection($this->getConnection());
     //$this->initScript('account-init.sql');
 }
Esempio n. 2
0
 function __construct()
 {
     if (!class_exists("TActiveRecordManager", false)) {
         throw new Exception("You need to enable the ActiveRecord module in your application configuration file.");
     }
     $ar_manager = TActiveRecordManager::getInstance();
     $_conn = $ar_manager->getDbConnection();
     $_conn->Active = true;
     $this->_dbMetaData = TDbMetaData::getInstance($_conn);
 }
Esempio n. 3
0
 function testLoadWithSqlMap_SaveWithActiveRecord()
 {
     $record = $this->sqlmap->queryForObject('GetActiveRecordAccounts');
     $registry = TActiveRecordManager::getInstance()->getObjectStateRegistry();
     $record->Account_FirstName = "Testing 123";
     $this->assertTrue($registry->isDirtyObject($record));
     $this->assertTrue($record->save());
     $check1 = $this->sqlmap->queryForObject('GetActiveRecordAccounts');
     $finder = ActiveAccount::finder();
     $check2 = $finder->findByAccount_FirstName($record->Account_FirstName);
     $this->assertSameAccount($record, $check1);
     $this->assertSameAccount($record, $check2);
     $this->initScript('account-init.sql');
 }
 function setup()
 {
     $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest', 'prado_unitest');
     TActiveRecordManager::getInstance()->setDbConnection($conn);
 }
Esempio n. 5
0
 /**
  * @return TActiveRecordManager
  */
 public function getManager()
 {
     if ($this->_manager === null) {
         $this->_manager = Prado::createComponent($this->getManagerClass());
     }
     return TActiveRecordManager::getInstance($this->_manager);
 }
Esempio n. 6
0
 protected function generateActiveRecord($config, $tablename, $output)
 {
     $manager = TActiveRecordManager::getInstance();
     if ($connection = $manager->getDbConnection()) {
         $gateway = $manager->getRecordGateway();
         $tableInfo = $gateway->getTableInfo($manager->getDbConnection(), $tablename);
         if (count($tableInfo->getColumns()) === 0) {
             echo '** Unable to find table or view "' . $tablename . '" in "' . $manager->getDbConnection()->getConnectionString() . "\".\n";
             return false;
         } else {
             $properties = array();
             foreach ($tableInfo->getColumns() as $field => $column) {
                 $properties[] = $this->generateProperty($field, $column);
             }
         }
         $classname = basename($output, '.php');
         $class = $this->generateClass($properties, $tablename, $classname);
         echo "  Writing class {$classname} to file {$output}\n";
         file_put_contents($output, $class);
     } else {
         echo '** Unable to connect to database with ConnectionID=\'' . $config->getConnectionID() . "'. Please check your settings in application.xml and ensure your database connection is set up first.\n";
     }
 }
Esempio n. 7
0
 public function performAction($args)
 {
     $app_dir = count($args) > 2 ? $this->getAppDir($args[2]) : $this->getAppDir();
     $this->_soap = count($args) > 3 ? $args[3] == "soap" || $args[3] == "true" ? true : false : false;
     $this->_overwrite = count($args) > 4 ? $args[4] == "overwrite" || $args[4] == "true" ? true : false : false;
     $this->_prefix = count($args) > 5 ? $args[5] : '';
     $this->_postfix = count($args) > 6 ? $args[6] : '';
     if ($app_dir !== false) {
         $config = $this->getActiveRecordConfig($app_dir);
         $manager = TActiveRecordManager::getInstance();
         $con = $manager->getDbConnection();
         $con->Active = true;
         $command = $con->createCommand("Show Tables");
         $dataReader = $command->query();
         $dataReader->bindColumn(1, $table);
         $generator = new PHP_Shell_Extensions_ActiveRecord();
         $tables = array();
         while ($dataReader->read() !== false) {
             $tables[] = $table;
         }
         $con->Active = False;
         foreach ($tables as $key => $table) {
             $output = $args[1] . "." . $this->_prefix . ucfirst($table) . $this->_postfix;
             if ($config !== false && $output !== false) {
                 $generator->generate("generate " . $table . " " . $output . " " . $this->_soap . " " . $this->_overwrite);
             }
         }
     }
     return true;
 }
Esempio n. 8
0
 /**
  * @return TActiveRecordGateway record table gateway.
  */
 public function getRecordGateway()
 {
     return TActiveRecordManager::getInstance()->getRecordGateway();
 }
Esempio n. 9
0
 function setup()
 {
     $conn = new TDbConnection('sqlite2:' . dirname(__FILE__) . '/ar_test.db');
     TActiveRecordManager::getInstance()->setDbConnection($conn);
 }
 /**
  * Initialize the active record manager.
  * @param TXmlDocument xml configuration.
  */
 public function init($xml)
 {
     parent::init($xml);
     $manager = TActiveRecordManager::getInstance();
     if ($this->getEnableCache()) {
         $manager->setCache($this->getApplication()->getCache());
     }
     $manager->setDbConnection($this->getDbConnection());
     $manager->setInvalidFinderResult($this->getInvalidFinderResult());
 }
Esempio n. 11
0
<?php

Prado::using('System.Data.*');
Prado::using('System.Web.UI.ActiveControls.*');
Prado::using('System.Data.ActiveRecord.TActiveRecordManager');
$db = new TDbConnection('mysql:host=localhost;dbname=xxxx', 'yyyy', 'zzzz');
$manager = TActiveRecordManager::getInstance();
$manager->setDbConnection($db);
class CommentRecord extends TActiveRecord
{
    const TABLE = 'qs_comments';
    public $id;
    public $username;
    public $date_added;
    public $page;
    public $block_id;
    public $content;
    public static function finder($className = __CLASS__)
    {
        return parent::finder($className);
    }
}
class CommentBlock extends TTemplateControl
{
    private $_page;
    function onLoad($param)
    {
        if (!$this->Page->IsCallBack) {
            $count = array();
            $data = $this->getCommentData();
            foreach ($data as $r) {
 function setup()
 {
     $conn = new TDbConnection('mysql:host=localhost;dbname=ar_test;port=3307', 'test5', 'test5');
     TActiveRecordManager::getInstance()->setDbConnection($conn);
 }