Archive for May, 2013

CakePHP HABTM List all related items

by on Wednesday, May 29th, 2013

public function getRolePermisions( $roleId ){
  $employee = $this->find('all', array(
   'conditions' => array( 'RolePermission.role_id' => $roleId )
 ));
 $list = Set::combine($employee,'{n}.Permission.id','{n}.Permission.name');
 return $list;
}

ExtJS 4 Loading data into form panel from store/model or via form.load

by on Tuesday, May 14th, 2013

var contactModel = component.contactDetails;
Ext.getCmp('EditContact_Form').getForm().loadRecord( contactModel );

OR

var form = this.getWebItemForm().getForm();
var data = this.getStore('WebItemsForm').getAt(0);
form.loadRecord(data);

OR

Ext.getCmp('patient-form').getForm().load({
     url:'formdata.php',
     params:{moduleId:moduleId,action:'doAction',activity:'getActivePatient'},
     success:function(form,action) {
                var res = action.result;
                Ext.getCmp('patient_count').setText(res.data.active_patient_count);
     },
    failure:function(response) {
    }
 });

sencha loading icon before app startup screen

by on Thursday, May 9th, 2013

In the index.html,  add a div in the body:


<body>
 <style type="text/css">
 #loading-mask {
 position: absolute;
 left: 0;
 top: 0;
 width: 100%;
 height: 100%;
 background: url(resources/img/indicator.gif) no-repeat;
 text-align: center;
 }
 </style>
 <div id="loading-mask"></div>
 <script type="text/javascript" src="app.js"></script>

 

In app.js, in the launch function, once all the app initialization is finished I remove the load mask with a fade animation:


if (Ext.get('loading')) {
 var loadmask = Ext.get('loading');
 Ext.Anim.run(loadmask, 'fade', {
 easing: 'out',
 duration: 500,
 after: function() {
 Ext.get('loading').remove();
 }
 });
}

Ext.Viewport.setMasked({
 xtype: 'loadmask',
 message: 'Please wait...'
});

Create some view here and call

Ext.Viewport.setMasked(null);

condition in find function cakephp

by on Wednesday, May 8th, 2013

How to get data on condition that start time only have current year data:


$event = $this->Event->find('first', array(
 'conditions' => array(
 'Event.id' => $targetEvent['Eventtarget']['event_id'],
 'Event.stage' => 'created',
 'year(Event.startTime)' => date('Y') ), //this is the condition we have to check
 'fields' => array('Event.startTime', 'Event.city', 'Event.zip', 'Event.employee_id')
 ));