Ejemplo n.º 1
0
 /**
  * Appends display field names to select statement.
  * @param string $selectStatement
  * @param DisplayField $displayField
  * @return string 
  */
 public function constructSelectClauseForDisplayField($selectStatement, $displayField)
 {
     $clause = $displayField->getName();
     if (KeyHandler::keyExists() && $displayField->getIsEncrypted()) {
         $clause = 'AES_DECRYPT(UNHEX(' . $displayField->getName() . '),"' . KeyHandler::readKey() . '")';
     }
     if ($displayField->getIsValueList()) {
         $clause = "GROUP_CONCAT(DISTINCT " . $clause . " SEPARATOR '|\\n|' ) ";
     }
     $fieldAlias = $displayField->getFieldAlias();
     if (!empty($fieldAlias)) {
         $clause = $clause . " AS " . $fieldAlias;
     }
     if (empty($selectStatement)) {
         $selectStatement = $clause;
     } else {
         $selectStatement .= ',' . $clause;
     }
     return $selectStatement;
 }
Ejemplo n.º 2
0
 /**
  * @param $bot Bot is the selected bot
  * @return form Form the form we return
  */
 private function _createDriverForm($bot)
 {
     $form = new Form('driver');
     $form->action = $bot->getUrl() . "/edit";
     switch ($bot->getStatus()) {
         case BotState::Idle:
         case BotState::Offline:
         case BotState::Error:
         case BotState::Waiting:
             break;
             // We're okay to edit with these states
         // We're okay to edit with these states
         default:
             $form->add(ErrorField::name('error')->value("The bot must be in an idle, offline, error, or waiting state in order to edit the driver config."));
             return $form;
     }
     //load up our apps.
     $authorized = User::$me->getAuthorizedApps()->getAll();
     $apps[0] = "None";
     foreach ($authorized as $row) {
         /* @var $e OAuthToken */
         $e = $row['OAuthToken'];
         $apps[$e->id] = $e->getName();
     }
     // load up our drivers
     $drivers = array('printcore' => 'RepRap Serial Driver', 'dummy' => 'Dummy Driver', 's3g' => 'Makerbot Driver (Experimental)');
     $form->add(DisplayField::name('title')->label('')->value("<h2>Driver Configuration</h2>"));
     $form->add(SelectField::name('oauth_token_id')->id('oauth_token_dropdown')->label('Computer')->help('Which computer is this bot connected to? <a href="/apps">Full list in the apps area.</a>')->value($bot->get('oauth_token_id'))->options($apps)->onchange('update_driver_form(this)'));
     $form->add(SelectField::name('driver_name')->id('driver_name_dropdown')->label('Driver Name')->help('Which driver to use? <a href="/help">More info available in the help area.</a>')->required(true)->value($bot->get('driver_name'))->options($drivers)->onchange('update_driver_form(this)'));
     $form->add(RawField::name("driver_edit_area")->value('<div id="driver_edit_area"></div>'));
     return $form;
 }
Ejemplo n.º 3
0
 /**
  * @param User $user
  * @return Form
  */
 private function _createProfileEditForm($user)
 {
     $form = new Form();
     $form->add(DisplayField::name('username')->label("Username")->value($user->get('username')));
     $form->add(EmailField::name('email')->label("Email")->value($user->get('email'))->required(true));
     if (User::$me->isAdmin()) {
         $form->add(CheckboxField::name('admin')->label("Is admin?")->help("Is this user an admin?")->checked($user->isAdmin()));
     }
     // todo add DateField
     /**
     $form->add(
     	DateField::name('birthday')
     		->label("Birthday")
     		->value($user->get('birthday'))
     );
     */
     $password_page = $user->getUrl() . "/changepass";
     $form->add(DisplayField::name('changepass')->label("Change Password")->value("Please visit the <a href=\"{$password_page}\">change password</a> page."));
     return $form;
 }
 public function testConstructSelectClauseForDisplayField()
 {
     $displayField = new DisplayField();
     $fieldName = 'Acme';
     $displayField->setName($fieldName);
     $options = array(array('is_value_list' => true, 'is_encrypted' => true, 'field_alias' => 'Abcd'), array('is_value_list' => true, 'is_encrypted' => true, 'field_alias' => null), array('is_value_list' => true, 'is_encrypted' => false, 'field_alias' => 'Abcd'), array('is_value_list' => true, 'is_encrypted' => false, 'field_alias' => null), array('is_value_list' => false, 'is_encrypted' => false, 'field_alias' => 'Abcd'), array('is_value_list' => false, 'is_encrypted' => false, 'field_alias' => null), array('is_value_list' => false, 'is_encrypted' => true, 'field_alias' => 'Abcd'), array('is_value_list' => false, 'is_encrypted' => true, 'field_alias' => null));
     $encrypt = KeyHandler::keyExists();
     if ($encrypt) {
         $key = KeyHandler::readKey();
     }
     foreach ($options as $option) {
         $displayField = new DisplayField();
         $displayField->setName($fieldName);
         $displayField->setIsValueList($option['is_value_list']);
         $displayField->setIsEncrypted($option['is_encrypted']);
         $displayField->setFieldAlias($option['field_alias']);
         $expected = $fieldName;
         if ($encrypt && $option['is_encrypted']) {
             $expected = 'AES_DECRYPT(UNHEX(' . $fieldName . '),"' . $key . '")';
         }
         if ($option['is_value_list']) {
             $expected = 'GROUP_CONCAT(DISTINCT ' . $expected . " SEPARATOR '|" . '\\n' . "|' ) ";
         }
         if ($option['field_alias']) {
             $expected = $expected . ' AS ' . $option['field_alias'];
         }
         $selectStatement = null;
         $selectStatement = $this->reportGeneratorService->constructSelectClauseForDisplayField($selectStatement, $displayField);
         $this->assertEquals($expected, $selectStatement);
         $selectStatement = "x";
         $expected = 'x,' . $expected;
         $selectStatement = $this->reportGeneratorService->constructSelectClauseForDisplayField($selectStatement, $displayField);
         $this->assertEquals($expected, $selectStatement);
     }
 }
Ejemplo n.º 5
0
 public function _createRegisterForm()
 {
     $form = new Form('register');
     if (!$this->args('username')) {
         $username = '';
     } else {
         $username = $this->args('username');
     }
     if (!$this->args('email')) {
         $email = '';
     } else {
         $email = $this->args('email');
     }
     $form->add(TextField::name('username')->label("Username")->value($username)->required(true));
     $form->add(EmailField::name('email')->label("Email address")->value($email)->required(true));
     $form->add(PasswordField::name('pass1')->label("Password")->required(true));
     $form->add(PasswordField::name('pass2')->label("Password Confirmation")->required(true));
     $tos = "By clicking on the \"Create your account\" button below, you certify that you have read and agree to our ";
     $tos .= "<a href=\"/tos\">Terms of use</a>";
     $tos .= " and ";
     $tos .= "<a href=\"/privacy\">Privacy Policy</a>.";
     $form->add(DisplayField::name('tos')->value($tos));
     $form->setSubmitText("Create your account");
     $form->setSubmitClass("btn btn-success btn-large");
     return $form;
 }
Ejemplo n.º 6
0
 /**
  * @param $bot Bot is the selected bot
  * @return form Form the form we return
  */
 private function _createDriverForm($bot)
 {
     //load up our apps.
     $authorized = User::$me->getAuthorizedApps()->getAll();
     $apps[0] = "None";
     foreach ($authorized as $row) {
         /* @var $e OAuthToken */
         $e = $row['OAuthToken'];
         $apps[$e->id] = $e->getName();
     }
     // load up our drivers
     $drivers = array('printcore' => 'RepRap Serial Driver', 'dummy' => 'Dummy Driver', 's3g' => 'Makerbot Driver (Experimental)');
     $form = new Form('driver');
     $form->action = $bot->getUrl() . "/edit";
     $form->add(DisplayField::name('title')->label('')->value("<h2>Driver Configuration</h2>"));
     $form->add(SelectField::name('oauth_token_id')->id('oauth_token_dropdown')->label('Computer')->help('Which computer is this bot connected to? <a href="/apps">Full list in the apps area.</a>')->value($bot->get('oauth_token_id'))->options($apps)->onchange('update_driver_form(this)'));
     $form->add(SelectField::name('driver_name')->id('driver_name_dropdown')->label('Driver Name')->help('Which driver to use? <a href="/help">More info available in the help area.</a>')->required(true)->value($bot->get('driver_name'))->options($drivers)->onchange('update_driver_form(this)'));
     // $driver_form = Controller::byName('bot')->renderView('driver_form', array(
     //   'bot_id' => $bot->id,
     //   'driver' => $bot->get('driver_name'),
     //   'token_id' => $bot->get('oauth_token_id')
     // ));
     $form->add(RawField::name("driver_edit_area")->value('<div id="driver_edit_area"></div>'));
     return $form;
 }
Ejemplo n.º 7
0
 /**
  * @param $file StorageInterface
  * @param $queue_id int
  * @return Form
  */
 private function _createJobForm($file, $queue_id)
 {
     //load up our queues.
     $queues = User::$me->getQueues()->getAll();
     $qs = array();
     foreach ($queues as $row) {
         /* @var $q Queue */
         $q = $row['Queue'];
         $qs[$q->id] = $q->getName();
     }
     $form = new Form();
     $form->add(DisplayField::name('file_name')->label('File')->help('The file that will be printed.')->value($file->getLink()));
     $form->add(SelectField::name('queue_id')->label('Queue')->help('Which queue are you adding this job to?')->required(true)->options($qs)->value($queue_id));
     $form->add(TextField::name('quantity')->label('Quantity')->help('How many copies? Minimum 1, Maximum 100')->required(true)->value(1));
     $form->add(CheckboxField::name('priority')->label('Is this a priority job?')->help('Check this box to push this job to the top of the queue')->checked(false));
     return $form;
 }
Ejemplo n.º 8
0
 /**
  *
  * @param <type> $columns
  * @return DisplayField 
  */
 public function saveCustomDisplayField($columns)
 {
     try {
         if (array_key_exists('displayFieldId', $columns)) {
             $displayField = Doctrine::getTable("DisplayField")->find($columns['displayFieldId']);
             $displayField->setLabel($columns['label']);
         } else {
             $displayField = new DisplayField();
             $displayField->setReportGroupId($columns['reportGroupId']);
             $displayField->setName($columns['name']);
             $displayField->setLabel($columns['label']);
             $displayField->setFieldAlias($columns['fieldAlias']);
             $displayField->setIsSortable($columns['isSortable']);
             $displayField->setSortOrder($columns['sortOrder']);
             $displayField->setSortField($columns['sortField']);
             $displayField->setElementType($columns['elementType']);
             $displayField->setElementProperty($columns['elementProperty']);
             $displayField->setWidth($columns['width']);
             $displayField->setIsExportable($columns['isExportable']);
             $displayField->setTextAlignmentStyle($columns['textAlignmentStyle']);
             $displayField->setIsValueList($columns['isValueList']);
             $displayField->setDisplayFieldGroupId($columns['displayFieldGroupId']);
             $displayField->setDefaultValue($columns['defaultValue']);
             $displayField->setIsEncrypted($columns['isEncrypted']);
         }
         $displayField->save();
         return $displayField;
     } catch (Exception $ex) {
         throw new DaoException($ex->getMessage());
     }
 }