コード例 #1
0
ファイル: ut_annotation.php プロジェクト: 119155012/kals
 function time2()
 {
     $id = 783;
     $text2 = '變項太多,這回歸的組合也不知道要排到什麼時候orz';
     $annotation = new Annotation(783);
     $this->unit->run($annotation->get_field('create_timestamp'), 'is_string', 'create_timestamp');
     $this->unit->run($annotation->get_field('update_timestamp'), 'is_string', 'update_timestamp');
     $this->unit->run_false(substr($annotation->get_field('create_timestamp'), 0, 19), substr($annotation->get_field('update_timestamp'), 0, 19), 'create_timestamp == update_timestamp');
     sleep(5);
     $annotation->set_note($text2);
     $annotation->update();
     $annotation->reload();
     $this->unit->run($annotation->get_field('create_timestamp'), 'is_string', 'create_timestamp');
     $this->unit->run($annotation->get_field('update_timestamp'), 'is_string', 'update_timestamp');
     $this->unit->run_false(substr($annotation->get_field('create_timestamp'), 0, 19), substr($annotation->get_field('update_timestamp'), 0, 19), 'create_timestamp != update_timestamp');
     context_complete();
     unit_test_report($this);
 }
コード例 #2
0
ファイル: image_spot.php プロジェクト: 119155012/kals
 /**
  *
  * @param Annotation $annotation
  * @param Object $data
  * @param String $callback
  */
 private function _setup_annotation(&$annotation, $data)
 {
     //$this->output->enable_profiler(TRUE);
     $url = $this->url;
     $user = $this->user;
     $auth = $this->authorize_manager;
     //設定標註細節
     //test_msg('設定標註細節');
     //type
     if (isset($data->type)) {
         if (is_string($data->type)) {
             $data->type = trim($data->type);
             if ($data->type !== '') {
                 $data->type = urldecode($data->type);
             } else {
                 //如果是空白的話,則視為自訂
                 $data->type = 7;
             }
         }
         $annotation->set_type($data->type);
     }
     //note
     if (isset($data->note) && $data->note != '') {
         $note = $data->note;
         if (is_string($note)) {
             $note = urldecode($note);
         }
         $annotation->set_note($note);
     } else {
         $note = $annotation->get_note();
         if (isset($note) && $note !== '') {
             $annotation->set_note(NULL);
         }
     }
     if (isset($data->image_spot_position)) {
         //test_msg("image_spot_position");
         $annotation->set_feature_image_spot_position($data->image_spot_position);
         //test_msg("image_spot_position 完成");
     }
     //        //設定respond
     //        //test_msg('設定respond');
     //topic
     //            if (isset($data->topic))
     //            {
     //                //理論上topic只會有一個,並設定他的ID
     //                $topic_id = $data->topic->annotation_id;
     //                $annotation->set_respond_to_topic($topic_id);
     //            }
     //
     //            //respond_coll
     //            if (isset($data->respond_to_coll))
     //            {
     //                $respond_to_annotations = array();
     //                foreach ($data->respond_to_coll AS $respond_to)
     //                {
     //                    $respond_to_annotation_id = $respond_to->annotation_id;
     //                    $respond_to_annotation = new Annotation($respond_to_annotation_id);
     //                    $respond_to_annotations[] = $respond_to_annotation;
     //                }
     //                $annotation->set_respond_to_coll($respond_to_annotations);
     //            }
     //-----------------------
     //設定policy
     //test_msg('設定policy');
     $policy_type = 1;
     if (isset($data->policy_type)) {
         $policy_type = $data->policy_type;
     }
     // 1    public
     // 2    private    private特別是指只有自己能閱讀
     // 3    share
     $share_user_coll = NULL;
     if ($policy_type === 1) {
         //什麼都不用作
     } else {
         if ($policy_type === 2) {
             $share_user_coll = array($user);
         } else {
             if ($policy_type === 3) {
                 $share_list = $data->share_list;
                 $share_user_coll = array();
                 foreach ($share_list as $share_user_data) {
                     $share_user_id = $share_user_data->id;
                     $share_user = new User($share_user_id);
                     array_push($share_user_coll, $share_user);
                 }
             }
         }
     }
     $this->load->library('policy/Authorize_manager');
     $ACTION_ANNOTATION_READ = 5;
     $auth->set_resource($annotation);
     if (is_array($share_user_coll)) {
         foreach ($share_user_coll as $share_user) {
             //在這邊為該$annotation設定policy readable
             $auth->policy_add_actor($ACTION_ANNOTATION_READ, $share_user);
         }
     } else {
         //清除該$annotation的policy
         $auth->policy_remove_actor($ACTION_ANNOTATION_READ);
     }
     //-------------------
     //回傳標註建立的ID跟timestamp
     //test_msg("更新前");
     $annotation->update();
     //test_msg("更新後");
     $return_data = array('annotation_id' => $annotation->get_id(), 'timestamp' => $annotation->get_update_epoch(), 'nav' => $this->annotation_getter->parse_navigation_level($annotation->get_score(0)->get_score()));
     /*
     else
     {
         $topic_annotation = $annotation->get_topic();
         $this->_setup_scores_recommend($topic_annotation);
     }
     */
     set_ignore_authorize(false);
     // 寫入資料庫
     context_complete();
     return $return_data;
 }