/** * Notify the listener of any action on a record. * * This method is called by the framework for each action called on a * node. Depending on the actionfilter passed in the constructor, the * call is forwarded to the actionPerformed($action, $record) method. * * @param string $trigger The trigger being performed * @param array $record The record on which the trigger is performed * @param string $mode The mode (add/update) * * @return bool Result of operation. */ public function notify($trigger, &$record, $mode = null) { if (method_exists($this, $trigger)) { Tools::atkdebug('Call listener ' . get_class($this) . " for trigger {$trigger} on " . $this->m_node->atkNodeUri() . ' (' . $this->m_node->primaryKey($record) . ')'); return $this->{$trigger}($record, $mode); } else { return true; } }
/** * Get an instance of the columnconfig class. * * @param Node $node * @param string $id * @param bool $forceNew force new instance? * * @return ColumnConfig An instance of the columnconfig class */ public static function getConfig($node, $id = null, $forceNew = false) { static $s_instances = []; $sm = SessionManager::getInstance(); if ($id == null) { $id = $node->atkNodeUri(); } if (!isset($s_instances[$id]) || $forceNew) { $cc = new self(); $s_instances[$id] = $cc; $cc->setNode($node); $colcfg = $sm != null ? $sm->pageVar('atkcolcfg_' . $id) : null; if (!is_array($colcfg) || $forceNew) { // create new Tools::atkdebug('New colconfig initialising'); $cc->init(); } else { // inherit old config from session. Tools::atkdebug('Resuming colconfig from session'); $cc->m_colcfg =& $colcfg; } // See if there are any url params which influence this colcfg. $cc->doUrlCommands(); } if ($sm != null) { $sm->pageVar('atkcolcfg_' . $id, $s_instances[$id]->m_colcfg); } return $s_instances[$id]; }
/** * Gets all the current identifiers and returns them in an array. * * @return array The identifiers */ public function getIdentifiers() { $identifiers = []; $identifiers[] = $this->m_node->atkNodeUri() . 'cache'; if ($this->m_node->m_cacheidentifiers) { $this->_formatIdentifiers($this->m_node->m_cacheidentifiers, $identifiers); } $this->_formatIdentifiers($this->m_cacheidentifiers, $identifiers); return $identifiers; }
/** * Check unique field combinations. * The function is called by the validate() method automatically. It is * not necessary to call this manually in a validation process. * Errors that are found are stored in the $record parameter. * * @param array $record The record to validate */ public function validateUniqueFieldSets(&$record) { $db = $this->m_nodeObj->getDb(); foreach ($this->m_nodeObj->m_uniqueFieldSets as $uniqueFieldSet) { $query = $db->createQuery(); $query->addField('*'); $query->addTable($this->m_nodeObj->m_table); $attribs = []; foreach ($uniqueFieldSet as $field) { $attrib = $this->m_nodeObj->m_attribList[$field]; if ($attrib) { $attribs[] = $attrib; if (method_exists($attrib, 'createDestination') && isset($attrib->m_refKey) && is_array($attrib->m_refKey) && count($attrib->m_refKey) > 1) { $attrib->createDestination(); foreach ($attrib->m_refKey as $refkey) { $query->addCondition($query->quoteField($refkey) . " = '" . $db->escapeSQL($record[$attrib->fieldName()][$refkey]) . "'"); } } else { if (!$attrib->isNotNullInDb() && $attrib->isEmpty($record)) { $query->addCondition($query->quoteField($field) . ' IS NULL'); } else { $query->addCondition($query->quoteField($field) . " = '" . $attrib->value2db($record) . "'"); } } } else { Tools::atkerror("Field {$field} is mentioned in uniquefieldset but does not exist in " . $this->m_nodeObj->atkNodeUri()); } } if ($this->m_mode != 'add') { $query->addCondition('NOT (' . $this->m_nodeObj->primaryKey($record) . ')'); } if (count($db->getRows($query->buildSelect())) > 0) { Tools::atkTriggerError($record, $attribs, 'error_uniquefieldset'); } } }
/** * String representation for this attribute (PHP5 only). * * @return string attribute name prefixed with node type */ public function __toString() { return $this->m_ownerInstance->atkNodeUri() . '::' . $this->fieldName(); }