Exemple #1
0
 /**
  * Clear the recordlist cache.
  */
 public function clearCache()
 {
     if ($this->m_node->hasFlag(Node::NF_CACHE_RECORDLIST)) {
         $recordlistcache = $this->getRecordlistCache();
         if ($recordlistcache) {
             $recordlistcache->clearCache();
         }
     }
 }
Exemple #2
0
 /**
  * Validate a record.
  *
  * @param string $mode Override the mode
  * @param array $ignoreList Override the ignoreList
  */
 public function validate($mode = '', $ignoreList = array())
 {
     // check overrides
     if (count($ignoreList)) {
         $this->setIgnoreList($ignoreList);
     }
     if ($mode != '') {
         $this->setMode($mode);
     }
     Tools::atkdebug('validate() with mode ' . $this->m_mode . ' for node ' . $this->m_nodeObj->atkNodeUri());
     // set the record
     $record =& $this->m_record;
     // Check flags and values
     $db = $this->m_nodeObj->getDb();
     foreach ($this->m_nodeObj->m_attribIndexList as $attribdata) {
         $attribname = $attribdata['name'];
         if (!Tools::atk_in_array($attribname, $this->m_ignoreList)) {
             $p_attrib = $this->m_nodeObj->m_attribList[$attribname];
             $this->validateAttributeValue($p_attrib, $record);
             if ($p_attrib->hasFlag(Attribute::AF_PRIMARY) && !$p_attrib->hasFlag(Attribute::AF_AUTO_INCREMENT)) {
                 $atkorgkey = $record['atkprimkey'];
                 if ($atkorgkey == '' || $atkorgkey != $this->m_nodeObj->primaryKey($record)) {
                     $cnt = $this->m_nodeObj->select($this->m_nodeObj->primaryKey($record))->ignoreDefaultFilters(true)->ignorePostvars(true)->getRowCount();
                     if ($cnt > 0) {
                         Tools::triggerError($record, $p_attrib, 'error_primarykey_exists');
                     }
                 }
             }
             // if no root elements may be added to the tree, then every record needs to have a parent!
             if ($p_attrib->hasFlag(Attribute::AF_PARENT) && $this->m_nodeObj->hasFlag(TreeNode::NF_TREE_NO_ROOT_ADD) && $this->m_nodeObj->m_action == 'save') {
                 $p_attrib->m_flags |= Attribute::AF_OBLIGATORY;
             }
             // validate obligatory fields (but not the auto_increment ones, because they don't have a value yet)
             if ($p_attrib->hasFlag(Attribute::AF_OBLIGATORY) && !$p_attrib->hasFlag(Attribute::AF_AUTO_INCREMENT) && $p_attrib->isEmpty($record)) {
                 Tools::atkTriggerError($record, $p_attrib, 'error_obligatoryfield');
             } else {
                 if ($p_attrib->hasFlag(Attribute::AF_UNIQUE) && !$p_attrib->hasFlag(Attribute::AF_PRIMARY) && !$p_attrib->isEmpty($record)) {
                     $condition = $this->m_nodeObj->getTable() . ".{$attribname}='" . $db->escapeSQL($p_attrib->value2db($record)) . "'";
                     if ($this->m_mode != 'add') {
                         $condition .= ' AND NOT (' . $this->m_nodeObj->primaryKey($record) . ')';
                     }
                     $cnt = $this->m_nodeObj->select($condition)->ignoreDefaultFilters(true)->ignorePostvars(true)->getRowCount();
                     if ($cnt > 0) {
                         Tools::atkTriggerError($record, $p_attrib, 'error_uniquefield');
                     }
                 }
             }
         }
     }
     if (isset($record['atkerror']) && count($record['atkerror']) > 0) {
         for ($i = 0, $_i = count($record['atkerror']); $i < $_i; ++$i) {
             $record['atkerror'][$i]['node'] = $this->m_nodeObj->m_type;
         }
     }
     $this->validateUniqueFieldSets($record);
     if (isset($record['atkerror'])) {
         for ($i = 0, $_i = count($record['atkerror']); $i < $_i; ++$i) {
             $record['atkerror'][$i]['node'] = $this->m_nodeObj->m_type;
         }
         return false;
     }
     return true;
 }