public function edit() { $this->view->set('field_name', $this->_data['field_name']); $modulecomponent = new ModuleComponent(); $modulecomponent->load($this->_data['module_components_id']); $model = new $modulecomponent->name(); $field = $model->getField($this->_data['field_name']); $this->view->set('field', $field); if (isset($model->belongsToField[$field->name])) { $x = $model->belongsTo[$model->belongsToField[$field->name]]["model"]; $cc = new ConstraintChain(); if ($model->belongsTo[$model->belongsToField[$field->name]]["cc"] instanceof ConstraintChain) { $cc->add($model->belongsTo[$model->belongsToField[$field->name]]["cc"]); } $x = new $x(); $this->view->set('options', $x->getAll($cc)); $field->type = 'select'; } if ($model->isEnum($field->name)) { $this->view->set('options', $model->getEnumOptions($field->name)); $field->type = 'select'; } if (empty($this->_data['id'])) { // sendTo($this->name,'new',$this->_modules); unset($this->_data['id']); $this->view->set('module_components_id', $this->_data['module_components_id']); parent::_new(); $this->_templateName = $this->getTemplateName('new'); } else { parent::edit(); } }
function load($classname) { $classname = preg_replace('[^a-zA-Z0-9_-]', '', $classname); if (isset($this->paths[$classname])) { require $this->paths[$classname]; return; } if (isset($this->paths[strtolower($classname)])) { require $this->paths[strtolower($classname)]; return; } $cache_id = array('module_component_path', strtolower($classname)); $cache = Cache::Instance(); $module_path = $cache->get($cache_id); // go and fetch the data and populate the cache if ($module_path === FALSE) { $module = new ModuleComponent(); $module->loadBy('name', strtolower($classname)); if ($module->isLoaded()) { if (substr($module->location, -4) === '.php') { $cache->add($cache_id, $module->location); require $module->location; } return; } } else { require $module_path; } }
function getComponentLocations() { $components = new ModuleComponent(); $components->idField = 'name'; $components->identifierField = 'location'; $cc = new ConstraintChain(); $cc->add(new Constraint('module_id', '=', $this->id)); $cc->add(new Constraint('type', 'in', "('C', 'E', 'M', 'R')")); return $components->getAll($cc); }
public function view() { if (!isset($this->_data) || !$this->loadData()) { $this->dataError(); sendBack(); } $dataset = $this->_uses[$this->modeltype]; $this->view->set('dataset', $dataset); $this->view->set('dataset_model', new DataObject($dataset->name)); $this->view->set('field_types', $dataset->getEnumOptions('field_type')); $this->view->set('links', ModuleComponent::getModelList()); $sidebar = new SidebarController($this->view); $actions = array(); $actions['viewall'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index'), 'tag' => 'View All Datasets'); $actions['edit'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'edit', $dataset->idField => $dataset->{$dataset->idField}), 'tag' => 'edit dataset'); $actions['delete'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'delete', $dataset->idField => $dataset->{$dataset->idField}), 'tag' => 'delete dataset'); $actions['listreports'] = array('link' => array('module' => 'reporting', 'controller' => 'reports', 'action' => 'index', 'tablename' => $this->getViewname($dataset->name)), 'tag' => 'list_reports'); $actions['newreport'] = array('link' => array('module' => 'reporting', 'controller' => 'reports', 'action' => 'new', 'tablename' => $this->getViewname($dataset->name)), 'tag' => 'new_report'); $actions['viewdata'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'view_collection', $dataset->idField => $dataset->{$dataset->idField}), 'tag' => 'view_data'); $sidebar->addList('Actions', $actions); // $this->sidebarRelatedItems($sidebar, $dataset); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); $this->view->set('dataset_fields', DataObjectFactory::Factory('DatasetField')); }
public function index() { $errors = array(); $s_data = array(); // Set context from calling module $this->setSearch('stitemsSearch', 'useDefault', $s_data); $this->view->set('clickaction', 'view'); // $this->view->set('page_title', 'Stock Items List'); parent::index(new STItemCollection($this->_templateobject)); $sidebar = new SidebarController($this->view); $sidebarlist = array(); $sidebarlist['new'] = array('tag' => 'New Stock Item', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'new')); $sidebarlist['documents'] = array('tag' => $this->_templateobject->getTitle() . ' Documents', 'link' => array('modules' => $this->_modules, 'controller' => 'attachments', 'action' => 'index', 'entity_id' => ModuleComponent::getComponentId($this->_modules['module'], strtolower(get_class($this))), 'data_model' => 'modulecomponent')); $sidebar->addList('Actions', $sidebarlist); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
private function buildDirTree($mydatapath, $module_id, $type = '', $parent_name = '') { if (file_exists(FILE_ROOT . $mydatapath)) { $files = array(); $mydata = dir(FILE_ROOT . $mydatapath); while (($current = $mydata->read()) !== false) { if (substr($current, 0, 1) != '.' && $current != 'CVS') { if (is_dir($mydatapath . $current)) { $module = new ModuleObject(); $module->loadBy('name', $current); if (!$module->isLoaded()) { if ($type != 'T') { $current_type = isset($this->components[$current]) ? $this->components[$current] : $type; } else { $current_type = $type; } $files[$current] = $this->buildDirTree($mydatapath . $current . DIRECTORY_SEPARATOR, $module_id, $current_type, $current); } } elseif (is_file($mydatapath . $current)) { if ($type == 'C') { $name = strtolower(str_replace('.php', '', $current)); } else { // ATTN: switch (get_file_extension($current)) { if (substr($current, -4) == '.css') { $type = 'S'; } if (substr($current, -3) == '.js') { $type = 'J'; } if (substr($current, -4) == '.yml') { $type = 'Y'; } if (empty($type) && substr($current, -4) == '.php') { $type = 'M'; } $name = strtolower(substr_replace($current, '', strrpos($current, '.'))); } $component = new ModuleComponent(); $component->loadBy(array('name', 'type', 'module_id'), array($name, $type, $module_id)); $component->addField('register', new DataField('register', false)); if (!$component->isLoaded()) { $component->name = $name; $component->type = $type; $component->module_id = $module_id; } else { $component->register = true; } if ($type == 'T') { $component->controller = $parent_name; } else { $component->controller = null; } $component->location = str_replace(FILE_ROOT, '', $mydatapath . $current); $files[$component->name] = $component; } } } ksort($files); $mydata->close(); return $files; } else { return FALSE; } }
public function __construct(Application $app, $module, $section = null) { parent::__construct($app, $module); $this->setSection($section); }
public function __construct(Application $app, $module, $action) { parent::__construct($app, $module); $this->setAction($action); }
public function get_action_list($controller_id = '') { if (is_ajax() && is_direct_request()) { $controller_id = $this->_data['controller_id']; } $html = ''; // attempt to load the controller based on the controller id $module_components = new ModuleComponent(); $module_components->load($controller_id); // if the component hs loaded it must mean we were dealing with an id // set the controller_id to the controller name if ($module_components->loaded) { $controller_id = $module_components->name; } // set actions as an array with a null first value $actions = array('' => ''); // fetch the methods for the controller $actions['Local Methods'] = get_final_class_methods($controller_id); // fetch the inherited methods $inherited_methods = get_class_methods($controller_id); $inherited_methods = array_combine($inherited_methods, $inherited_methods); $actions['Inherited Methods'] = array_diff($inherited_methods, $actions['Local Methods']); if (is_ajax() && is_direct_request()) { $output['action'] = array('data' => $actions, 'is_array' => is_array($actions)); $this->view->set('data', $output); $this->setTemplateName('ajax_multiple'); } else { return $actions; } }
function smarty_function_select($params, &$smarty) { // set a few variables $attribute = $params['attribute']; $fallback = TRUE; $use_autocomplete = FALSE; $rowid = ''; $selected = ''; $opt_counter = 0; $data = array('select' => array('attrs' => array()), 'display_tags' => !(isset($params['tags']) && $params['tags'] == 'none')); // append any data attributes passed in through params with the attrs array $data['select']['attrs'] += build_data_attributes($params); $controller_data =& $smarty->getTemplateVars('controller_data'); if (empty($params['force']) && (isset($controller_data[$attribute]) || !empty($params['hidden']))) { if (isset($controller_data['dialog'])) { // force select to be hidden on a dialog $params['hidden'] = ''; } return smarty_function_input($params, $smarty); } $with =& $smarty->getTemplateVars('with'); // not empty = TRUE, empty = FALSE $use_collection = !empty($params['use_collection']); if (!empty($params['model'])) { $model =& $params['model']; } else { $model = $with['model']; } $field = $model->getField($attribute); $cc = new ConstraintChain(); if (!empty($params['constraint'])) { $constraint = $params['constraint']; if (class_exists($constraint . 'Constraint')) { $cname = $constraint . 'Constraint'; $constraint = new $cname($attribute); if (!$constraint instanceof Constraint) { throw new Exception($cname . ' is not a valid Constraint'); } } else { $exp = explode(',', $constraint); $constraint = new Constraint($exp[0], $exp[1], $exp[2]); } $cc->add($constraint); } if (empty($params['alias'])) { $params['alias'] = isset($with['alias']) ? $with['alias'] : ''; } if (!empty($params['alias'])) { $alias = $model->getAlias($params['alias']); $aliasModelName = $alias['modelName']; $newmodel = new $aliasModelName(); $name = $model->get_name() . '[' . $params['alias'] . '][' . $attribute . ']'; $id = $model->get_name() . '_' . $params['alias'] . '_' . $attribute; if (isset($_POST[$model->get_name()][$params['alias']][$attribute])) { $value = $_POST[$model->get_name()][$params['alias']][$attribute]; } elseif ($model->isLoaded()) { $newmodel = $model->{$params}['alias']; $value = $newmodel->{$attribute}; } $model = $newmodel; } if (empty($params['composite'])) { $params['composite'] = isset($with['composite']) ? $with['composite'] : ''; // DEFAULT } if (!empty($params['composite'])) { $alias = $model->getComposite($params['composite']); $aliasModelName = $alias['modelName']; $newmodel = new $aliasModelName(); $name = $model->get_name() . '[' . $aliasModelName . '][' . $attribute . ']'; $id = $model->get_name() . '_' . $aliasModelName . '_' . $attribute; if (isset($_POST[$model->get_name()][$aliasModelName][$attribute])) { $value = $_POST[$model->get_name()][$aliasModelName][$attribute]; } elseif ($model->isLoaded()) { $newmodel = $model->{$params}['composite']; $value = $newmodel->{$attribute}; } $model = $newmodel; } if (isset($params['options'])) { $get_options = $params['options']; } else { $get_options = ''; } if (!isset($params['autocomplete']) || empty($get_options)) { $use_autocomplete = false; } else { $use_autocomplete = true; } if (!is_null($field->options)) { $get_options = $field->options->_data; $use_autocomplete = $field->options->_autocomplete; $text_value = $model->{$model->belongsToField[$attribute]}; if (trim($text_value) == '' && count($get_options) > 0) { $text_value = current($get_options); } $selected = key($get_options); } if (!empty($params['label'])) { $data['select']['label'] = $params['label']; } else { $data['select']['label'] = $field->tag; } if (isset($params['number'])) { $name = $model->get_name() . '[' . $params['number'] . '][' . $attribute . ']'; } elseif (!isset($name)) { $name = $model->get_name() . '[' . $attribute . ']'; } if (isset($params['rowid']) && !empty($params['rowid'])) { $rowid = $params['rowid']; $data['select']['attrs']['data-row-number'] = $params['rowid']; } $id = $model->get_name() . '_' . $attribute . $rowid; if (!isset($name)) { $name = $model->get_name() . '[' . $attribute . ']'; $id = $model->get_name() . '_' . $attribute . $rowid; } if (isset($params['postfix'])) { $name .= $params['postfix']; } // set field (data) attribute if (isset($field) && !empty($field)) { $data['select']['attrs']['data-field'] = $field->name; } else { $data['select']['attrs']['data-field'] = $attribute; } if (!empty($params['depends'])) { $depends = explode(',', $params['depends']); } elseif (!is_null($field->options->_depends)) { $depends = array_keys($field->options->_depends); } else { $depends = ''; } // echo 'Smarty function.select depends='.$depends.'<br>'; if (!empty($params['constrains'])) { $affects = explode(',', $params['constrains']); $constrains = true; } elseif (!is_null($field->options->_affects)) { $affects = array_keys($field->options->_affects); $constrains = true; } else { $affects = ''; $constrains = false; } // set the selected value from the value of the field, if present if ($model->isLoaded()) { $selected = $model->{$attribute}; } elseif (isset($controller_data[$attribute])) { $selected = $controller_data[$attribute]; } // set the selected value from the params value // can override the value of the field, if present if (isset($params['value'])) { $selected = $params['value']; } $autocomplete_select_limit = get_config('AUTOCOMPLETE_SELECT_LIMIT'); if (!empty($get_options) && !isset($params['forceselect']) && count($get_options) > $autocomplete_select_limit) { $use_autocomplete = true; } if (isset($model->belongsToField[$attribute])) { $x = $model->belongsTo[$model->belongsToField[$attribute]]["model"]; $controllername = strtolower($x) . 's'; if (isset($_SESSION['cache']['select'][$controllername])) { $data['select']['fk_link']['module'] = $_SESSION['cache']['select'][$controllername]; } else { $component = new ModuleComponent(); $component->loadBy(array('name', 'type'), array($controllername . 'controller', 'C')); if ($component->isLoaded()) { $data['select']['fk_link']['module'] = $_SESSION['cache']['select'][$controllername] = $component->module_name; } } if (isset($data['select']['fk_link']['module'])) { $data['select']['fk_link']['controller'] = $controllername; $data['select']['fk_link']['action'] = 'new'; } if (isset($params['data'])) { if ($params['data'] instanceof DataObjectCollection) { $options = $params['data']->getAssoc(); } elseif (is_array($params['data'])) { $options = $params['data']; } else { throw new Exception('"data" paramater should be an associative array, or a DataObjectCollection'); } } elseif (empty($get_options)) { if ($model->belongsTo[$model->belongsToField[$attribute]]["cc"] instanceof ConstraintChain) { $cc->add($model->belongsTo[$model->belongsToField[$attribute]]["cc"]); } if (!empty($depends)) { foreach ($depends as $depends_field) { if (!is_null($model->{$depends_field})) { $cc->add(new Constraint($depends_field, '=', $model->{$depends_field})); } } } $model->belongsTo[$model->belongsToField[$attribute]]["cc"] = $cc; if (!isset($params['forceselect']) && $model->getOptionsCount($attribute) > $autocomplete_select_limit) { $use_autocomplete = TRUE; $text_value = $model->{$model->belongsToField[$attribute]}; if (trim($text_value) == '') { if (empty($selected) && !$model->isLoaded() && $field->has_default) { $selected = $field->default_value; } $temp = new $x(); $temp->load($selected); $text_value = $temp->getIdentifierValue(); } } else { $x = DataObjectFactory::Factory($x); if ($model->checkUniqueness($attribute)) { // TODO: this can be inefficient in large data sets // needs to be 'not exists' correlated subquery $cc->add(new Constraint($x->idField, 'NOT IN', '(SELECT ' . $attribute . ' FROM ' . $model->getTableName() . ')')); $options = $x->getAll($cc, TRUE, $use_collection); $fallback = FALSE; } elseif ($attribute == 'assigned') { $c_user = $smarty->getTemplateVars('current_user'); $cc = new ConstraintChain(); $db = DB::Instance(); if (!is_null($c_user->person_id)) { $cc->add(new Constraint('person_id', 'IN', '(SELECT px.id FROM person px JOIN company cx ON (px.company_id=cx.id) JOIN person pz ON (pz.company_id=cx.id) WHERE pz.id=' . $db->qstr($c_user->person_id) . ')')); } $options = $x->getAll($cc, TRUE, $use_collection); } elseif (get_class($x) == 'User') { $options = $x->getActive($cc, FALSE); } else { $options = $x->getAll($cc, FALSE, $use_collection); } } } } elseif ($model->hasParentRelationship($attribute) && !isset($params['ignore_parent_rel'])) { $db = DB::Instance(); $x = clone $model; if ($model->isLoaded()) { $cc->add(new Constraint($model->idField, '<>', $model->{$model->idField})); } $options = $x->getAll($cc, FALSE, $use_collection); } elseif ($model->isEnum($attribute)) { //enumeration $options = $model->getEnumOptions($attribute); foreach ($options as $key => $option) { if ($selected == $option) { $selected = $key; break; } } } if ($field->not_null == 1) { $data['select']['label'] .= ' *'; $data['select']['class'][] = 'required'; } if (isset($_POST[$model->get_name()][$attribute])) { $selected = $_POST[$model->get_name()][$attribute]; } elseif (isset($_SESSION['_controller_data'][get_class($model)][$attribute])) { $selected = $_SESSION['_controller_data'][get_class($model)][$attribute]; } elseif (isset($_POST[$model->get_name()][$params['number']])) { $selected = $_POST[$model->get_name()][$params['number']][$attribute]; } if (empty($selected) && $field->has_default && !$model->isLoaded()) { $selected = $field->default_value; } if (isset($params['nonone']) && $params['nonone'] == 'true' || !is_null($field->options->_nonone) && $field->options->_nonone) { $data['select']['class'][] = "nonone"; } if (!empty($depends)) { $data['select']['attrs']['data-depends'] = htmlspecialchars(json_encode($depends)); } if (!empty($affects)) { $data['select']['attrs']['data-constrains'] = htmlspecialchars(json_encode($affects)); } //*************************** // COMPILE SELECT ATTRIBUTES $data['select']['attrs']['name'] = $name; $data['select']['attrs']['id'] = $id; if (isset($data['select']['fk_link'])) { $data['select']['id'] = $id; } // join the select class items with a space and pop them in the attrs class item if (!empty($data['select']['class'])) { $data['select']['attrs']['class'] = implode(' ', $data['select']['class']); } // append any class passed in from params if (!empty($params['class'])) { $data['select']['attrs']['class'] .= ' ' . $params['class']; } // For new records, initialise the model attribute with the selected value if (!empty($selected)) { $model->{$attribute} = $selected; } if (!$use_autocomplete || isset($params['multiple']) && $params['multiple']) { if ($constrains) { $data['select']['attrs']['class'] .= ' uz-constrains'; } if (isset($params['multiple']) && $params['multiple']) { $data['dd']['attrs']['class'] = 'for_multiple'; $data['select']['id'] = $id; $data['select']['attrs']['name'] = $data['select']['attrs']['name'] . '[]'; $data['select']['attrs']['multiple'] = 'multiple'; } if (isset($params['onchange'])) { $data['select']['attrs']['onchange'] = $params['onchange']; } if (isset($params['size'])) { $data['select']['attrs']['size'] = $params['size']; } if (isset($params['disabled'])) { $data['select']['attrs']['disabled'] = 'disabled'; } // for the sake of it, trim the class string $data['select']['attrs']['class'] = trim($data['select']['attrs']['class']); // build the attribute string // $data['select']['attrs'] is no longer an array!!! $data['select']['attrs'] = build_attribute_string($data['select']['attrs']); //***************** // COMPILE OPTIONS // check whether required field if (!$field->not_null == 1 && (!isset($params['nonone']) || $params['nonone'] != 'true') && (is_null($field->options->_nonone) || !$field->options->_nonone)) { $opt_counter++; $option_attrs = array('value' => ''); if (empty($selected)) { $option_attrs['selected'] = 'selected'; $selected = 'None'; } $data['select']['options'][$opt_counter]['attrs'] = build_attribute_string($option_attrs); $data['select']['options'][$opt_counter]['value'] = 'None'; } if (isset($params['start'])) { $opt_counter++; $option_attrs = array('value' => ''); if (empty($selected)) { $option_attrs['selected'] = 'selected'; $selected = $params['start']; } $data['select']['options'][$opt_counter]['attrs'] = build_attribute_string($option_attrs); $data['select']['options'][$opt_counter]['value'] = $params['start']; } // fallback is a horrible hack for now (for uniqueness constraints on dropdowns) if ($fallback && is_array($get_options)) { $options = $get_options; } if (!empty($options)) { foreach ($options as $key => $value) { $option_attrs = array(); $opt_counter++; $option_attrs['value'] = h($key, ENT_COMPAT); if (is_array($selected) && in_array($key, $selected) || $selected == $key) { $option_attrs['selected'] = 'selected'; } $data['select']['options'][$opt_counter]['attrs'] = build_attribute_string($option_attrs); $data['select']['options'][$opt_counter]['value'] = h($value); $data['autocomplete'] = false; } } $data['dt']['attrs'] = empty($data['dt']['attrs']) ? '' : build_attribute_string($data['dt']['attrs']); $data['dd']['attrs'] = empty($data['dd']['attrs']) ? '' : build_attribute_string($data['dd']['attrs']); } elseif (is_null($field->options) && !empty($get_options)) { if (empty($selected)) { $selected = key($get_options); } $data['autocomplete'] = true; $data['data_inline'] = true; $data['select']['selected'] = $selected; $data['select']['value'] = $get_options[$selected]; $data['select']['options'] = json_encode(dataObject::toJSONArray($get_options)); $data['select']['attrs']['class'] = 'uz-autocomplete ui-autocomplete-input icon ' . $data['select']['attrs']['class']; } else { $data['autocomplete'] = true; $data['data_inline'] = false; if (isset($params['action'])) { $data['select']['attrs']['data-action'] = $params['action']; } elseif (!is_null($field->options)) { $data['select']['attrs']['data-action'] = $field->options->_action; } else { $data['select']['attrs']['data-action'] = 'getOptions'; } if (!empty($params['identifierfield'])) { $data['select']['attrs']['data-identifierfield'] = json_encode(explode(',', $params['identifierfield'])); } elseif (!is_null($field->options->_identifierfield)) { $data['select']['attrs']['data-identifierfield'] = json_encode(array_keys($field->options->_identifierfield)); } else { $data['select']['attrs']['data-identifierfield'] = '""'; } if (!empty($params['use_collection'])) { $data['select']['attrs']['data-use_collection'] = $params['use_collection'] ? 'true' : 'false'; } elseif (!is_null($field->options->_use_collection)) { $data['select']['attrs']['data-use_collection'] = $field->options->_use_collection ? 'true' : 'false'; } else { $data['select']['attrs']['data-use_collection'] = '""'; } if (empty($text_value) && !empty($selected)) { $text_value = $selected; } $text_attribute = $attribute . '_text'; $text_name = str_replace($attribute, $text_attribute, $name); if (isset($_POST[$model->get_name()][$text_attribute])) { $text_value = $_POST[$model->get_name()][$text_attribute]; } elseif (isset($_SESSION['_controller_data'][get_class($model)][$text_attribute])) { $text_value = $_SESSION['_controller_data'][get_class($model)][$text_attribute]; } elseif (isset($_POST[$model->get_name()][$params['number']])) { $text_value = $_POST[$model->get_name()][$params['number']][$text_attribute]; } $data['select']['attrs']['data-attribute'] = $attribute; $data['select']['attrs']['class'] = 'uz-autocomplete ui-autocomplete-input icon ' . $data['select']['attrs']['class']; $attrs = array('name' => $data['select']['attrs']['name'], 'id' => $data['select']['attrs']['id'], 'value' => h($selected, ENT_COMPAT), 'data-text_id' => $data['select']['attrs']['id'] . '_text'); if (isset($data['select']['attrs']['data-depends'])) { $attrs['data-depends'] = $data['select']['attrs']['data-depends']; } if (isset($data['select']['attrs']['data-constrains'])) { $attrs['data-constrains'] = $data['select']['attrs']['data-constrains']; unset($data['select']['attrs']['data-constrains']); } if ($constrains) { $attrs['class'] = '"uz-constrains"'; } $data['select']['attrs']['data-id'] = $data['select']['attrs']['id']; $data['select']['attrs']['value'] = $text_value; $data['select']['attrs']['id'] = $data['select']['attrs']['id'] . '_text'; $data['select']['attrs']['name'] = $text_name; $data['select']['attrs_text'] = build_attribute_string($data['select']['attrs']); $data['select']['attrs'] = build_attribute_string($attrs); } // this should be further up? if (prettify($params['attribute']) == 'EGS_HIDDEN_FIELD') { return ''; } // fetch smarty plugin template return smarty_plugin_template($smarty, $data, 'function.select'); }
private function getAttachments() { $attachments = new EntityAttachmentCollection(); $sh = new SearchHandler($attachments, FALSE); $sh->addConstraint(new Constraint('data_model', '=', 'modulecomponent')); $sh->addConstraint(new Constraint('entity_id', '=', ModuleComponent::getComponentId($this->_modules['module'], strtolower(get_class($this))))); $sh->addConstraint(new Constraint('createdby', '=', EGS_USERNAME)); $files = $attachments->load($sh, null, RETURN_ROWS); $dirobjs = array(); if (count($files) > 0) { foreach ($files as $attachment) { $link = '/?' . setParamsString(array('modules' => $this->_modules, 'controller' => 'attachments', 'action' => 'view_file', 'other' => array(file_id => $attachment['file_id']))); $details = array('name' => $attachment['file'], 'link' => $link, 'type' => 'attachment', 'delete' => array('modules' => $this->_modules, 'controller' => 'attachments', 'action' => 'delete', 'id' => $attachment['id']), 'size' => sizify($attachment['size']), 'mtime' => un_fix_date($attachment['lastupdated'])); $dirobjs['file'][] = $details; } } return $dirobjs; }
/** * Initialize the configuration file. * @param Application $app The application. * @param string $module The module. */ public function __construct(Application $app, $module) { parent::__construct($app, $module); }
protected function setDefaultFieldValues() { $modulecomponent = ModuleComponent::Instance($this, 'M'); if ($modulecomponent && $modulecomponent->isLoaded()) { if (!is_null($modulecomponent->title)) { $this->setTitle($modulecomponent->title); } if (count($modulecomponent->module_defaults) > 0) { foreach ($modulecomponent->module_defaults as $default) { if ($this->isField($default->field_name) && $this->_fields[$default->field_name]->user_defaults_allowed) { // override existing defaults $this->_fields[$default->field_name]->dropDefault(); $this->getField($default->field_name)->setDefault($default->default_value); $this->_fields[$default->field_name]->display_default_value = $default->default_value; if ($default->enabled == 't') { $this->defaultDisplayFields[] = $default->field_name; } else { $this->setHidden($default->field_name); $this->_fields[$default->field_name]->system_override = TRUE; } } } } } }