Ejemplo n.º 1
0
 /**
  * Get hook action objects for a given event
  *
  * @param string $type
  * @param string $action
  * @return array
  * @throws Zend_Db_Exception if trouble with database or tables
  */
 protected function getHooks($type, $action)
 {
     $cacheId = "flex_hooks_{$type}_{$action}";
     $ret = array();
     try {
         $ret = Zoo::getService("cache")->load($cacheId);
         if ($ret == array('none')) {
             return array();
         }
     } catch (Zoo_Exception_Service $e) {
         // No cache service
     }
     if (!$ret) {
         $factory = new Utility_Hook_Factory();
         $hooks = $factory->fetchAll(array('type = ?' => $type, 'action = ?' => $action), 'weight ASC');
         if ($hooks->count() > 0) {
             foreach ($hooks as $hook) {
                 $class = $hook->class . "_Hook_" . $type;
                 $ret[] = new $class();
             }
         }
         if (!$ret) {
             $ret = array('none');
         }
         try {
             Zoo::getService("cache")->save($ret, $cacheId, array('hooks'));
         } catch (Zoo_Exception_Service $e) {
             // No cache service
         }
     }
     if ($ret == array('none')) {
         return array();
     }
     return $ret;
 }
Ejemplo n.º 2
0
 /**
  * Save a hook
  *
  */
 public function saveAction()
 {
     $factory = new Utility_Hook_Factory();
     if (@$_REQUEST['id'] > 0) {
         $item = $factory->find($_REQUEST['id'])->current();
     } else {
         $item = $factory->createRow();
     }
     $form = $item->getForm(@$_REQUEST['id']);
     if ($form->isValid($_REQUEST)) {
         $values = $form->getValues();
         list($type, $action, $class) = explode('_', $values['type']);
         $item->type = $type;
         $item->action = $action;
         $item->weight = $values['weight'];
         $item->class = $class;
         $item->save();
         $this->_helper->redirector->gotoRoute(array('module' => 'utility', 'controller' => 'hook', 'action' => 'index'));
     }
     $this->view->form = $form;
     $this->view->form->populate($_REQUEST);
     $factory = new Utility_Hook_Factory();
     $this->view->hooks = $factory->fetchAll(null, "weight");
     $this->render('form');
 }
Ejemplo n.º 3
0
 /**
  * Get hook action objects for a given event
  *
  * @param string $type
  * @param string $action
  * @return array
  * @throws Zend_Db_Exception if trouble with database or tables
  */
 protected function getHooks($type, $action)
 {
     static $hook_cache = array();
     if (!isset($hook_cache[$type][$action])) {
         $factory = new Utility_Hook_Factory();
         $hooks = $factory->fetchAll(array('type = ?' => $type, 'action = ?' => $action), 'weight ASC');
         if ($hooks->count() > 0) {
             foreach ($hooks as $hook) {
                 $class = $hook->class . "_Hook_" . $type;
                 $hook_cache[$type][$action][] = new $class();
             }
         } else {
             $hook_cache[$type][$action] = array();
         }
     }
     return $hook_cache[$type][$action];
 }