Example #1
0
 public function setFields()
 {
     parent::setFields();
     $this->fields[self::FIELD_ParentID] = new \Core\ORM_Fields_Integer($this, self::FIELD_ParentID, 'Tree Parent ID', 'system');
     $this->fields[self::FIELD_Level] = new \Core\ORM_Fields_Integer($this, self::FIELD_Level, 'Tree Level', 'system');
     $this->fields[self::FIELD_LeftKey] = new \Core\ORM_Fields_Integer($this, self::FIELD_LeftKey, 'Tree Left Key', 'system');
     $this->fields[self::FIELD_RightKey] = new \Core\ORM_Fields_Integer($this, self::FIELD_RightKey, 'Tree Right Key', 'system');
 }
Example #2
0
 /**
  * @param string $counter_field_name
  * @param ORM_Record $changed_record
  * @param string $changed_record_field_name
  * @param int $delta
  *
  * @return bool
  */
 public function counterUpdateMulti($counter_field_name, ORM_Record $changed_record, $changed_record_field_name, $delta = 1)
 {
     $action = null;
     $old_value = \Lib_Text::clearIDs($changed_record->getShadow($changed_record_field_name));
     $new_value = \Lib_Text::clearIDs($changed_record->getFieldValue($changed_record_field_name));
     if (empty(array_diff($new_value, $old_value)) && empty(array_diff($old_value, $new_value))) {
         return false;
     }
     $ids_removed = array_diff($old_value, $new_value);
     $ids_added = array_diff($new_value, $old_value);
     foreach ($ids_removed as $id) {
         $record_counter = $this->getByID($id);
         if (null !== $record_counter) {
             $record_counter->counterDecrement($counter_field_name, $delta);
         }
     }
     foreach ($ids_added as $id) {
         $record_counter = $this->getByID($id);
         if (null !== $record_counter) {
             $record_counter->counterIncrement($counter_field_name, $delta);
         }
     }
     return true;
 }