Wednesday, December 19, 2012

YII framework dynamic Table Model


/**
 * CActiveRecord implementation that allows specifying
 * DB table name instead of creating a class for each table.
 *
 * Usage (assuming table 'user' with columns 'id' and 'name'):
 *
 * $userModel = DynamicActiveRecord::forTable('user');
 * //list existing users
 * foreach ($userModel->findAll() as $user)
 * echo $user->id . ': ' . $user->name . '
';
 * //add new user
 * $userModel->name = 'Pavle Predic';
 * $userModel->save();
 *
 * @author Pavle Predic
 */
class DynamicActiveRecord extends CActiveRecord
{
/**
* Name of the DB table
* @var string
*/
protected $_tableName;

/**
* Table meta-data.
* Must redeclare, as parent::_md is private
* @var CActiveRecordMetaData
*/
protected $_md;

/**
* Constructor
* @param string $scenario (defaults to 'insert')
* @param string $tableName
*/
public function __construct($scenario = 'insert', $tableName = null)
{
$this->_tableName = $tableName;
parent::__construct($scenario);
}

/**
* Overrides default instantiation logic.
* Instantiates AR class by providing table name
* @see CActiveRecord::instantiate()
* @return DynamicActiveRecord
*/
protected function instantiate($attributes)
{
return new DynamicActiveRecord(null, $this->tableName());
}

/**
* Returns meta-data for this DB table
* @see CActiveRecord::getMetaData()
* @return CActiveRecordMetaData
*/
public function getMetaData()
{
if ($this->_md !== null)
return $this->_md;
else
return $this->_md = new CActiveRecordMetaData($this);
}

/**
* Returns table name
* @see CActiveRecord::tableName()
* @return string
*/
public function tableName()
{
if (!$this->_tableName)
$this->_tableName = parent::tableName();
return $this->_tableName;
}

/**
* Returns an instance of DynamicActiveRecord for the provided DB table.
* This is a helper method that may be used instead of constructor.
* @param string $tableName
* @param string $scenario
* @return DynamicActiveRecord
*/
public static function forTable($tableName, $scenario = 'insert')
{
return new DynamicActiveRecord($scenario, $tableName);
}
}

Thursday, December 6, 2012

YII Framework - Highcharts Extension - datetime issue Resolved


$this->Widget('ext.highcharts.HighchartsWidget', array(
   'options'=>'{
      "title": { "text": "MYSQL Replication" },
      "xAxis": {
      "title": { "text": "Month" },
"type": "datetime",
            "dateTimeLabelFormats": {
                "day": "%e"  
            }
      },
      "yAxis": {
         "title": { "text": "Time" },
"type": "datetime",
        "dateTimeLabelFormats": {
                "hour": "%H"
            }
      },
      "tooltip": {
            "xDateFormat": "%Y-%m-%d"
        },      
      "series": [
{ "name": "success", "data": [[x_ms,y_ms],[x_ms,y_ms]],"pointStart": utc_ms, "pointInterval": date_ms},
         { "name": "failure", "data": [[x_ms,y_ms],[x_ms,y_ms]],"pointStart": utc_ms, "pointInterval": date_ms}
      ]
   }'
));

<script src="http://code.highcharts.com/highcharts.js"></script>

Tuesday, December 4, 2012

SoapUI for ubuntu

http://askubuntu.com/questions/198896/what-is-a-simple-free-soap-client-gui


You can still use SOAPUI
download the script from here and save it on the disk.
then from a terminal
cd /path-to-directory-where-you-downlaod-it
sudo chmod +x soapUI-x32-4_0_0.sh
sudo ./soapUI-x32-4_0_0.sh