public static function getMemberRecordsByOrgType($orgType = 0)
 {
     $orgTable = new FM_Models_FM_Orgdata();
     $memberIds = $orgTable->getOrgMemberIdsByKeys(array('type' => $orgType));
     //print_r($memberIds);exit;
     $userModel = new FM_Models_FM_User();
     $users = array();
     foreach ($memberIds as $key => $values) {
         $users[$values['uid']] = $userModel->getUserByKeys(array('id' => $values['uid']));
         $users[$values['admin']] = $userModel->getUserByKeys(array('id' => $values['admin']));
     }
     return $users;
 }
 public static function populate()
 {
     $table[] = new FM_Models_FM_OrgTabs();
     $table[] = new FM_Models_FM_OrgWidgets();
     $table[] = new FM_Models_FM_OrgOptions();
     $orgsTable = new FM_Models_FM_Orgdata();
     $allOrgs = $orgsTable->getAll();
     foreach ($allOrgs as $all => $org) {
         foreach ($table as $model) {
             $model->insert(array('orgId' => $org['id']));
         }
     }
 }
 public static function getByCategoryForRoot($catId)
 {
     $orgData = new FM_Models_FM_Orgdata();
     $morgs = $orgData->getBzOrgsByCategoryForRoot($catId);
     $catTable = new FM_Models_FM_BzorgCat();
     foreach ($morgs as $org) {
         $o = $orgData->getOrgRecordsForRoot($org['id']);
         $o['cats'] = self::parseCats($catTable->getOrgNames($org['id']));
         $orgs[] = $o;
     }
     return $orgs;
 }
 public static function regionSearch($searchTerm)
 {
     if ($searchTerm == 25) {
         return FM_Components_Util_LimeCard::statenIslandSearch();
     }
     if ($searchTerm == 26) {
         return FM_Components_Util_LimeCard::oceanCountySearch();
     }
     $regions = array();
     $towns = FM_Components_Util_Region::getTownIdsByRegion($searchTerm);
     foreach ($towns as $index => $town) {
         $regions[] = $town['id'];
     }
     $model = new FM_Models_FM_LimeCard();
     $nonOrg = $model->regionSearch($searchTerm);
     $orgDataModel = new FM_Models_FM_Orgdata();
     $orgs = $orgDataModel->regionSearch($regions);
     $orgArray = array();
     foreach (array_merge($orgs, $nonOrg) as $index => $org) {
         if (array_key_exists($org['name'], $orgArray)) {
             $orgArray[$org['name']]['categories'][] = $org['catName'];
         } else {
             $orgArray[$org['name']]['record'] = $org;
             $orgArray[$org['name']]['categories'][] = $org['catName'];
         }
     }
     return $orgArray;
 }
 public static function getByCategoryForRoot($catId)
 {
     $orgData = new FM_Models_FM_Orgdata();
     $morgs = array();
     $catTable = new FM_Models_FM_OrgdataSports();
     $orgs = $catTable->getOrgsByKeys(array('category' => $catId));
     foreach ($orgs as $org) {
         $data = $orgData->getOrgByKeys(array('id' => $org['orgId']));
         if ($data['id']) {
             $morgs[] = $data;
         }
     }
     return $morgs;
 }
 /**
 	public static function setTowns() {
 		$orgModel = new FM_Models_FM_Orgdata();
 		$orgTowns = new FM_Models_FM_OrgTown();
 		
 		$orgs = $orgModel->getAll();
 		foreach ($orgs as $key=>$value) {
 			$orgTowns->insertRecord(array('orgId'=>$value['id'], 'townId'=>$value['region']));
 		}
 	}
 
 
 	public static function setTowns() {
 		$orgModel = new FM_Models_FM_Orgdata();
 		$orgTowns = new FM_Models_FM_OrgTown();
 		$regions = new FM_Models_FM_OrgRegion();
 		
 		$otowns = $orgTowns->getAll();
 		$i = 0;
 		foreach ($otowns as $key=>$value) {
 			$i++;
 			$town = new FM_Components_Util_Town(array('id'=>$value['townId']));
 			print $value['orgId'];
 			$regions->insertRecord(array('orgId'=>$value['orgId'], 'regionId'=>$town->getRegion()));
 		}
 		print 'total ' . $i;
 	}
 	
 **/
 public static function update($args)
 {
     $orgModel = new FM_Models_FM_Orgdata();
     $orgTowns = new FM_Models_FM_OrgTown();
     $towns = $args['town'];
     $args['town'] = 1;
     $id = $args['orgId'];
     unset($args['orgId']);
     $orgRegion = new FM_Models_FM_OrgRegion();
     $ri = 0;
     foreach ($args as $value => $t) {
         if (stristr($value, 'region')) {
             if ($ri === 0) {
                 $orgRegion->remove(array('orgId' => $id));
                 $ri++;
             }
             $regions = explode('_', $value);
             $orgRegion->insertRecord(array('orgId' => $id, 'regionId' => $regions[1]));
         }
     }
     if (is_array($towns)) {
         $orgTowns->remove(array('orgId' => $id));
         foreach ($towns as $index => $value) {
             $orgTowns->insertRecord(array('orgId' => $id, 'townId' => $value));
         }
     }
     if ($orgModel->edit(array('id' => $id), $args)) {
         return true;
     }
     return true;
 }
 public function limecardAction()
 {
     $this->view->form = new FM_Forms_LimeCard();
     $this->view->regionsForm = new FM_Forms_LimeCardRegion();
     $this->view->results = false;
     if ($this->_getParam('var') === '0') {
         $this->view->searchTerm = 'ALL';
         $orgs = FM_Components_Util_LimeCard::alphaSearch('');
         //print_r($orgs);
         $this->view->selected = '0';
         $this->view->results = $final = FM_Components_Util_LimeCard::sort($orgs, 'name');
     } elseif ($this->_getParam('do') == 'alph') {
         $this->view->searchTerm = $this->_getParam('var');
         $orgs = FM_Components_Util_LimeCard::alphaSearch($this->_getParam('var'));
         $this->view->selected = $this->_getParam('var');
         $this->view->results = $final = FM_Components_Util_LimeCard::sort($orgs, 'name');
     } elseif ($this->_getParam('do') == 'cat') {
         $orgs = FM_Components_Util_LimeCard::catSearch($this->_getParam('var'));
         $this->view->results = $final = FM_Components_Util_LimeCard::sort($orgs, 'name');
         $this->view->searchTerm = ucwords(strtolower(FM_Components_Util_Category::getCategoryName($this->_getParam('var'), false)));
     } elseif ($this->_getParam('do') == 'region') {
         $orgs = FM_Components_Util_LimeCard::regionSearch($this->_getParam('var'));
         $this->view->results = $final = FM_Components_Util_LimeCard::sort($orgs, 'name');
         $region = new FM_Components_Util_Region(array('id' => $this->_getParam('var')));
         $this->view->searchTerm = ucwords(strtolower($region->getName()));
         if ($this->_getParam('var') == 25) {
             $this->view->searchTerm = 'Staten Island';
         }
         if ($this->_getParam('var') == 26) {
             $this->view->searchTerm = 'Ocean County';
         }
     } else {
         if ($_POST['limecardsearch']) {
             $this->view->searchTerm = $_POST['limecardsearch'];
             $bzOrgsModel = new FM_Models_FM_SearchPrimaryCategories();
             $npOrgsModel = new FM_Models_FM_SearchPrimaryCategoriesOrgs();
             $bzResults = $bzOrgsModel->searchByCat($_POST['limecardsearch']);
             $npResults = $npOrgsModel->searchByCat($_POST['limecardsearch']);
             $orgIds = array();
             foreach (array_merge($bzResults, $npResults) as $key => $value) {
                 $orgIds[] = $value['orgId'];
             }
             $orgDataModel = new FM_Models_FM_Orgdata();
             $orgs = $orgDataModel->limecardSearch(array_values($orgIds), $_POST['limecardsearch']);
             $orgDataModel->alphabeticalSearch();
             $nonOrgs = FM_Components_Util_LimeCard::search($_POST['limecardsearch']);
             $this->view->results = $final = FM_Components_Util_LimeCard::sort(array_merge($orgs, $nonOrgs), 'name');
         }
     }
 }