/** * Upload the latest version of a file before saving the upload record (or potentially the first/only version) */ public function beforeSave() { if (!isset($this->data['Upload']['id'])) { $this->data['UploadVersion']['upload_id'] = null; } else { $this->data['UploadVersion']['upload_id'] = $this->data['Upload']['id']; } // Save just the uploadversion $data['UploadVersion'] = $this->data['UploadVersion']; if (!$this->UploadVersion->save($data)) { $this->validationErrors = Set::Merge($this->validationErrors, $this->UploadVersion->validationErrors); return; } $this->data['Upload']['active_version_id'] = $this->UploadVersion->id; // First version if (empty($this->data['Upload']['id'])) { $this->__firstVersion = true; } return true; }
function _getClass($type, $name) { $_this =& ClassCollection::getInstance(); $options = $_this->getOption($type, $name); $res = array('class' => null, 'import' => array(), 'isParent' => false); if (!empty($options['parent'])) { $inerit = array_intersect_key($options, array_flip($_this->parentInerit)); $parentOpt = Set::Merge($inerit, $options['parent']); $parent = $_this->_getClass(null, $parentOpt); if (empty($parent)) { return null; } else { $res['import'] = $parent['import']; } } $importOpt = $_this->parseImportOption($options); foreach ($importOpt['search'] as $plugin => $search) { foreach ($search as $path) { $iopt = $importOpt; $iopt['search'] = $path; if (App::import($iopt)) { $res['import'][] = $iopt; $res['class'] = $iopt['name']; $res['plugin'] = $plugin == 'app' ? null : $plugin; break 2; } } } if (!$res['class']) { if (!empty($parent) && $options['defaultByParent']) { $res['isParent'] = true; $res['class'] = $parent['class']; $res['plugin'] = $parent['plugin']; } elseif ($options['throwException']) { return array('error' => array('%name% not found.', array('%name%' => $importOpt['name']))); } else { return null; } } return $res; }
function getClass($type, $name, &$isParent = false) { $_this =& ClassCollection::getInstance(); $options = $_this->getOption($type, $name); if (!empty($options['parent'])) { $inerit = array_intersect_key($options, array_flip($_this->parentInerit)); $parentOpt = Set::Merge($inerit, $options['parent']); $parent = $_this->getClass(null, $parentOpt); if (empty($parent)) { return null; } } $importOpt = $_this->parseImportOption($options); //debug($importOpt); if (App::import($importOpt)) { return $importOpt['name']; } else { if (!empty($parent) && $options['defaultByParent']) { $isParent = true; return $parent; } if ($options['throwException']) { debug($importOpt['name'] . ' not found.'); } return null; } }
/** * This action simply creates a textarea with the 'markitup-editor' class */ function textarea($fieldName, $options = array()) { $FormHelper = ClassRegistry::init('Form'); $options = Set::Merge($options, array('class' => 'markitup-editor')); return $FormHelper->text($fieldName, $options); }
function _queueSkill($data = array()) { if (!empty($data['skill_id']) && !empty($data['caster_id'])) { $format = $this->Skill->SkillInstance->getDataSource()->columns['datetime']['format']; $now = date($format); //////// Get conflict SkillInstance //////// $findOpt = array('conditions' => array('caster_id' => $data['caster_id'], 'or' => array('recovered_time >' => $now, array('skill_id' => $data['skill_id'], 'cooled_down_time > ' => $now))), 'order' => array('IF(`skill_id` = ' . $data['skill_id'] . ',cooled_down_time,recovered_time) DESC')); $lastConflict = $this->Skill->SkillInstance->find('first', $findOpt); //////// Create SkillInstance //////// $allowed = array('skill_id', 'caster_id', 'main_target_id'); $inst = array_intersect_key($data, array_flip($allowed)); //debug($inst); $start_time = $now; if (!empty($lastConflict)) { $inst['prev_id'] = $lastConflict['SkillInstance']['id']; $afterCooldown = $lastConflict['SkillInstance']['skill_id'] == $data['skill_id']; if ($afterCooldown) { if (!empty($lastConflict['SkillInstance']['cooled_down_time'])) { $start_time = $lastConflict['SkillInstance']['cooled_down_time']; } } else { if (!empty($lastConflict['SkillInstance']['recovered_time'])) { $start_time = $lastConflict['SkillInstance']['recovered_time']; } } } $this->Skill->SkillInstance->create(); $inst = $this->Skill->SkillInstance->save($inst); if ($inst) { $instance_id = $this->Skill->SkillInstance->id; $inst = Set::Merge($inst, $this->Skill->SkillInstance->save(array('id' => $instance_id, 'start_time' => $start_time))); if (!empty($lastConflict)) { $lastData = array('id' => $lastConflict['SkillInstance']['id'], 'next_id' => $instance_id, 'next_need_cooldown' => $afterCooldown); $this->Skill->SkillInstance->save($lastData); } if (!empty($inst['TimedEvent']['start_time']['TimedEvent']['id'])) { $this->TimedEvent = ClassRegistry::init('TimedEvent'); $this->TimedEvent->checkEvents($inst['TimedEvent']['start_time']); } return $inst; } } return null; }