111 lines
2.6 KiB
PHP
111 lines
2.6 KiB
PHP
<?php
|
|
App::uses('AppModel', 'Model');
|
|
/**
|
|
* MicSysMicapp Model
|
|
*
|
|
* @property User $User
|
|
* @property Mannerofaddress $Mannerofaddress
|
|
*/
|
|
class AppUser extends AppModel {
|
|
|
|
/**
|
|
* Use database config
|
|
*
|
|
* @var string
|
|
*/
|
|
public $useDbConfig = 'dreamjobMain';
|
|
|
|
/**
|
|
* Use table
|
|
*
|
|
* @var mixed False or table name
|
|
*/
|
|
public $useTable = 'mic_sys_micapp';
|
|
|
|
/**
|
|
* Display field
|
|
*
|
|
* @var string
|
|
*/
|
|
public $displayField = 'id';
|
|
public $uploadDir = 'uploads';
|
|
/**
|
|
* Validation rules
|
|
*
|
|
* @var array
|
|
*/
|
|
public function imageUpload($data){
|
|
$dataSource = $this->getDataSource();
|
|
$dataSource->begin();
|
|
$this->id = $data["AppUser"]['id'];
|
|
$this->User->id = $data["AppUser"]['user_id'];
|
|
$filename = $this->id . "_-profil.". pathinfo($data[$this->alias]['avatar']['name'], PATHINFO_EXTENSION);
|
|
$filename = WWW_ROOT . $this->uploadDir . DS . $filename;
|
|
if(file_exists($filename)){
|
|
chmod($filename,0755); //Change the file permissions if allowed
|
|
unlink($filename); //remove the file
|
|
}
|
|
if (!move_uploaded_file($data[$this->alias]['avatar']['tmp_name'], $filename)) {
|
|
$result = false;
|
|
} else {
|
|
$result = $this->saveField('avatar', str_replace(DS, "/", str_replace(WWW_ROOT.$this->uploadDir.DS, "", $filename) ));
|
|
}
|
|
|
|
if ($result) {
|
|
$dataSource->commit();
|
|
return true;
|
|
} else {
|
|
$dataSource->rollback();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public $validate = array(
|
|
'id' => array(
|
|
'naturalNumber' => array(
|
|
'rule' => array('naturalNumber'),
|
|
//'message' => 'Your custom message here',
|
|
//'allowEmpty' => false,
|
|
//'required' => false,
|
|
//'last' => false, // Stop validation after this rule
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
),
|
|
),
|
|
'user_id' => array(
|
|
'numeric' => array(
|
|
'rule' => array('numeric'),
|
|
//'message' => 'Your custom message here',
|
|
//'allowEmpty' => false,
|
|
//'required' => false,
|
|
//'last' => false, // Stop validation after this rule
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
),
|
|
),
|
|
'take_systemwide' => array(
|
|
'boolean' => array(
|
|
'rule' => array('boolean'),
|
|
//'message' => 'Your custom message here',
|
|
//'allowEmpty' => false,
|
|
//'required' => false,
|
|
//'last' => false, // Stop validation after this rule
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
),
|
|
),
|
|
);
|
|
|
|
|
|
public $belongsTo = array(
|
|
'User' => array(
|
|
'className' => 'User',
|
|
'foreignKey' => 'user_id'
|
|
),
|
|
'Mannerofaddress' => array(
|
|
'className' => 'Mannerofaddress',
|
|
'foreignKey' => 'mannerofaddress_id',
|
|
'conditions' => '',
|
|
'fields' => '',
|
|
'order' => ''
|
|
)
|
|
);
|
|
}
|