Example #1
0
 public function save()
 {
     $hasSpecifiedAvailability = false;
     if ($this->availability != null) {
         foreach ($this->availability as $day => $timeOfDay) {
             if ($timeOfDay == 0) {
                 continue;
             }
             $hasSpecifiedAvailability = true;
             $existing = RequestToUser::model()->find('User_ID=:User_ID AND Request_ID=:Request_ID AND Day=:Day', array(':User_ID' => $this->user_ID, ':Request_ID' => $this->request_ID, ':Day' => $day));
             if ($existing == null) {
                 $requestToUser = new RequestToUser();
                 $requestToUser->User_ID = $this->user_ID;
                 $requestToUser->Request_ID = $this->request_ID;
                 $requestToUser->Day = $day;
                 $requestToUser->Time_of_day = $timeOfDay;
                 $requestToUser->save();
             }
         }
     }
     if (!$hasSpecifiedAvailability) {
         $requestToUser = new RequestToUser();
         $requestToUser->User_ID = $this->user_ID;
         $requestToUser->Request_ID = $this->request_ID;
         $requestToUser->save();
     }
     $request = Request::model()->findByPk($this->request_ID);
     $user = User::model()->findByPk($this->user_ID);
     $userName = CHtml::link($user->fullName, array('user/view', 'id' => $user->User_ID));
     $requestName = CHtml::link($request->Name, array('request/view', 'id' => $request->Request_ID));
     Message::SendNotification($request->Create_User_ID, "{$userName} has joined your request \"{$requestName}\".");
 }
Example #2
0
 public function actionDeleteRequest()
 {
     $request = Request::model()->findByAttributes(array('user_id' => Yii::app()->getRequest()->getParam('user_id'), 'contact_id' => Yii::app()->getRequest()->getParam('contact_id')));
     if ($request === null || !($request->user_id === Yii::app()->getUser()->getId() || $request->contact_id === Yii::app()->getUser()->getId())) {
         throw new CHttpException(404, Yii::t('application', 'The requested page does not exist.'));
     }
     $request->delete();
     $this->redirect(Yii::app()->getUser()->returnUrl);
 }
Example #3
0
 /**
  * This method parses raw request using Request::$model callback for parsing.
  * @return boolean if validation was successfull
  * @throws Exception 
  */
 public static function validate()
 {
     if (is_null(self::$model)) {
         throw new Exception('Model was not set, it is not possible to perform validation');
     } else {
         $rules = Request::model()->rules();
         if (!empty($rules)) {
             $params = call_user_func(Request::model()->parseRawRequestCallBack(), self::$rawRequest);
             Request::model()->attributes = $params;
             return Request::model()->validate();
         } else {
             return true;
         }
     }
 }
Example #4
0
 public function actionLend($book_id, $user_id)
 {
     $model = Book::model()->findByPk($book_id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested book does not exist.');
     }
     $request = Request::model()->find('book_id=:book_id AND requester_id=:user_id', array(':book_id' => $book_id, ':user_id' => $user_id));
     if ($request === null) {
         throw new CHttpException(404, 'The request does not exist.');
     }
     $request->delete();
     $model->borrower_id = $user_id;
     $model->save();
     $this->redirect(array('book/index'));
 }
Example #5
0
 public function actionGetSuccess()
 {
     // A mirror funciton that returns what it got, just for example
     return Response::success(array('parameter' => Request::model()->parameter));
 }
Example #6
0
<div class="form" style="padding-top:10px;">
    <?php 
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'request-form', 'action' => $this->createUrl("request")));
?>
    <?php 
$model = new Request();
echo $form->textField($model, 'user_name', array("id" => "askUser", "placeholder" => "搜索您想邀请的用户", "class" => "pull-left"));
echo $form->hiddenField($model, 'to_user');
echo $form->hiddenField($model, 'question_id', array('value' => $question->id));
?>
    <?php 
$requestion = Request::model()->findAll("question_id=:question_id and create_user=:create_user and delete_flag!=1", array(":question_id" => $question->id, ":create_user" => Yii::app()->user->id), array('order' => 'create_time desc'));
$i = 0;
?>
    <?php 
if (!empty($requestion)) {
    ?>
        <div class="pull-left" style="height: 30px;line-height: 30px;margin-left: 4px;">
            您已经邀请
            <?php 
    foreach ($requestion as $key => $value) {
        $i++;
        ?>
                <a class="user-label" href="javascript:;" data-id="<?php 
        echo $value->to_user;
        ?>
"><?php 
        echo User::getNameById($value->to_user);
        ?>
</a>
                <?php 
Example #7
0
 public function save()
 {
     $isSaved = null;
     $experience = new Experience();
     $transaction = $experience->dbConnection->beginTransaction();
     try {
         if (isset($this->free) && $this->free === true) {
             unset($this->Price);
         }
         $experience->Name = $this->Name;
         $experience->ExperienceType = $this->ExperienceType;
         $experience->Audience = $this->Audience;
         $experience->Category_ID = $this->Category_ID;
         $experience->Start = $this->Start;
         $experience->End = $this->End;
         $experience->Description = $this->Description;
         $experience->Offering = $this->Offering;
         $experience->FinePrint = $this->FinePrint;
         $experience->Price = $this->Price;
         $experience->Min_occupancy = $this->Min_occupancy;
         $experience->Max_occupancy = $this->Max_occupancy;
         $experience->MaxPerPerson = $this->MaxPerPerson;
         $experience->MultipleAllowed = $this->MultipleAllowed;
         $appropriateAges = 0;
         if (isset($this->AppropriateAges) && is_array($this->AppropriateAges)) {
             foreach ($this->AppropriateAges as $age) {
                 $appropriateAges += $age;
             }
         }
         $experience->AppropriateAges = $appropriateAges;
         $location = $this->getLocation();
         $experience->Location_ID = $location->Location_ID;
         $experience->save();
         $this->experience = $experience;
         if ($this->imageFiles != null) {
             foreach ($this->imageFiles as $imageFile) {
                 $content = Content::AddContent($imageFile, 'Class Image', ContentType::ImageID);
                 $experienceToContent = new ExperienceToContent();
                 $experienceToContent->Experience_ID = $this->experience->Experience_ID;
                 $experienceToContent->Content_ID = $content->Content_ID;
                 $experienceToContent->save();
             }
         }
         if (isset($this->fromRequest_ID) && is_numeric($this->fromRequest_ID)) {
             $request = Request::model()->findByPk($this->fromRequest_ID);
             if ($request != null) {
                 $request->Created_Experience_ID = $this->experience->Experience_ID;
                 $request->save();
                 // Notify the students
                 foreach ($request->requestors as $user) {
                     if ($user->User_ID != $this->experience->Create_User_ID) {
                         $userName = CHtml::link($this->experience->createUser->fullName, array('//user/view', 'id' => $this->experience->createUser->User_ID));
                         $requestName = CHtml::link($request->Name, array('//request/view', 'id' => $request->Request_ID));
                         $experienceName = CHtml::link($this->experience->Name, array('//experience/view', 'id' => $this->experience->Experience_ID));
                         Message::SendNotification($user->User_ID, "{$userName} has picked up the request \"{$requestName}\" and created the experience \"{$experienceName}\".");
                     }
                 }
             }
         }
         $tagsArray = Tag::model()->string2array($this->tags);
         foreach ($tagsArray as $tagName) {
             $tag = Tag::model()->findOrCreate($tagName);
             $experienceToTag = new ExperienceToTag();
             $experienceToTag->Experience_ID = $this->experience->Experience_ID;
             $experienceToTag->Tag_ID = $tag->Tag_ID;
             $experienceToTag->save();
         }
         if (isset($this->sessions) && strlen($this->sessions) > 0) {
             $sessionData = json_decode($this->sessions);
             foreach ($sessionData as $sessionItem) {
                 $session = new Session();
                 $session->Experience_ID = $this->experience->Experience_ID;
                 $session->Start = $sessionItem->Start;
                 $session->End = $sessionItem->End;
                 $session->save();
             }
         }
         $transaction->commit();
         $isSaved = true;
     } catch (Exception $e) {
         $isSaved = false;
         $transaction->rollback();
     }
     return $isSaved;
 }
Example #8
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Request::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #9
0
 /**
  * Send request rejected notification.
  */
 public function actionSendRequestNotification($idRequest)
 {
     // is current user has the required privilege ?
     /*if (!Yii::app()->user->checkAccess('mail_meetingReminder')) {
           throw new CHttpException(
           403, 'You are not authorized to perform this action.'
           );
       }*/
     $request = Request::model()->findByPk($idRequest);
     $subject = '[Notification] Request ditolak';
     $content = 'Melalui email ini, kami menyampaikan bahwa agenda yang Anda ajukan ditolak.<br/>';
     $content .= 'Demikian email ini, terima kasih.<br/>';
     $content .= '<br/>Salam,';
     $content .= '<br/>Admin';
     $members = Member::model()->findAll();
     foreach ($members as $member) {
         while ($this->sendEmail($member->email, $subject, $content) == false) {
             $this->sendEmail($member->email, $subject, $content);
         }
     }
     return true;
 }
Example #10
0
 /**
  * 获取JSON Portal数据
  */
 public static function getJSONData($type = "comment", $read_flag = true, $json = true, $action = false)
 {
     $criteria = new CDbCriteria();
     $criteria->order = 'remind_time desc';
     if (!$action || (!isset($_GET["action"]) || $_GET["action"] == "inbox")) {
         $criteria->condition = '(to_id = :to_id and remind_flag != :to_remind_flag and delete_flag != :to_delete_flag)';
         $criteria->params = array(':to_id' => Yii::app()->user->id, ':to_remind_flag' => $read_flag ? 1 : 2, ':to_delete_flag' => 1);
     } else {
         $criteria->condition = '(to_id  = :to_id and remind_flag != :to_remind_flag and delete_flag != :to_delete_flag)';
         $criteria->params = array(':to_id' => Yii::app()->user->id, ':to_remind_flag' => $read_flag ? 1 : 2, ':to_delete_flag' => 2);
         $criteria->addInCondition("content_id", NotificationContent::model()->getIdArray());
     }
     $models = self::model()->findAll($criteria);
     $data = array();
     $commentData = array();
     $reportData = array();
     $attentionData = array();
     foreach ($models as $model) {
         $contentModel = NotificationContent::model()->findByPk($model->content_id);
         if (in_array($contentModel->notification_type, array("attention", "report", "reportanswer", "reportquestion", "reportarticle"))) {
             if ($contentModel->notification_type == "report") {
                 $userID = $contentModel->pk_id;
                 $content = $contentModel->content;
                 $userString = User::getNameById($userID);
             } else {
                 if ($contentModel->notification_type == "reportanswer") {
                     $anwerModel = Answer::model()->findByPk($contentModel->pk_id);
                     $userID = $anwerModel->create_user;
                     $userString = User::getNameById($userID) . " 的回答";
                     $content = $contentModel->content;
                 } else {
                     if ($contentModel->notification_type == "reportquestion") {
                         $questionModel = Question::model()->findByPk($contentModel->pk_id);
                         $userID = $questionModel->create_user;
                         $userString = User::getNameById($userID) . " 的问题";
                         $content = $questionModel->title . "(" . $contentModel->content . ")";
                     } else {
                         if ($contentModel->notification_type == "reportarticle") {
                             $articleModel = Article::model()->findByPk($contentModel->pk_id);
                             $userID = $articleModel->create_user;
                             $userString = User::getNameById($userID) . " 的文章";
                             $content = $articleModel->subject . "(" . $contentModel->content . ")";
                         }
                     }
                 }
             }
             $dataArray = array('id' => $model->id, 'type' => $contentModel->notification_type, 'content' => $content, 'remindFlag' => $model->remind_flag, 'createUserId' => $contentModel->from_id, 'reportUser' => $userString, 'createUser' => User::getNameById($contentModel->from_id), 'reportUserId' => $userID, 'createTime' => Comment::model()->timeintval($contentModel->send_time), 'avatarSrc' => Yii::app()->controller->createUrl("getimage", array("id" => $contentModel->from_id, "type" => "avatar")), 'reportAvatar' => Yii::app()->controller->createUrl("getimage", array("id" => $userID, "type" => "avatar")), 'dataUrl' => Yii::app()->controller->createUrl("userinfo", array("user_id" => $contentModel->from_id, "pk_id" => $model->id)), 'reportUrl' => $contentModel->notification_type != "attention" ? Yii::app()->controller->createUrl("viewnotify", array("id" => $model->id)) : Yii::app()->controller->createUrl("userinfo", array("user_id" => $contentModel->pk_id, "pk_id" => $model->id)));
             if ($type == "attention" && $contentModel->notification_type == "attention") {
                 $attentionData[] = $dataArray;
             } else {
                 if ($type == "report" && in_array($contentModel->notification_type, array("report", "reportanswer", "reportquestion", "reportarticle"))) {
                     $reportData[] = $dataArray;
                 } else {
                     $data[] = $dataArray;
                 }
             }
         } else {
             $pk_id = Comment::model()->findByPk($contentModel->pk_id)->pk_id;
             if ($contentModel->notification_type == "answer") {
                 $dataUrl = Yii::app()->controller->createUrl("answer", array("id" => $pk_id, "pk_id" => $model->id));
             } else {
                 if ($contentModel->notification_type == "article") {
                     $dataUrl = Yii::app()->controller->createUrl("article", array("id" => $pk_id, "pk_id" => $model->id));
                 } else {
                     if ($contentModel->notification_type == "question") {
                         $content = Answer::model()->findByPk($contentModel->pk_id)->content;
                         $dataUrl = Yii::app()->controller->createUrl("answer", array("id" => $contentModel->pk_id, "pk_id" => $model->id));
                     } else {
                         if ($contentModel->notification_type == "comment") {
                             $commentModel = Comment::model()->findByPk($contentModel->pk_id);
                             $dataUrl = Yii::app()->controller->createUrl($commentModel->model, array("id" => $commentModel->pk_id, "pk_id" => $model->id));
                         } else {
                             if ($contentModel->notification_type == "topic") {
                                 $dataUrl = Yii::app()->controller->createUrl("question", array("id" => $contentModel->pk_id, "pk_id" => $model->id));
                             } else {
                                 if ($contentModel->notification_type == "createask") {
                                     $questionModel = Question::model()->findByPk(Request::model()->findByPk($contentModel->pk_id)->question_id);
                                     $dataUrl = Yii::app()->controller->createUrl("question", array("id" => $contentModel->pk_id, "pk_id" => $questionModel->id));
                                 }
                             }
                         }
                     }
                 }
             }
             $commentData[] = array('id' => $model->id, 'desc' => $contentModel->notification_type == "question" ? strlen(strip_tags($content)) > 100 ? mb_strcut(strip_tags($content), 0, 100, 'utf-8') . "..." : $content : ($contentModel->notification_type == "topic" ? Question::model()->findByPk($contentModel->pk_id)->title : Comment::model()->findByPk($contentModel->pk_id)->content), 'content' => $contentModel->content, 'remindFlag' => $model->remind_flag, 'reportUserId' => $model->to_id, 'createUserId' => $contentModel->from_id, 'createUser' => User::getNameById($contentModel->from_id), 'reportUser' => User::getNameById($model->to_id), 'createTime' => Comment::model()->timeintval($contentModel->send_time), 'avatarSrc' => Yii::app()->controller->createUrl("getimage", array("id" => $contentModel->from_id, "type" => "avatar")), 'dataUrl' => $dataUrl);
         }
     }
     if (Yii::app()->user->name != "admin" && !Yii::app()->user->isGuest) {
         $criteria = new CDbCriteria();
         $criteria->order = 'send_time desc';
         $criteria->addCondition("notification_type='report'");
         $criteria->addCondition("from_id=" . Yii::app()->user->id);
         $notificationModel = NotificationContent::model()->findAll($criteria);
         foreach ($notificationModel as $notification) {
             $model = self::model()->find("content_id=" . $notification->id);
             if ($model->delete_flag != "2") {
                 $reportData[] = array('id' => $model->id, 'type' => $notification->notification_type, 'content' => $notification->content, 'remindFlag' => $model->remind_flag, 'createUserId' => $notification->from_id, 'reportUser' => User::getNameById($notification->pk_id), 'createUser' => User::getNameById($notification->from_id), 'reportUserId' => $notification->pk_id, 'createTime' => Comment::model()->timeintval($notification->send_time), 'avatarSrc' => User::getAvatarById($notification->from_id), 'reportAvatar' => User::getAvatarById($notification->pk_id), 'dataUrl' => Yii::app()->controller->createUrl("userinfo", array("user_id" => $notification->from_id, "pk_id" => $model->id)), 'reportUrl' => Yii::app()->controller->createUrl("userinfo", array("user_id" => $notification->pk_id, "pk_id" => $model->id)));
             }
         }
     }
     if ($type == "comment") {
         $returnData = $json ? CJSON::encode($commentData) : $commentData;
     } else {
         if ($type == "report") {
             $returnData = $json ? CJSON::encode($reportData) : $reportData;
         } else {
             if ($type == "attention") {
                 $returnData = $json ? CJSON::encode($attentionData) : $attentionData;
             } else {
                 $returnData = $json ? CJSON::encode($data) : $data;
             }
         }
     }
     return $returnData;
 }
Example #11
0
 public function findRequest($contactId)
 {
     $request = Request::model()->findByAttributes(array('user_id' => $this->id, 'contact_id' => $contactId));
     return $request;
 }
Example #12
0
 /** Заявки МЖ */
 public function actionRequest()
 {
     //throw new CHttpException(404,'Страница временно недоступна');
     $me = Yii::app()->user->me;
     /** @var $me Anketa */
     $me->setLastRequestVisit(time());
     Request::checkStatus();
     if (!($request = Request::model()->find('id_user = :id_user and isdeleted = 0', array(':id_user' => Yii::app()->user->id)))) {
         $request = new Request();
     }
     if (!empty($_POST)) {
         //echo $me->getAccountType(), '= ', Anketa::ACCOUNT_PREMIUM; die();
         $request->attributes = $_POST['Request'];
         if ($request->isNewRecord) {
             $request->id_user = Yii::app()->user->id;
             $request->time_start = time();
             $request->city = $me->city;
             $request->time_end = $request->time_start + Request::DEFAULT_REQUEST_TIME;
         }
         if ($me->disallowMessageTo($me)) {
             $request->addError('text', 'Вы не можете оставлять заявки!');
         } else {
             if ($request->save()) {
                 $this->refresh();
             }
         }
     }
     $dataProvider = new CActiveDataProvider(Request::model()->published()->sorted()->byCity($me->city), array('pagination' => array('pageSize' => 1000, 'pageVar' => 'page')));
     $this->render('request', compact('request', 'dataProvider'));
 }
 public function beforeAction($action)
 {
     if ($this->isActionAttachedByActionsMethod($action) || $this->isSpecialAction($action)) {
         return parent::beforeAction($action);
     }
     try {
         $requestModel = $this->createApiValidation($this->getId(), $action->id);
         $postParamsKey = self::$configuration['requestKey'];
         if (empty($this->request)) {
             $this->request = isset($_POST[$postParamsKey]) ? $_POST[$postParamsKey] : file_get_contents('php://input');
         }
         Request::setModel($requestModel);
         Request::setRawRequest($this->request);
         if (Request::validate()) {
             return parent::beforeAction($action);
         } else {
             Response::error(ErrorCodes::VALIDATION_ERROR, Request::model()->getErrors());
             $this->afterAction($action);
         }
     } catch (Exception $e) {
         if ($e instanceof CHttpException) {
             throw $e;
         }
         $trace = YII_DEBUG ? ' Trace: ' . $e->getTraceAsString() : '';
         Response::error(ErrorCodes::SERVER_ERROR, $e->getMessage() . $trace);
         $this->renderAndLogResponse();
     }
 }
Example #14
0
 public function search()
 {
     $requestCriteria = new CDbCriteria();
     $experienceCriteria = new CDbCriteria();
     $requestCriteria->with = array('category', 'tags', 'createUser');
     $experienceCriteria->with = array('location', 'category', 'tags', 'createUser');
     $keywords = explode(' ', $this->keywords);
     if (isset($this->includedResults)) {
         $included = json_decode($this->includedResults);
         $experiences = array();
         $requests = array();
         foreach ($included as $item) {
             if ($item->type == 'experience') {
                 $experiences[] = $item->id;
             } else {
                 $requests[] = $item->id;
             }
         }
         $experienceCriteria->addInCondition('t.Experience_ID', $experiences);
         $requestCriteria->addInCondition('t.Request_ID', $requests);
     } else {
         foreach ($keywords as $keyword) {
             $requestCriteria->compare('t.Name', $keyword, true, 'OR');
             $requestCriteria->compare('t.Description', $keyword, true, 'OR');
             $requestCriteria->compare('category.Name', $keyword, true, 'OR');
             $requestCriteria->compare('tags.Name', $keyword, true, 'OR');
             $requestCriteria->compare('createUser.First_name', $keyword, true, 'OR');
             $requestCriteria->compare('createUser.Last_name', $keyword, true, 'OR');
             $requestCriteria->compare('createUser.DisplayName', $keyword, true, 'OR');
             $experienceCriteria->compare('t.Name', $keyword, true, 'OR');
             $experienceCriteria->compare('t.Description', $keyword, true, 'OR');
             $experienceCriteria->compare('category.Name', $keyword, true, 'OR');
             $experienceCriteria->compare('tags.Name', $keyword, true, 'OR');
             $experienceCriteria->compare('createUser.First_name', $keyword, true, 'OR');
             $experienceCriteria->compare('createUser.Last_name', $keyword, true, 'OR');
             $experienceCriteria->compare('createUser.DisplayName', $keyword, true, 'OR');
         }
     }
     $requestCriteria->addCondition('t.Created_Experience_ID is NULL');
     if (isset($this->category) && is_numeric($this->category) && $this->category > 0) {
         $requestCriteria->compare('t.Category_ID', $this->category);
         $experienceCriteria->compare('t.Category_ID', $this->category);
     }
     if ($this->minPrice != null && $this->minPrice > 0) {
         $experienceCriteria->compare('t.Price', '>=' . $this->minPrice);
     }
     if ($this->maxPrice != null && $this->maxPrice > 0) {
         $experienceCriteria->compare('t.Price', '<=' . $this->maxPrice);
     }
     if ($this->start != null && strlen($this->start) > 0) {
         $experienceCriteria->compare('t.End', '>' . date('Y-m-d', strtotime($this->start)));
     }
     if ($this->end != null && strlen($this->end) > 0) {
         $experienceCriteria->compare('t.Start', '<' . date('Y-m-d', strtotime($this->end)));
     }
     if ($this->posterType != null && $this->posterType > 0) {
         $experienceCriteria->compare('createUser.PosterType', '=' . $this->posterType);
     }
     if ($this->experienceType != null && $this->experienceType > 0) {
         $experienceCriteria->compare('t.ExperienceType', '=' . $this->experienceType);
     }
     if ($this->ageRanges != null && !in_array(0, $this->ageRanges)) {
         $ageRange = 0;
         foreach ($this->ageRanges as $item) {
             $ageRange += $item;
         }
         $experienceCriteria->addCondition('t.AppropriateAges | ' . $ageRange . ' = ' . $ageRange);
         $experienceCriteria->compare('t.AppropriateAges', '>' . 0);
     }
     $experiences = Experience::model()->active()->current()->findAll($experienceCriteria);
     $requests = Request::model()->findAll($requestCriteria);
     foreach ($requests as $i => $request) {
         if (count($request->requestors) == 0) {
             unset($requests[$i]);
         }
     }
     if (isset($this->location) && strlen($this->location) > 0) {
         foreach ($experiences as $i => $experience) {
             if (!stristr($experience->location->fullAddress, $this->location)) {
                 unset($experiences[$i]);
             }
         }
         foreach ($requests as $i => $request) {
             if ($request->Zip != $this->location) {
                 unset($requests[$i]);
             }
         }
     }
     $experiences = array_values($experiences);
     $items = array_merge($experiences, $requests);
     $scores = array();
     foreach ($items as $item) {
         $score = 1;
         $locationFound = false;
         foreach ($keywords as $keyword) {
             if (strlen($keyword) == 0) {
                 continue;
             }
             if (stristr($item->Name, $keyword)) {
                 $score += ExperienceSearchForm::NameValue;
             }
             if (stristr($item->Description, $keyword)) {
                 $score += ExperienceSearchForm::NameValue;
             }
             if (stristr($item->category->Name, $keyword)) {
                 $score += ExperienceSearchForm::CategoryValue;
             }
             if (stristr($item->tagstring, $keyword)) {
                 $score += ExperienceSearchForm::TagValue;
             }
             if ($item instanceof Experience && $item->location != null && !$locationFound) {
                 if (stristr($item->location->fulladdress, $keyword)) {
                     $score *= ExperienceSearchForm::LocationMultiplier;
                     $locationFound = true;
                 }
             }
         }
         array_push($scores, $score);
     }
     arsort($scores);
     $sortedItems = array();
     foreach ($scores as $i => $score) {
         $sortedItems[] = $items[$i];
     }
     $this->totalResults = count($sortedItems);
     $this->totalPages = ceil($this->totalResults / ExperienceSearchForm::PageSize);
     if (isset($this->disablePaging) && $this->disablePaging != null) {
         return $sortedItems;
     }
     if (!isset($this->page)) {
         $this->page = 1;
     }
     $offset = ($this->page - 1) * ExperienceSearchForm::PageSize;
     $sortedItems = array_slice($sortedItems, $offset, ExperienceSearchForm::PageSize);
     return $sortedItems;
 }
Example #15
0
 /**
  * 发送提醒
  */
 public function afterSave()
 {
     parent::afterSave();
     $createUser = Question::Model()->findByPk($this->question_id)->create_user;
     $createUserModel = User::model()->findByPk($createUser);
     $answerModel = User::model()->findByPk($this->create_user);
     $score = Sys::model()->getvaluesByType("answer_score");
     $type = Sys::model()->getvaluesByType("answer_type");
     $time = strtotime(date("Y-m-d", time()));
     $count = Answer::model()->count("create_user=:create_user and create_time>:create_time", array(":create_user" => $this->create_user, ":create_time" => $time));
     if ($count == 1) {
         $wealthModel = new Wealth();
         if ($type == "0") {
             $answerModel->wealth = $answerModel->wealth + intval($score);
             $content = "回答成功,奖励" . $score . "个财富值";
             $data = array('content' => $content, 'create_time' => $this->create_time);
             $wealthModel->insertWealth($data);
         }
     }
     if ($type == 1) {
         $answerModel->wealth = $answerModel->wealth - intval($score);
         $content = "回答成功,花费" . $score . "个财富值";
         $data = array('content' => $content, 'create_time' => $this->create_time);
         $wealthModel->insertWealth($data);
     }
     $answerModel->save();
     $recvArray = unserialize($createUserModel->recv_option);
     $value = "subscribe_question_like";
     $inser = false;
     if ($recvArray[$value] == 1 || $recvArray[$value] == 2 && $createUserModel->followees != "" && in_array($this->create_user, explode(",", trim($createUserModel->followees, ",")))) {
         $inser = true;
     }
     $notificationContentModel = new NotificationContent();
     $notificationData = array("pk_id" => $this->id, "content" => "回答了你的问题", "send_time" => $this->create_time, "notification_type" => "createanswer");
     $notificationContentModel->insertNotificationContent($notificationData, $inser);
     Request::model()->updateAll(array("answer_flag" => 1), "to_user=:to_user and question_id=:question_id", array(":to_user" => $this->create_user, ":question_id" => $this->question_id));
     Question::model()->updateAll(array("update_time" => $this->create_time), "id=:id", array(":id" => $this->question_id));
 }
Example #16
0
     echo Yii::app()->user->id != $artcileModel->create_user ? str_replace("你", CHtml::tag("img", array("style" => "margin:0 4px;", "height" => "20", "width" => "20", "src" => $this->createUrl("getimage", array("id" => $artcileModel->create_user, "type" => "avatar")))) . CHtml::link(User::getNameById($artcileModel->create_user), array("default/userinfo", 'user_id' => $artcileModel->create_user), array('data-id' => $artcileModel->create_user, 'class' => 'user-label', 'target' => '_blank')), $data->content) : $data->content;
     $this->widget('bootstrap.widgets.TbButton', array('type' => 'info', 'label' => strlen($artcileModel->subject) > 40 ? mb_substr($artcileModel->subject, 0, 40, 'utf-8') . '...' : $artcileModel->subject, 'type' => 'link', 'url' => $this->createUrl("article", array("id" => $artcileModel->id))));
 } else {
     if ($data->notification_type == "createquestion") {
         $questionModel = Question::model()->findByPk($data->pk_id);
         echo Yii::app()->user->id != $questionModel->create_user ? str_replace("你", CHtml::tag("img", array("style" => "margin:0 4px;", "height" => "20", "width" => "20", "src" => $this->createUrl("getimage", array("id" => $questionModel->create_user, "type" => "avatar")))) . CHtml::link(User::getNameById($questionModel->create_user), array("default/userinfo", 'user_id' => $questionModel->create_user), array('data-id' => $topicModel->create_user, 'class' => 'user-label', 'target' => '_blank')), $data->content) : $data->content;
         $this->widget('bootstrap.widgets.TbButton', array('type' => 'info', 'label' => strlen($questionModel->title) > 40 ? mb_substr($questionModel->title, 0, 40, 'utf-8') . '...' : $questionModel->title, 'type' => 'link', 'url' => $this->createUrl("question", array("id" => $questionModel->id))));
     } else {
         if ($data->notification_type == "answer" || $data->notification_type == "createanswer") {
             $answerModel = $data->notification_type == "createanswer" ? Answer::model()->findByPk($data->pk_id) : Answer::model()->findByPk(Comment::model()->findByPk($data->pk_id)->pk_id);
             $questionModel = Question::model()->findByPk($answerModel->question_id);
             echo Yii::app()->user->id != $questionModel->create_user ? str_replace("你", CHtml::tag("img", array("style" => "margin:0 4px;", "height" => "20", "width" => "20", "src" => $this->createUrl("getimage", array("id" => $questionModel->create_user, "type" => "avatar")))) . CHtml::link(User::getNameById($questionModel->create_user), array("default/userinfo", 'user_id' => $questionModel->create_user), array('data-id' => $questionModel->create_user, 'class' => 'user-label', 'style' => 'margin-right:10px;')), $data->content) : $data->content;
             $this->widget('bootstrap.widgets.TbButton', array('type' => 'info', 'label' => strlen($questionModel->title) > 40 ? mb_substr($questionModel->title, 0, 40, 'utf-8') . '...' : $questionModel->title, 'type' => 'link', 'url' => $this->createUrl("answer", array("id" => $answerModel->id))));
         } else {
             if ($data->notification_type == "createask") {
                 $requestModel = Request::model()->findByPk($data->pk_id);
                 $questionModel = Question::model()->findByPk($requestModel->question_id);
                 echo Yii::app()->user->id != $requestModel->to_user ? str_replace("你", CHtml::tag("img", array("style" => "margin:0 4px;", "height" => "20", "width" => "20", "src" => $this->createUrl("getimage", array("id" => $requestModel->to_user, "type" => "avatar")))) . CHtml::link(User::getNameById($requestModel->to_user), array("default/userinfo", 'user_id' => $requestModel->to_user), array('data-id' => $requestModel->to_user, 'class' => 'user-label', 'target' => '_blank')), $data->content) : $data->content;
                 $this->widget('bootstrap.widgets.TbButton', array('type' => 'info', 'label' => strlen($questionModel->title) > 40 ? mb_substr($questionModel->title, 0, 40, 'utf-8') . '...' : $questionModel->title, 'type' => 'link', 'url' => $this->createUrl("question", array("id" => $questionModel->id))));
             } else {
                 if ($data->notification_type == "question") {
                     $answerModel = Answer::model()->findByPk($data->pk_id);
                     $questionModel = Question::model()->findByPk($answerModel->question_id);
                     echo Yii::app()->user->id != $questionModel->create_user ? str_replace("你", CHtml::tag("img", array("style" => "margin:0 4px;", "height" => "20", "width" => "20", "src" => $this->createUrl("getimage", array("id" => $questionModel->create_user, "type" => "avatar")))) . CHtml::link(User::getNameById($questionModel->create_user), array("default/userinfo", 'user_id' => $questionModel->create_user), array('data-id' => $questionModel->create_user, 'class' => 'user-label', 'target' => '_blank')), $data->content) : $data->content;
                     $this->widget('bootstrap.widgets.TbButton', array('type' => 'info', 'label' => strlen($questionModel->title) > 40 ? mb_substr($questionModel->title, 0, 40, 'utf-8') . '...' : $questionModel->title, 'type' => 'link', 'url' => $this->createUrl("answer", array("id" => $answerModel->id))));
                 } else {
                     if ($data->notification_type == "comment") {
                         $commentModel = Comment::model()->findByPk($data->pk_id);
                         $parentModel = Comment::model()->findByPk($commentModel->parent_id);
                         $dataUrl = Yii::app()->controller->createUrl($commentModel->model, array("id" => $commentModel->pk_id, "pk_id" => $data->id));
                         echo Yii::app()->user->id == $parentModel->user_id ? str_replace("你", CHtml::tag("img", array("style" => "margin:0 4px;", "height" => "20", "width" => "20", "src" => $this->createUrl("getimage", array("id" => $parentModel->user_id, "type" => "avatar")))) . CHtml::link(User::getNameById($parentModel->user_id), array("default/userinfo", 'user_id' => $parentModel->user_id), array('data-id' => $parentModel->user_id, 'class' => 'user-label', 'target' => '_blank')), $data->content) : $data->content;
Example #17
0
 /**
  * @return int число для отображения в меню, заявок или ответов.
  */
 public function getNewRequestCount()
 {
     //return null;
     $time = $this->getLastRequestVisit();
     $ret = array(0, 0);
     //if ($this->gender == self::GENDER_MAN) { // количество откликов на текущую заявку
     if ($request = Request::model()->find('id_user = :id_user and isdeleted = 0', array(':id_user' => Yii::app()->user->id))) {
         $cnt = Request2anketa::model()->newer($time)->countByAttributes(array('id_request' => $request->id, 'status' => 1));
         $ret[1] = $cnt;
     }
     //} else { // количество новых заявок в этом городе для женщин
     $cnt = Request::model()->published()->byCity($this->city)->newer($this->getLastRequestVisit())->count();
     $ret[0] = $cnt;
     //}
     if ($ret[0] > 0 || $ret[1] > 0) {
         $ret = implode('/', $ret);
     } else {
         $ret = null;
     }
     return $ret;
 }
Example #18
0
 /**
  * 删除邀请
  */
 public function actionRemoverequest()
 {
     $login_user_id = Yii::app()->user->id;
     $request_id = $_POST["request_id"];
     $model = Request::model()->findByPk($request_id);
     if ($model != NULL) {
         if ($model->create_user == $login_user_id) {
             if ($model->delete_flag == 2 || $model->to_user == $login_user_id) {
                 Request::model()->deleteByPK($request_id);
             } else {
                 Request::model()->updateByPk($request_id, array("delete_flag" => 1));
             }
             $message = "ok";
         } else {
             if ($model->to_user == $login_user_id) {
                 if ($model->delete_flag == 1) {
                     Request::model()->deleteByPK($request_id);
                 } else {
                     Request::model()->updateByPk($request_id, array("delete_flag" => 2));
                 }
                 $message = "ok";
             } else {
                 $message = "false";
             }
         }
     } else {
         $message = "false";
     }
     $return = array('message' => $message);
     echo CJSON::encode($return);
     Yii::app()->end();
 }
 /**
  * Return de Details about an Order
  **/
 public function actionGetDetail($id)
 {
     $return = array();
     if ($id != '') {
         $request = Request::model()->findByPk($id);
         $models = OrderDetail::model()->findAll('request_id=:request_id', array(':request_id' => $id));
         foreach ($models as $item) {
             $temp['StockTime'] = $item->StockTime;
             $temp['ShipTime'] = $item->ShipTime;
             $temp['ManualQty'] = $item->ManualQty;
             $Items[] = Item::model()->findByPk($item->item_id);
             $params[] = $temp;
         }
         $reqDet = RequestDetail::getItemDetails($Items, $request->P1Start, $request->P1End, $request->P2Start, $request->P2End, $params);
         $return['success'] = true;
         // Agregar aca los mismos criterios de busqueda que se apliquen a findAll
         $return['totalCount'] = count($reqDet);
         //$models["totalCount"]; //Item::model()->count();//$criteria
         $return['orderDetails'] = $reqDet;
     } else {
         $return['success'] = false;
         $return['totalCount'] = 0;
         //$models["totalCount"]; //Item::model()->count();//$criteria
         $return['orderDetails'] = array();
     }
     echo CJSON::encode($return);
 }