public function postModuleNew() { $inputData = Input::get('modData'); parse_str($inputData, $formFields); $moduleData = array('mfulltitle' => $formFields['mname'], 'mshorttitle' => $formFields['mshorttitle'], 'mdescription' => $formFields['mdescription'], 'mcode' => $formFields['mcode'], 'mfieldofstudy' => $formFields['mfieldofstudy'], 'mcoordinator' => $formFields['mcoordinator'], 'mlevel' => $formFields['mlevel'], 'mcredits' => $formFields['mcredits'], 'departmentid' => Auth::user()->department); Validator::extend('ranked', function ($attribute, $value, $parameters) { // This is the correct way to do this. $coord = User::where('name', $value)->first(); if (!$coord && $coord->rank < 1) { return false; } return true; }); $rules = array('mfulltitle' => 'required|max:50|unique:modules', 'mshorttitle' => 'required|max:50|unique:modules', 'mdescription' => 'required|min:30', 'mcode' => 'required|min:7|max:8|alpha_num|unique:modules', 'mfieldofstudy' => 'required|max:100', 'mcoordinator' => 'required|exists:users,name|ranked', 'mlevel' => 'required|in:Fundamental,Intermediate,Advanced,Expert', 'mcredits' => 'required|integer|between:5,25', 'departmentid' => 'required'); $messages = ['ranked' => "This user can't coordinate this class."]; $validator = Validator::make($moduleData, $rules, $messages); if ($validator->fails()) { return Response::json(array('fail' => true, 'errors' => $validator->getMessageBag()->toArray())); } else { if (Modules::create($moduleData)) { Session::flash('global', 'You have created the module "' . $moduleData['mfulltitle'] . '".'); //return success message return Response::json(array('success' => true, 'mName' => $moduleData['mfulltitle'])); } } }
/** * Registers a module with the modules database table * @param string $module */ public static function register_module($module) { $mod = new Modules(); $mod->getModuleByName($module); if ($mod->count() == 0) { // load the installer file $file = "modules/{$module}/{$module}.install.php"; if (file_exists('sites/' . FabriqStack::site() . "/{$file}")) { require_once 'sites/' . FabriqStack::site() . "/{$file}"; } else { if (file_exists($file)) { require_once $file; } else { throw new Exception("Module {$module} could not be found"); } } eval('$installer = new ' . $module . '_install();'); $info = $installer->info(); $mod->module = $module; $mod->enabled = 0; $mod->installed = 0; $mod->hasconfigs = 0; $mod->description = $info['description']; $mod->versioninstalled = $info['version']; if (isset($info['dependsOn'])) { $mod->dependson = implode(',', $info['dependsOn']); } $mod->id = $mod->create(); // register configs if available if (isset($info['configs'])) { foreach ($info['configs'] as $con) { $config = new ModuleConfigs(); $config->module = $mod->id; $config->var = $con; if (isset($info['configDefaults']) && array_key_exists($con, $info['configDefaults'])) { $config->val = $info['configDefaults'][$con]; } else { $config->val = ''; } $config->create(); } $mod->hasconfigs = 1; $mod->update(); } } return $mod->id; }
/** * Function that creates a dummy elective. */ protected function createDummyElective() { return Modules::create(array('mfulltitle' => 'name', 'mshorttitle' => 'shorttitle', 'mdescription' => 'description', 'mcode' => 'code', 'mfieldofstudy' => 'field', 'mcoordinator' => 'coordinator', 'mlevel' => 'level', 'mcredits' => 5, 'melective' => true, 'departmentid' => Auth::user()->department)); }
function render() { $listModuleFile = array(); $listIgnores = array('.', '..', '.DS_Store', '.svn'); $primaryArray = array('Create', 'Read', 'Edit', 'Delete'); $listFiles = array_diff(scandir($this->modulePath), $listIgnores); // GET LIST FILE IN FOLDER if (!empty($listFiles)) { foreach ($listFiles as $file) { $fileName = ucwords(str_replace("_", " ", $file)); $fileSlug = str_replace("_", "-", $file); $listModuleFile[$fileSlug] = $fileName; } } // GET LIST FILE IN DATABASE $listModuleStore = Modules::get()->toArray(); $listModuleStore = array_column($listModuleStore, 'name', 'slug'); // NEW MODULE $diffInsert = array_diff($listModuleFile, $listModuleStore); $insertData = array(); if (!empty($diffInsert)) { foreach ($diffInsert as $k => $v) { $mA = explode("-", $k); $suffix = last($mA); if ($suffix == 'manager') { $count = count($mA); $preSuffix = $mA[$count - 2]; $suffix = $preSuffix . "_" . $suffix; } $groupString = "group_" . $suffix . "_id"; $group = 0; if (Config::has("backend.{$groupString}")) { $group = Config::get("backend.{$groupString}"); } $insertData = array('slug' => $k, 'name' => $v, 'group_id' => $group, 'status' => 1); if ($item = Modules::create($insertData)) { if ($item->save()) { // // Insert Menu // $menuInsert = array( // 'status' => 0, // 'name' => $item->name, // 'module_id' => $item->id, // 'slug' => $item->slug.'/show-list', // ); // Menus::create($menuInsert); // Create Primary Permission foreach ($primaryArray as $p) { $primaryInsert = array('name' => $item->name . " " . $p, 'slug' => $item->slug . "-" . strtolower($p), 'module_id' => $item->id, 'group_id' => $group, 'action' => strtolower($p)); Permission::create($primaryInsert); } } } } } // REMOVE MODULE $diffRemove = array_diff($listModuleStore, $listModuleFile); if (!empty($diffRemove)) { foreach ($diffRemove as $k => $v) { $item = Modules::where(array('slug' => $k, 'name' => $v))->first(); $deleteID = $item->id; if ($item->delete()) { // Menus::where('module_id', $deleteID)->delete(); Permission::where('module_id', $deleteID)->delete(); } } } }
/** * AutoLoader for BMO. * * This implements a half-arsed spl_autoload that ignore PSR1 and PSR4. I am * admitting that at the start so no-one gets on my case about it. * * However, as we're having no end of issues with PHP Autoloading things properly * (as of PHP 5.3.3, which is our minimum version at this point in time), this will * do in the interim. * * This tries to load the BMO Object called. It looks first in the BMO Library * dir, which is assumed to be the same directory as this file. It then grabs * a list of all active modules, and looks through them for the class requested. * * If it doesn't find it, it'll throw an exception telling you why. * * @return object * @access private */ function autoload() { // Figure out what is wanted, and return it. if (func_num_args() == 0) { throw new \Exception("Nothing given to the AutoLoader"); } // If we have TWO arguments, we've been called by __call, if we only have // one we've been called by __get. $args = func_get_args(); $var = $args[0]; if ($var == "UCP") { throw new \Exception("No. You ALREADY HAVE the UCP Object. You don't need another one."); } // Ensure no-one's trying to include something with a path in it. if (strpos($var, "/") || strpos($var, "..")) { throw new \Exception("Invalid include given to AutoLoader - {$var}"); } // This will throw an Exception if it can't find the class. $this->loadObject($var); // Now, we may have paramters (__call), or we may not.. if (isset($args[1])) { // We do. We were __call'ed. Sanity check if (isset($args[1][1])) { throw new \Exception("Multiple params to autoload (__call) not supported. Don't do that. Or re-write this."); } $class = __NAMESPACE__ . "\\Modules\\{$var}"; $this->{$var} = new $class($this, $args[1][0]); } else { $class = __NAMESPACE__ . "\\Modules\\{$var}"; $this->{$var} = new $class($this); Modules::create()->{$var} = $this->{$var}; } return $this->{$var}; }
function render() { $listModuleFile = array(); $listIgnores = array('dashboard', 'home', 'chat', 'search', '.', '..', '.DS_Store', '.svn'); $primaryArray = array('Create', 'Read', 'Edit', 'Delete'); $listFiles = array_diff(scandir($this->modulePath), $listIgnores); // GET LIST FILE IN FOLDER if (!empty($listFiles)) { foreach ($listFiles as $file) { $file = str_replace("_backend", "", $file); $fileName = ucwords(str_replace("_", " ", $file)); $fileSlug = str_replace("_", "-", $file); $listModuleFile[$fileSlug] = $fileName; } } // GET LIST FILE IN DATABASE $listModuleStore = Modules::get()->toArray(); $listModuleStore = array_column($listModuleStore, 'name', 'slug'); // NEW MODULE $diffInsert = array_diff($listModuleFile, $listModuleStore); $insertData = array(); if (!empty($diffInsert)) { foreach ($diffInsert as $k => $v) { $insertData = array('slug' => $k, 'name' => $v, 'status' => 1); if ($item = Modules::create($insertData)) { if ($item->save()) { // Insert Menu $menuInsert = array('status' => 0, 'name' => $item->name, 'module_id' => $item->id, 'slug' => $item->slug . '/show-list'); Menus::create($menuInsert); // Create Primary Permission foreach ($primaryArray as $p) { $primaryInsert = array('name' => $item->name . " " . $p, 'slug' => $item->slug . "-" . strtolower($p), 'module_id' => $item->id, 'action' => strtolower($p)); Permission::create($primaryInsert); } } } } } // REMOVE MODULE $diffRemove = array_diff($listModuleStore, $listModuleFile); if (!empty($diffRemove)) { foreach ($diffRemove as $k => $v) { $item = Modules::where(array('slug' => $k, 'name' => $v))->first(); $deleteID = $item->id; if ($item->delete()) { Menus::where('module_id', $deleteID)->delete(); Permission::where('module_id', $deleteID)->delete(); } } } }