protected function processForm(sfWebRequest $request, sfForm $form) { $requestparam = $request->getParameter('accountentry'); $account = AccountTable::fetchById($requestparam['account_id']); $qty = $requestparam['qty']; $date = $requestparam['date']['year'] . "-" . $requestparam['date']['month'] . "-" . $requestparam['date']['day']; //$ref_class=$requestparam['ref_class']; //$ref_id=$requestparam['ref_id']; $type = $requestparam['type'] != "" ? $requestparam['type'] : 'Adjustment'; //$priority=0; $description = $requestparam['description']; if ($qty == 0) { $this->redirect('home/error?msg="Invalid Qty"'); } $accountentry = $account->addEntry($date, $qty, null, null, $type, $description); $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.'; $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $accountentry))); $this->getUser()->setFlash('notice', $notice); $this->redirect('account/view?id=' . $accountentry->getaccountId()); } else { if ($form['qty']->getError()) { $this->redirect('home/error?msg="Invalid Qty: ' . $qty . '"'); } if ($form['date']->getError()) { $this->redirect('home/error?msg="Invalid Date: ' . $date . '"'); } //$this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false); } }
public function executeAdd(sfWebRequest $request) { //Set the local vars used in this function for easy access. $uid_from = $this->getUser()->getAttribute('id'); $uid_to = $request->getParameter('uid'); //Error Checking $this->errorCheck(!$this->getUser()->hasAttribute('id'), "Required request paramater uid_from is not set."); $this->errorCheck(!$request->hasParameter('uid'), "Required request paramater uid is not set."); $this->errorCheck($uid_to == null || $uid_to == 0, "Account id can not be null."); $this->errorCheck($uid_to == 1, "Friendship requests to the Administrator account are not allowed."); $this->errorCheck(!AccountTable::accountExists($uid_from), "Account ({$uid_from}) does not exist in database."); $this->errorCheck(!AccountTable::accountExists($uid_to), "Account ({$uid_to}) does not exist in database."); $this->errorCheck(FriendTable::areFriends($uid_from, $uid_to), "Account ({$uid_from}) and ({$uid_to}) are already friends."); $this->errorCheck(FriendRequestTable::requestPending($uid_from, $uid_to), "Account ({$uid_from}) has already requested ({$uid_to}) for friendship."); $this->errorCheck(FriendRequestTable::requestPending($uid_to, $uid_from), "Account ({$uid_to}) has already requested ({$uid_from}) for friendship."); $this->errorCheck($uid_from == $uid_to, "Account ({$uid_from}) can not request friendship with itself."); //Request is valid if code reaches here so make a friend request object and save it. $friendRequest = new FriendRequest(); $friendRequest->uid_from = $uid_from; $friendRequest->uid_to = $uid_to; $friendRequest->save(); $url = "default/index"; if ($request->hasParameter('redirect_url')) { $url = $request->getParameter('redirect_url') . 'index'; } $this->flashAndRedirect("Friendship successfully requested.", $url); }
public function rules() { $oldRules = parent::rules(); $oldRules[0] = array('email, pass', 'required'); $oldRules[3] = array('pass', 'length', 'max' => 32); array_push($oldRules, array('salt', 'safe')); array_push($oldRules, array('email', 'unique', 'message' => 'Такая почта уже занята!', 'on' => 'reg')); array_push($oldRules, array('first_name, last_name', 'required', 'on' => 'reg')); return $oldRules; }
public function executeNew(sfWebRequest $request) { $account_id = $this->getUser()->getAttribute('account_id'); $account = AccountTable::getInstance()->find($account_id); if ($account->hasEnoughLicensesToAddUser() == false) { $this->getUser()->setFlash('error.license_count', 1); $this->redirect('adminUser/list'); } $this->form = new UserForm(); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->week = $request->getParameter('week', date('W')); $this->year = $request->getParameter('year', date('Y')); $days = DateTimeHelper::create()->getDaysOfWeek($this->week, $this->year); $this->weekstart = $days[1]; $account_id = $this->getUser()->getAttribute('account_id'); $this->projects = ProjectTable::getInstance()->findByAccountId($account_id); $this->user = UserTable::getInstance()->find($this->getUser()->getAttribute('uid')); $this->item_types = TimeItemTypeTable::getInstance()->findByAccountId($account_id); $this->default_item_type = TimeItemTypeTable::getInstance()->findDefaultForAccount($account_id); if ($this->default_item_type) { $this->default_item_type_name = $this->default_item_type->getName(); } else { $this->default_item_type_name = null; } $items = Doctrine_Query::create()->from('TimeLogItem ti')->where('ti.itemdate >= ? and itemdate <= ? and ti.user_id = ?', array(date('Y-m-d', $days[1]), date('Y-m-d', $days[1] + 5 * 24 * 60 * 60), $this->getUser()->getAttribute('uid')))->execute(); $this->time_items = new TimeItemSelector($items); $this->account = AccountTable::getInstance()->find($account_id); }
public function getAccountEntry($settingname, $create = false, $qty = 0, $description = null) { $this->getAccountentriesArray(); $account_id = SettingsTable::fetch($settingname); $entry = $this->accountentriesarray[$account_id]; //if it does not exist, and "create or update" if (!$entry and $create) { $account = AccountTable::fetchById($account_id); $entry = $account->addEntry($this->getDate(), $qty, "Event", $this->getId(), null, $description); } else { if ($create) { $entry->setQty($qty); $entry->setBalance(null); $entry->save(); $entry->getAccount()->calcFromAccountentry($entry); } } return $entry; }
<?php include dirname(__FILE__) . '/../bootstrap/unit.php'; require_once dirname(__FILE__) . '/../../lib/model/doctrine/AccountTable.class.php'; $t = new lime_test(1, new lime_output_color()); $conn = Doctrine_Connection::getAvailableDrivers(); $accountTable = new AccountTable('Account', $conn); $t->diag('login()'); $t->ok($accountTable->login('beau', 'admin'), true, 'whats up?'); $t->todo();