function process(Mobile_API_Request $request) { $response = new Mobile_API_Response(); $current_user = $this->getActiveUser(); $module = $request->get('module'); $moduleWSID = Mobile_WS_Utils::getEntityModuleWSId($module); if (empty($module)) { $response->setError(1501, "Module not specified."); return $response; } $records = array(); // Fetch the request parameters $idlist = $request->get('ids'); $alertid = $request->get('alertid'); // List of ids specified? if (!empty($idlist)) { $idlist = Zend_Json::decode($idlist); $records = $this->fetchRecordsWithId($module, $idlist, $current_user); } else { if (!empty($alertid)) { $alert = Mobile_WS_AlertModel::modelWithId($alertid); if ($alert === false) { $response->setError(1404, "Alert not found."); $records = false; } $alert->setUser($current_user); $records = $this->fetchAlertRecords($module, $alert); } } if ($records !== false) { $response->setResult(array('records' => $records)); } return $response; }
function getAlertDetails($alertid) { $alertModel = Mobile_WS_AlertModel::modelWithId($alertid); $alert = false; if ($alertModel) { $alert = $alertModel->serializeToSend(); $alertModel->setUser($this->getActiveUser()); $alert['message'] = $alertModel->message(); } return $alert; }
function processSearchRecordLabel(Mobile_API_Request $request) { global $current_user; // Few core API assumes this variable availability $current_user = $this->getActiveUser(); $module = $request->get('module'); $alertid = $request->get('alertid'); $filterid = $request->get('filterid'); $search = $request->get('search'); $filterOrAlertInstance = false; if (!empty($alertid)) { $filterOrAlertInstance = Mobile_WS_AlertModel::modelWithId($alertid); } else { if (!empty($filterid)) { $filterOrAlertInstance = Mobile_WS_FilterModel::modelWithId($module, $filterid); } else { if (!empty($search)) { $filterOrAlertInstance = $this->getSearchFilterModel($module, $search); } } } if ($filterOrAlertInstance && strcmp($module, $filterOrAlertInstance->moduleName)) { $response = new Mobile_API_Response(); $response->setError(1001, 'Mistached module information.'); return $response; } // Initialize with more information if ($filterOrAlertInstance) { $filterOrAlertInstance->setUser($current_user); } // Paging model $pagingModel = $this->getPagingModel($request); if ($this->isCalendarModule($module)) { return $this->processSearchRecordLabelForCalendar($request, $pagingModel); } $records = $this->fetchRecordLabelsForModule($module, $current_user, array(), $filterOrAlertInstance, $pagingModel); $modifiedRecords = array(); foreach ($records as $record) { if ($record instanceof SqlResultIteratorRow) { $record = $record->data; // Remove all integer indexed mappings for ($index = count($record); $index > -1; --$index) { if (isset($record[$index])) { unset($record[$index]); } } } $recordid = $record['id']; unset($record['id']); $eventstart = ''; if ($this->isCalendarModule($module)) { $eventstart = $record['date_start']; unset($record['date_start']); } $values = array_values($record); $label = implode(' ', $values); $modifiedRecord = array('id' => $recordid, 'label' => $label); if (!empty($eventstart)) { $modifiedRecord['eventstart'] = $eventstart; } $modifiedRecords[] = $modifiedRecord; } $response = new Mobile_API_Response(); $response->setResult(array('records' => $modifiedRecords, 'module' => $module)); return $response; }