Пример #1
0
 public function getSubscribers($obj = null, $action = 127, $delivery = 15)
 {
     if (is_null($obj)) {
         return array();
     }
     $cls = get_class($obj);
     switch ($cls) {
         case "Default_Model_Researcher":
             $type = 'app';
             break;
         case "Default_Model_Applciation":
             $type = 'ppl';
             break;
         default:
             return array();
     }
     $act = array();
     if (NewsEventType::has($action, NewsEventType::E_INSERT)) {
         $act[] = "insert";
     }
     if (NewsEventType::has($action, NewsEventType::E_UPDATE)) {
         $act[] = "update";
     }
     if (NewsEventType::has($action, NewsEventType::E_INSERT_COMMENT)) {
         $act[] = "insertcmm";
     }
     if (NewsEventType::has($action, NewsEventType::E_INSERT_CONTACT)) {
         $act[] = "insertcnt";
     }
     $subs = new Default_Model_MailSubscriptions();
     $subs->filter->type->equals($type)->and($subs->filter->events->hasbit($event))->and($subd->filter->delivery->hasbit($delivery));
     if ($subs->count() == 0) {
         return array();
     }
     $subs = $subs->items;
     foreach ($subs as $sub) {
         switch ($type) {
             case "app-entry":
                 $f = FilterParser::getApplications($sub->flt);
                 break;
             case "app":
                 $f = FilterParser::getApplications($sub->flt);
                 break;
             case "ppl":
                 $f = FilterParser::getPeople($sub->flt);
                 break;
         }
         $news = new Default_Model_AggregateNews();
         $nf = new Default_Model_AggregateNewsFilter();
         if (count($act) > 0) {
             for ($i = 0; $i < count($act); $i += 1) {
                 if (isset($a)) {
                     $a = $a->or($nf->action->equals(trim($act[$i])));
                 } else {
                     $a = $nf->action->equals(trim($act[$i]));
                 }
             }
             $news->filter = $news->filter->chain($nf, "AND");
         }
         $nf->subjecttype->equals(trim($type));
         $news->filter = $news->filter->chain($nf, "AND");
         $news->filter->orderBy('timestamp DESC');
         $news->refresh();
     }
     return array();
 }
Пример #2
0
 /**
  * @overrides delete from RestResource
  */
 public function delete()
 {
     if (parent::delete() !== false) {
         $bms = new Default_Model_MailSubscriptions();
         $appid = $this->getParam("appid");
         $bms->filter->flt->equals("=application.id:{$appid} application.id:SYSTAG_FOLLOW")->and($bms->filter->researcherid->equals($this->getParam("id")));
         if (count($bms->items) > 0) {
             $bm = $bms->items[0];
             $bms->remove($bm);
             $res = new RestAppItem(array("id" => $appid), $this);
             return $res->get();
         } else {
             $this->setError(RestErrorEnum::RE_ITEM_NOT_FOUND);
             return false;
         }
     } else {
         return false;
     }
 }