array('numeric'), 'name' => array('notempty'), 'key' => array('notempty') ); var $hasMany = array( 'LocksUnits' ); var $hasAndBelongsToMany = array( 'Unit' ); var $default_log_level = array('log' => 30, 'show' => 15); /************************************************************************** ************************************************************************** ************************************************************************** * function: saveLock * - save data about a new or existing lock */ function saveLock($data) { $this->prEnter(compact('data')); $id = $data['Lock']['id']; if ($id) { $this->id = $id; // Save the old key $oldkey = $this->field('key'); $this->pr(5, compact('oldkey')); if ($this->field('key') != $data['Lock']['key']) $data['Lock']['last_key'] = $this->field('key'); /* // Find the number of outstanding locks in use */ /* $locks = $this->find('first', */ /* array('link' => array('Unit' => array('fields' => array('Unit.id'))), */ /* 'fields' => 'SUM(Unit.id) AS inuse', */ /* 'conditions' => array('Lock.id' => $id), */ /* )); */ /* $this->pr(5, compact('locks')); */ /* // Can't reduce the locks if there are all in use */ /* if ($locks[0]['inuse'] > $data['Lock']['qty']) */ /* return $this->prReturn(false); */ } // Everything looks good... save it! return $this->prReturn($this->save($data, false)); } function lockList() { return $this->find('list', array('order' => array('name'), )); } }