Example #1
0
 /**
  * ダッシュボード
  * @context OpenpearMaintainer $maintainer ログインしてるメンテナ
  * @context OpenpearCharge[] $my_package_charges
  * @context OpenpearTimeline[] $timelines
  * @context OpenpearFavorite[] $my_favorites
  * @context OpenpearMessage[] $notices
  */
 public function dashboard()
 {
     $this->vars('maintainer', $this->user());
     $this->vars('my_packages', C(OpenpearPackage)->find_all(Q::in('id', C(OpenpearCharge)->find_sub('package_id', Q::eq('maintainer_id', $this->user()->id()))), Q::order('-updated')));
     $this->vars('timelines', OpenpearTimeline::get_by_maintainer($this->user()));
     $this->vars('fav_packages', C(OpenpearPackage)->find_all(Q::in('id', C(OpenpearFavorite)->find_sub('package_id', Q::eq('maintainer_id', $this->user()->id()))), Q::order('-updated')));
     $this->vars('notices', C(OpenpearMessage)->find_all(Q::eq('maintainer_to_id', $this->user()->id()), Q::eq('type', 'system_notice'), Q::eq('unread', true)));
 }
Example #2
0
 public static function get_by_maintainer(OpenpearMaintainer $maintainer, $limit = 20)
 {
     try {
         $favorites = C(OpenpearFavorite)->find_all(Q::eq('maintainer_id', $maintainer->id()));
         $charges = C(OpenpearCharge)->find_all(Q::eq('maintainer_id', $maintainer->id()));
         $ids = array();
         foreach ($favorites as $f) {
             $ids[] = $f->package_id();
         }
         foreach ($charges as $c) {
             $ids[] = $c->package_id();
         }
         return C(OpenpearTimeline)->find_all(new Paginator($limit), Q::in('package_id', array_unique($ids)), Q::order('-id'));
     } catch (Exception $e) {
         return array();
     }
 }
Example #3
0
File: Dao.php Project: hisaboh/w2t
 /**
  * 検索結果をすべて取得する
  *
  * @return array Dao
  */
 public final function find_all()
 {
     $this->verify_class_access("call C(DAO_CLASS)->find_all()");
     $args = func_get_args();
     $result = array();
     $it = call_user_func_array(array($this, "find"), $args);
     $has_many_column = array();
     $is_has_many = !empty($this->_has_many_conds_);
     foreach ($it as $p) {
         if ($is_has_many) {
             foreach ($this->_has_many_conds_ as $name => $conds) {
                 $has_many_column[$name][] = $p->{$conds[2]}();
             }
         }
         $result[] = $p;
     }
     if ($is_has_many) {
         foreach ($this->_has_many_conds_ as $name => $conds) {
             foreach ($conds[0]->find(Q::in($conds[1], $has_many_column[$name])) as $dao) {
                 foreach ($result as $self_dao) {
                     if ($dao->{$conds[1]}() === $self_dao->{$conds[2]}()) {
                         $self_dao->{$name}($dao);
                     }
                 }
             }
         }
     }
     return $result;
     /***
     			# test
     			create_tmp_table("test_1","test_dao_find",array("id"=>"serial","value"=>"string","value2"=>"string","updated"=>"timestamp","order"=>"number"));
     			class TestDaoFind extends Dao{
     				static protected $__id__ = "type=serial";
     				static protected $__order__ = "type=number";
     				static protected $__updated__ = "type=timestamp";
     				protected $id;
     				protected $order;
     				protected $value;
     				protected $value2;
     				protected $updated;
     			}
     			R(new TestDaoFind("value=abc,updated=2008/12/24 10:00:00,order=4"))->save();
     			R(new TestDaoFind("value=def,updated=2008/12/24 10:00:00,order=3"))->save();
     			R(new TestDaoFind("value=ghi,updated=2008/12/24 10:00:00,order=1"))->save();
     			R(new TestDaoFind("value=jkl,updated=2008/12/24 10:00:00,order=2"))->save();
     			R(new TestDaoFind("value=aaa,updated=2008/12/24 10:00:00,order=2"))->save();
     
     			eq(5,sizeof(C(TestDaoFind)->find_all()));
     			foreach(C(TestDaoFind)->find(Q::eq("value","abc")) as $obj){
     				eq("abc",$obj->value());
     			}
     
     			$paginator = new Paginator(1,2);
     			eq(1,sizeof($result = C(TestDaoFind)->find_all(Q::neq("value","abc"),$paginator)));
     			eq("ghi",$result[0]->value());
     			eq(4,$paginator->total());
     
     			$i = 0;
     			foreach(C(TestDaoFind)->find(
     					Q::eq("value","abc"),
     					Q::or_block(
     						Q::eq("id",2),
     						Q::or_block(
     							Q::eq("value","ghi")
     						)
     					),
     					Q::neq("value","aaa")
     				) as $obj){
     				$i++;
     			}
     			eq(3,$i);
     
     			$list = array("abc","def","ghi","jkl","aaa");
     			$i = 0;
     			foreach(C(TestDaoFind)->find() as $obj){
     				eq($list[$i],$obj->value());
     				eq("2008/12/24 10:00:00",$obj->fmUpdated());
     				$i++;
     			}
     			foreach(C(TestDaoFind)->find(Q::eq("value","AbC",Q::IGNORE)) as $obj){
     				eq("abc",$obj->value());
     			}
     			foreach(C(TestDaoFind)->find(Q::neq("value","abc")) as $obj){
     				neq("abc",$obj->value());
     			}
     			try{
     				C(TestDaoFind)->find(Q::eq("value_error","abc"));
     				eq(false,true);
     			}catch(Exception $e){
     				eq(true,true);
     			}
     			try{
     				$dao = new TestDaoFind();
     				$dao->find(Q::eq("value_error","abc"));
     				eq(false,true);
     			}catch(Exception $e){
     				eq(true,true);
     			}
     
     			$i = 0;
     			foreach(C(TestDaoFind)->find(Q::startswith("value,value2",array("aa"))) as $obj){
     				$i++;
     				eq("aaa",$obj->value());
     			}
     			eq(1,$i);
     
     			$i = 0;
     			foreach(C(TestDaoFind)->find(Q::endswith("value,value2",array("c"))) as $obj){
     				eq("abc",$obj->value());
     				$i++;
     			}
     			eq(1,$i);
     
     			$i = 0;
     			foreach(C(TestDaoFind)->find(Q::contains("value,value2",array("b"))) as $obj){
     				eq("abc",$obj->value());
     				$i++;
     			}
     			eq(1,$i);
     
     			$i = 0;
     			foreach(C(TestDaoFind)->find(Q::endswith("value,value2",array("C"),Q::NOT|Q::IGNORE)) as $obj){
     				neq("abc",$obj->value());
     				$i++;
     			}
     			eq(4,$i);
     
     
     			$i = 0;
     			foreach(C(TestDaoFind)->find(Q::in("value",array("abc"))) as $obj){
     				eq("abc",$obj->value());
     				$i++;
     			}
     			eq(1,$i);
     
     			foreach(C(TestDaoFind)->find(Q::match("value=abc")) as $obj){
     				eq("abc",$obj->value());
     			}
     			foreach(C(TestDaoFind)->find(Q::match("value=!abc")) as $obj){
     				neq("abc",$obj->value());
     			}
     			foreach(C(TestDaoFind)->find(Q::match("abc")) as $obj){
     				eq("abc",$obj->value());
     			}
     			foreach(C(TestDaoFind)->find(Q::neq("value","abc"),new Paginator(1,3),Q::order("-id")) as $obj){
     				eq("ghi",$obj->value());
     			}
     			foreach(C(TestDaoFind)->find(Q::neq("value","abc"),new Paginator(1,3),Q::order("id")) as $obj){
     				eq("jkl",$obj->value());
     			}
     			foreach(C(TestDaoFind)->find(Q::neq("value","abc"),new Paginator(1,2),Q::order("order,-id")) as $obj){
     				eq("aaa",$obj->value());
     			}
     		 */
     /***
     			# ref_test
     			create_tmp_table("test_1","test_dao_find_ref_1",array("id1"=>"serial","value1"=>"string"));
     			create_tmp_table("test_1","test_dao_find_ref_2",array("id2"=>"serial","id1"=>"number","value2"=>"string"));
     			ACTIVE_TABLE("test_dao_find_ref_1","test_1","value1=aaa")->save();
     			ACTIVE_TABLE("test_dao_find_ref_2","test_1","id1=1,value2=bbb")->save();
     
     			class TestDaoFindRef2 extends Dao{
     				static protected $__id2__ = "type=serial";
     				static protected $__id1__ = "type=number";
     				static protected $__value1__ = "cond=id1(test_dao_find_ref_1.id1)";
     				protected $id2;
     				protected $id1;
     				protected $value1;
     			}
     			$result = C(TestDaoFindRef2)->find_all();
     			eq(1,sizeof($result));
     			eq("aaa",$result[0]->value1());
     
     			create_tmp_table("test_1","test_dao_find_ref_3",array("id3"=>"serial","id2"=>"number"));
     			ACTIVE_TABLE("test_dao_find_ref_3","test_1","id2=1")->save();
     
     			class TestDaoFindRef3 extends Dao{
     				static protected $__id3__ = "type=serial";
     				static protected $__id2__ = "type=number";
     				static protected $__value1__ = "cond=id2(test_dao_find_ref_2.id2, test_dao_find_ref_2.id1, test_dao_find_ref_1.id1)";
     				static protected $__value2__ = "cond=id2(test_dao_find_ref_2.id2)";
     				protected $id3;
     				protected $id2;
     				protected $value1;
     				protected $value2;
     			}
     			$result = C(TestDaoFindRef3)->find_all();
     			eq(1,sizeof($result));
     			eq("aaa",$result[0]->value1());
     			eq("bbb",$result[0]->value2());
     		*/
     /***
     			# has_test
     			create_tmp_table("test_1","test_dao_find_has_1",array("id1"=>"serial","value1"=>"string"));
     			create_tmp_table("test_1","test_dao_find_has_2",array("id2"=>"serial","id1"=>"number"));
     			ACTIVE_TABLE("test_dao_find_has_1","test_1","value1=aaa")->save();
     			ACTIVE_TABLE("test_dao_find_has_2","test_1","id1=1")->save();
     
     			class TestDaoFindHas1 extends Dao{
     				static protected $__id1__ = "type=serial";
     				protected $id1;
     				protected $value1;
     			}
     			class TestDaoFindHas2 extends Dao{
     				static protected $__id2__ = "type=serial";
     				static protected $__ref1__ = "type=TestDaoFindHas1,cond=id1()id1";
     				protected $id2;
     				protected $ref1;
     			}
     			$result = C(TestDaoFindHas2)->find_all();
     			eq(1,sizeof($result));
     			eq(true,$result[0]->ref1() instanceof TestDaoFindHas1);
     			eq("aaa",$result[0]->ref1()->value1());
     		 */
 }
Example #4
0
 /**
  * 活発なカテゴリを取得する
  * @param int $limit
  * @return array OpenpearTag[]
  **/
 public static function getActiveCategories($limit = 10)
 {
     $tag_ids_count = C(OpenpearPackageTag)->find_count_by('package_id', 'tag_id', Q::eq('prime', true));
     arsort($tag_ids_count);
     if (count($tag_ids_count) == 0) {
         $categories = array();
     } else {
         $categories = C(OpenpearTag)->find_all(Q::in('id', array_slice(array_keys($tag_ids_count), 0, $limit)));
     }
     return $categories;
 }
Example #5
0
 /**
  * メンテナのプロフィール
  * @param string $maintainer_name メンテナのアカウント名
  * @context OpenpearMaintainer $object メンテナ
  * @context OpenpearCharge[] $charges
  * @context OpenpearFavorite[] $favorites
  * @context OpenpearTimeline[] $timelines
  */
 public function maintainer_profile($maintainer_name)
 {
     try {
         $maintainer = C(OpenpearMaintainer)->find_get(Q::eq('name', $maintainer_name));
     } catch (NotfoundDaoException $e) {
         $this->not_found($e);
     } catch (Exception $e) {
         // 共通エラーに飛ばす
         throw $e;
     }
     $this->vars('object', $maintainer);
     $this->vars('packages', C(OpenpearPackage)->find_all(Q::in('id', C(OpenpearCharge)->find_sub('package_id', Q::eq('maintainer_id', $maintainer->id()))), Q::order('-updated')));
     $this->vars('fav_packages', C(OpenpearPackage)->find_all(Q::in('id', C(OpenpearFavorite)->find_sub('package_id', Q::eq('maintainer_id', $maintainer->id()))), Q::order('-updated')));
     $this->vars('timelines', C(OpenpearTimeline)->find_all(new Paginator(10), Q::eq('maintainer_id', $maintainer->id()), Q::order('-created')));
 }