مکان مورد نظر کاربر را جستجو می‌کند.

@param unknown $request
@param unknown $match
@throws Pluf_Exception_NotImplemented
186392
function find ($request, $match)
    {
        /*
         * XXX: maso, 1394: استفاده از برچسب‌ها در جستجو
         *
         * هر مکان با استفاده از یک برچسب تعیین دسته بندی می‌شود. این برچسب‌ها
         * در حال
         * حاضر در جستجو استفاده نمی‌شود؟!
         */
        $count = 10;
        if (array_key_exists("_px_c", $request->REQUEST)) {
            $count = $request->REQUEST["count"];
        }
        $count = Geo_Shortcuts_locationCount($request, $count);
        $distance = 1000;
        if (array_key_exists("radius", $request->REQUEST)) {
            $distance = $request->REQUEST["radius"];
        }
        $distance = Geo_Shortcuts_locationRadios($request, $distance);
        
        if (! array_key_exists('latitude', $request->REQUEST)) {
            throw new Pluf_Exception("Latitude is not defined.", 4000, null, 405, 
                    "/");
        }
        $latitude = $request->REQUEST['latitude'];
        if (! array_key_exists('longitude', $request->REQUEST)) {
            throw new Pluf_Exception("Longitude is not defined.", 4000, null, 
                    405, "/");
        }
        $longitude = $request->REQUEST['longitude'];
        $bound = Geo_Shortcuts_locationBound($request, $latitude, $longitude, 
                $distance);
        // maso, 1394: گرفتن فهرست مناسبی از پیام‌ها
        // Paginator to paginate messages
        $pag = new Pluf_Paginator(new Geo_Point());
        $pag->list_filters = array(
                'reporter',
                'community'
        );
        $pag->forced_where = new Pluf_SQL(
                'jayab_location.tenant=%s AND latitude<%s AND latitude>%s AND longitude<%s AND longitude>%s', 
                array(
                        $request->tenant->id,
                        $bound['max']['lat'],
                        $bound['min']['lat'],
                        $bound['max']['long'],
                        $bound['min']['long']
                ));
//         $tag = new SaaSKM_Tag();
//         if (array_key_exists('tag_key', $request->REQUEST) &&
//                  array_key_exists('tag_key', $request->REQUEST)) {
//             $pag->model_view = 'with_tag';
//             $tag = SaaSKM_Tag::getFromString($request->tenant, 
//                     $request->REQUEST['tag_key'] . '.' .
//                              $request->REQUEST['tag_value']);
//             if(!$tag){
//                 throw new Pluf_Exception_DoesNotExist("Tag not found");
//             }
//             $pag->forced_where->SAnd(
//                     new Pluf_SQL('tag=%s', 
//                             array(
//                                     $tag->id
//                             )));
//         }
        $list_display = array(
                'title' => __('location title'),
                'description' => __('description')
        );
        $search_fields = array(
                'name',
                'description'
        );
        $sort_fields = array(
                'creation_date',
                'modif_dtime'
        );
        $pag->configure($list_display, $search_fields, $sort_fields);
        $pag->items_per_page = $count;
        $pag->sort_order = array(
                'creation_dtime',
                'DESC'
        );
        $pag->setFromRequest($request);
        
        // // Add statistic
        // $stat = new Geo_SearchStatistic();
        // $stat->user = $request->user;
        // $stat->application = $request->application;
        // $stat->tag = $tag;
        // if (array_key_exists('spa', $request->REQUEST))
        // $stat->spa = $request->REQUEST['spa'];
        // if (array_key_exists('device', $request->REQUEST))
        // $stat->spa = $request->REQUEST['device'];
        // $stat->latitude = $latitude;
        // $stat->longitude = $longitude;
        // $stat->create();
        
        return new Pluf_HTTP_Response_Json($pag->render_object());
    }
832207
public function putMap ($request, $match)
    {
        if (isset($match['collectionId'])) {
            $collectionId = $match['collectionId'];
        } else {
            $collectionId = $request->REQUEST['collectionId'];
        }
        // $collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
        // $collectionId);
        if (isset($match['documentId'])) {
            $documentId = $match['documentId'];
        } else {
            $documentId = $request->REQUEST['documentId'];
        }
        $document = Pluf_Shortcuts_GetObjectOr404('Collection_Document', 
                $documentId);
        
        if ($document->collection != $collectionId) {
            throw new Pluf_Exception_DoesNotExist(
                    'Document with id (' . $documentId .
                             ') does not exist in collection with id (' .
                             $collectionId . ')');
        }
        
        $this->putDocumentMap($document, $request->REQUEST);
        return new Pluf_HTTP_Response_Json($this->getDocumentMap($document));
    }
1143268
public function remove ($request, $match)
    {
        if (isset($match['collectionId'])) {
            $collectionId = $match['collectionId'];
        } else {
            $collectionId = $request->REQUEST['collectionId'];
        }
        $collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection', 
                $collectionId);
        if (isset($match['documentId'])) {
            $documentId = $match['documentId'];
        } else {
            $documentId = $request->REQUEST['documentId'];
        }
        $document = Pluf_Shortcuts_GetObjectOr404('Collection_Document', 
                $documentId);
        
        if ($document->collection !== $collection->id) {
            throw new Pluf_Exception_DoesNotExist(
                    'Document with id (' . $documentId .
                             ') does not exist in collection with id (' .
                             $collectionId . ')');
        }
        $documentCopy = Pluf_Shortcuts_GetObjectOr404('Collection_Document', 
                $documentId);
        $document->delete();
        return new Pluf_HTTP_Response_Json($documentCopy);
    }
427926
public function get($request, $match, $p)
    {
        $backend = parent::getObject($request, $match, $p);
        if ($backend->tenant !== Tenant_Shortcuts_GetMainTenant()->id) {
            throw new Pluf_HTTP_Error404("Object not found (" . $p['model'] . "," . $backend->id . ")");
        }
        return $backend;
    }
67992
public static function count ($request, $match)
    {
        $userId = $request->user ? $request->user->id : 0;
        $sql = new Pluf_SQL('account_id=%s', array($userId));
        
        $message = new User_Message();
        $res = $message->getList(
                array(
                        'count' => true,
                        'filter' => $sql->gen()
                ));
        // Check permission
        return $res[0]['nb_items'];
    }
620221
public function get($request, $match)
    {
        // تعیین داده‌ها
        if (array_key_exists('id', $match)) {
            $content = Pluf_Shortcuts_GetObjectOr404('CMS_Content', $match['id']);
        } else {
            $content = CMS_Shortcuts_GetNamedContentOr404($match['name']);
        }
        // اجرای درخواست
        return $content;
    }
938610
public function update($request, $match)
    {
        $currentUser = $request->user;
        $user = Pluf_Shortcuts_GetObjectOr404('User', $match['userId']);
        if($currentUser->getId() === $user->getId() || User_Precondition::ownerRequired($request)){
            $profileDoc = User_Views_CProfile::get_profile_document($user->id);
            User_Views_CProfile::putDocumentMap($profileDoc, $request->REQUEST);
            $docMap = User_Views_CProfile::getDocumentMap($profileDoc);
            $docMap['user'] = $user->id;
            return new Pluf_HTTP_Response_Json($docMap);
        }
        throw new Pluf_Exception_PermissionDenied("Permission is denied");
    }
239009
public function delete($request, $match)
    {
        $model = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['id']);
        $model2 = new User_Role($match['id']);
        if ($model->delete()) {
            return new Pluf_HTTP_Response_Json($model2);
        }
        throw new Pluf_HTTP_Error500('Unexpected error while removing role: ' . $model2->code_name);
    }
1010785
public static function delete($request, $match)
    {
        $perm = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['role_id']);
        $owner = Pluf_Shortcuts_GetObjectOr404('User_Group', $match['group_id']);
        $perm->delAssoc($owner);
        return $owner;
    }
669201
private function internalGet($request, $match){
        if ($request->user->hasPerm('tenant.owner')) {
            $sql = new Pluf_SQL('`key`=%s', array(
                $match['key']
            ));
        } else {
            $sql = new Pluf_SQL('`key`=%s AND `mode`=%s', array(
                $match['key'],
                Tenant_Setting::MOD_PUBLIC
            ));
        }
        $model = new Tenant_Setting();
        $model = $model->getOne(array(
            'filter' => $sql->gen()
        ));
        return $model;
    }
461169
public function matchRequest(Request $request)
    {
        try {
            $parameters = parent::matchRequest($request);
            $this->matchedRouteRequest = $request;
            return $parameters;
        } catch (\Exception $e) {
            throw $e;
        }


    }
419541
public function matchesPattern(Request $request)
    {
        if (preg_match($this->regexPattern, $request->getRequestUri()) <= 0) {
            return false;
        }

        return true;
    }
928672
public function create($request, $match)
    {
        // 1- upload & extract
        $key = 'spa-' . md5(microtime() . rand(0, 123456789));
        Pluf_Form_Field_File_moveToUploadFolder($request->FILES['file'], array(
            'file_name' => $key . '.zip',
            'upload_path' => Pluf::f('temp_folder', '/tmp'),
            'upload_path_create' => true,
            'upload_overwrite' => true
        ));
        $spa = Tenant_SpaService::installFromFile(Pluf::f('temp_folder', '/tmp') . '/' . $key . '.zip', true);
        return Tenant_Shortcuts_SpaManager($spa)->apply($spa, 'create');
    }
35764
private function internalGet($request, $match){
        $model = new Tenant_Configuration();
        $model = $model->getOne("`key`='" . $match['key'] . "'");
        return $model;
    }
1161830
public function updateFile($request, $match)
    {
        // Get data
        $resource = Pluf_Shortcuts_GetObjectOr404('Tenant_Resource', $match['modelId']);
        // Do action
        if (array_key_exists('file', $request->FILES)) {
            $extra = array(
                'model' => $resource
            );
            $form = new Tenant_Form_ResourceUpdate(array_merge($request->REQUEST, $request->FILES), $extra);
            $resource = $form->save();
            return $resource;
        } else {
            $myfile = fopen($resource->getAbsloutPath(), "w") or die("Unable to open file!");
            $entityBody = file_get_contents('php://input', 'r');
            fwrite($myfile, $entityBody);
            fclose($myfile);
            $resource->update();
        }
        return $resource;
    }
179048
public function delete($request, $match)
    {
        // تعیین داده‌ها
        $content = Pluf_Shortcuts_GetObjectOr404('CMS_Content', $match['modelId']);
        // بررسی دسترسی‌ها
        if (! CMS_Precondition::isAuthor($request)) {
            throw new Pluf_Exception_PermissionDenied('You are not an author');
        }
        if (! CMS_Precondition::isEditor($request) && $request->user->id !== $content->author_id) {
            throw new Pluf_Exception_PermissionDenied('You can not delete content created by another author');
        }
        return parent::deleteObject($request, $match, array(
            'model' => 'CMS_Content'
        ));
    }
96098
public function addTag ($request, $match)
    {
        $location = Geo_Shortcuts_GetLocationOr404($match[1]);
        Geo_Precondition::canEditLocation($request, $location);
        $tag = SaaSKM_Shortcuts_GetTagOr404($match[2]);
        SaaSKM_Precondition::userCanAccessTag($request, $tag); 
        SaaSKM_TagRow::add($request->tenant, $location, $tag);
        return new Pluf_HTTP_Response_Json($location);
    }