/** * Returns main media file by unit * * @param RM_Unit $unit * @return Zend_Db_Table_Row */ function getMainFile($unit) { $typeModel = new RM_UnitMediaTypes(); $type = $typeModel->find(RM_UnitMediaTypes::MAIN)->current(); $file = $this->get($unit, $type)->current(); if ($file == null) { //we don't have a main file - so we just pick up the first file in the list $file = $this->get($unit)->current(); //In any way, unit could be without images at all, so we need to check return value for 'null' } return $file; }
/** * Return a tree nodes for unit media type files * * @return array */ function getTree() { $typesModel = new RM_UnitMediaTypes(); $types = $typesModel->fetchAll(); $jsonTypes = array(); $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN); foreach ($types as $type) { $jsonType = new stdClass(); $jsonType->id = $type->id; $jsonType->type_id = $type->id; $jsonType->text = $translate->_('Admin.Unit.Media.FileTypes', $type->name); $jsonType->cls = "folder"; $jsonType->iconCls = "rm-tree-node"; $jsonType->leaf = 0; $jsonType->allowDrag = false; $jsonType->expanded = true; $files = $this->_getTypeFilesNodes($type); if (count($files) > 0) { $jsonType->children = $files; } else { $jsonType->children = array(); } $jsonTypes[] = $jsonType; } //Add additional node for deleting images $jsonType = new stdClass(); $jsonType->id = 0; $jsonType->type_id = RM_UnitMediaTypes::DELETED; $jsonType->text = $translate->_('Admin.Unit.Media.FileTypes', 'Delete'); $jsonType->cls = "folder"; $jsonType->iconCls = "rm-tree-delete"; $jsonType->leaf = 0; $jsonType->allowDrag = false; $jsonType->children = array(); $jsonType->expanded = true; $jsonTypes[] = $jsonType; return $jsonTypes; }