/** * Drop the test database between tests. * * @since 2.0 */ protected function tearDown() { $config = ConfigProvider::getInstance(); foreach ($this->getActiveRecordProviders() as $provider) { $config->set('db.provider.name', $provider[0]); ActiveRecord::dropDatabase(); ActiveRecord::disconnect(); } }
/** * The constructor. * * @since 1.0 */ public function __construct() { // ensure to call the parent constructor parent::__construct(); $this->value = new String(); $this->value->setRule(Validator::REQUIRED_STRING); $this->value->setHelper('A blank dropdown value is not allowed!'); $this->DEnumID = new Integer(); $this->markTransient('helper'); }
/** * Private method to generate the main body HTML for this page. * * @since 1.0 * * @return string */ private function displayBodyContent() { $classNames = ActiveRecord::getBOClassNames(); $body = ''; $fields = array('formAction' => $this->request->getURI()); foreach ($classNames as $className) { try { $activeRecord = new $className(); $view = View::getInstance($activeRecord); $body .= $view->adminView($fields); } catch (AlphaException $e) { self::$logger->error("[{$classname}]:" . $e->getMessage()); // its possible that the exception occured due to the table schema being out of date if ($activeRecord->checkTableExists() && $activeRecord->checkTableNeedsUpdate()) { $missingFields = $activeRecord->findMissingFields(); $count = count($missingFields); for ($i = 0; $i < $count; ++$i) { $activeRecord->addProperty($missingFields[$i]); } // now try again... $activeRecord = new $className(); $view = View::getInstance($activeRecord); $body .= $view->adminView($fields); } } catch (\Exception $e) { self::$logger->error($e->getMessage()); $body .= View::displayErrorMessage('Error accessing the class [' . $classname . '], check the log!'); } } return $body; }
/** * Constructor. * * @since 1.0 */ public function __construct() { self::$logger = new Logger('Rights'); // ensure to call the parent constructor parent::__construct(); $this->name = new String(); // add unique key to name field $this->markUnique('name'); $this->members = new Relation(); $this->markTransient('members'); $this->setupRels(); }
/** * Method to load all of the BO items to the feed from the database, from the newest to the * $limit provided. * * @param int $limit The amount of items to render in the feed. * @param string $sortBy The name of the field to sort the feed by. * * @since 1.0 */ public function loadBOs($limit, $sortBy) { $BOs = $this->BO->loadAll(0, $limit, $sortBy, 'DESC'); ActiveRecord::disconnect(); foreach ($BOs as $BO) { $this->addBO($BO); } }
/** * Constructor for the class. * * @since 1.0 */ public function __construct() { self::$logger = new Logger('ArticleVote'); // ensure to call the parent constructor parent::__construct(); $this->articleOID = new Relation(); $this->articleOID->setRelatedClass('Alpha\\Model\\Article'); $this->articleOID->setRelatedClassField('OID'); $this->articleOID->setRelatedClassDisplayField('description'); $this->articleOID->setRelationType('MANY-TO-ONE'); $this->personOID = new Relation(); $this->personOID->setRelatedClass('Alpha\\Model\\Person'); $this->personOID->setRelatedClassField('OID'); $this->personOID->setRelatedClassDisplayField('email'); $this->personOID->setRelationType('MANY-TO-ONE'); $this->score = new Integer(); }
/** * {@inheritdoc} */ public static function displayPageHead($controller) { if (self::$logger == null) { self::$logger = new Logger('RendererProviderHTML'); } self::$logger->debug('>>displayPageHead(controller=[' . var_export($controller, true) . '])'); $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); if (!class_exists(get_class($controller))) { throw new IllegalArguementException('The controller provided [' . get_class($controller) . '] is not defined anywhere!'); } $allowCSSOverrides = true; $request = new Request(array('method' => 'GET')); if ($session->get('currentUser') != null && ActiveRecord::isInstalled() && $session->get('currentUser')->inGroup('Admin') && mb_strpos($request->getURI(), '/tk/') !== false) { $allowCSSOverrides = false; } $html = View::loadTemplateFragment('html', 'head.phtml', array('title' => $controller->getTitle(), 'description' => $controller->getDescription(), 'allowCSSOverrides' => $allowCSSOverrides)); if (method_exists($controller, 'during_displayPageHead_callback')) { $html .= $controller->during_displayPageHead_callback(); } $html .= '</head>'; try { if ($controller->getRecord() != null) { $html .= '<body' . ($controller->getRecord()->get('bodyOnload') != '' ? ' onload="' . $controller->getRecord()->get('bodyOnload') . '"' : '') . '>'; } else { $html .= '<body>'; } } catch (AlphaException $e) { $html .= '<body>'; } $html .= '<div class="container">'; if (method_exists($controller, 'insert_CMSDisplayStandardHeader_callback')) { $html .= $controller->insert_CMSDisplayStandardHeader_callback(); } self::$logger->debug('<<displayPageHead [HTML]'); return $html; }
/** * Tear down tests. * * @since 1.2.3 */ protected function tearDown() { unset($this->article); ActiveRecord::dropDatabase(); ActiveRecord::disconnect(); }
/** * Handle POST requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @throws Alpha\Exception\SecurityException * * @since 1.0 */ public function doPOST($request) { self::$logger->debug('>>doPOST($request=[' . var_export($request, true) . '])'); $params = $request->getParams(); try { // check the hidden security fields before accepting the form POST data if (!$this->checkSecurityFields()) { throw new SecurityException('This page cannot accept post data from remote servers!'); self::$logger->debug('<<doPOST'); } // ensure that a OID is provided if (isset($params['denumOID'])) { $BOoid = $params['denumOID']; } else { throw new IllegalArguementException('Could not load the DEnum object as an denumOID was not supplied!'); } if (isset($params['saveBut'])) { try { $this->BO->load($BOoid); // update the object from post data $this->BO->populateFromArray($params); ActiveRecord::begin(); $this->BO->save(); self::$logger->action('DEnum ' . $this->BO->getOID() . ' saved'); // now save the DEnumItems $tmp = new DEnumItem(); $denumItems = $tmp->loadItems($this->BO->getID()); foreach ($denumItems as $item) { $item->set('value', $params['value_' . $item->getID()]); $item->save(); self::$logger->action('DEnumItem ' . $item->getOID() . ' saved'); } // handle new DEnumItem if posted if (isset($params['new_value']) && trim($params['new_value']) != '') { $newItem = new DEnumItem(); $newItem->set('value', $params['new_value']); $newItem->set('DEnumID', $this->BO->getID()); $newItem->save(); self::$logger->action('DEnumItem ' . $newItem->getOID() . ' created'); } ActiveRecord::commit(); $this->setStatusMessage(View::displayUpdateMessage(get_class($this->BO) . ' ' . $this->BO->getID() . ' saved successfully.')); return $this->doGET($request); } catch (FailedSaveException $e) { self::$logger->error('Unable to save the DEnum of id [' . $params['oid'] . '], error was [' . $e->getMessage() . ']'); ActiveRecord::rollback(); } ActiveRecord::disconnect(); } } catch (SecurityException $e) { $this->setStatusMessage(View::displayErrorMessage($e->getMessage())); self::$logger->warn($e->getMessage()); } catch (IllegalArguementException $e) { $this->setStatusMessage(View::displayErrorMessage($e->getMessage())); self::$logger->error($e->getMessage()); } catch (RecordNotFoundException $e) { self::$logger->warn($e->getMessage()); $this->setStatusMessage(View::displayErrorMessage('Failed to load the requested item from the database!')); } $body = View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $body .= View::displayPageFoot($this); self::$logger->debug('<<doPOST'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * Handle POST requests (adds $currentUser Person to the session). * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @throws Alpha\Exception\IllegalArguementException * * @since 1.0 */ public function doPOST($request) { self::$logger->debug('>>doPOST($request=[' . var_export($request, true) . '])'); $params = $request->getParams(); if (!is_array($params)) { throw new IllegalArguementException('Bad $params [' . var_export($params, true) . '] passed to doPOST method!'); } $config = ConfigProvider::getInstance(); $body = ''; try { // check the hidden security fields before accepting the form POST data if (!$this->checkSecurityFields()) { throw new SecurityException('This page cannot accept post data from remote servers!'); } if (isset($params['loginBut'])) { // if the database has not been set up yet, accept a login from the config admin username/password if (!ActiveRecord::isInstalled()) { if ($params['email'] == $config->get('app.install.username') && password_verify($params['password'], password_hash($config->get('app.install.password'), PASSWORD_DEFAULT, ['cost' => 12]))) { self::$logger->info('Logging in [' . $params['email'] . '] at [' . date('Y-m-d H:i:s') . ']'); $admin = new Person(); $admin->set('displayName', 'Admin'); $admin->set('email', $params['email']); $admin->set('password', password_hash($params['password'], PASSWORD_DEFAULT, ['cost' => 12])); $admin->set('OID', '00000000001'); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $session->set('currentUser', $admin); $response = new Response(301); if ($this->getNextJob() != '') { $response->redirect(FrontController::generateSecureURL('act=' . $this->getNextJob())); $this->clearUnitOfWorkAttributes(); } else { $response->redirect(FrontController::generateSecureURL('act=InstallController')); } return $response; } else { throw new ValidationException('Failed to login user ' . $params['email'] . ', the password is incorrect!'); } } else { // here we are attempting to load the person from the email address $this->personObject->loadByAttribute('email', $params['email'], true); ActiveRecord::disconnect(); // checking to see if the account has been disabled if (!$this->personObject->isTransient() && $this->personObject->get('state') == 'Disabled') { throw new SecurityException('Failed to login user ' . $params['email'] . ', that account has been disabled!'); } // check the password return $this->doLoginAndRedirect($params['password']); } $body .= View::displayPageHead($this); $body .= $this->personView->displayLoginForm(); } if (isset($params['resetBut'])) { // here we are attempting to load the person from the email address $this->personObject->loadByAttribute('email', $params['email']); ActiveRecord::disconnect(); // generate a new random password $newPassword = $this->personObject->generatePassword(); // now encrypt and save the new password, then e-mail the user $this->personObject->set('password', password_hash($newPassword, PASSWORD_DEFAULT, ['cost' => 12])); $this->personObject->save(); $message = 'The password for your account has been reset to ' . $newPassword . ' as you requested. You can now login to the site using your ' . 'e-mail address and this new password as before.'; $subject = 'Password change request'; $this->personObject->sendMail($message, $subject); $body .= View::displayUpdateMessage('The password for the user <strong>' . $params['email'] . '</strong> has been reset, and the new password ' . 'has been sent to that e-mail address.'); $body .= '<a href="' . $config->get('app.url') . '">Home Page</a>'; } } catch (ValidationException $e) { $body .= View::displayPageHead($this); $body .= View::displayErrorMessage($e->getMessage()); if (isset($params['reset'])) { $body .= $this->personView->displayResetForm(); } else { $body .= $this->personView->displayLoginForm(); } self::$logger->warn($e->getMessage()); } catch (SecurityException $e) { $body .= View::displayPageHead($this); $body .= View::displayErrorMessage($e->getMessage()); self::$logger->warn($e->getMessage()); } catch (RecordNotFoundException $e) { $body .= View::displayPageHead($this); $body .= View::displayErrorMessage('Failed to find the user \'' . $params['email'] . '\''); if (isset($params['reset'])) { $body .= $this->personView->displayResetForm(); } else { $body .= $this->personView->displayLoginForm(); } self::$logger->warn($e->getMessage()); } $body .= View::displayPageFoot($this); self::$logger->debug('<<doPOST'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * (non-PHPdoc). * * @see Alpha\Model\ActiveRecordProviderInterface::isTableOverloaded() */ public function isTableOverloaded() { self::$logger->debug('>>isTableOverloaded()'); $reflection = new ReflectionClass($this->BO); $classname = $reflection->getShortName(); $tablename = ucfirst($this->BO->getTableName()); // use reflection to check to see if we are dealing with a persistent type (e.g. DEnum) which are never overloaded $implementedInterfaces = $reflection->getInterfaces(); foreach ($implementedInterfaces as $interface) { if ($interface->name == 'Alpha\\Model\\Type\\TypeInterface') { self::$logger->debug('<<isTableOverloaded [false]'); return false; } } if ($classname != $tablename) { // loop over all BOs to see if there is one using the same table as this BO $BOclasses = ActiveRecord::getBOClassNames(); foreach ($BOclasses as $BOclassName) { $reflection = new ReflectionClass($BOclassName); $classname = $reflection->getShortName(); if ($tablename == $classname) { self::$logger->debug('<<isTableOverloaded [true]'); return true; } } throw new BadTableNameException('The table name [' . $tablename . '] for the class [' . $classname . '] is invalid as it does not match a BO definition in the system!'); self::$logger->debug('<<isTableOverloaded [false]'); return false; } else { // check to see if there is already a "classname" column in the database for this BO $query = 'SHOW COLUMNS FROM ' . $this->BO->getTableName(); $result = self::getConnection()->query($query); if ($result) { while ($row = $result->fetch_array(MYSQLI_ASSOC)) { if ('classname' == $row['Field']) { self::$logger->debug('<<isTableOverloaded [true]'); return true; } } } else { self::$logger->warn('Error during show columns [' . self::getConnection()->error . ']'); } self::$logger->debug('<<isTableOverloaded [false]'); return false; } }
/** * Constructor that sets up the DEnum options. * * @param Alpha\Model\Type\String $name */ public function __construct($name = null) { self::$logger = new Logger('DEnum'); // ensure to call the parent constructor parent::__construct(); $this->markTransient('options'); $this->markTransient('value'); $this->markTransient('helper'); $this->name = new String($name); if (isset($name) && $this->checkTableExists()) { try { $this->loadByAttribute('name', $name); } catch (RecordNotFoundException $e) { // DEnum does not exist so create it $this->save(); } try { $this->getOptions(); } catch (AlphaException $e) { self::$logger->warn($e->getMessage()); } } }
/** * Constructor for the class. * * @since 1.0 */ public function __construct() { self::$logger = new Logger('BadRequest'); self::$logger->debug('>>__construct()'); // ensure to call the parent constructor parent::__construct(); $this->client = new String(); $this->IP = new String(); $this->requestedResource = new String(); self::$logger->debug('<<__construct'); }
/** * The constructor. * * @since 1.0 */ public function __construct() { self::$logger = new Logger('Tag'); // ensure to call the parent constructor parent::__construct(); $this->taggedClass = new String(); $this->taggedOID = new Integer(); $this->content = new String(); $this->markUnique('taggedClass', 'taggedOID', 'content'); }
/** * Handle POST requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @throws Alpha\Exception\SecurityException * @throws Alpha\Exception\IllegalArguementException * * @since 1.0 */ public function doPOST($request) { self::$logger->debug('>>doPOST($request=[' . var_export($request, true) . '])'); $params = $request->getParams(); try { // check the hidden security fields before accepting the form POST data if (!$this->checkSecurityFields()) { throw new SecurityException('This page cannot accept post data from remote servers!'); } if (isset($params['clearTaggedClass']) && $params['clearTaggedClass'] != '') { try { self::$logger->info('About to start rebuilding the tags for the class [' . $params['clearTaggedClass'] . ']'); $startTime = microtime(true); $record = new $params['clearTaggedClass'](); $records = $record->loadAll(); self::$logger->info('Loaded all of the active records (elapsed time [' . round(microtime(true) - $startTime, 5) . '] seconds)'); ActiveRecord::begin(); $tag = new Tag(); $tag->deleteAllByAttribute('taggedClass', $params['clearTaggedClass']); self::$logger->info('Deleted all of the old tags (elapsed time [' . round(microtime(true) - $startTime, 5) . '] seconds)'); $this->regenerateTagsOnRecords($records); self::$logger->info('Saved all of the new tags (elapsed time [' . round(microtime(true) - $startTime, 5) . '] seconds)'); self::$logger->action('Tags recreated on the [' . $params['clearTaggedClass'] . '] class'); ActiveRecord::commit(); $this->setStatusMessage(View::displayUpdateMessage('Tags recreated on the ' . $record->getFriendlyClassName() . ' class.')); self::$logger->info('Tags recreated on the [' . $params['clearTaggedClass'] . '] class (time taken [' . round(microtime(true) - $startTime, 5) . '] seconds).'); } catch (AlphaException $e) { self::$logger->error($e->getMessage()); ActiveRecord::rollback(); } ActiveRecord::disconnect(); return $this->doGET($request); } elseif (isset($params['ActiveRecordType']) && isset($params['ActiveRecordOID'])) { $ActiveRecordType = urldecode($params['ActiveRecordType']); $ActiveRecordOID = $params['ActiveRecordOID']; if (class_exists($ActiveRecordType)) { $record = new $ActiveRecordType(); } else { throw new IllegalArguementException('No ActiveRecord available to display tags for!'); } if (isset($params['saveBut'])) { try { $record->load($ActiveRecordOID); $tags = $record->getPropObject('tags')->getRelatedObjects(); ActiveRecord::begin(); foreach ($tags as $tag) { $tag->set('content', Tag::cleanTagContent($params['content_' . $tag->getID()])); $tag->save(); self::$logger->action('Saved tag ' . $tag->get('content') . ' on ' . $ActiveRecordType . ' instance with OID ' . $ActiveRecordOID); } // handle new tag if posted if (isset($params['NewTagValue']) && trim($params['NewTagValue']) != '') { $newTag = new Tag(); $newTag->set('content', Tag::cleanTagContent($params['NewTagValue'])); $newTag->set('taggedOID', $ActiveRecordOID); $newTag->set('taggedClass', $ActiveRecordType); $newTag->save(); self::$logger->action('Created a new tag ' . $newTag->get('content') . ' on ' . $ActiveRecordType . ' instance with OID ' . $ActiveRecordOID); } ActiveRecord::commit(); $this->setStatusMessage(View::displayUpdateMessage('Tags on ' . get_class($record) . ' ' . $record->getID() . ' saved successfully.')); return $this->doGET($request); } catch (ValidationException $e) { /* * The unique key has most-likely been violated because this BO is already tagged with this * value. */ ActiveRecord::rollback(); $this->setStatusMessage(View::displayErrorMessage('Tags on ' . get_class($record) . ' ' . $record->getID() . ' not saved due to duplicate tag values, please try again.')); return $this->doGET($request); } catch (FailedSaveException $e) { self::$logger->error('Unable to save the tags of id [' . $params['ActiveRecordOID'] . '], error was [' . $e->getMessage() . ']'); ActiveRecord::rollback(); $this->setStatusMessage(View::displayErrorMessage('Tags on ' . get_class($record) . ' ' . $record->getID() . ' not saved, please check the application logs.')); return $this->doGET($request); } ActiveRecord::disconnect(); } } else { return parent::doPOST($request); } } catch (SecurityException $e) { $this->setStatusMessage(View::displayErrorMessage($e->getMessage())); self::$logger->warn($e->getMessage()); } catch (IllegalArguementException $e) { self::$logger->error($e->getMessage()); } catch (RecordNotFoundException $e) { self::$logger->warn($e->getMessage()); $this->setStatusMessage(View::displayErrorMessage('Failed to load the requested item from the database!')); } self::$logger->debug('<<doPOST'); }
/** * Custom version of the check rights method that only checks for a session for the config admin username/password, * when the system database is not set-up. * * @return bool * * @since 1.0 */ public function checkRights() { self::$logger->debug('>>checkRights()'); $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); if ($this->getVisibility() == 'Public') { self::$logger->debug('<<checkRights [true]'); return true; } if (ActiveRecord::isInstalled()) { self::$logger->debug('<<checkRights [false]'); return false; } // the person is logged in? if ($session->get('currentUser') !== false) { if ($session->get('currentUser')->get('email') == $config->get('app.install.username')) { self::$logger->debug('<<checkRights [true]'); return true; } } }
/** * Loads the BO indicated in the GET request and handles the conversion to Excel. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @throws Alpha\Exception\ResourceNotFoundException * * @since 1.0 */ public function doGet($request) { self::$logger->debug('>>doGet(request=[' . var_export($request, true) . '])'); $params = $request->getParams(); $body = ''; try { if (isset($params['ActiveRecordType'])) { $ActiveRecordType = $params['ActiveRecordType']; $className = "Alpha\\Model\\{$ActiveRecordType}"; if (class_exists($className)) { $this->BO = new $className(); } else { throw new IllegalArguementException('No ActiveRecord available to render!'); } // the name of the file download if (isset($params['ActiveRecordOID'])) { $fileName = $this->BO->getTableName() . '-' . $params['ActiveRecordOID']; } else { $fileName = $this->BO->getTableName(); } $response = new Response(200); // header info for browser $response->setHeader('Content-Type', 'application/vnd.ms-excel'); $response->setHeader('Content-Disposition', 'attachment; filename=' . $fileName . '.xls'); $response->setHeader('Pragma', 'no-cache'); $response->setHeader('Expires', '0'); // handle a single BO if (isset($params['ActiveRecordOID'])) { $this->BO->load($params['ActiveRecordOID']); ActiveRecord::disconnect(); $convertor = new ActiveRecord2Excel($this->BO); $body .= $convertor->render(); } else { // handle all BOs of this type $BOs = $BO->loadAll(); ActiveRecord::disconnect(); $first = true; foreach ($BOs as $BO) { $convertor = new ActiveRecord2Excel($BO); if ($first) { $body .= $convertor->render(true); $first = false; } else { $body .= $convertor->render(false); } } } } else { throw new IllegalArguementException('No ActiveRecordType parameter available for ViewExcel controller!'); } } catch (RecordNotFoundException $e) { self::$logger->error($e->getMessage()); throw new ResourceNotFoundException($e->getMessage()); } catch (IllegalArguementException $e) { self::$logger->error($e->getMessage()); throw new ResourceNotFoundException($e->getMessage()); } self::$logger->debug('<<__doGet'); $response->setBody($body); return $response; }
/** * Constructor for the class that populates all of the complex types with default values. * * @since 1.0 */ public function __construct() { self::$logger = new Logger('Person'); self::$logger->debug('>>__construct()'); // ensure to call the parent constructor parent::__construct(); $this->displayName = new String(); $this->displayName->setRule(Validator::REQUIRED_USERNAME); $this->displayName->setSize(70); $this->displayName->setHelper('Please provide a name for display on the website (only letters, numbers, and .-_ characters are allowed!).'); $this->email = new String(); $this->email->setRule(Validator::REQUIRED_EMAIL); $this->email->setSize(70); $this->email->setHelper('Please provide a valid e-mail address as your username.'); $this->password = new String(); $this->password->setSize(70); $this->password->setHelper('Please provide a password for logging in.'); $this->password->isPassword(true); $this->state = new Enum(array('Active', 'Disabled')); $this->state->setValue('Active'); $this->URL = new String(); $this->URL->setRule(Validator::OPTIONAL_HTTP_URL); $this->URL->setHelper('URLs must be in the format http://some_domain/ or left blank!'); // add unique keys to displayName and email (which is effectively the username in Alpha) $this->markUnique('displayName'); $this->markUnique('email'); $this->rights = new Relation(); $this->markTransient('rights'); $this->actions = new Relation(); $this->markTransient('actions'); $this->setupRels(); self::$logger->debug('<<__construct'); }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $params = $request->getParams(); $body = View::displayPageHead($this); $sequence = new Sequence(); // make sure that the Sequence tables exist if (!$sequence->checkTableExists()) { $body .= View::displayErrorMessage('Warning! The Sequence table do not exist, attempting to create it now...'); $sequence->makeTable(); } // set the start point for the list pagination if (isset($params['start']) ? $this->startPoint = $params['start'] : ($this->startPoint = 1)) { } $records = $sequence->loadAll($this->startPoint); ActiveRecord::disconnect(); $this->BOCount = $sequence->getCount(); $body .= View::renderDeleteForm($this->request->getURI()); foreach ($records as $record) { $view = View::getInstance($record); $body .= $view->listView(array('URI' => $request->getURI())); } $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * The constructor. * * @since 1.0 */ public function __construct() { // ensure to call the parent constructor parent::__construct(); $this->validationRule = Validator::ALLOW_ALL; $this->sequence = new Integer(); $this->prefix = new String(); $this->prefix->setRule(Validator::REQUIRED_ALPHA_UPPER); $this->prefix->setHelper('Sequence prefix must be uppercase string!'); $this->markUnique('prefix'); $this->markTransient('helper'); $this->markTransient('validationRule'); $this->markTransient('size'); }
/** * {@inheritdoc} */ public function renderAllFields($mode, $filterFields = array(), $readOnlyFields = array()) { self::$logger->debug('>>renderAllFields(mode=[' . $mode . '], filterFields=[' . var_export($filterFields, true) . '], readOnlyFields=[' . var_export($readOnlyFields, true) . '])'); $html = ''; // get the class attributes $properties = array_keys($this->BO->getDataLabels()); $orignalMode = $mode; foreach ($properties as $propName) { if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $filterFields)) { // render readonly fields in the supplied array if (in_array($propName, $readOnlyFields)) { $mode = 'view'; } else { $mode = $orignalMode; } if (!is_object($this->BO->getPropObject($propName))) { continue; } $reflection = new ReflectionClass($this->BO->getPropObject($propName)); $propClass = $reflection->getShortName(); // exclude non-Relation transient attributes from create and edit screens if ($propClass != 'Relation' && ($mode == 'edit' || $mode == 'create') && in_array($propName, $this->BO->getTransientAttributes())) { continue; } switch (mb_strtoupper($propClass)) { case 'INTEGER': if ($mode == 'view') { $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName)); } else { $html .= $this->renderIntegerField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName)); } break; case 'DOUBLE': if ($mode == 'view') { $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName)); } else { $html .= $this->renderDoubleField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName)); } break; case 'DATE': if ($mode == 'view') { $value = $this->BO->get($propName); if ($value == '0000-00-00') { $value = ''; } $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $value); } else { $date = new DateBox($this->BO->getPropObject($propName), $this->BO->getDataLabel($propName), $propName); $html .= $date->render(); } break; case 'TIMESTAMP': if ($mode == 'view') { $value = $this->BO->get($propName); if ($value == '0000-00-00 00:00:00') { $value = ''; } $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $value); } else { $timestamp = new DateBox($this->BO->getPropObject($propName), $this->BO->getDataLabel($propName), $propName); $html .= $timestamp->render(); } break; case 'STRING': $html .= $this->renderStringField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName)); break; case 'TEXT': $html .= $this->renderTextField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName)); break; case 'BOOLEAN': if ($mode == 'view') { $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName)); } else { $html .= $this->renderBooleanField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName)); } break; case 'ENUM': if ($mode == 'view') { $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->get($propName)); } else { $enum = $this->BO->getPropObject($propName); $html .= $this->renderEnumField($propName, $this->BO->getDataLabel($propName), $mode, $enum->getOptions(), $this->BO->get($propName)); } break; case 'DENUM': if ($mode == 'view') { $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), 'view', $this->BO->getPropObject($propName)->getDisplayValue()); } else { $denum = $this->BO->getPropObject($propName); $html .= $this->renderDEnumField($propName, $this->BO->getDataLabel($propName), $mode, $denum->getOptions(), $this->BO->get($propName)); } break; case 'RELATION': $html .= $this->renderRelationField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName)); break; default: $html .= $this->renderDefaultField($propName, $this->BO->getDataLabel($propName), $mode, $this->BO->get($propName)); break; } } } self::$logger->debug('<<renderAllFields [' . $html . ']'); return $html; }
/** * constructor for the class. * * @since 1.0 */ public function __construct() { self::$logger = new Logger('ArticleComment'); // ensure to call the parent constructor parent::__construct(); $this->articleOID = new Relation(); $this->articleOID->setRelatedClass('Alpha\\Model\\Article'); $this->articleOID->setRelatedClassField('OID'); $this->articleOID->setRelatedClassDisplayField('description'); $this->articleOID->setRelationType('MANY-TO-ONE'); $this->content = new Text(); $this->content->setAllowHTML(false); }
/** * Constructor for the class. * * @since 1.2 */ public function __construct() { self::$logger = new Logger('BlacklistedIP'); // ensure to call the parent constructor parent::__construct(); $this->IP = new String(); $this->markUnique('IP'); }
/** * Set the name of the business object class that this class is related to. * * @param string $RC * @param string $side Only required for MANY-TO-MANY relations * * @since 1.0 * * @throws Alpha\Exception\IllegalArguementException */ public function setRelatedClass($RC, $side = '') { if (in_array($RC, ActiveRecord::getBOClassNames())) { switch ($side) { case '': $this->relatedClass = $RC; break; case 'left': $this->relatedClassLeft = $RC; break; case 'right': $this->relatedClassRight = $RC; break; default: throw new IllegalArguementException('The side paramter [' . $RC . '] is not valid!'); } } else { throw new IllegalArguementException('The class [' . $RC . '] is not defined anywhere!'); } }
/** * Method for adding a BO to the current feed. * * @param Alpha\Model\ActiveRecord $BO */ public function addBO($BO) { $title = $BO->get($this->fieldNameMappings['title']); $url = $BO->get($this->fieldNameMappings['url']); if (isset($this->fieldNameMappings['description'])) { $description = $BO->get($this->fieldNameMappings['description']); } else { $description = ''; } if (isset($this->fieldNameMappings['pubDate'])) { $dateTS = strtotime($BO->get($this->fieldNameMappings['pubDate'])); $pubDate = date(DATE_ATOM, $dateTS); } else { $pubDate = ''; } if (isset($this->fieldNameMappings['id'])) { $id = $BO->get($this->fieldNameMappings['id']); } else { $id = ''; } $this->addItem($title, $url, $description, $pubDate, $id); }
/** * Method to handle DELETE requests. * * @param Alpha\Util\Http\Request $request * * @throws Alpha\Exception\IllegalArguementException * @throws Alpha\Exception\SecurityException * * @return Alpha\Util\Http\Response * * @since 2.0 */ public function doDELETE($request) { self::$logger->debug('>>doDELETE(request=[' . var_export($request, true) . '])'); $config = ConfigProvider::getInstance(); $params = $request->getParams(); $accept = $request->getAccept(); try { // check the hidden security fields before accepting the form data if (!$this->checkSecurityFields()) { throw new SecurityException('This page cannot accept data from remote servers!'); } if (isset($params['ActiveRecordType'])) { $ActiveRecordType = urldecode($params['ActiveRecordType']); } else { throw new IllegalArguementException('No ActiveRecord available to edit!'); } if (class_exists($ActiveRecordType)) { $record = new $ActiveRecordType(); } else { throw new IllegalArguementException('No ActiveRecord [' . $ActiveRecordType . '] available to edit!'); } // check the hidden security fields before accepting the form POST data if (!$this->checkSecurityFields()) { throw new SecurityException('This page cannot accept post data from remote servers!'); } $record->load($params['ActiveRecordOID']); ActiveRecord::begin(); $record->delete(); ActiveRecord::commit(); ActiveRecord::disconnect(); self::$logger->action('Deleted ' . $ActiveRecordType . ' instance with OID ' . $params['ActiveRecordOID']); if ($accept == 'application/json') { $response = new Response(200); $response->setHeader('Content-Type', 'application/json'); $response->setBody(json_encode(array('message' => 'deleted'))); } else { $response = new Response(301); if (isset($params['statusMessage'])) { $this->setStatusMessage(View::displayUpdateMessage($params['statusMessage'])); } else { $this->setStatusMessage(View::displayUpdateMessage('Deleted')); } if ($this->getNextJob() != '') { $response->redirect($this->getNextJob()); } else { if ($this->request->isSecureURI()) { $response->redirect(FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . $ActiveRecordType . '&start=0&limit=' . $config->get('app.list.page.amount'))); } else { $response->redirect($config->get('app.url') . '/records/' . $params['ActiveRecordType']); } } } } catch (SecurityException $e) { self::$logger->warn($e->getMessage()); throw new ResourceNotAllowedException($e->getMessage()); } catch (RecordNotFoundException $e) { self::$logger->warn($e->getMessage()); throw new ResourceNotFoundException('The item that you have requested cannot be found!'); } catch (AlphaException $e) { self::$logger->error($e->getMessage()); ActiveRecord::rollback(); } self::$logger->debug('<<doDELETE'); return $response; }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET(request=[' . var_export($request, true) . '])'); $config = ConfigProvider::getInstance(); if ($config->get('app.check.installed') && !ActiveRecord::isInstalled()) { $response = new Response(301); $response->redirect($config->get('app.url') . '/install'); self::$logger->warn('App not installed so re-directing to the install controller'); self::$logger->debug('<<doGET'); return $response; } $params = $request->getParams(); $body = View::loadTemplateFragment('html', 'head.phtml', array('title' => $config->get('app.title'), 'description' => 'Welcome to our site', 'allowCSSOverrides' => true)); $body .= View::loadTemplateFragment('html', 'index.phtml'); $body .= View::loadTemplateFragment('html', 'footer.phtml'); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * Constructor. * * @since 1.0 */ public function __construct() { self::$logger = new Logger('ActionLog'); // ensure to call the parent constructor parent::__construct(); $this->client = new String(); $this->IP = new String(); $this->message = new String(); $this->personOID = new Relation(); $this->personOID->setRelatedClass('Alpha\\Model\\Person'); $this->personOID->setRelatedClassField('OID'); $this->personOID->setRelatedClassDisplayField('displayName'); $this->personOID->setRelationType('MANY-TO-ONE'); $this->personOID->setValue($this->created_by->getValue()); }
/** * The constructor which sets up some housekeeping attributes. * * @since 1.0 */ public function __construct() { self::$logger = new Logger('Article'); // ensure to call the parent constructor parent::__construct(); $this->title = new String(); $this->title->setHelper('Please provide a title for the article.'); $this->title->setSize(100); $this->title->setRule("/\\w+/"); $this->section = new DEnum('Alpha\\Model\\Article::section'); $this->description = new String(); $this->description->setHelper('Please provide a brief description of the article.'); $this->description->setSize(200); $this->description->setRule("/\\w+/"); $this->bodyOnload = new String(); $this->content = new Text(); $this->headerContent = new Text(); $this->author = new String(); $this->author->setHelper('Please state the name of the author of this article'); $this->author->setSize(70); $this->author->setRule("/\\w+/"); $this->published = new Boolean(0); $this->comments = new Relation(); $this->markTransient('comments'); $this->votes = new Relation(); $this->markTransient('votes'); $this->tags = new Relation(); $this->markTransient('tags'); $this->URL = ''; $this->printURL = ''; // mark the URL attributes as transient $this->markTransient('URL'); $this->markTransient('printURL'); // mark title as unique $this->markUnique('title'); $this->markTransient('filePath'); $this->markTransient('taggedAttributes'); $this->setupRels(); }
/** * The constructor. * * @throws Alpha\Exception\FailedLookupCreateException * @throws Alpha\Exception\IllegalArguementException * * @since 1.0 */ public function __construct($leftClassName, $rightClassName) { self::$logger = new Logger('RelationLookup'); self::$logger->debug('>>__construct(leftClassName=[' . $leftClassName . '], rightClassName=[' . $rightClassName . '])'); // ensure to call the parent constructor parent::__construct(); if (empty($leftClassName) || empty($rightClassName)) { throw new IllegalArguementException('Cannot create RelationLookup object without providing the left and right class names!'); } $this->leftClassName = $leftClassName; $this->rightClassName = $rightClassName; $this->leftID = new Integer(); $this->rightID = new Integer(); $this->markTransient('leftClassName'); $this->markTransient('rightClassName'); $this->markTransient('helper'); $this->markTransient('TABLE_NAME'); // add a unique composite key to these fields $this->markUnique('leftID', 'rightID'); // make sure the lookup table exists if (!$this->checkTableExists() && ActiveRecord::isInstalled()) { // first make sure that the two BO tables exist before relating them with a lookup table if (ActiveRecord::checkBOTableExists($leftClassName) && ActiveRecord::checkBOTableExists($rightClassName)) { $this->makeTable(); } else { throw new FailedLookupCreateException('Error trying to create a lookup table [' . $this->getTableName() . '], as tables for BOs [' . $leftClassName . '] or [' . $rightClassName . '] don\'t exist!'); } } self::$logger->debug('<<__construct'); }