Exemplo n.º 1
1
 static function checkDuplicatePo($key)
 {
     $purchase = new Purchase($key);
     //Search Duplicate
     $records = fRecordSet::build('Purchase', array('po_number=' => $purchase->getPoNumber()));
     if ($records->count() > 1) {
         //Generate New PO
         echo 'Duplicate PO';
         $exploded = explode('/', $purchase->getPoNumber());
         echo (int) $exploded[2] + 1;
         $exploded[2] = sprintf("%03d", (int) $exploded[2] + 1);
         $newPONumber = implode('/', $exploded);
         $purchase->setPoNumber($newPONumber);
         $purchase->store();
     }
 }
Exemplo n.º 2
0
	/**
	 * Returns all active checks on the system
	 * 
	 * @param  string  $sort_column  The column to sort by
	 * @param  string  $sort_dir     The direction to sort the column
	 * @return fRecordSet  An object containing all meetups
	 */
	static function findActive()
	{
       return fRecordSet::buildFromSQL(
          __CLASS__,
          array("SELECT checks.* FROM checks JOIN subscriptions ON checks.check_id = subscriptions.check_id WHERE enabled = 1;")
          );
	}    
Exemplo n.º 3
0
 public function addInterest($name, $category)
 {
     global $db;
     $db->execute("INSERT INTO interests (category,name) VALUES (%s, %s)", $category, $name);
     $record = fRecordSet::build('Interest', array('name=' => $name, 'category=' => $category));
     return $record[0]->getInterestId();
 }
Exemplo n.º 4
0
 public function show()
 {
     $this->editable = UserHelper::isEditor();
     $cons = array();
     $field = trim(fRequest::get('field'));
     $start_year = trim(fRequest::get('start_year'));
     $major = trim(fRequest::get('major'));
     $location = trim(fRequest::get('location'));
     $words = trim(fRequest::get('words'));
     $cons['login_name|display_name~'] = $words;
     if (!empty($field)) {
         $cons['field='] = $field;
     }
     if (!empty($start_year)) {
         $cons['start_year='] = $start_year;
     }
     if (!empty($major)) {
         $cons['major='] = $major;
     }
     if (!empty($location)) {
         $cons['location~'] = $location;
     }
     $this->users = fRecordSet::build('Profile', $cons, array('id' => 'asc'));
     $this->field = $field;
     $this->start_year = $start_year;
     $this->major = $major;
     $this->location = $location;
     $this->words = $words;
     $this->render('search/index');
 }
Exemplo n.º 5
0
 public function index()
 {
     $this->articles = fRecordSet::build('Article', array('type=' => 'news', 'visible=' => 1), array('priority' => 'desc', 'created_at' => 'desc'), ACTIVITIES_LIMIT - 2);
     $this->posts = fRecordSet::build('Article', array('type=' => 'post', 'visible=' => 1, 'priority<' => 999999), array('priority' => 'desc', 'created_at' => 'desc'), ACTIVITIES_LIMIT - 1);
     $this->activities = fRecordSet::buildFromSQL('Activity', 'SELECT activities.* FROM activities GROUP BY realname,type,DATE(timestamp),HOUR(timestamp) ORDER BY timestamp DESC LIMIT ' . ACTIVITIES_LIMIT);
     $this->render('home/index');
 }
Exemplo n.º 6
0
  /**
	 * Returns all meetups on the system
	 *
	 * @param  string  $sort_column  The column to sort by
	 * @param  string  $sort_dir     The direction to sort the column
	 * @return fRecordSet  An object containing all meetups
	 */
	static function findAll($dashboard_id=NULL)
	{
       return fRecordSet::build(
          __CLASS__,
          array('dashboard_id=' =>$dashboard_id),
          array('weight' => 'asc')
          );
	}
Exemplo n.º 7
0
 public static function invalidate($username, $problem_id, $submit_time)
 {
     global $cache;
     $affected_reports = fRecordSet::build('Report', array('problem_list~' => $problem_id, 'user_list~' => $username, 'start_datetime<=' => $submit_time, 'end_datetime>=' => $submit_time));
     foreach ($affected_reports as $report) {
         $cache->delete($report->getBoardCacheKey());
     }
 }
Exemplo n.º 8
0
 public function showKnown()
 {
     if (!UserHelper::isEditor()) {
         throw new fValidationException('not allowed');
     }
     $this->users = fRecordSet::build('Name', array('registered=' => 0), array('student_number' => 'asc'));
     $this->render('users/known');
 }
 public static function findByBranch($branch, $doctype)
 {
     //return fRecordSet::buildFromSQL('Production_issue',
     //		"SELECT production_issues.* FROM production_issues, (SELECT * FROM users WHERE branch_id = '$branch') AS tbl WHERE production_issues.issuer = tbl.username AND production_issues.doc_type = '$doctype' AND YEAR( production_issues.doc_date ) = YEAR( CURDATE( ) ) AND MONTH( production_issues.doc_date ) = MONTH( CURDATE( ))",
     //		"SELECT count(*) FROM production_issues"
     //	);
     return fRecordSet::buildFromSQL('Production_issue', "SELECT production_issues.* FROM production_issues WHERE production_issues.doc_number LIKE '" . $doctype . "/" . $branch . "/" . "%" . "' AND YEAR( production_issues.doc_date ) = YEAR( CURDATE( ) ) AND MONTH( production_issues.doc_date ) = MONTH( CURDATE( ) )", "SELECT count(*) FROM production_issues");
 }
Exemplo n.º 10
0
  /**
	 * Returns all meetups on the system
	 * 
	 * @param  string  $sort_column  The column to sort by
	 * @param  string  $sort_dir     The direction to sort the column
	 * @return fRecordSet  An object containing all meetups
	 */
	static function findAll($graph_id=NULL)
	{
       return fRecordSet::build(
          __CLASS__,
          array('graph_id=' =>$graph_id),
          array()
          );
	}   
Exemplo n.º 11
0
 /**
  * @param array $where
  * @return WpTesting_Model_AbstractTerm
  * @throws fNotFoundException
  */
 protected function findByParams(array $where = array())
 {
     $taxonomyTable = fORM::tablize('WpTesting_Model_Taxonomy');
     try {
         return fRecordSet::build($this->modelName, array($taxonomyTable . '.taxonomy=' => $this->getTaxonomy()) + $where)->getRecord(0);
     } catch (fNoRemainingException $e) {
         throw new fNotFoundException($this->modelName . ' not found by conditions: ' . var_export($where, true));
     }
 }
Exemplo n.º 12
0
 static function findActive($check_id = NULL)
 {
     if (!is_null($check_id) && is_numeric($check_id)) {
         $filter = ' AND check_id=' . $check_id;
     } else {
         $filter = '';
     }
     return fRecordSet::buildFromSQL(__CLASS__, array('SELECT subscriptions.* FROM subscriptions WHERE user_id = ' . fSession::get('user_id') . $filter));
 }
Exemplo n.º 13
0
 /**
  * Returns all meetups on the system
  * 
  * @return fRecordSet  An object containing all meetups
  */
 static function findAll($group_id = NULL)
 {
     if (!is_null($group_id) && is_numeric($group_id)) {
         $filter = array('group_id=' => $group_id);
     } else {
         $filter = array();
     }
     return fRecordSet::build(__CLASS__, $filter, array());
 }
 static function findStatus($po)
 {
     $records = fRecordSet::build('Good_receipt_note', array('po_no=' => $po));
     if ($records->count() > 1) {
         return false;
     } else {
         return true;
     }
 }
Exemplo n.º 15
0
	/**
	 * Returns all meetups on the system
	 * 
	 * @param  string  $sort_column  The column to sort by
	 * @param  string  $sort_dir     The direction to sort the column
	 * @return fRecordSet  An object containing all meetups
	 */
	static function findAll()
	{
		
       return fRecordSet::build(
          __CLASS__,
          array(),
          array()
          );
	}    
Exemplo n.º 16
0
 /**
  * Return entries by month and branch
  *
  * @param string 	$branch	Branch ID to represent a branch 
  * @param int		$month	Specific month as the input
  * @param string	$item	Item code to specify an individual item
  * @return  int	The total movement by month
  */
 static function findByMonth($branch, $month, $item)
 {
     $movements = fRecordSet::build('Inv_movement', array('branch_id=' => $branch, 'date>=' => '2010-' . $month . '-1', 'date<=' => '2010-' . $month . '-31', 'item_id=' => $item));
     if ($movements->count()) {
         return $movements->getRecord(0)->prepareQuantity();
     } else {
         return 0;
     }
 }
Exemplo n.º 17
0
 public function getContactOrEmpty($type)
 {
     try {
         $records = fRecordSet::build('Contact', array('profile_id=' => $this->getId(), 'type=' => $type), array(), 1);
         $records->tossIfEmpty();
         return $records->getRecord(0)->getContent();
     } catch (Exception $e) {
         return '';
     }
 }
Exemplo n.º 18
0
 public static function hasParent($category_id, $region = 0)
 {
     $category = fRecordSet::build(__CLASS__, array('id_category=' => $category_id, 'id_region=' => $region));
     $category = $category[0];
     if ($category->getIdParent() > 0) {
         return $category->getIdParent();
     } else {
         return $category->getIdCategory();
     }
 }
Exemplo n.º 19
0
 private static function fetchFromDB($user_name, $permission_name)
 {
     if (!array_key_exists($user_name, self::$permission_cache)) {
         self::$permission_cache[$user_name] = array();
         $permissions = fRecordSet::build('Permission', array('user_name=' => $user_name));
         foreach ($permissions as $permission) {
             self::$permission_cache[$user_name][] = $permission->getPermissionName();
         }
     }
     return in_array($permission_name, self::$permission_cache[$user_name]);
 }
Exemplo n.º 20
0
 protected function fillSteps()
 {
     $questions = $this->test->buildQuestions();
     $total = $questions->count();
     $answered = $this->answeredQuestions->count();
     foreach ($questions as $q => $question) {
         $records = fRecordSet::buildFromArray('WpTesting_Model_Question', array($q => $question));
         $isCurrent = $answered == $q;
         $this->addStep(new WpTesting_Model_Step('', $records), $isCurrent);
     }
     return $this->enableStepsCounter();
 }
Exemplo n.º 21
0
 public function halloffames()
 {
     $this->editable = UserHelper::isEditor();
     if ($this->editable) {
         $this->articles = fRecordSet::build('Article', array('type=' => 'halloffame'), array('priority' => 'desc', 'created_at' => 'asc'));
     } else {
         $this->articles = fRecordSet::build('Article', array('type=' => 'halloffame', 'visible=' => 1), array('priority' => 'desc', 'created_at' => 'asc'));
     }
     $this->title = "校友风采";
     $this->articleType = "halloffame";
     $this->render('article/index');
 }
Exemplo n.º 22
0
 /**
  * Authors Ranklist
  */
 public function ranklist()
 {
     $this->page = fRequest::get('page', 'integer', 1);
     if ($this->page <= 0) {
         $this->page = 1;
     }
     $this->user_stats = fRecordSet::build('UserStat', array(), array('solved' => 'desc', 'tried' => 'asc', 'submissions' => 'asc'), Variable::getInteger('users-per-page', 50), $this->page);
     $this->page_url = SITE_BASE . '/ranklist?page=';
     $this->page_records = $this->user_stats;
     $this->nav_class = 'ranklist';
     $this->render('user/ranklist');
 }
Exemplo n.º 23
0
 public static function markRegistered($email, $invitecode)
 {
     try {
         if (self::isGlobalInvitation($email, $invitecode)) {
             return;
         }
         $invitation = fRecordSet::build('Invitation', array('email=' => $email, 'invitecode=' => $invitecode))->getRecord(0);
         $invitation->setUserRegistered(1);
         $invitation->store();
     } catch (Exception $e) {
         // do nothing
     }
 }
Exemplo n.º 24
0
 public static function fetch($username)
 {
     if (self::$profile_cache === NULL) {
         self::$profile_cache = array();
         $profiles = fRecordSet::build('Profile');
         foreach ($profiles as $profile) {
             self::$profile_cache[$profile->getUsername()] = array('realname' => $profile->getRealname(), 'class_name' => $profile->getClassName(), 'phone_number' => $profile->getPhoneNumber(), 'gender' => $profile->getGender(), 'school' => $profile->getSchool(), 'major' => $profile->getMajor(), 'grade' => $profile->getGrade(), 'qq' => $profile->getQq());
         }
     }
     if (array_key_exists($username, self::$profile_cache)) {
         return self::$profile_cache[$username];
     }
     return array('realname' => '', 'class_name' => '', 'phone_number' => '', 'gender' => '', 'school' => '', 'major' => '', 'grade' => '', 'qq' => '');
 }
Exemplo n.º 25
0
 public static function markRegistered($realname, $stuid)
 {
     try {
         /*	$userid=fRecordSet::build('Name', array('student_number=' => $stuid,'realname'=>$realname))->getRecord(0)->getId();
               $user = new Name($userid);
               $user->delete();
          */
         $user = fRecordSet::build('Name', array('student_number=' => $stuid, 'realname=' => $realname))->getRecord(0);
         $user->setRegistered(1);
         $user->store();
     } catch (Exception $e) {
         // do nothing
     }
 }
Exemplo n.º 26
0
 public function homework()
 {
     if (fAuthorization::checkLoggedIn()) {
         $this->cache_control('private', 5);
     } else {
         $this->cache_control('private', 10);
     }
     $conditions = array('title~' => array('homework', '作业'));
     if (!User::can('view-any-report')) {
         $conditions['visible='] = TRUE;
     }
     $this->reports = fRecordSet::build('Report', $conditions, array('id' => 'desc'));
     $this->nav_class = 'homework';
     $this->render('report/homework');
 }
Exemplo n.º 27
0
 public static function find($view_any, $page, $title, $author)
 {
     $conditions = array();
     if (!$view_any) {
         $conditions['secret_before<='] = Util::currentTime();
     }
     if (strlen($title)) {
         $conditions['title~'] = $title;
     }
     if (strlen($author)) {
         $conditions['author~'] = $author;
     }
     $limit = Variable::getInteger('problems-per-page', 10);
     return fRecordSet::build('Problem', $conditions, array('id' => 'asc'), $limit, $page);
 }
Exemplo n.º 28
0
 public function hasUnRead($id = 0)
 {
     $mails = fRecordSet::build('Mail', array('receiver=' => $id, 'parent=' => $this->getId(), 'read=' => 0), array('timestamp' => 'asc'));
     foreach ($mails as $m) {
         $m->setRead(1);
         $m->store();
     }
     if ($this->getReceiver() == $id) {
         $this->setRead(1);
         $this->store();
     }
     if ($this->getRead()) {
         return $mails->count() > 0;
     } else {
         return true;
     }
 }
Exemplo n.º 29
0
 public static function find($top, $owner, $problem_id, $language, $verdict, $page = 1)
 {
     $conditions = array();
     if (!empty($top)) {
         $conditions['id<='] = $top;
     }
     if (strlen($owner)) {
         $conditions['owner='] = $owner;
     }
     if (strlen($problem_id)) {
         $conditions['problem_id='] = $problem_id;
     }
     if (!empty($language)) {
         $conditions['code_language='] = $language - 1;
     }
     if (!empty($verdict)) {
         $conditions['verdict='] = $verdict;
     }
     $limit = Variable::getInteger('records-per-page', 50);
     return fRecordSet::build('Record', $conditions, array('id' => 'desc'), $limit, $page);
 }
Exemplo n.º 30
0
 public function create()
 {
     try {
         $profileId = UserHelper::getProfileId();
         $mail = new Mail();
         $mail->setSender($profileId);
         $mail->setContent(trim(fRequest::get('mail-content')));
         $re = trim(fRequest::get('dest'));
         if (empty($re)) {
             $re = trim(fRequest::get('destre', 'integer'));
             $pa = trim(fRequest::get('parent', 'integer', -1));
             $x = new Profile($re);
             $mail->setReceiver($re);
             $mail->setParent($pa);
         } else {
             //$receiver=fRecordSet::build('Profile',array('login_name=' => $re ),array())->getRecord(0);
             $receiver = fRecordSet::build('Profile', array('login_name=' => $re), array());
             if ($receiver->count()) {
                 $receiver = $receiver->getRecord(0);
             } else {
                 throw new fNotFoundException('user doesn\'t exist');
             }
             $mail->setReceiver($receiver->getId());
         }
         if (strlen($mail->getContent()) < 1) {
             throw new fValidationException('信息长度不能少于1个字符');
         }
         if (strlen($mail->getContent()) > 140) {
             throw new fValidationException('信息长度不能超过140个字符');
         }
         $mail->store();
         //Activity::fireNewTweet();
         fMessaging::create('success', 'create mail', '信息发送成功!');
     } catch (fNotFoundException $e) {
         fMessaging::create('failure', 'create mail', '该用户名不存在,或该用户没有创建个人资料!');
     } catch (fException $e) {
         fMessaging::create('failure', 'create mail', $e->getMessage());
     }
     fURL::redirect(SITE_BASE . '/inbox');
 }