00001 <?php
00002 class DAOJcsscompressedfiles extends DataObjectBase {
00003 public $type;
00004 public $filename;
00005 public $hash;
00006 public $num_sources;
00007 public $sources;
00008 public $version;
00009
00010
00011
00012
00013
00014 protected function create_table_object() {
00015 return new DBTable(
00016 'jcsscompressedfiles',
00017 array(
00018 new DBFieldEnum('type', array_keys(JCSSManager::get_types()), null, DBField::NOT_NULL),
00019 new DBFieldText('filename', 255, null, DBField::NOT_NULL),
00020 new DBFieldText('hash', 255, null, DBField::NOT_NULL),
00021 new DBFieldInt('num_sources', 1, DBFieldInt::UNSIGNED | DBField::NOT_NULL),
00022 new DBFieldSerialized('sources', DBFieldText::BLOB_LENGTH_SMALL, null, DBField::NOT_NULL),
00023 new DBFieldInt('version', 1,DBFieldInt::UNSIGNED | DBField::NOT_NULL)
00024 ),
00025 array('type', 'filename')
00026 );
00027 }
00028
00029
00030
00031
00032
00033
00034 public function get_versioned_filename() {
00035 $arr = explode('.', $this->filename);
00036 $ext = array_pop($arr);
00037 $arr[] = $this->version;
00038 $arr[] = $ext;
00039 return implode('.', $arr);
00040 }
00041
00042
00043
00044
00045
00046
00047
00048 public function substitute($arr_files) {
00049 if (count($arr_files) < count($this->sources)) {
00050 return $arr_files;
00051 }
00052
00053 $ret = array();
00054 $matches = 0;
00055 foreach($arr_files as $file) {
00056 if (in_array($file, $this->sources)) {
00057 if ($matches == 0) {
00058 $ret[] = $this->get_versioned_filename();
00059 }
00060 $matches++;
00061 }
00062 else {
00063 $ret[] = $file;
00064 }
00065 }
00066
00067 if ($matches != count($this->sources)) {
00068 $ret = $arr_files;
00069 }
00070
00071 return $ret;
00072 }
00073 }