function afterSave($created) { if ($created) { // its a creation $id = $this->getLastInsertID(); $aro = new Aro(); $aro->updateAll(array('alias' => '\'User:'******'\''), array('Aro.model' => 'User', 'Aro.foreign_key' => $id)); } else { // its an edit, we have to update the tree $data = $this->read(); $parent_id = $data['User']['group_id']; $aro = new Aro(); $aro_record = $aro->findByAlias($this->name . ':' . $this->id); $parent_record = $aro->findByAlias('Group:' . $parent_id); if (!empty($aro_record)) { $parent_id = '0'; if (!empty($parent_record)) { $parent_id = $parent_record['Aro']['id']; } // just changing parents $this->Aro->save(array('parent_id' => $parent_id, 'id' => $aro_record['Aro']['id'])); } } return true; }
function afterSave($created = null) { if ($created) { $users_id = $this->getLastInsertId(); $aro = new Aro(); $aro->updateAll(array('alias' => "'" . $this->data['Users']['username'] . "'"), array('Aro.model' => 'Users', 'Aro.foreign_key' => $users_id)); } }
function afterSave($created) { if ($created) { // its a creation $id = $this->getLastInsertID(); $aro = new Aro(); $aro->updateAll(array('alias' => '\'Group:' . $id . '\''), array('Aro.model' => 'Group', 'Aro.foreign_key' => $id)); } else { // its an edit, we have to update the tree $data = $this->read(); $parent_id = $data['Group']['parent_id']; $aro = new Aro(); $aro_record = $aro->findByForeignKey($this->id); $parent_record = $aro->findByForeignKey($parent_id); if (empty($aro_record)) { // orphaned child $this->Aro->save(array('model' => $this->name, 'foreign_key' => $this->id, 'alias' => $this->name . ':' . $this->id, 'parent_id' => $parent_record['Aro']['id'])); } else { // just moving nodes $this->Aro->save(array('model' => $this->name, 'foreign_key' => $this->id, 'alias' => $this->name . ':' . $this->id, 'parent_id' => $parent_record['Aro']['id'], 'id' => $aro_record['Aro']['id'])); } } return true; }