public function __construct() { // call parent constructor parent::__construct(); // register events $this->app->event->dispatcher->connect('element:afterdisplay', array($this, 'afterDisplay')); }
public function __construct() { // call parent constructor parent::__construct(); // register events $this->app->event->dispatcher->connect('element:afterdisplay', array($this, 'afterDisplay')); $this->app->event->dispatcher->connect('item:beforeSaveCategoryRelations', array($this, 'saveCategoryRelations')); $this->app->event->dispatcher->connect('submission:saved', array($this, 'triggerCategoryRelations')); }
public function bindData($data = array()) { // set data as JSON if item is new if (isset($this->_item) && $this->_item->id == 0) { /* when Item is new there is no Item ID and we can't store the relations in our DB, instead let's store them as JSON (ZOO way) and in next save will be moved to DB */ parent::bindData($data); } else { if (isset($this->_item) && $this->_item->id != 0) { // delete item relations /* the related items order is the order of the rows in the DB, to let the user reorder them from the Item those are deleted and created again each time */ $query = "DELETE FROM #__zoo_relateditemsproxref" . " WHERE item_id=" . (int) $this->_item->id . ' AND element_id=' . $this->db->Quote($this->identifier); $this->db->query($query); if (empty($data)) { return true; } // if no relations return // save relations and it's params foreach ($data['item'] as $key => $ritem) { // get params in the same order $params = array(); foreach ($data as $k => $v) { if (stripos($k, 'param_') === 0) { $new_k = str_ireplace('param_', '', $k); $params[$new_k] = $data[$k][$key]; } } // encode params $params = json_encode($params); // then save $query = "INSERT INTO #__zoo_relateditemsproxref" . " SET item_id = " . (int) $this->_item->id . " ,ritem_id = " . (int) $ritem . ' ,element_id = ' . $this->db->Quote($this->identifier) . ' ,params = ' . $this->db->Quote($params); $this->db->query($query); } // remove any JSON record parent::bindData(array()); } } }
public function getConfigForm() { $form = parent::getConfigForm(); $form->addElementPath($this->app->path->path('zoocart:fields')); return $form; }