예제 #1
0
 /**
  * This Function is used to get a record of company and person on search keyword to fill the autocomplete textbox. 
  * @access_type public
  * @param string $ssKeyword keyword of search textbox.
  */
 public static function getAutoCompleteData($ssKeyword)
 {
     $arNominationResult = Doctrine_Query::create()->select("n.first_name as name")->from('Nomination n')->Where('n.first_name LIKE ?', $ssKeyword . "%")->andwhere('n.id_nomination != -1')->andwhere('n.approval_status = ?', 1)->andwhere('n.is_nominator = ?', 'N')->groupBy('n.first_name')->fetchArray();
     $arCompanyResult = Doctrine_Query::create()->select('c.company_name as name')->from('Company c')->where('c.company_name LIKE ?', $ssKeyword . "%")->andwhere('c.id_company != 0')->groupBy('c.company_name')->fetchArray();
     $ssResult = array_merge($arNominationResult, $arCompanyResult);
     //function to sort the array by key in asecending order.
     function makeSortFunction($field)
     {
         $code = "return strnatcmp(\$a['{$field}'], \$b['{$field}']);";
         return create_function('$a,$b', $code);
     }
     $compare = makeSortFunction('name');
     usort($ssResult, $compare);
     return $ssResult;
 }
 public function __default()
 {
     $this->user->postGet();
     $a = $this->user->getPref('msg_002');
     if (empty($a)) {
         $msg_002 = "<span class='msg'>Learn about our upgraded <a target='_newtab' href='http://helpcenter.adwhirl.com/content/step-6-allocate-your-house-ads'>House Ads</a> functionality</span>";
         $this->smarty->assign('message', $msg_002);
         $this->smarty->assign('msg_id', 'msg_002');
     }
     $this->smarty->assign('returnPage', isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : null);
     $this->styleSheets[] = "/css/preview.css";
     $this->jsFiles[] = "/js/jqsm135.js";
     $this->displayFinalArrowInBreadcrumbs = true;
     $houseAds = HouseAdUtil::getHouseAdsByUid($_SESSION['uid']);
     $apps = AppUtil::getAppsByUid($this->user->id);
     $o = isset($_REQUEST['o']) ? $_REQUEST['o'] : 0;
     $o = intval($o);
     $haveMissingAd = false;
     // Assume we don't have the missing ad until we scan them all
     if (!empty($_REQUEST['n_cid'])) {
         foreach ($houseAds as $houseAd) {
             // if the current ad has the same id, we know we have the missing ad
             $haveMissingAd |= $houseAd->id == $_REQUEST['n_cid'];
             // Stop if we know we have the missing ad
             if ($haveMissingAd) {
                 break;
             }
         }
     } else {
         $haveMissingAd = true;
         // no new ad id passed in, so all ads should be in the DB
     }
     if (!empty($_REQUEST['del_cid'])) {
         foreach ($houseAds as $idx => $houseAd) {
             if ($houseAd->id == $_REQUEST['del_cid']) {
                 unset($houseAds[$idx]);
             }
         }
     }
     fb('haveMissingAd', $haveMissingAd);
     // Do we have all the ads? If not, let's add the missing one.
     if (!$haveMissingAd) {
         $houseAd = new HouseAd();
         $houseAd->id = $_REQUEST['n_cid'];
         $houseAd->name = $_REQUEST['n_name'];
         $houseAd->type = intval($_REQUEST['n_type']);
         $houseAd->linkType = intval($_REQUEST['n_linkType']);
         $houseAds[] = $houseAd;
         fb("houseAd", $houseAd);
     }
     $fields = array('name', 'linkType', 'type');
     $total = count($houseAds);
     if ($total <= 10) {
         $fields[] = 'numApp';
     }
     $sortBy = isset($_REQUEST['sortBy']) ? $_REQUEST['sortBy'] : 'nameAsc';
     if (substr($sortBy, -1) == '?') {
         $sortBy = substr($sortBy, 0, -1);
     }
     $isAsc = substr($sortBy, -3) == 'Asc';
     $sortBy = substr($sortBy, 0, strlen($sortBy) - 3);
     foreach ($fields as $field) {
         $fname = $field;
         if ($field == $sortBy) {
             $val = $fname . ($isAsc ? 'Dsc' : 'Asc');
         } else {
             $val = isset($_REQUEST[$fname]) ? $_REQUEST[$fname] : $field . 'Asc';
         }
         $this->smarty->assign($fname, $val);
     }
     $itemsPerPage = 10;
     if ($sortBy == 'numApp' && $total <= 10) {
         $fname = 'numApp' . ($isAsc ? 'Asc' : 'Dsc');
         foreach ($houseAds as $houseAd) {
             $houseAd->getApps();
         }
         usort($houseAds, $fname);
     } else {
         if ($sortBy == 'numApp') {
             $sortBy = 'name';
             $isAsc = 'true';
         }
         usort($houseAds, makeSortFunction($sortBy, $isAsc));
         $houseAds = array_slice($houseAds, $o, $itemsPerPage);
         foreach ($houseAds as $houseAd) {
             $houseAd->getApps();
         }
     }
     $this->smarty->assign('appsCount', count($apps));
     $this->smarty->assign('current_offset', $o);
     $this->smarty->assign('total', $total);
     $this->smarty->assign('itemsPerPage', $itemsPerPage);
     $this->subtitle = "House Ads";
     $this->smarty->assign('linkLabels', HouseAd::$HOUSEAD_LINKTYPES);
     fb($houseAds);
     $this->smarty->assign('houseAds', $houseAds);
     $this->smarty->assign('houseAdTypes', HouseAd::$HOUSEAD_TYPES);
     fb("smarty", $this->smarty->get_template_vars());
     return $this->smarty->fetch('../tpl/www/houseAds/houseAds.tpl');
 }