diff --git a/application/modules/default/models/Tags.php b/application/modules/default/models/Tags.php index 71fc587f1..2fac60024 100644 --- a/application/modules/default/models/Tags.php +++ b/application/modules/default/models/Tags.php @@ -1,765 +1,940 @@ . * * Created: 11.09.2017 */ class Default_Model_Tags { const TAG_TYPE_PROJECT = 1; const TAG_TYPE_MEMBER = 2; const TAG_TYPE_FILE = 3; const TAG_USER_GROUPID = 5; const TAG_CATEGORY_GROUPID = 6; const TAG_LICENSE_GROUPID = 7; const TAG_PACKAGETYPE_GROUPID = 8; const TAG_ARCHITECTURE_GROUPID = 9; const TAG_GHNS_EXCLUDED_GROUPID = 10; const TAG_PRODUCT_ORIGINAL_GROUPID = 11; const TAG_PRODUCT_ORIGINAL_ID = 2451; + + const TAG_PRODUCT_EBOOK_GROUPID = 14; + const TAG_PRODUCT_EBOOK_AUTHOR_GROUPID = 15; + const TAG_PRODUCT_EBOOK_EDITOR_GROUPID = 16; + const TAG_PRODUCT_EBOOK_ILLUSTRATOR_GROUPID = 17; + const TAG_PRODUCT_EBOOK_TRANSLATOR_GROUPID = 18; + const TAG_PRODUCT_EBOOK_SUBJECT_GROUPID = 19; + const TAG_PRODUCT_EBOOK_SHELF_GROUPID = 20; + const TAG_PRODUCT_EBOOK_LANGUAGE_GROUPID = 21; + const TAG_PRODUCT_EBOOK_TYPE_GROUPID = 22; + + + + const TAG_PRODUCT_EBOOK_ID = 2532; const TAG_PROJECT_GROUP_IDS = '6,7,10';//type product : category-tags, license-tags,ghns_excluded const TAG_FILE_GROUP_IDS = '8,9';//file-packagetype-tags,file-architecture-tags // $tag_project_group_ids ='6,7,10'; // $tag_file_group_ids ='8,9'; /** * Default_Model_Tags constructor. */ public function __construct() { } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function processTags($object_id, $tags, $tag_type) { $this->assignTags($object_id, $tags, $tag_type); $this->deassignTags($object_id, $tags, $tag_type); } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function assignTags($object_id, $tags, $tag_type) { $new_tags = array_diff(explode(',', $tags), explode(',', $this->getTags($object_id, $tag_type))); $tableTags = new Default_Model_DbTable_Tags(); $listIds = $tableTags->storeTags(implode(',', $new_tags)); $prepared_insert = array_map(function ($id) use ($object_id, $tag_type) { return "({$id}, {$tag_type}, {$object_id})"; }, $listIds); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTags($object_id, $tag_type) { $sql = " SELECT GROUP_CONCAT(tag.tag_name) AS tag_names FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id join tag_group_item on tag_object.tag_id = tag_group_item.tag_id WHERE tag_type_id = :type AND tag_object_id = :object_id and tag_group_item.tag_group_id <> :tag_user_groupid and tag_object.is_deleted = 0 GROUP BY tag_object.tag_object_id "; $result = $this->getAdapter()->fetchRow($sql, array('type' => $tag_type, 'object_id' => $object_id, 'tag_user_groupid' =>Default_Model_Tags::TAG_USER_GROUPID )); if (isset($result['tag_names'])) { return $result['tag_names']; } return null; } /** * @param int $object_id * @param int $tag_type * @param String $tag_group_ids * * @return string|null */ public function getTagsArray($object_id, $tag_type,$tag_group_ids) { $sql = " - SELECT tag.tag_id,tag.tag_name,tag_group_item.tag_group_id + SELECT tag.tag_id,tag.tag_name,tag_group_item.tag_group_id,tag.tag_fullname FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id join tag_group_item on tag_object.tag_id = tag_group_item.tag_id and tag_object.tag_group_id = tag_group_item.tag_group_id WHERE tag_type_id = :type AND tag_object_id = :object_id and tag_object.tag_group_id in ({$tag_group_ids} ) and tag_object.is_deleted = 0 order by tag_group_item.tag_group_id desc , tag.tag_name asc "; $result = $this->getAdapter()->fetchAll($sql, array('type' => $tag_type, 'object_id' => $object_id)); return $result; } + /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsUser($object_id, $tag_type) { $tag_group_ids =$this::TAG_USER_GROUPID; $tags = $this->getTagsArray($object_id, $tag_type,$tag_group_ids); $tag_names = ''; foreach ($tags as $tag) { $tag_names=$tag_names.$tag['tag_name'].','; } $len = strlen($tag_names); if ($len>0) { return substr($tag_names,0,($len-1)); } return null; } /** * @param int $projectid * @param int $tag * * @return string|null */ public function isTagsUserExisting($project_id, $tagname) { $sql_object= "select count(1) as cnt from tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :tagname and tag_object.tag_group_id=:tag_group_id and tag_object.is_deleted=0 and tag_object.tag_object_id=:project_id and tag_object.tag_type_id=:tag_type_id"; $r = $this->getAdapter()->fetchRow($sql_object, array( 'tagname' => $tagname ,'tag_group_id'=>Default_Model_Tags::TAG_USER_GROUPID , 'project_id'=>$project_id , 'tag_type_id'=>Default_Model_Tags::TAG_TYPE_PROJECT )); if($r['cnt'] ==0){ return false; }else{ return true; } } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsCategory($object_id, $tag_type) { $tag_group_ids = $this::TAG_CATEGORY_GROUPID; $tags = $this->getTagsArray($object_id, $tag_type,$tag_group_ids); $tag_names = ''; foreach ($tags as $tag) { $tag_names=$tag_names.$tag['tag_name'].','; } $len = strlen($tag_names); if ($len>0) { return substr($tag_names,0,($len-1)); } return null; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsSystem($object_id, $tag_type) { $tag_group_ids ='6,7,10'; $tags = $this->getTagsArray($object_id, $tag_type,$tag_group_ids); $tag_names = ''; foreach ($tags as $tag) { $tag_names=$tag_names.$tag['tag_name'].','; } $len = strlen($tag_names); if ($len>0) { return substr($tag_names,0,($len-1)); } return null; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsSystemList($project_id) { $tag_project_group_ids = SELF::TAG_PROJECT_GROUP_IDS; $tag_file_group_ids = SELF::TAG_FILE_GROUP_IDS; $sql =" SELECT tag.tag_id,tag.tag_name,tag_object.tag_group_id FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag_type_id = :type_project AND tag_object_id = :project_id and tag_object.tag_group_id in ({$tag_project_group_ids} ) and tag_object.is_deleted = 0 union all SELECT distinct t.tag_id,t.tag_name,o.tag_group_id FROM tag_object o JOIN tag t ON t.tag_id = o.tag_id inner join project p on o.tag_parent_object_id = p.project_id inner join ppload.ppload_files f on p.ppload_collection_id = f.collection_id and o.tag_object_id=f.id and f.active = 1 WHERE o.tag_type_id = :type_file AND p.project_id = :project_id and o.tag_group_id in ({$tag_file_group_ids} ) and o.is_deleted = 0 order by tag_group_id , tag_name "; $result = $this->getAdapter()->fetchAll($sql, array('type_project' => Default_Model_Tags::TAG_TYPE_PROJECT , 'project_id' => $project_id , 'type_file' => Default_Model_Tags::TAG_TYPE_FILE )); return $result; } /** * @param int $object_id * @param int $tag_type * * @return string|null */ public function getTagsUserCount($object_id, $tag_type) { $sql = " SELECT count(*) as cnt FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id join tag_group_item on tag_object.tag_id = tag_group_item.tag_id and tag_object.tag_group_id = tag_group_item.tag_group_id WHERE tag_type_id = :type AND tag_object_id = :object_id and tag_object.is_deleted = 0 and tag_group_item.tag_group_id = :tag_user_groupid "; $result = $this->getAdapter()->fetchRow($sql, array('type' => $tag_type, 'object_id' => $object_id, 'tag_user_groupid' =>Default_Model_Tags::TAG_USER_GROUPID )); if (isset($result['cnt'])) { return $result['cnt']; } return 0; } public function filterTagsUser($filter, $limit) { $sql = " select tag.tag_id ,tag.tag_name from tag join tag_group_item on tag.tag_id = tag_group_item.tag_id and tag_group_item.tag_group_id = :tag_user_groupid where tag.tag_name like '%".$filter."%' "; if (isset($limit)) { $sql.= ' limit ' . $limit; } $result = $this->getAdapter()->fetchAll($sql, array('tag_user_groupid' =>Default_Model_Tags::TAG_USER_GROUPID )); return $result; } /** * @return Zend_Db_Adapter_Abstract */ private function getAdapter() { return Zend_Db_Table::getDefaultAdapter(); } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function deassignTags($object_id, $tags, $tag_type) { $removable_tags = array_diff(explode(',', $this->getTags($object_id, $tag_type)), explode(',', $tags)); //$sql = "DELETE tag_object FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id SET tag_changed = NOW() , is_deleted = 1 WHERE tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $this->getAdapter()->query($sql, array('tagObjectId' => $object_id, 'tagType' => $tag_type)); foreach ($removable_tags as $removable_tag) { $this->getAdapter()->query($sql, array('name' => $removable_tag,'object_id' => $object_id)); } $this->updateChanged($object_id, $tag_type); } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function processTagsUser($object_id, $tags, $tag_type) { if($tags) { $this->assignTagsUser($object_id, $tags, $tag_type); } $this->deassignTagsUser($object_id, $tags, $tag_type); } public function isProuductOriginal($project_id) { $sql_object= "select tag_item_id from tag_object WHERE tag_id = :tag_id and tag_object_id=:tag_object_id and tag_group_id=:tag_group_id and tag_type_id = :tag_type_id and is_deleted = 0"; $r = $this->getAdapter()->fetchRow($sql_object, array('tag_id' => self::TAG_PRODUCT_ORIGINAL_ID, 'tag_object_id' =>$project_id, 'tag_group_id' => self::TAG_PRODUCT_ORIGINAL_GROUPID, 'tag_type_id' => self::TAG_TYPE_PROJECT )); if($r){ return true; }else { return false; } } + + + public function isProuductEbook($project_id) + { + $sql_object= "select tag_item_id from tag_object WHERE tag_id = :tag_id and tag_object_id=:tag_object_id and tag_group_id=:tag_group_id + and tag_type_id = :tag_type_id and is_deleted = 0"; + $r = $this->getAdapter()->fetchRow($sql_object, array('tag_id' => self::TAG_PRODUCT_EBOOK_ID, + 'tag_object_id' =>$project_id, + 'tag_group_id' => self::TAG_PRODUCT_EBOOK_GROUPID, + 'tag_type_id' => self::TAG_TYPE_PROJECT + )); + if($r){ + return true; + }else + { + return false; + } + } /** * @param int $object_id * @param string $value */ public function processTagProductOriginal($object_id, $is_original) { $sql_object= "select tag_item_id from tag_object WHERE tag_id = :tag_id and tag_object_id=:tag_object_id and tag_group_id=:tag_group_id and tag_type_id = :tag_type_id and is_deleted = 0"; $r = $this->getAdapter()->fetchRow($sql_object, array('tag_id' => self::TAG_PRODUCT_ORIGINAL_ID, 'tag_object_id' =>$object_id, 'tag_group_id' => self::TAG_PRODUCT_ORIGINAL_GROUPID, 'tag_type_id' => self::TAG_TYPE_PROJECT )); if($is_original=='1') { if(!$r){ $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => self::TAG_PRODUCT_ORIGINAL_ID, 'tag_type_id' => self::TAG_TYPE_PROJECT , 'tag_object_id' => $object_id, 'tag_group_id' => self::TAG_PRODUCT_ORIGINAL_GROUPID)); } }else{ if($r){ $sql = "UPDATE tag_object set tag_changed = NOW() , is_deleted = 1 WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $r['tag_item_id'])); } } } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function assignTagsUser($object_id, $tags, $tag_type) { $tags = strtolower($tags); $tag_group_id = 5; $new_tags = array_diff(explode(',', $tags), explode(',', $this->getTagsUser($object_id, $tag_type))); if(sizeof($new_tags)>0) { $tableTags = new Default_Model_DbTable_Tags(); $listIds = $tableTags->storeTagsUser(implode(',', $new_tags)); $prepared_insert = array_map(function ($id) use ($object_id, $tag_type,$tag_group_id) { return "({$id}, {$tag_type}, {$object_id},{$tag_group_id})"; }, $listIds); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id,tag_group_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } } /** * @param int $object_id * @param string $tags * @param int $tag_type */ public function addTagUser($object_id, $tag, $tag_type) { $tableTags = new Default_Model_DbTable_Tags(); $listIds = $tableTags->storeTagsUser($tag); $tag_group_id = $this::TAG_USER_GROUPID; $prepared_insert = array_map(function ($id) use ($object_id, $tag_type,$tag_group_id) { return "({$id}, {$tag_type}, {$object_id},{$tag_group_id})"; }, $listIds); $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id,tag_group_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } public function deassignTagsUser($object_id, $tags, $tag_type) { if($tags) { $tags = strtolower($tags); $removable_tags = array_diff(explode(',', $this->getTagsUser($object_id, $tag_type)), explode(',', $tags)); } else { $removable_tags = explode(',', $this->getTagsUser($object_id, $tag_type)); } //$sql = "DELETE tag_object FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id"; foreach ($removable_tags as $removable_tag) { $this->getAdapter()->query($sql, array('name' => $removable_tag,'object_id' => $object_id)); // if Tag is the only one in Tag_object table then delete this tag for user_groupid = 5 $sql_object= "select count(1) as cnt from tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :name"; $r = $this->getAdapter()->fetchRow($sql_object, array('name' => $removable_tag)); if($r['cnt'] ==0){ // then remove tag if not existing in Tag_object $sql_delete_tag = "delete from tag where tag_name=:name"; $this->getAdapter()->query($sql_delete_tag, array('name' => $removable_tag)); } } $this->updateChanged($object_id, $tag_type); } public function deleteTagUser($object_id, $tag, $tag_type) { $removable_tag =$tag; // $sql = "DELETE tag_object FROM tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id // and tag_group_id =".Default_Model_Tags::TAG_USER_GROUPID; $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = ".Default_Model_Tags::TAG_USER_GROUPID." and tag.tag_name = :name and tag_object.tag_object_id=:object_id"; $this->getAdapter()->query($sql, array('name' => $removable_tag,'object_id' => $object_id)); // if Tag is the only one in Tag_object table then delete this tag for user_groupid = 5 $sql_object= "select count(1) as cnt from tag_object JOIN tag ON tag.tag_id = tag_object.tag_id WHERE tag.tag_name = :name "; $r = $this->getAdapter()->fetchRow($sql_object, array('name' => $removable_tag)); if($r['cnt'] ==0){ // then remove tag if not existing in Tag_object $sql_delete_tag = "delete from tag where tag_name=:name"; $this->getAdapter()->query($sql_delete_tag, array('name' => $removable_tag)); } $this->updateChanged($object_id, $tag_type); } private function updateChanged($object_id, $tag_type) { $sql = "UPDATE tag_object SET tag_changed = NOW() WHERE tag_object_id = :tagObjectId AND tag_type_id = :tagType"; $this->getAdapter()->query($sql, array('tagObjectId' => $object_id, 'tagType' => $tag_type)); } public function getTagsPerCategory($cat_id) { $sql = "select t.* from category_tag as c ,tag as t where c.tag_id = t.tag_id and c.category_id = :cat_id"; $r = $this->getAdapter()->fetchAll($sql, array('cat_id' => $cat_id)); return $r; } public function updateTagsPerCategory($cat_id,$tags) { $sql = "delete from category_tag where category_id=:cat_id"; $this->getAdapter()->query($sql, array('cat_id' => $cat_id)); if($tags){ $tags_id =explode(',', $tags); $prepared_insert = array_map(function ($id) use ($cat_id) { return "({$cat_id},{$id})"; }, $tags_id); $sql = "INSERT IGNORE INTO category_tag (category_id, tag_id) VALUES " . implode(',', $prepared_insert); $this->getAdapter()->query($sql); } } public function getTagsPerGroup($groupid) { $sql = " select tag.tag_id ,tag.tag_name from tag join tag_group_item on tag.tag_id = tag_group_item.tag_id and tag_group_item.tag_group_id = :groupid order by tag_name "; $result = $this->getAdapter()->fetchAll($sql, array('groupid' => $groupid)); return $result; } public function saveLicenseTagForProject($object_id, $tag_id) { $tableTags = new Default_Model_DbTable_Tags(); $tags = $tableTags->fetchLicenseTagsForProject($object_id); if(count($tags) ==0){ //insert new tag if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_LICENSE_GROUPID)); } }else { $tag = $tags[0]; //remove tag license if(!$tag_id) { //$sql = "DELETE FROM tag_object WHERE tag_item_id = :tagItemId"; $sql = "UPDATE tag_object set tag_changed = NOW() , is_deleted = 1 WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'])); } else { //Update old tag if($tag_id <> $tag['tag_id']) { $sql = "UPDATE tag_object SET tag_changed = NOW(),tag_id = :tag_id WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'], 'tag_id' => $tag_id)); } } } // if(count($tags) >= 1) { // $tag = $tags[0]; // //remove tag license // if(!$tag_id) { // //$sql = "DELETE FROM tag_object WHERE tag_item_id = :tagItemId"; // $sql = "UPDATE tag_object set tag_changed = NOW() , is_deleted = 1 WHERE tag_item_id = :tagItemId"; // $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'])); // } else { // //Update old tag // if($tag_id <> $tag['tag_id']) { // $sql = "UPDATE tag_object SET tag_changed = NOW(),tag_id = :tag_id WHERE tag_item_id = :tagItemId"; // $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'], 'tag_id' => $tag_id)); // } // } // } else { // //insert new tag // if($tag_id) { // $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; // $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_LICENSE_GROUPID)); // } // } } public function saveGhnsExcludedTagForProject($object_id, $tag_value) { $tableTags = new Default_Model_DbTable_Tags(); $ghnsExcludedTagId = $tableTags->fetchGhnsExcludedTagId(); $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_GHNS_EXCLUDED_GROUPID, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id)); if($tag_value == 1) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $ghnsExcludedTagId, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_GHNS_EXCLUDED_GROUPID)); } } public function saveArchitectureTagForProject($project_id, $file_id, $tag_id) { //first delte old //$sql = "DELETE FROM tag_object WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id)); if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_parent_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_parent_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id, 'tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID)); } /** $tableTags = new Default_Model_DbTable_Tags(); $tags = $tableTags->fetchArchitectureTagsForProject($object_id); if(count($tags) == 1) { $tag = $tags[0]; //remove tag license if(!$tag_id) { $sql = "DELETE FROM tag_object WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'])); } else { //Update old tag if($tag_id <> $tag['tag_id']) { $sql = "UPDATE tag_object SET tag_changed = NOW(),tag_id = :tag_id WHERE tag_item_id = :tagItemId"; $this->getAdapter()->query($sql, array('tagItemId' => $tag['tag_item_id'], 'tag_id' => $tag_id)); } } } else { //insert new tag if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_PROJECT, 'tag_object_id' => $object_id, 'tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID)); } } * */ } public function savePackagetypeTagForProject($project_id, $file_id, $tag_id) { //first delte old $sql = "UPDATE tag_object SET tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id AND tag_type_id = :tag_type_id AND tag_object_id = :tag_object_id AND tag_parent_object_id = :tag_parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id)); if($tag_id) { $sql = "INSERT IGNORE INTO tag_object (tag_id, tag_type_id, tag_object_id, tag_parent_object_id, tag_group_id) VALUES (:tag_id, :tag_type_id, :tag_object_id, :tag_parent_object_id, :tag_group_id)"; $this->getAdapter()->query($sql, array('tag_id' => $tag_id, 'tag_type_id' => $this::TAG_TYPE_FILE, 'tag_object_id' => $file_id, 'tag_parent_object_id' => $project_id, 'tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID)); } } public function getProjectPackageTypesString($projectId) { $sql = 'SELECT DISTINCT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID,'project_id' => $projectId)); $resultString = ''; if (count($resultSet) > 0) { foreach ($resultSet as $item) { $resultString = $resultString . ' ' . stripslashes($item['name']) . ''; } return $resultString; } return ''; } public function getProjectPackageTypesPureStrings($projectId) { $sql = 'SELECT DISTINCT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID,'project_id' => $projectId)); $resultString = ''; if (count($resultSet) > 0) { foreach ($resultSet as $item) { $resultString = $resultString .' '. stripslashes($item['name']) ; } return $resultString; } return ''; } public function deleteFileTagsOnProject($projectId, $fileId) { $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_type_id = :tag_type_id and tag_object.tag_object_id=:object_id and tag_object.tag_parent_object_id=:parent_object_id"; $this->getAdapter()->query($sql, array('tag_type_id' => $this::TAG_TYPE_FILE, 'object_id' => $fileId, 'parent_object_id' => $projectId)); } public function deletePackageTypeOnProject($projectId, $fileId) { $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id and tag_object.tag_object_id=:object_id and tag_object.tag_parent_object_id=:parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID, 'object_id' => $fileId, 'parent_object_id' => $projectId)); } public function deleteArchitectureOnProject($projectId, $fileId) { $sql = "UPDATE tag_object inner join tag ON tag.tag_id = tag_object.tag_id set tag_changed = NOW() , is_deleted = 1 WHERE tag_group_id = :tag_group_id and tag_object.tag_object_id=:object_id and tag_object.tag_parent_object_id=:parent_object_id"; $this->getAdapter()->query($sql, array('tag_group_id' => $this::TAG_ARCHITECTURE_GROUPID, 'object_id' => $fileId, 'parent_object_id' => $projectId)); } /** * @param int $projectId * @param int $fileId * @return string */ public function getPackageType($projectId, $fileId) { $sql = 'SELECT ta.tag_fullname as name FROM tag_object t INNER JOIN tag ta on ta.tag_id = t.tag_id WHERE t.tag_group_id = :tag_group_id AND t.tag_parent_object_id = :project_id AND t.tag_object_id = :file_id AND t.is_deleted = 0'; $resultSet = $this->getAdapter()->fetchAll($sql, array('tag_group_id' => $this::TAG_PACKAGETYPE_GROUPID,'project_id' => $projectId, 'file_id' => $fileId)); if (count($resultSet) > 0) { return $resultSet[0]['name']; } else { return ''; } } + + + /** + * @param int $object_id + * + * @return string|null + */ + public function getTagsEbookSubject($object_id) + { + $tag_group_ids =$this::TAG_PRODUCT_EBOOK_SUBJECT_GROUPID; + $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); + + $tag_names = array(); + foreach ($tags as $tag) { + $tag_names[]=$tag['tag_fullname']; + } + return $tag_names; + } + + /** + * @param int $object_id + * + * @return string|null + */ + public function getTagsEbookAuthor($object_id) + { + $tag_group_ids =$this::TAG_PRODUCT_EBOOK_AUTHOR_GROUPID; + $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); + + $tag_names = array(); + foreach ($tags as $tag) { + $tag_names[]=$tag['tag_fullname']; + } + return $tag_names; + } + + + /** + * @param int $object_id + * + * @return string|null + */ + public function getTagsEbookEditor($object_id) + { + $tag_group_ids =$this::TAG_PRODUCT_EBOOK_EDITOR_GROUPID; + $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); + + $tag_names = array(); + foreach ($tags as $tag) { + $tag_names[]=$tag['tag_fullname']; + } + return $tag_names; + } + + + /** + * @param int $object_id + * + * @return string|null + */ + public function getTagsEbookIllustrator($object_id) + { + $tag_group_ids =$this::TAG_PRODUCT_EBOOK_ILLUSTRATOR_GROUPID; + $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); + + $tag_names = array(); + foreach ($tags as $tag) { + $tag_names[]=$tag['tag_fullname']; + } + return $tag_names; + } + + + /** + * @param int $object_id + * + * @return string|null + */ + public function getTagsEbookTranslator($object_id) + { + $tag_group_ids =$this::TAG_PRODUCT_EBOOK_TRANSLATOR_GROUPID; + $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); + $tag_names = array(); + foreach ($tags as $tag) { + $tag_names[]=$tag['tag_fullname']; + } + return $tag_names; + } + + + /** + * @param int $object_id + * + * @return string|null + */ + public function getTagsEbookShelf($object_id) + { + $tag_group_ids =$this::TAG_PRODUCT_EBOOK_SHELF_GROUPID; + $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); + + $tag_names = array(); + foreach ($tags as $tag) { + $tag_names[]=$tag['tag_fullname']; + } + return $tag_names; + } + + + /** + * @param int $object_id + * + * @return string|null + */ + public function getTagsEbookLanguage($object_id) + { + $tag_group_ids =$this::TAG_PRODUCT_EBOOK_LANGUAGE_GROUPID; + $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); + + $tag_names = array(); + foreach ($tags as $tag) { + $tag_names[]=$tag['tag_fullname']; + } + return $tag_names; + } + + + /** + * @param int $object_id + * + * @return string|null + */ + public function getTagsEbookType($object_id) + { + $tag_group_ids =$this::TAG_PRODUCT_EBOOK_TYPE_GROUPID; + $tags = $this->getTagsArray($object_id, $this::TAG_TYPE_PROJECT,$tag_group_ids); + + $tag_names = array(); + foreach ($tags as $tag) { + $tag_names[]=$tag['tag_fullname']; + } + return $tag_names; + } } \ No newline at end of file diff --git a/application/modules/default/views/helpers/IsProjectEbook.php b/application/modules/default/views/helpers/IsProjectEbook.php new file mode 100755 index 000000000..5ff105d2f --- /dev/null +++ b/application/modules/default/views/helpers/IsProjectEbook.php @@ -0,0 +1,36 @@ +. + **/ + +class Default_View_Helper_IsProjectEbook extends Zend_View_Helper_Abstract +{ + + /** + * @param int $project_id + * @return bool + */ + public function isProjectEbook($project_id) + { + $model = new Default_Model_Tags(); + return $model->isProuductEbook($project_id); + } + +} \ No newline at end of file diff --git a/application/modules/default/views/scripts/product/index.phtml b/application/modules/default/views/scripts/product/index.phtml index 6cba4f1dc..c6b0b5992 100644 --- a/application/modules/default/views/scripts/product/index.phtml +++ b/application/modules/default/views/scripts/product/index.phtml @@ -1,1047 +1,1163 @@ . **/ $helpAddDefaultScheme = new Default_View_Helper_AddDefaultScheme(); $helpMemberUrl = new Default_View_Helper_BuildMemberUrl(); $helpEncryptUrl = new Default_View_Helper_EncryptUrl(); $helpImage = new Default_View_Helper_Image(); $helpTruncate = new Default_View_Helper_Truncate(); $helpProductUrl = new Default_View_Helper_BuildProductUrl(); $helpBBCode = new Default_View_Helper_Bbcode2html(); $identity = Zend_Auth::getInstance()->getStorage()->read(); $loginUrl = '/login?redirect=' . $helpEncryptUrl->encryptUrl(Zend_Controller_Front::getInstance()->getRequest() ->getRequestUri(), true); $viewSidebar = 'product/partials/productAboutSidebar.phtml'; $viewClaimBox = false; if ($this->product->claimable == 1) { $viewClaimBox = 'product/partials/productClaimTopHeader.phtml'; } $helpProjectFiles = new Default_View_Helper_ProjectFiles(); $productFileInfos = $helpProjectFiles->projectFiles($this->product->ppload_collection_id); $this->product->title = Default_Model_HtmlPurify::purify($this->product->title); $this->product->description = Default_Model_BBCode::renderHtml(Default_Model_HtmlPurify::purify($this->product->description)); $this->product->version = Default_Model_HtmlPurify::purify($this->product->version); //$this->product->embed_code =Default_Model_HtmlPurify::purify($this->product->embed_code,Default_Model_HtmlPurify::ALLOW_EMBED); $this->product->link_1 = Default_Model_HtmlPurify::purify($helpAddDefaultScheme->addDefaultScheme($this->product->link_1),Default_Model_HtmlPurify::ALLOW_URL); $this->product->source_url = Default_Model_HtmlPurify::purify($this->product->source_url,Default_Model_HtmlPurify::ALLOW_URL); $this->product->facebook_code = Default_Model_HtmlPurify::purify($this->product->facebook_code,Default_Model_HtmlPurify::ALLOW_URL); $this->product->twitter_code = Default_Model_HtmlPurify::purify($this->product->twitter_code,Default_Model_HtmlPurify::ALLOW_URL); $this->product->google_code = Default_Model_HtmlPurify::purify($this->product->google_code,Default_Model_HtmlPurify::ALLOW_URL); $this->headTitle($this->product->title . ' - ' . $_SERVER['HTTP_HOST'], 'SET'); $this->doctype(Zend_View_Helper_Doctype::XHTML1_RDFA); $this->headMeta()->setName('description', $helpTruncate->truncate($this->product->description, 200, '...', false, true)); $this->headMeta()->setName('title', $helpTruncate->truncate($this->product->title, 200, '...', false, true)); $this->headMeta()->appendProperty('og:url', $helpProductUrl->buildProductUrl($this->product->project_id, '', null, true)); $this->headMeta()->appendProperty('og:type', 'website'); $this->headMeta()->appendProperty('og:title', $this->product->title); $this->headMeta()->appendProperty('og:description', $helpTruncate->truncate($this->product->description, 200, '...', false, true)); $this->headMeta()->appendProperty('og:image', $helpImage->Image($this->product->image_small, array('width' => 400, 'height' => 400))); $tableProject = new Default_Model_Project(); $tableProjectUpdates = new Default_Model_ProjectUpdates(); $this->updates = $tableProjectUpdates->fetchProjectUpdates($this->product->project_id); $tableProjectRatings = new Default_Model_DbTable_ProjectRating(); $this->ratings = $tableProjectRatings->fetchRating($this->product->project_id); $cntRatingsActive = 0; foreach ($this->ratings as $p) { if($p['rating_active']==1) $cntRatingsActive =$cntRatingsActive+1; } if (Zend_Auth::getInstance()->hasIdentity()){ $this->ratingOfUser = $tableProjectRatings->getProjectRateForUser($this->product->project_id,$identity->member_id); } $tableProjectFollower = new Default_Model_DbTable_ProjectFollower(); $this->likes = $tableProjectFollower->fetchLikesForProject($this->product->project_id); $projectplings = new Default_Model_ProjectPlings(); $this->projectplings = $projectplings->fetchPlingsForProject($this->product->project_id); $tagmodel = new Default_Model_Tags(); $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); $productJson = Zend_Json::encode($this->product); $filesJson = $this->filesJson; $helperCatXdgType = new Default_View_Helper_CatXdgType(); $xdgTypeJson = Zend_Json::encode($helperCatXdgType->catXdgType($this->product->project_category_id)); $isowner = false; if(Zend_Auth::getInstance()->hasIdentity() && $identity->member_id==$this->product->member_id){ $isowner = true; } ?>
hasIdentity()) { ?> hasIdentity()) { ?> hasIdentity()) { ?>
product->link_1)): ?> product->title; ?> product->title; ?> product->featured=='1'){ ?> Featured isProjectOriginal($this->product->project_id)){?> Original

product->project_category_id . '/order/latest">' . $this->product->cat_title . ' '; ?> '; $tagsuser = $tagmodel->getTagsUser($this->product->project_id, Default_Model_Tags::TAG_TYPE_PROJECT); echo ''; if(false === empty($tagsuser)) { foreach (explode(',',$tagsuser) as $tag) { ?> '; if($isowner){ $this->headLink()->appendStylesheet('/theme/flatui/css/select2.min.css'); $this->headLink()->appendStylesheet('/theme/flatui/css/select2.custmized.css'); $this->inlineScript()->appendFile('/theme/flatui/js/lib/select2.min.js'); ?> Saved inlineScript()->appendScript( ' $(document).ready(function(){ TagingProductDetail.setup(); }); '); } echo ''; ?>

Source (link to git-repo or to original if based on someone elses unmodified work): product->gitlab_project_id)) { $url = $this->gitlab_project['web_url']; $url = str_replace("http://", "https://", $url); echo ' ' . $url . ' '; } else if (false === empty($this->product->source_url)) { echo '' . $this->product->source_url . ' '; if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $cntSameSource = $tableProject->getCountSourceurl($this->product->source_url); if($cntSameSource>1){ echo '['.$cntSameSource.']'; } } } else { echo ' Add the source-code for this project on git.opendesktop.org'; } ?>

partial( '/product/partials/projectlike.phtml', array( "authMember" => $identity, "project_id" => $this->product->project_id ) ); ?>
render('partials/sidebarRating.phtml'); ?>
product->is_gitlab_project && $this->product->use_gitlab_project_readme && null != $this->gitlab_project['readme_url']) { ?>
Description:

- readme ?> + readme ?>

Description:

product->description ?> +

+ isProjectEbook($this->product->project_id)){?> + getTagsEbookSubject($this->product->project_id); + + if(false === empty($tagsuser)) + { + echo 'Subjects:
    '; + foreach ($tagsuser as $tag) { + ?> +
  • + '; + } ?> + + + getTagsEbookAuthor($this->product->project_id); + if(false === empty($tagsuser)) + { + echo 'Author/s:
      '; + foreach ($tagsuser as $tag) { + ?> +
    • + '; + } ?> + + + getTagsEbookEditor($this->product->project_id); + if(false === empty($tagsuser)) + { + echo 'Editor/s:
        '; + foreach ($tagsuser as $tag) { + ?> +
      • + '; + } ?> + + + getTagsEbookIllustrator($this->product->project_id); + if(false === empty($tagsuser)) + { + echo 'Illustrator/s:
          '; + foreach ($tagsuser as $tag) { + ?> +
        • + '; + } ?> + + + getTagsEbookTranslator($this->product->project_id); + if(false === empty($tagsuser)) + { + echo 'Tranlator/s:
            '; + foreach ($tagsuser as $tag) { + ?> +
          • + '; + } ?> + + + getTagsEbookShelf($this->product->project_id); + if(false === empty($tagsuser)) + { + echo 'Bookshelf:
              '; + foreach ($tagsuser as $tag) { + ?> +
            • + '; + } ?> + + + getTagsEbookLanguage($this->product->project_id); + if(false === empty($tagsuser)) + { + echo 'Language:
                '; + foreach ($tagsuser as $tag) { + ?> +
              • + '; + } ?> + + + getTagsEbookType($this->product->project_id); + if(false === empty($tagsuser)) + { + echo 'Type:
                  '; + foreach ($tagsuser as $tag) { + ?> +
                • + '; + } ?> + + +
updates) > 0) { $this->productUpdate = $this->updates[0]; ?>
Last changelog: render('product/partials/productUpdatesV1.phtml'); ?>
paramPageId; $testComments = $modelComments->getCommentTreeForProject($this->product->project_id); $testComments->setItemCountPerPage(25); $testComments->setCurrentPageNumber($offset); $this->comments = $testComments; echo $this->render('product/partials/productCommentsUX1.phtml'); ?>
partial( $viewClaimBox, array( "member" => $this->member, "product" => $this->product ) ); } ?>
product->embed_code)): ?> product->embed_code ?>
updates) > 0) { ?>
updates as $this->productUpdate) { echo $this->render('product/partials/productUpdatesV1.phtml'); } ?>
ratings) > 0) { ?>
render('product/partials/productRating.phtml'); ?>
likes) > 0) { ?>
render('product/partials/productLikes.phtml'); ?>
projectplings) > 0) { ?>
render('product/partials/productPlings.phtml'); ?>
render('product/partials/ppload.phtml'); ?>
product->claimable)) { ?>
partial( '/product/partials/projectplings.phtml', array( "authMember" => $identity, "project_id" => $this->product->project_id, "ppload_collection_id" => $this->product->ppload_collection_id, "project_category_id" => $this->product->project_category_id ) ); ?>
render('partials/sidebarRating.phtml'); */ ?>
*/ ?>
fetchOrigins($this->product->project_id); $this->moreProducts = $origins; $this->moreProductsTitle = 'Based on'; if (count($this->moreProducts) > 0) { echo $this->render('product/partials/productCloneFrom.phtml'); } ?> fetchRelatedProducts($this->product->project_id); $bflag = false; foreach ($related as $r){ $rid = $r->project_id; $bflag = false; foreach ($origins as $o){ $oid = $o->project_id; if($rid == $oid){ $bflag = true; break; } } if(!$bflag) { $relatednew[] = $r; } } $this->moreProducts = $relatednew; $this->moreProductsTitle = 'Variants'; if (count($this->moreProducts) > 0) { echo $this->render('product/partials/productCloneFrom.phtml'); } ?>
moreProducts = $tableProject->fetchMoreProjects($this->product, 6); $this->moreProductsTitle = 'More ' . $this->product->cat_title . ' from ' . $this->product->username; if (count($this->moreProducts) > 0) { echo $this->render('product/partials/productMoreProductsWidgetV1.phtml'); } ?>
moreProducts = $tableProject->fetchMoreProjectsOfOtherUsr($this->product, 6); $this->moreProductsTitle = 'Other ' . $this->product->cat_title; if (count($this->moreProducts) > 0) { echo $this->render('product/partials/productMoreProductsWidgetV1.phtml'); } ?>
render('partials/sidebarCcLicense.phtml'); ?> render('product/partials/details.phtml'); ?> product->show_gitlab_project_issues) { $helpPrintDate = new Default_View_Helper_PrintDate(); ?>
Git Issues gitlab_project_issues; $i = 0; foreach ($issues as $issue){ $date = date('Y-m-d H:i:s', strtotime($issue['created_at'])); echo '
' . $issue['title'] . '
'.$helpPrintDate->printDate($date).'
'; $i ++; if($i>5) { break; } } ?> Show all Issues
render('product/partials/tags.phtml'); ?>
inlineScript()->appendScript( ' $(document).ready(function(){ InitActiveHashTab.setup(); PartialJson.setup(); PartialJsonFraud.setup(); ProductDetailCarousel.setup(); PartialCommentReviewForm.setup(); PartialsButtonHeartDetail.setup(); PartialsButtonPlingProject.setup(); TooltipUser.setup("tooltipuserleft","left"); AppimagequestionOnClick.setup(); OpendownloadfileWerbung.setup(); }); ');