/** * wrapper for delete * * @return ORM */ public function delete() { // hook Event::raise($this, Event::BEFORE_DELETE, array('model' => $this)); // delete $result = parent::delete(); // hook Event::raise($this, Event::AFTER_DELETE, array('model' => $this)); // return orm return $result; }
/** * Overwrite delete * dont check on owner id, as the entire tree will be gone * deleted is an array with items */ protected function delete($model) { // check rights if (!Acl::instance()->allowed($this->_controller, 'delete', $model->owner_id, $model->website_id)) { throw HTTP_Exception::factory(403, 'Delete not allowed on :controller :id', array(':controller' => $this->_controller, ':id' => $model->id)); } // call hook Event::raise($this, Event::BEFORE_DELETE, array('model' => $model)); //delete $deleted = $model->delete(); // call hook Event::raise($this, Event::AFTER_DELETE, array('deleted' => $deleted)); }
/** * Get module navigation */ public function action_module() { // get request $request = Request::initial(); // get settings $settings = Settings::factory($request->controller()); // navigation viewer $navigation = Viewer::instance('Navigation')->settings($settings->get('navigation'))->request(Request::initial())->acl(Acl::instance()); // create view $view = View::factory($settings->get('view.navigation'), array('navigation' => $navigation)); // raise event Event::raise($this, Event::BEFORE_NAVIGATION_RENDER, array('navigation' => $navigation)); // render view $this->response->body($view->render()); }
/** * init */ public function init() { // raise event Event::raise($this, Event::BEFORE_INIT); // get website and feed it the current uri so we can figure out the ->id() $website = Website::instance()->uri(Request::initial()->uri()); // set controller vars $this->_website = $website->id(); $this->_directory = Request::current()->directory(); $this->_controller = Request::current()->controller(); $this->_action = Request::current()->action(); $this->_language = isset(Identity::instance()->user) ? Identity::instance()->user->language : 'nl'; // manually set website in Website // this will be used by alias Website::instance()->id($this->_website); // set state session // get state instance for this website / controller State::session(Session::instance('database')); $this->_state = State::instance($this->_website . '.' . $this->_controller); // set route in URL helper URL::route('backend'); // Let Filereader cache results Reader::cache(Cache::instance('reader_backend'), 'backend'); // set default language Text::language($this->_language); // get that language's text instance and configure it Text::instance($this->_language)->load(array_keys(Settings::factory('modules')->as_array()))->group($this->_controller)->substitutes('module'); // set URL presets $base = URL::base(); URL::set('base', $base); URL::set('library', $base . 'library/'); URL::set('vendor', $base . 'vendor/'); URL::set('files', $base . 'files/'); // set website in view View::set_global('_website', $this->_website); // set language in view View::set_global('_language', $this->_language); }
/** * copy * */ protected function copy($model) { // check rights if (!Acl::instance()->allowed($this->_controller, 'copy', $model->owner_id, $model->website_id)) { throw HTTP_Exception::factory(403, 'Copy not allowed on :controller :id', array(':controller' => $this->_controller, ':id' => $model->id)); } // create copied values $values = $model->as_array(); unset($values['id']); $values['title'] = 'Copy ' . $values['title']; $values['owner_id'] = Identity::instance()->id; $values['editor_id'] = Identity::instance()->id; // create copy $copy = ORM::factory($this->_settings->get('model')); $copy->values($values); // call hook Event::raise($this, Event::BEFORE_COPY, array('model' => $model, 'copy' => $copy)); // save copy $copy->save(); // call hook Event::raise($this, Event::AFTER_COPY, array('model' => $model, 'copy' => $copy)); // return copy return $copy; }
/** * Form::markup() * add non functioning element to elements list * used for markup in the view * * @param string $type * @param array $attributes * @return */ public function markup($keyOrType, $typeOrSettings = array(), $settings = array()) { // normalize if (is_array($typeOrSettings)) { $key = FALSE; $type = $keyOrType; $settings = $typeOrSettings; } else { $key = $keyOrType; $type = $typeOrSettings; } // raise hook Event::raise($this, Event::BEFORE_FORM_MARKUP, array('form' => $this, 'key' => $key, 'type' => $type, 'settings' => $settings)); // create element $element = new stdClass(); // store settings foreach ($settings as $var => $val) { $element->{$var} = $val; } // set default values $element->key = $key; $element->type = $type; $element->required = FALSE; $element->error = FALSE; $element->attributes = isset($settings['attributes']) ? $settings['attributes'] : array(); $element->attributes['class'] = isset($element->attributes['class']) ? $element->attributes['class'] : ''; // store element in list $this->_elements[] = $element; // rais hook Event::raise($this, Event::AFTER_FORM_MARKUP, array('form' => $this, 'element' => $element)); // return it return $element; }
/** * create files in db */ protected function store($form, $hash) { // get files in the temp/hash dir $files = FS::files($this->_settings->get('path_temp') . $hash . DIRECTORY_SEPARATOR); // set the files in the form $form->files($files); Event::raise($this, Event::BEFORE_STORE_FORM_PARSE, array('form' => $form)); if ($form->valid()) { // get the hash of the temp dir from qs $hash = $this->request->param('id'); // get the form values $values = $form->values(); // loop through temp files for ($i = 0; $i < count($files); $i++) { // createmodel $model = ORM::factory($this->_settings->get('model')); // set group if one is active if ($group = $this->_state->get('group', FALSE)) { $model->group_id = $group; } // undouble filename $file = FS::name_unique($files[$i], $this->_settings->get('path_files')); // store it FS::move($this->_settings->get('path_temp') . $hash . DIRECTORY_SEPARATOR . $files[$i], $this->_settings->get('path_files') . $file); // permissions FS::permissions($this->_settings->get('path_files') . $file, 0744); // set item properties $model->created = date('y-m-d H:i:s', time()); $model->owner_id = Identity::instance()->id; $model->editor_id = Identity::instance()->id; $model->website_id = $this->_website; // set file $model->file = $file; // set additional info (mostly title) foreach ($values as $key => $value) { if (is_array($value) && isset($value[$i])) { $model->{$key} = $value[$i]; } } // call hook Event::raise($this, Event::BEFORE_STORE, array('model' => $model, 'form' => $form)); //save $model->save(); // call hook Event::raise($this, Event::AFTER_STORE, array('model' => $model, 'form' => $form)); } // return true return TRUE; } else { // create viewer $viewer = Viewer::factory('Form', $form)->text(Text::instance()); // render form $view = View::factory($this->_settings->get('view.create'), array('viewer' => $viewer)); // event Event::raise($this, Event::BEFORE_STORE_RENDER, array('model' => NULL, 'form' => $form, 'viewer' => $viewer, 'view' => $view)); // render $this->response->body($view->render()); // return false return FALSE; } }
/** * Queues an event to be dispatched later. * * @param string $eventName * @param ...$args */ public function queue($eventName, $args = null) { $args = func_get_args(); $eventArgs = array_splice($args, 1); \Event::raise($eventName, $eventArgs); }