/** * Configures this model. * * @param Array $config Configuration array */ protected static function configure($config = array()) { $config['db_table'] = 'datafields'; $config['has_many']['entries'] = array('class_name' => 'DatafieldEntryModel', 'on_delete' => function ($df) { return DatafieldEntryModel::deleteBySQL("datafield_id = ?", array($df->id)); }); $config['has_many']['visibility_settings'] = array('class_name' => 'User_Visibility_Settings', 'assoc_foreign_key' => 'identifier', 'on_delete' => function ($df) { return User_Visibility_Settings::deleteBySQL("identifier = ?", array($df->id)); }); parent::configure($config); }
/** * Removes all datafields from a given range_id (and secondary range * id if passed as array) * * @param mixed $range_id Range id (or array with range id and secondary * range id) * @return int representing the number of deleted entries */ public static function removeAll($range_id) { if (is_array($range_id)) { list($rangeID, $secRangeID) = $range_id; } else { $rangeID = $range_id; $secRangeID = ""; } if (!$rangeID && !$secRangeID) { return; } $conditions = array(); $parameters = array(); if ($rangeID) { $conditions[] = 'range_id = ?'; $parameters[] = $rangeID; } if ($secRangeID) { $conditions[] = 'sec_range_id = ?'; $parameters[] = $secRangeID; } $where = implode(' AND ', $conditions); return DatafieldEntryModel::deleteBySQL($where, $parameters); }