dreamjob/app/Model/AppUser.php

113 lines
2.8 KiB
PHP
Raw Normal View History

2014-02-18 12:10:29 +01:00
<?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';
2014-04-15 19:47:57 +02:00
public $uploadDir = 'uploads';
2014-02-18 12:10:29 +01:00
/**
* Validation rules
*
* @var array
*/
2014-04-15 19:47:57 +02:00
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($data["AppUser"]['take_systemwide'])
$result = $this->User->saveField('avatar', str_replace(DS, "/", str_replace(WWW_ROOT.$this->uploadDir.DS, "", $filename) ));
}
if ($result) {
$dataSource->commit();
return true;
} else {
$dataSource->rollback();
}
return false;
}
2014-02-18 12:10:29 +01:00
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' => ''
)
);
}